Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 47a9c38

Browse files
author
Matt Goo
authored
feat(ripple): convert to ts (#4300)
1 parent c649de5 commit 47a9c38

File tree

16 files changed

+420
-464
lines changed

16 files changed

+420
-464
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/material-components-web/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import * as menu from '@material/menu/index';
4040
import * as menuSurface from '@material/menu-surface/index';
4141
import * as notchedOutline from '@material/notched-outline/index';
4242
import * as radio from '@material/radio/index';
43-
import * as ripple from '@material/ripple/index';
43+
import * as ripple from '@material/ripple/index.ts';
4444
import * as select from '@material/select/index';
4545
import * as selectionControl from '@material/selection-control/index';
4646
import * as slider from '@material/slider/index';

packages/mdc-dom/events.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
24+
export type EventType = keyof GlobalEventHandlersEventMap;
25+
export type SpecificEventListener<K extends EventType> = (evt: GlobalEventHandlersEventMap[K]) => void;

packages/mdc-dom/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* THE SOFTWARE.
2222
*/
2323

24+
import {EventType, SpecificEventListener} from './events';
2425
import * as ponyfill from './ponyfill';
2526

26-
export {ponyfill};
27+
export {ponyfill, EventType, SpecificEventListener};

packages/mdc-dom/ponyfill.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
* This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
2727
*/
2828

29-
interface MsElement extends Element {
30-
msMatchesSelector(selector: string): boolean;
31-
}
32-
3329
function closest(element: Element, selector: string): Element | null {
3430
if (element.closest) {
3531
return element.closest(selector);
@@ -48,7 +44,7 @@ function closest(element: Element, selector: string): Element | null {
4844
function matches(element: Element, selector: string): boolean {
4945
const nativeMatches = element.matches
5046
|| element.webkitMatchesSelector
51-
|| (element as MsElement).msMatchesSelector;
47+
|| element.msMatchesSelector;
5248
return nativeMatches.call(element, selector);
5349
}
5450

packages/mdc-ripple/adapter.js renamed to packages/mdc-ripple/adapter.ts

Lines changed: 40 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
* THE SOFTWARE.
2222
*/
2323

24-
/* eslint no-unused-vars: [2, {"args": "none"}] */
25-
2624
/**
2725
* Adapter for MDC Ripple. Provides an interface for managing
2826
* - classes
@@ -42,75 +40,46 @@
4240
* for more details.
4341
* https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
4442
*
45-
* @record
4643
*/
47-
class MDCRippleAdapter {
48-
/** @return {boolean} */
49-
browserSupportsCssVars() {}
50-
51-
/** @return {boolean} */
52-
isUnbounded() {}
53-
54-
/** @return {boolean} */
55-
isSurfaceActive() {}
56-
57-
/** @return {boolean} */
58-
isSurfaceDisabled() {}
59-
60-
/** @param {string} className */
61-
addClass(className) {}
62-
63-
/** @param {string} className */
64-
removeClass(className) {}
65-
66-
/** @param {!EventTarget} target */
67-
containsEventTarget(target) {}
68-
69-
/**
70-
* @param {string} evtType
71-
* @param {!Function} handler
72-
*/
73-
registerInteractionHandler(evtType, handler) {}
74-
75-
/**
76-
* @param {string} evtType
77-
* @param {!Function} handler
78-
*/
79-
deregisterInteractionHandler(evtType, handler) {}
80-
81-
/**
82-
* @param {string} evtType
83-
* @param {!Function} handler
84-
*/
85-
registerDocumentInteractionHandler(evtType, handler) {}
86-
87-
/**
88-
* @param {string} evtType
89-
* @param {!Function} handler
90-
*/
91-
deregisterDocumentInteractionHandler(evtType, handler) {}
92-
93-
/**
94-
* @param {!Function} handler
95-
*/
96-
registerResizeHandler(handler) {}
97-
98-
/**
99-
* @param {!Function} handler
100-
*/
101-
deregisterResizeHandler(handler) {}
102-
103-
/**
104-
* @param {string} varName
105-
* @param {?number|string} value
106-
*/
107-
updateCssVariable(varName, value) {}
108-
109-
/** @return {!ClientRect} */
110-
computeBoundingRect() {}
111-
112-
/** @return {{x: number, y: number}} */
113-
getWindowPageOffset() {}
44+
import {EventType, SpecificEventListener} from '@material/dom/index';
45+
46+
interface Point {
47+
x: number;
48+
y: number;
49+
}
50+
51+
interface MDCRippleAdapter {
52+
browserSupportsCssVars(): boolean;
53+
54+
isUnbounded(): boolean;
55+
56+
isSurfaceActive(): boolean;
57+
58+
isSurfaceDisabled(): boolean;
59+
60+
addClass(className: string): void;
61+
62+
removeClass(className: string): void;
63+
64+
containsEventTarget(target: EventTarget | null): boolean;
65+
66+
registerInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
67+
68+
deregisterInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
69+
70+
registerDocumentInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
71+
72+
deregisterDocumentInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void;
73+
74+
registerResizeHandler(handler: SpecificEventListener<'resize'>): void;
75+
76+
deregisterResizeHandler(handler: SpecificEventListener<'resize'>): void;
77+
78+
updateCssVariable(varName: string, value: string|null): void;
79+
80+
computeBoundingRect(): ClientRect;
81+
82+
getWindowPageOffset(): Point;
11483
}
11584

116-
export default MDCRippleAdapter;
85+
export {MDCRippleAdapter as default, Point};

packages/mdc-ripple/constants.js renamed to packages/mdc-ripple/constants.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ const cssClasses = {
2525
// Ripple is a special case where the "root" component is really a "mixin" of sorts,
2626
// given that it's an 'upgrade' to an existing component. That being said it is the root
2727
// CSS class that all other CSS classes derive from.
28-
ROOT: 'mdc-ripple-upgraded',
29-
UNBOUNDED: 'mdc-ripple-upgraded--unbounded',
3028
BG_FOCUSED: 'mdc-ripple-upgraded--background-focused',
3129
FG_ACTIVATION: 'mdc-ripple-upgraded--foreground-activation',
3230
FG_DEACTIVATION: 'mdc-ripple-upgraded--foreground-deactivation',
31+
ROOT: 'mdc-ripple-upgraded',
32+
UNBOUNDED: 'mdc-ripple-upgraded--unbounded',
3333
};
3434

3535
const strings = {
36-
VAR_LEFT: '--mdc-ripple-left',
37-
VAR_TOP: '--mdc-ripple-top',
38-
VAR_FG_SIZE: '--mdc-ripple-fg-size',
3936
VAR_FG_SCALE: '--mdc-ripple-fg-scale',
40-
VAR_FG_TRANSLATE_START: '--mdc-ripple-fg-translate-start',
37+
VAR_FG_SIZE: '--mdc-ripple-fg-size',
4138
VAR_FG_TRANSLATE_END: '--mdc-ripple-fg-translate-end',
39+
VAR_FG_TRANSLATE_START: '--mdc-ripple-fg-translate-start',
40+
VAR_LEFT: '--mdc-ripple-left',
41+
VAR_TOP: '--mdc-ripple-top',
4242
};
4343

4444
const numbers = {
45-
PADDING: 10,
46-
INITIAL_ORIGIN_SCALE: 0.6,
4745
DEACTIVATION_TIMEOUT_MS: 225, // Corresponds to $mdc-ripple-translate-duration (i.e. activation animation duration)
4846
FG_DEACTIVATION_MS: 150, // Corresponds to $mdc-ripple-fade-out-duration (i.e. deactivation animation duration)
47+
INITIAL_ORIGIN_SCALE: 0.6,
48+
PADDING: 10,
4949
TAP_DELAY_MS: 300, // Delay between touch and simulated mouse events on touch devices
5050
};
5151

0 commit comments

Comments
 (0)