-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathbasic.tsx
More file actions
175 lines (166 loc) Β· 5.16 KB
/
basic.tsx
File metadata and controls
175 lines (166 loc) Β· 5.16 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import type { Moment } from 'moment';
import moment from 'moment';
import React from 'react';
import '../../assets/index.less';
import { Picker, type PickerRef } from '../../src';
import momentGenerateConfig from '../../src/generate/moment';
import enUS from '../../src/locale/en_US';
import zhCN from '../../src/locale/zh_CN';
// const defaultValue = moment('2019-09-03 05:02:03');
const defaultValue = moment('2019-11-28 01:02:03');
export default () => {
const [value, setValue] = React.useState<Moment | null>(defaultValue);
const weekRef = React.useRef<PickerRef>(null);
const onSelect = (newValue: Moment) => {
console.log('Select:', newValue);
};
const onChange = (newValue: Moment | null, formatString?: string) => {
console.log('Change:', newValue, formatString);
setValue(newValue);
};
const sharedProps = {
generateConfig: momentGenerateConfig,
value,
onSelect,
onChange,
presets: [
{
label: 'Hello World!',
value: moment(),
},
{
label: 'Now',
value: () => moment(),
},
],
};
const keyDown = (e, preventDefault) => {
if (e.keyCode === 13) preventDefault();
};
return (
<div>
<h1>Value: {value ? value.format('YYYY-MM-DD HH:mm:ss') : 'null'}</h1>
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<div style={{ margin: '0 8px' }}>
<h3>Basic</h3>
<Picker<Moment>
{...sharedProps}
locale={zhCN}
suffixIcon="SUFFIX"
rootClassName="bamboo"
className="little"
classNames={{
root: 'light',
popup: {
container: 'popup-c',
},
}}
open={false}
styles={{
popup: {
container: {
backgroundColor: 'red',
},
},
}}
/>
<Picker<Moment> {...sharedProps} locale={enUS} />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Uncontrolled</h3>
<Picker<Moment>
generateConfig={momentGenerateConfig}
locale={zhCN}
allowClear
showToday
renderExtraFooter={() => 'extra'}
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Datetime</h3>
<Picker<Moment>
{...sharedProps}
locale={zhCN}
defaultPickerValue={defaultValue.clone().subtract(1, 'month')}
showTime={{
showSecond: false,
defaultValue: moment('11:28:39', 'HH:mm:ss'),
}}
showToday
disabledTime={(date) => {
if (date && date.isSame(defaultValue, 'date')) {
return {
disabledHours: () => [1, 3, 5, 7, 9, 11],
};
}
return {};
}}
changeOnBlur
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Uncontrolled Datetime</h3>
<Picker<Moment>
format="YYYY-MM-DD HH:mm:ss"
generateConfig={momentGenerateConfig}
locale={enUS}
showTime
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Week</h3>
<Picker<Moment>
{...sharedProps}
locale={zhCN}
allowClear
picker="week"
renderExtraFooter={() => 'I am footer!!!'}
ref={weekRef}
/>
<button
type="button"
onClick={() => {
if (weekRef.current) {
weekRef.current.focus();
}
}}
>
Focus
</button>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Week</h3>
<Picker<Moment> generateConfig={momentGenerateConfig} locale={enUS} picker="week" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Quarter</h3>
<Picker<Moment> generateConfig={momentGenerateConfig} locale={enUS} picker="quarter" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Time</h3>
<Picker<Moment> {...sharedProps} locale={zhCN} picker="time" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Time 12</h3>
<Picker<Moment> {...sharedProps} locale={zhCN} picker="time" use12Hours />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Year</h3>
<Picker<Moment> {...sharedProps} locale={zhCN} picker="year" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Keyboard navigation (Tab key) disabled</h3>
<Picker<Moment> {...sharedProps} locale={enUS} tabIndex={-1} />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Keyboard event with prevent default behaviors</h3>
<Picker<Moment> {...sharedProps} locale={enUS} onKeyDown={keyDown} />
</div>
<div style={{ margin: '0 8px' }}>
<h3>PreviewValue is false</h3>
<Picker<Moment> {...sharedProps} locale={enUS} onKeyDown={keyDown} previewValue={false} />
</div>
</div>
</div>
);
};