-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathscroll-tab.tsx
More file actions
103 lines (95 loc) · 3.17 KB
/
scroll-tab.tsx
File metadata and controls
103 lines (95 loc) · 3.17 KB
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
/* tslint:disable:no-console */
import 'rmc-tabs/assets/index.less';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Tabs, DefaultTabBar } from '../src';
const tabData = [
{ title: 'title 1' },
{ title: 'title 2' },
{ title: 'title 3' },
{ title: 'title 4' },
{ title: 'title 5' },
{ title: 'title 6' },
{ title: 'title 7' },
{ title: 'title 8' },
{ title: 'title 9' },
];
class BasicDemo extends React.Component<{}, any> {
constructor(props: any) {
super(props);
this.state = {
scData: JSON.stringify({ index: 0, tab: { title: 't1' } }),
scData2: JSON.stringify({ index: 0, tab: { title: 't1' } }),
dynamicTabs: [] as { title: string }[],
};
}
render() {
const baseStyle = {
display: 'flex', flexDirection: 'column', marginTop: 10, marginBottom: 10, fontSize: 14
} as React.CSSProperties;
return (
<div>
<div style={{ ...baseStyle }}>
<h2>normal</h2>
<Tabs tabs={tabData} onChange={(tab, index) => {
this.setState({
scData: JSON.stringify({ index: index + Math.random(), tab })
});
}} renderTabBar={(props) => <DefaultTabBar {...props} />}
>
<div style={{ padding: 10, background: '#ADFFD7' }}>
<p>single content</p>
<p>{this.state.scData}</p>
<p>single content</p>
<p>single content</p>
<p>single content</p>
</div>
</Tabs>
<h2>page</h2>
<Tabs tabs={tabData} onChange={(tab, index) => {
this.setState({
scData2: JSON.stringify({ index: index + Math.random(), tab })
});
}} renderTabBar={(props) => <DefaultTabBar {...props} page={4} />}
>
<div style={{ padding: 10, background: '#ADFFD7' }}>
<p>single content</p>
<p>{this.state.scData2}</p>
<p>single content</p>
<p>single content</p>
<p>single content</p>
</div>
</Tabs>
<h2>add page</h2>
<div style={{ background: '#eee', boxShadow: '0 0 0 5px #eee', margin: 10, padding: 10 }}
onClick={() => {
this.setState({
dynamicTabs: [
...this.state.dynamicTabs,
{ title: 'title-' + this.state.dynamicTabs.length + 1 }
],
});
}}
>
add page
</div>
<Tabs tabs={this.state.dynamicTabs} onChange={(tab, index) => {
this.setState({
scData2: JSON.stringify({ index: index + Math.random(), tab })
});
}} renderTabBar={(props) => <DefaultTabBar {...props} page={3} />}
>
<div style={{ padding: 10, background: '#ADFFD7' }}>
<p>single content</p>
<p>{this.state.scData2}</p>
<p>single content</p>
<p>single content</p>
<p>single content</p>
</div>
</Tabs>
</div>
</div>
);
}
}
ReactDOM.render(<BasicDemo />, document.getElementById('__react-content'));