-
Notifications
You must be signed in to change notification settings - Fork 154
/
index.tsx
96 lines (85 loc) · 2.55 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as RMWC from '@rmwc/types';
import * as React from 'react';
import { FoundationComponent } from '@rmwc/base';
import { MDCNotchedOutlineFoundation } from '@material/notched-outline';
export interface NotchedOutlineProps {
notch?: number;
}
class NotchedOutlineLeading extends React.Component<{}> {
shouldComponentUpdate() {
return false;
}
render() {
return <div className="mdc-notched-outline__leading" />;
}
}
class NotchedOutlineTrailing extends React.Component<{}> {
shouldComponentUpdate() {
return false;
}
render() {
return <div className="mdc-notched-outline__trailing" />;
}
}
export class NotchedOutline extends FoundationComponent<
MDCNotchedOutlineFoundation,
NotchedOutlineProps
> {
static displayName = 'NotchedOutline';
private root = this.createElement('root');
private notchElement = this.createElement('root');
label: HTMLLabelElement | null = null;
componentDidMount() {
super.componentDidMount();
this.label = this.root.ref && this.root.ref.querySelector('label');
if (this.label) {
this.label.style.transitionDuration = '0s';
this.root.addClass(
MDCNotchedOutlineFoundation.cssClasses.OUTLINE_UPGRADED
);
requestAnimationFrame(() => {
this.label && (this.label.style.transitionDuration = '');
});
} else {
this.root.addClass(MDCNotchedOutlineFoundation.cssClasses.NO_LABEL);
}
}
getDefaultFoundation() {
return new MDCNotchedOutlineFoundation({
addClass: (className: string) => this.root.addClass(className),
removeClass: (className: string) => this.root.removeClass(className),
setNotchWidthProperty: (width: number) =>
this.notchElement.setStyle('width', width + 'px'),
removeNotchWidthProperty: () => this.notchElement.setStyle('width', '')
});
}
sync(props: NotchedOutlineProps, prevProps: NotchedOutlineProps) {
this.syncProp(props.notch, prevProps.notch, () => {
!!props.notch
? this.foundation.notch(props.notch)
: this.foundation.closeNotch();
});
}
render() {
const { children, ...rest } = this.props;
return (
<div
{...this.root.props({
...rest,
className: 'mdc-notched-outline'
})}
ref={this.root.setRef}
>
<NotchedOutlineLeading />
<div
{...this.notchElement.props({})}
className="mdc-notched-outline__notch"
ref={this.notchElement.setRef}
>
{children}
</div>
<NotchedOutlineTrailing />
</div>
);
}
}