|
| 1 | +import React from 'react'; |
| 2 | +import moment, { Moment } from 'moment'; |
| 3 | +import PickerPanel from '../src/PickerPanel'; |
| 4 | +import momentGenerateConfig from '../src/generate/moment'; |
| 5 | +import zhCN from '../src/locale/zh_CN'; |
| 6 | +import enUS from '../src/locale/en_US'; |
| 7 | +import jaJP from '../src/locale/ja_JP'; |
| 8 | +import '../assets/index.less'; |
| 9 | + |
| 10 | +// const defaultValue = moment('2019-09-03 05:02:03'); |
| 11 | +const defaultValue = moment('2019-11-28 01:02:03'); |
| 12 | + |
| 13 | +export default () => { |
| 14 | + const [value, setValue] = React.useState<Moment | null>(defaultValue); |
| 15 | + |
| 16 | + const onSelect = (newValue: Moment) => { |
| 17 | + console.log('Select:', newValue); |
| 18 | + }; |
| 19 | + |
| 20 | + const onChange = (newValue: Moment | null, formatString?: string) => { |
| 21 | + console.log('Change:', newValue, formatString); |
| 22 | + setValue(newValue); |
| 23 | + }; |
| 24 | + |
| 25 | + const sharedProps = { |
| 26 | + generateConfig: momentGenerateConfig, |
| 27 | + value, |
| 28 | + onSelect, |
| 29 | + onChange, |
| 30 | + }; |
| 31 | + |
| 32 | + return ( |
| 33 | + <div> |
| 34 | + <h1>Value: {value ? value.format('YYYY-MM-DD HH:mm:ss') : 'null'}</h1> |
| 35 | + |
| 36 | + <div style={{ display: 'flex', flexWrap: 'wrap' }}> |
| 37 | + <div style={{ margin: '0 8px' }}> |
| 38 | + <h3>Basic</h3> |
| 39 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} /> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div style={{ margin: '0 8px' }}> |
| 43 | + <h3>Uncontrolled</h3> |
| 44 | + <PickerPanel<Moment> |
| 45 | + generateConfig={momentGenerateConfig} |
| 46 | + locale={zhCN} |
| 47 | + onChange={onChange} |
| 48 | + defaultValue={moment('2000-01-01', 'YYYY-MM-DD')} |
| 49 | + /> |
| 50 | + </div> |
| 51 | + |
| 52 | + <div style={{ margin: '0 8px' }}> |
| 53 | + <h3>1 Month earlier</h3> |
| 54 | + <PickerPanel<Moment> |
| 55 | + {...sharedProps} |
| 56 | + defaultPickerValue={defaultValue.clone().subtract(1, 'month')} |
| 57 | + locale={enUS} |
| 58 | + /> |
| 59 | + </div> |
| 60 | + |
| 61 | + <div style={{ margin: '0 8px' }}> |
| 62 | + <h3>Week Picker CN</h3> |
| 63 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} picker="week" /> |
| 64 | + </div> |
| 65 | + |
| 66 | + <div style={{ margin: '0 8px' }}> |
| 67 | + <h3>Month Picker</h3> |
| 68 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} picker="month" /> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div style={{ margin: '0 8px' }}> |
| 72 | + <h3>Week Picker US</h3> |
| 73 | + <PickerPanel<Moment> {...sharedProps} locale={enUS} picker="week" /> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div style={{ margin: '0 8px' }}> |
| 77 | + <h3>Time</h3> |
| 78 | + <PickerPanel<Moment> {...sharedProps} locale={jaJP} mode="time" /> |
| 79 | + </div> |
| 80 | + <div style={{ margin: '0 8px' }}> |
| 81 | + <h3>Time AM/PM</h3> |
| 82 | + <PickerPanel<Moment> |
| 83 | + {...sharedProps} |
| 84 | + locale={jaJP} |
| 85 | + mode="time" |
| 86 | + showTime={{ |
| 87 | + use12Hours: true, |
| 88 | + showSecond: false, |
| 89 | + format: 'hh:mm A', |
| 90 | + }} |
| 91 | + /> |
| 92 | + </div> |
| 93 | + <div style={{ margin: '0 8px' }}> |
| 94 | + <h3>Datetime</h3> |
| 95 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} showTime /> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + ); |
| 100 | +}; |
0 commit comments