-
Notifications
You must be signed in to change notification settings - Fork 81
/
index.tsx
147 lines (121 loc) · 3.26 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import {MDCToolbar} from '@material/toolbar';
import {bind} from 'bind-decorator';
import {h} from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
export interface IToolbarRowProps {}
export interface IToolbarRowState {}
export class ToolbarRow extends MaterialComponent<
IToolbarRowProps,
IToolbarRowState
> {
protected componentName = 'toolbar__row';
protected mdcProps = [];
protected materialDom(props) {
return <div {...props}>{this.props.children}</div>;
}
}
export interface IToolbarSectionProps {
'align-start'?: boolean;
'align-end'?: boolean;
'shrink-to-fit'?: boolean;
}
export interface IToolbarSectionState {}
export class ToolbarSection extends MaterialComponent<
IToolbarSectionProps,
IToolbarSectionState
> {
protected componentName = 'toolbar__section';
protected mdcProps = ['align-start', 'align-end', 'shrink-to-fit'];
protected materialDom(props) {
return <section {...props}>{props.children}</section>;
}
}
export interface IToolbarIconProps {
menu?: boolean;
}
export interface IToolbarIconState {}
export class ToolbarIcon extends MaterialComponent<
IToolbarIconProps,
IToolbarIconState
> {
protected componentName = 'toolbar__icon';
protected mdcProps = [];
constructor(props) {
super();
if (props.menu) {
this.componentName = 'toolbar__menu-icon';
}
}
protected materialDom(props) {
return (
<a className="material-icons" {...props}>
{props.children || 'menu'}
</a>
);
}
}
export interface IToolbarTitleProps {
title?: string; // TODO: Add to docs / remove from here
}
export interface IToolbarTitleState {}
export class ToolbarTitle extends MaterialComponent<
IToolbarTitleProps,
IToolbarTitleState
> {
protected componentName = 'toolbar__title';
protected mdcProps = [];
protected materialDom(props) {
return <span {...props}>{props.children}</span>;
}
}
export interface IToolbarProps {
fixed?: boolean;
'fixed-lastrow-only'?: boolean;
waterfall?: boolean;
flexible?: boolean;
'flexible-default-behavior'?: boolean;
}
export interface IToolbarState {}
export class Toolbar extends MaterialComponent<IToolbarProps, IToolbarState> {
public static readonly Section = ToolbarSection;
public static readonly Icon = ToolbarIcon;
public static readonly Title = ToolbarTitle;
public static readonly Row = ToolbarRow;
protected componentName = 'toolbar';
protected mdcProps = [
'fixed',
'fixed-lastrow-only',
'waterfall',
'flexible',
'flexible-default-behavior'
];
protected MDComponent?: MDCToolbar;
public componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCToolbar(this.control);
this.MDComponent.listen('MDCToolbar:change', this.onChange);
}
}
public componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.unlisten('MDCToolbar:change', this.onChange);
this.MDComponent.destroy();
}
}
@bind
protected onChange(e) {
if (this.props.onChange) {
this.props.onChange(e);
}
}
protected materialDom(props) {
return (
<header ref={this.setControlRef} {...props}>
{props.children}
</header>
);
}
}
export default Toolbar;