-
Notifications
You must be signed in to change notification settings - Fork 81
/
index.tsx
106 lines (90 loc) · 2.7 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
import {MDCTabBar} from '@material/tab-bar';
import {h} from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
export interface ITabLabelProps {}
export interface ITabLabelState {}
export class TabLabel extends MaterialComponent<
ITabLabelProps,
ITabLabelState
> {
protected componentName = 'tab__text-label';
protected mdcProps = [];
protected materialDom(props) {
return <span {...props}>{props.children}</span>;
}
}
export interface ITabIconProps {}
export interface ITabIconState {}
export class TabIcon extends MaterialComponent<ITabIconProps, ITabIconState> {
protected componentName = 'tab__icon';
protected mdcProps = [];
protected materialDom(props) {
return (
<span className="material-icons" {...props}>
{props.children}
</span>
);
}
}
export interface ITabProps {
active?: boolean;
}
export interface ITabState {}
export class Tab extends MaterialComponent<ITabProps, ITabState> {
protected componentName = 'tab';
protected mdcProps = ['active'];
protected mdcNotifyProps = ['active'];
protected materialDom(props) {
return (
<button class="mdc-tab" role="tab" aria-selected="true" {...props}>
<span class="mdc-tab__content">{props.children}</span>
<span
class={`mdc-tab-indicator ${
props.active ? 'mdc-tab-indicator--active' : ''
}`}>
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline" />
</span>
<span class="mdc-tab__ripple" />
</button>
);
}
}
export interface ITabsProps {
activeTabIndex?: number; // TODO: Fix type in docs
}
export interface ITabsState {}
export class TabBar extends MaterialComponent<ITabsProps, ITabsState> {
public MDComponent?: MDCTabBar;
protected componentName = 'tab-bar';
protected mdcProps = [];
protected mdcNotifyProps = ['activeTabIndex'];
public componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCTabBar(this.control);
}
this.afterComponentDidMount();
}
public componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.destroy();
}
}
protected materialDom(props) {
return (
<div class="mdc-tab-bar" role="tablist" ref={this.setControlRef}>
<div class="mdc-tab-scroller">
<div class="mdc-tab-scroller__scroll-area">
<div class="mdc-tab-scroller__scroll-content">{props.children}</div>
</div>
</div>
</div>
);
}
}
export default class extends TabBar {
public static readonly Tab = Tab;
public static readonly TabLabel = TabLabel;
public static readonly TabIcon = TabIcon;
}