|
| 1 | +import React from 'react'; |
| 2 | +import moment, { Moment } from 'moment'; |
| 3 | +import RangePicker from '../src/RangePicker'; |
| 4 | +import momentGenerateConfig from '../src/generate/moment'; |
| 5 | +import zhCN from '../src/locale/zh_CN'; |
| 6 | +import '../assets/index.less'; |
| 7 | +import './common.less'; |
| 8 | + |
| 9 | +const defaultStartValue = moment('2019-09-03 05:02:03'); |
| 10 | +const defaultEndValue = moment('2019-11-28 01:02:03'); |
| 11 | + |
| 12 | +function formatDate(date: Moment | null) { |
| 13 | + return date ? date.format('YYYY-MM-DD HH:mm:ss') : 'null'; |
| 14 | +} |
| 15 | + |
| 16 | +export default () => { |
| 17 | + const [value, setValue] = React.useState< |
| 18 | + [Moment | null, Moment | null] | null |
| 19 | + >([defaultStartValue, defaultEndValue]); |
| 20 | + |
| 21 | + const onChange = ( |
| 22 | + newValue: [Moment | null, Moment | null] | null, |
| 23 | + formatStrings?: string[], |
| 24 | + ) => { |
| 25 | + console.log('Change:', newValue, formatStrings); |
| 26 | + setValue(newValue); |
| 27 | + }; |
| 28 | + |
| 29 | + const onPanelChange = (values: [Moment | null, Moment | null] | null) => { |
| 30 | + setValue(values); |
| 31 | + }; |
| 32 | + |
| 33 | + const sharedProps = { |
| 34 | + generateConfig: momentGenerateConfig, |
| 35 | + value, |
| 36 | + onChange, |
| 37 | + onPanelChange, |
| 38 | + }; |
| 39 | + |
| 40 | + return ( |
| 41 | + <div> |
| 42 | + <h2> |
| 43 | + Value:{' '} |
| 44 | + {value ? `${formatDate(value[0])} ~ ${formatDate(value[1])}` : 'null'} |
| 45 | + </h2> |
| 46 | + |
| 47 | + <div style={{ display: 'flex', flexWrap: 'wrap' }}> |
| 48 | + <div style={{ margin: '0 8px' }}> |
| 49 | + <h3>Basic</h3> |
| 50 | + <RangePicker<Moment> |
| 51 | + {...sharedProps} |
| 52 | + locale={zhCN} |
| 53 | + mode={['month', 'month']} |
| 54 | + defaultValue={[moment('1990-09-03'), moment('1989-11-28')]} |
| 55 | + /> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + ); |
| 60 | +}; |
0 commit comments