-
Notifications
You must be signed in to change notification settings - Fork 81
/
Toolbar.jsx
107 lines (101 loc) · 2.34 KB
/
Toolbar.jsx
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
97
98
99
100
101
102
103
104
105
106
107
import {h} from 'preact';
import MaterialComponent from '../MaterialComponent';
import {MDCToolbar} from '@material/toolbar';
/**
* @prop fixed = false
* @prop fixed-lastrow-only = false
* @prop waterfall = false
* @prop flexible = false
* @prop flexible-default-behavior = false
*/
class Toolbar extends MaterialComponent {
constructor() {
super();
this.componentName = 'toolbar';
this._mdcProps = [
'fixed',
'fixed-lastrow-only',
'waterfall',
'flexible',
'flexible-default-behavior'
];
this._onChange = this._onChange.bind(this);
}
_onChange(e) {
if (this.props.onChange) {
this.props.onChange(e);
}
}
componentDidMount() {
this.MDComponent = new MDCToolbar(this.control);
this.MDComponent.listen('MDCToolbar:change', this._onChange);
}
componentWillUnmount() {
this.MDComponent.unlisten('MDCToolbar:change', this._onChange);
this.MDComponent.destroy && this.MDComponent.destroy();
}
materialDom(props) {
return (
<header ref={this.setControlRef} {...props}>
{props.children}
</header>
);
}
}
class ToolbarRow extends MaterialComponent {
constructor() {
super();
this.componentName = 'toolbar__row';
}
}
/**
* @prop align-end = false
* @prop align-start = false
* @prop shrink-to-fit = false
*/
class ToolbarSection extends MaterialComponent {
constructor() {
super();
this.componentName = 'toolbar__section';
this._mdcProps = ['align-start', 'align-end', 'shrink-to-fit'];
}
materialDom(props) {
return <section {...props}>{props.children}</section>;
}
}
/**
* @prop menu = false
*/
class ToolbarIcon extends MaterialComponent {
constructor(props) {
super();
this.componentName = 'toolbar__icon';
if (props.menu) {
this.componentName = 'toolbar__menu-icon';
}
}
materialDom(props) {
return (
<a className="material-icons" {...props}>
{props.children || 'menu'}
</a>
);
}
}
/**
* @prop title = ''
*/
class ToolbarTitle extends MaterialComponent {
constructor() {
super();
this.componentName = 'toolbar__title';
}
materialDom(props) {
return <span {...props}>{props.children}</span>;
}
}
Toolbar.Section = ToolbarSection;
Toolbar.Icon = ToolbarIcon;
Toolbar.Title = ToolbarTitle;
Toolbar.Row = ToolbarRow;
export default Toolbar;