-
Notifications
You must be signed in to change notification settings - Fork 153
/
index.tsx
79 lines (68 loc) · 1.96 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as RMWC from '@rmwc/types';
import * as React from 'react';
import { MDCRadioFoundation } from '@material/radio';
import { componentFactory } from '@rmwc/base';
import { withRipple } from '@rmwc/ripple';
import {
ToggleableFoundationComponent,
ToggleableFoundationProps
} from '@rmwc/toggleable';
/** A Radio button component. */
export interface RadioProps
extends RMWC.WithRippleProps,
ToggleableFoundationProps {}
const RadioRoot = withRipple({ unbounded: true, accent: true })(
componentFactory<RadioProps>({
displayName: 'RadioRoot',
classNames: (props: RadioProps) => [
'mdc-radio',
{ 'mdc-radio--disabled': props.disabled }
]
})
);
const RadioNativeControl = componentFactory<{}>({
displayName: 'RadioNativeControl',
defaultProps: {
type: 'radio'
},
tag: 'input',
classNames: ['mdc-radio__native-control']
});
class RadioBackground extends React.Component<{}> {
static displayName = 'RadioBackground';
shouldComponentUpdate() {
return false;
}
render() {
return (
<div className="mdc-radio__background">
<div className="mdc-radio__outer-circle" />
<div className="mdc-radio__inner-circle" />
</div>
);
}
}
/** A Radio button component. */
export class Radio extends ToggleableFoundationComponent<
MDCRadioFoundation,
RadioProps
> {
static displayName = 'Radio';
private root = this.createElement('root');
getDefaultFoundation() {
return new MDCRadioFoundation({
addClass: (className: string) => this.root.addClass(className),
removeClass: (className: string) => this.root.removeClass(className)
});
}
render() {
const { children, className, label, style, inputRef, ...rest } = this.props;
const radio = (
<RadioRoot {...this.toggleRootProps} ref={this.root.setRef}>
<RadioNativeControl {...rest} id={this.id} ref={inputRef} />
<RadioBackground />
</RadioRoot>
);
return this.renderToggle(radio);
}
}