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

Commit 3eb8a4b

Browse files
bonniezhouMatt Goo
authored andcommitted
feat(switch): Add component (#208)
1 parent ac0f87f commit 3eb8a4b

File tree

17 files changed

+679
-58
lines changed

17 files changed

+679
-58
lines changed

package-lock.json

Lines changed: 30 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@material/notched-outline": "^0.39.0",
5757
"@material/ripple": "^0.39.0",
5858
"@material/select": "^0.39.0",
59+
"@material/switch": "^0.39.0",
5960
"@material/tab": "^0.39.0",
6061
"@material/tab-indicator": "^0.39.0",
6162
"@material/textfield": "^0.39.0",

packages/ripple/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Icon = (props) => {
3333
const {
3434
children,
3535
className = '',
36-
// call `initRipple` from the root element's ref. This attaches the ripple
36+
// You must call `initRipple` from the root element's ref. This attaches the ripple
3737
// to the element.
3838
initRipple,
3939
// include `unbounded` to remove warnings when passing `otherProps` to the
@@ -62,6 +62,57 @@ const RippleIcon = withRipple(Icon);
6262
Wrap your Icon component with the HOC `withRipple`, which returns a component
6363
with a ripple capable surface.
6464

65+
## Advanced Usage
66+
67+
### Ripple surface and ripple activator
68+
69+
You may want to apply the visual treatment (CSS classes and styles) for a ripple surface on one element, but have its activation rely on a different element. For example, putting a ripple on a `<div>` which will be activated by focusing on a child `<input>` element. We call the visual element the "ripple surface" and the activating element the "ripple activator".
70+
71+
The `initRipple` callback prop can take in an extra `activator` argument for the case where the ripple activator differs from the ripple surface. If the `activator` argument is not provided, the ripple surface will also serve as the ripple activator.
72+
73+
```js
74+
import withRipple from '@material/react-ripple';
75+
76+
const MyInput = (props) => {
77+
const {
78+
rippleActivator,
79+
...otherProps
80+
} = props;
81+
82+
return (
83+
<input ref={rippleActivator} {...otherProps} />
84+
);
85+
}
86+
87+
class MyComponent extends React.Component {
88+
rippleActivator = React.createRef();
89+
90+
init = (el) => {
91+
this.props.initRipple(el /* surface */, this.rippleActivator.current /* activator */);
92+
}
93+
94+
render() {
95+
const {
96+
className,
97+
initRipple,
98+
unbounded,
99+
...otherProps
100+
} = this.props;
101+
102+
return (
103+
<div
104+
className={`my-component ${className}`}
105+
ref={this.init}
106+
{...otherProps}>
107+
<MyInput rippleActivator={this.rippleActivator} />
108+
</div>
109+
);
110+
}
111+
};
112+
113+
const MyRippledComponent = withRipple(MyComponent);
114+
```
115+
65116
## Props
66117

67118
Prop Name | Type | Description

0 commit comments

Comments
 (0)