This repository was archived by the owner on Jul 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
feat(ripple) mdc-web typescript conversion #711
Merged
moog16
merged 14 commits into
material-components:rc0.11.0
from
Short-io:ripple-typescript
Mar 14, 2019
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f192417
WIP ripple
gugu dedeb35
Merge branch 'base11' into ripple-typescript
gugu 893fbae
feat(ripple): fix types issues
gugu 8c7a5bf
feat(ripple): fix low-hanging fruits
gugu 429e2fa
feat(ripple): typescript style fixed, added comments
gugu d4cf165
feat(ripple): Move ref property to the RippledInterface
gugu d3ddb9c
feat(ripple): move foundation property to the component interface
gugu 916765d
fix(ripple): unbounded type fixed
gugu c524abc
feat(ripple): remove default value for disabled
gugu fed4ef4
Merge branch 'rc0.11.0' into ripple-typescript
gugu 4193c6b
feat(ripple): test fixed
gugu fd6b875
Merge branch 'ripple-typescript' of github.com:gugu/material-componen…
gugu 34f98ab
feat(ripple): fix tests
gugu 42c00a6
feat(ripple): disable default value for disabled prop
gugu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,10 @@ import * as React from 'react'; | |
import * as classnames from 'classnames'; | ||
import {Subtract} from 'utility-types'; // eslint-disable-line no-unused-vars | ||
|
||
// @ts-ignore no mdc .d.ts file | ||
import {MDCRippleFoundation, MDCRippleAdapter, util} from '@material/ripple/dist/mdc.ripple'; | ||
// @ts-ignore no mdc .d.ts file | ||
import {MDCRippleFoundation} from '@material/ripple/foundation'; | ||
import {MDCRippleAdapter} from '@material/ripple/adapter'; | ||
import * as util from '@material/ripple/util'; | ||
import {SpecificEventListener} from '@material/base/types'; | ||
import {matches} from '@material/dom/ponyfill'; | ||
|
||
export interface RippledComponentProps<T> { | ||
|
@@ -71,12 +72,12 @@ export interface RippledComponentInterface<Surface, Activator = Element> { | |
handleKeyDown: React.KeyboardEventHandler<Surface>; | ||
handleKeyUp: React.KeyboardEventHandler<Surface>; | ||
activateRipple: (e: ActivateEventTypes<Surface>) => void; | ||
deactivateRipple: (e: ActivateEventTypes<Surface>) => void; | ||
deactivateRipple: () => void; | ||
classes: string; | ||
style: React.CSSProperties; | ||
displayName: string; | ||
createAdapter: (surface: Surface, activator?: Activator) => MDCRippleAdapter; | ||
updateCssVariable: (varName: keyof React.CSSProperties, value: string | number) => void; | ||
updateCssVariable: (varName: string, value: string | null) => void; | ||
gugu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
componentDidMount: () => void; | ||
componentWillUnmount: () => void; | ||
render: () => JSX.Element; | ||
|
@@ -87,7 +88,9 @@ export function withRipple < | |
P extends InjectedProps<Surface, Activator>, | ||
Surface extends Element = Element, | ||
Activator extends Element = Element | ||
>(WrappedComponent: React.ComponentType<P>) { | ||
>(WrappedComponent: React.ComponentType<P>): | ||
React.ComponentType<Subtract<P, InjectedProps<Surface, Activator>> | ||
& RippledComponentProps<Surface>> { | ||
return class RippledComponent extends React.Component< | ||
// Subtract removes any props "InjectedProps" if they are on "P" | ||
// This allows the developer to override any props | ||
|
@@ -147,18 +150,18 @@ export function withRipple < | |
this.foundation.init(); | ||
}; | ||
|
||
createAdapter: MDCRippleAdapter = (surface: Surface, activator?: Activator) => { | ||
createAdapter = (surface: Surface, activator?: Activator): MDCRippleAdapter => { | ||
return { | ||
browserSupportsCssVars: () => util.supportsCssVariables(window), | ||
isUnbounded: () => this.props.unbounded, | ||
isUnbounded: () => (this.props.unbounded || false) as boolean, | ||
gugu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isSurfaceActive: () => { | ||
if (activator) { | ||
return matches(activator, ':active'); | ||
} | ||
|
||
return matches(surface, ':active'); | ||
}, | ||
isSurfaceDisabled: () => this.props.disabled, | ||
isSurfaceDisabled: () => (this.props.disabled || false) as boolean, | ||
gugu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
addClass: (className: string) => { | ||
if (!this.isComponentMounted) { | ||
return; | ||
|
@@ -185,21 +188,29 @@ export function withRipple < | |
handler, | ||
util.applyPassive() | ||
), | ||
registerResizeHandler: (handler: EventListener) => | ||
registerResizeHandler: (handler: SpecificEventListener<'resize'>) => | ||
window.addEventListener('resize', handler), | ||
deregisterResizeHandler: (handler: EventListener) => | ||
deregisterResizeHandler: (handler: SpecificEventListener<'resize'>) => | ||
window.removeEventListener('resize', handler), | ||
updateCssVariable: this.updateCssVariable, | ||
computeBoundingRect: () => { | ||
if (!this.isComponentMounted) { | ||
// need to return object since foundation expects it | ||
return {}; | ||
return new ClientRect(); | ||
} | ||
if (this.props.computeBoundingRect) { | ||
return this.props.computeBoundingRect(surface); | ||
} | ||
return surface.getBoundingClientRect(); | ||
}, | ||
containsEventTarget: (target: EventTarget | null) => { | ||
if (activator && target !== null) { | ||
return activator.contains(target as Node); | ||
} | ||
return false; | ||
}, | ||
registerInteractionHandler: () => null, | ||
deregisterInteractionHandler: () => null, | ||
getWindowPageOffset: () => ({ | ||
x: window.pageXOffset, | ||
y: window.pageYOffset, | ||
|
@@ -209,12 +220,12 @@ export function withRipple < | |
|
||
handleFocus = (e: React.FocusEvent<Surface>) => { | ||
this.props.onFocus && this.props.onFocus(e); | ||
this.foundation.handleFocus(); | ||
this.foundation!.handleFocus(); | ||
gugu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
handleBlur = (e: React.FocusEvent<Surface>) => { | ||
this.props.onBlur && this.props.onBlur(e); | ||
this.foundation.handleBlur(); | ||
this.foundation!.handleBlur(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ! |
||
}; | ||
|
||
handleMouseDown = (e: React.MouseEvent<Surface>) => { | ||
|
@@ -226,7 +237,7 @@ export function withRipple < | |
|
||
handleMouseUp = (e: React.MouseEvent<Surface>) => { | ||
this.props.onMouseUp && this.props.onMouseUp(e); | ||
this.deactivateRipple(e); | ||
this.deactivateRipple(); | ||
}; | ||
|
||
handleTouchStart = (e: React.TouchEvent<Surface>) => { | ||
|
@@ -237,7 +248,7 @@ export function withRipple < | |
|
||
handleTouchEnd = (e: React.TouchEvent<Surface>) => { | ||
this.props.onTouchEnd && this.props.onTouchEnd(e); | ||
this.deactivateRipple(e); | ||
this.deactivateRipple(); | ||
}; | ||
|
||
handleKeyDown = (e: React.KeyboardEvent<Surface>) => { | ||
|
@@ -247,26 +258,31 @@ export function withRipple < | |
|
||
handleKeyUp = (e: React.KeyboardEvent<Surface>) => { | ||
this.props.onKeyUp && this.props.onKeyUp(e); | ||
this.deactivateRipple(e); | ||
this.deactivateRipple(); | ||
}; | ||
|
||
activateRipple = (e: ActivateEventTypes<Surface>) => { | ||
// https://reactjs.org/docs/events.html#event-pooling | ||
e.persist(); | ||
this.foundation.activate(e); | ||
this.foundation!.activate(e.nativeEvent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ! |
||
}; | ||
|
||
deactivateRipple = (e: ActivateEventTypes<Surface>) => { | ||
this.foundation.deactivate(e); | ||
deactivateRipple = () => { | ||
this.foundation!.deactivate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ! |
||
}; | ||
|
||
updateCssVariable = (varName: keyof React.CSSProperties, value: string | number) => { | ||
updateCssVariable = (varName: string, value: string | null) => { | ||
if (!this.isComponentMounted) { | ||
return; | ||
} | ||
this.setState((prevState) => { | ||
const updatedStyle = Object.assign({}, this.state.style, prevState.style) as React.CSSProperties; | ||
updatedStyle[varName] = value; | ||
if (value === null) { | ||
delete updatedStyle[varName as keyof React.CSSProperties]; | ||
} else { | ||
updatedStyle[varName as keyof React.CSSProperties] = value; | ||
} | ||
|
||
return Object.assign(prevState, { | ||
style: updatedStyle, | ||
}); | ||
|
@@ -326,7 +342,7 @@ export function withRipple < | |
/> | ||
); | ||
} | ||
}; | ||
} as any; | ||
gugu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
function getDisplayName<P extends {}>(WrappedComponent: React.ComponentType<P>): string { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
kill $(ps aux | grep 'webpack' | awk '{print $2}') || echo 'already stopped' | ||
kill $(ps aux | grep 'webpack' | grep 'screenshot' | awk '{print $2}') || echo 'already stopped' | ||
gugu marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.