-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathrtl.tsx
More file actions
199 lines (180 loc) Β· 6.05 KB
/
rtl.tsx
File metadata and controls
199 lines (180 loc) Β· 6.05 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import moment, { type Moment } from 'moment';
import React from 'react';
import '../../assets/index.less';
import { Picker, PickerPanel, RangePicker } from '../../src/';
import momentGenerateConfig from '../../src/generate/moment';
import enUS from '../../src/locale/en_US';
import jaJP from '../../src/locale/ja_JP';
import zhCN from '../../src/locale/zh_CN';
const defaultValue = moment();
function formatDate(date: Moment | null) {
return date ? date.format('YYYY-MM-DD HH:mm:ss') : 'null';
}
export default () => {
const [value, setValue] = React.useState<Moment | null>(defaultValue);
const weekRef = React.useRef<Picker<Moment>>(null);
const onSelect = (newValue: Moment) => {
console.log('Select:', newValue);
};
const onChange = (newValue: Moment | null, formatString?: string) => {
const lastValue = Array.isArray(newValue) ? newValue[1] : newValue;
console.log('Change:', lastValue, newValue, formatString);
setValue(lastValue);
};
const sharedProps = {
generateConfig: momentGenerateConfig,
value,
onSelect,
onChange,
direction: 'rtl',
};
const rangePickerRef = React.useRef<RangePicker<Moment>>(null);
return (
<div dir="rtl">
<h2>Value: {value ? `${formatDate(value[0])} ~ ${formatDate(value[1])}` : 'null'}</h2>
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<div style={{ margin: '0 8px' }}>
<h3>Basic</h3>
<PickerPanel<Moment> {...sharedProps} locale={zhCN} />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Uncontrolled</h3>
<PickerPanel<Moment>
generateConfig={momentGenerateConfig}
locale={zhCN}
onChange={onChange}
defaultValue={moment('2000-01-01', 'YYYY-MM-DD')}
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>1 Month earlier</h3>
<PickerPanel<Moment>
{...sharedProps}
defaultPickerValue={defaultValue.clone().subtract(1, 'month')}
locale={enUS}
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Week Picker CN</h3>
<PickerPanel<Moment> {...sharedProps} locale={zhCN} picker="week" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Month Picker</h3>
<PickerPanel<Moment> {...sharedProps} locale={zhCN} picker="month" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Week Picker US</h3>
<PickerPanel<Moment> {...sharedProps} locale={enUS} picker="week" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Time</h3>
<PickerPanel<Moment> {...sharedProps} locale={jaJP} mode="time" />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Time AM/PM</h3>
<PickerPanel<Moment>
{...sharedProps}
locale={jaJP}
mode="time"
showTime={{
use12Hours: true,
showSecond: false,
format: 'hh:mm A',
}}
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Datetime</h3>
<PickerPanel<Moment> {...sharedProps} locale={zhCN} showTime />
</div>
</div>
<div style={{ display: 'flex' }}>
<div style={{ margin: '0 8px' }}>
<h3>Basic</h3>
<Picker<Moment> {...sharedProps} locale={zhCN} />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Uncontrolled</h3>
<Picker<Moment> generateConfig={momentGenerateConfig} locale={zhCN} allowClear />
</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 {};
}}
/>
</div>
<div style={{ margin: '0 8px' }}>
<h3>Uncontrolled Datetime</h3>
<Picker<Moment> generateConfig={momentGenerateConfig} locale={zhCN} />
</div>
<div style={{ margin: '0 8px' }}>
<h3>Week</h3>
<Picker<Moment>
{...sharedProps}
locale={zhCN}
format="gggg-Wo"
allowClear
picker="week"
extraFooterRender={() => '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={zhCN} picker="week" />
</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>
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<div style={{ margin: '0 8px' }}>
<h3>Basic RangePicker</h3>
<RangePicker<Moment>
{...sharedProps}
value={undefined}
locale={zhCN}
allowClear
ref={rangePickerRef}
defaultValue={[moment(), moment().add(1, 'M')]}
placeholder={['start...', 'end...']}
/>
</div>
</div>
</div>
);
};