|
| 1 | +import React from 'react'; |
| 2 | +import moment, { Moment } from 'moment'; |
| 3 | +import Picker from '../src/Picker'; |
| 4 | +import RangePicker from '../src/RangePicker'; |
| 5 | +import PickerPanel from '../src/PickerPanel'; |
| 6 | +import momentGenerateConfig from '../src/generate/moment'; |
| 7 | +import zhCN from '../src/locale/zh_CN'; |
| 8 | +import enUS from '../src/locale/en_US'; |
| 9 | +import jaJP from '../src/locale/ja_JP'; |
| 10 | +import '../assets/index.less'; |
| 11 | + |
| 12 | +const defaultValue = moment('2019-11-28 01:02:03'); |
| 13 | + |
| 14 | +function formatDate(date: Moment | null) { |
| 15 | + return date ? date.format('YYYY-MM-DD HH:mm:ss') : 'null'; |
| 16 | +} |
| 17 | + |
| 18 | +export default () => { |
| 19 | + const [value, setValue] = React.useState<Moment | null>(defaultValue); |
| 20 | + |
| 21 | + const weekRef = React.useRef<Picker<Moment>>(null); |
| 22 | + |
| 23 | + const onSelect = (newValue: Moment) => { |
| 24 | + console.log('Select:', newValue); |
| 25 | + }; |
| 26 | + |
| 27 | + const onChange = (newValue: Moment | null, formatString?: string) => { |
| 28 | + console.log('Change:', newValue, formatString); |
| 29 | + setValue(newValue); |
| 30 | + }; |
| 31 | + |
| 32 | + const sharedProps = { |
| 33 | + generateConfig: momentGenerateConfig, |
| 34 | + value, |
| 35 | + onSelect, |
| 36 | + onChange, |
| 37 | + direction: 'rtl', |
| 38 | + }; |
| 39 | + |
| 40 | + const rangePickerRef = React.useRef<RangePicker<Moment>>(null); |
| 41 | + |
| 42 | + return ( |
| 43 | + <div dir="rtl"> |
| 44 | + <h2> |
| 45 | + Value:{' '} |
| 46 | + {value ? `${formatDate(value[0])} ~ ${formatDate(value[1])}` : 'null'} |
| 47 | + </h2> |
| 48 | + |
| 49 | + <div style={{ display: 'flex', flexWrap: 'wrap' }}> |
| 50 | + <div style={{ margin: '0 8px' }}> |
| 51 | + <h3>Basic</h3> |
| 52 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} /> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div style={{ margin: '0 8px' }}> |
| 56 | + <h3>Uncontrolled</h3> |
| 57 | + <PickerPanel<Moment> |
| 58 | + generateConfig={momentGenerateConfig} |
| 59 | + locale={zhCN} |
| 60 | + onChange={onChange} |
| 61 | + defaultValue={moment('2000-01-01', 'YYYY-MM-DD')} |
| 62 | + /> |
| 63 | + </div> |
| 64 | + |
| 65 | + <div style={{ margin: '0 8px' }}> |
| 66 | + <h3>1 Month earlier</h3> |
| 67 | + <PickerPanel<Moment> |
| 68 | + {...sharedProps} |
| 69 | + defaultPickerValue={defaultValue.clone().subtract(1, 'month')} |
| 70 | + locale={enUS} |
| 71 | + /> |
| 72 | + </div> |
| 73 | + |
| 74 | + <div style={{ margin: '0 8px' }}> |
| 75 | + <h3>Week Picker CN</h3> |
| 76 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} picker="week" /> |
| 77 | + </div> |
| 78 | + |
| 79 | + <div style={{ margin: '0 8px' }}> |
| 80 | + <h3>Month Picker</h3> |
| 81 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} picker="month" /> |
| 82 | + </div> |
| 83 | + |
| 84 | + <div style={{ margin: '0 8px' }}> |
| 85 | + <h3>Week Picker US</h3> |
| 86 | + <PickerPanel<Moment> {...sharedProps} locale={enUS} picker="week" /> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div style={{ margin: '0 8px' }}> |
| 90 | + <h3>Time</h3> |
| 91 | + <PickerPanel<Moment> {...sharedProps} locale={jaJP} mode="time" /> |
| 92 | + </div> |
| 93 | + <div style={{ margin: '0 8px' }}> |
| 94 | + <h3>Time AM/PM</h3> |
| 95 | + <PickerPanel<Moment> |
| 96 | + {...sharedProps} |
| 97 | + locale={jaJP} |
| 98 | + mode="time" |
| 99 | + showTime={{ |
| 100 | + use12Hours: true, |
| 101 | + showSecond: false, |
| 102 | + format: 'hh:mm A', |
| 103 | + }} |
| 104 | + /> |
| 105 | + </div> |
| 106 | + <div style={{ margin: '0 8px' }}> |
| 107 | + <h3>Datetime</h3> |
| 108 | + <PickerPanel<Moment> {...sharedProps} locale={zhCN} showTime /> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + |
| 112 | + <div style={{ display: 'flex' }}> |
| 113 | + <div style={{ margin: '0 8px' }}> |
| 114 | + <h3>Basic</h3> |
| 115 | + <Picker<Moment> {...sharedProps} locale={zhCN} /> |
| 116 | + </div> |
| 117 | + <div style={{ margin: '0 8px' }}> |
| 118 | + <h3>Uncontrolled</h3> |
| 119 | + <Picker<Moment> |
| 120 | + generateConfig={momentGenerateConfig} |
| 121 | + locale={zhCN} |
| 122 | + allowClear |
| 123 | + /> |
| 124 | + </div> |
| 125 | + <div style={{ margin: '0 8px' }}> |
| 126 | + <h3>Datetime</h3> |
| 127 | + <Picker<Moment> |
| 128 | + {...sharedProps} |
| 129 | + locale={zhCN} |
| 130 | + defaultPickerValue={defaultValue.clone().subtract(1, 'month')} |
| 131 | + showTime={{ |
| 132 | + showSecond: false, |
| 133 | + defaultValue: moment('11:28:39', 'HH:mm:ss'), |
| 134 | + }} |
| 135 | + showToday |
| 136 | + disabledTime={date => { |
| 137 | + if (date && date.isSame(defaultValue, 'date')) { |
| 138 | + return { |
| 139 | + disabledHours: () => [1, 3, 5, 7, 9, 11], |
| 140 | + }; |
| 141 | + } |
| 142 | + return {}; |
| 143 | + }} |
| 144 | + /> |
| 145 | + </div> |
| 146 | + <div style={{ margin: '0 8px' }}> |
| 147 | + <h3>Uncontrolled Datetime</h3> |
| 148 | + <Picker<Moment> generateConfig={momentGenerateConfig} locale={zhCN} /> |
| 149 | + </div> |
| 150 | + <div style={{ margin: '0 8px' }}> |
| 151 | + <h3>Week</h3> |
| 152 | + <Picker<Moment> |
| 153 | + {...sharedProps} |
| 154 | + locale={zhCN} |
| 155 | + format="YYYY-Wo" |
| 156 | + allowClear |
| 157 | + picker="week" |
| 158 | + renderExtraFooter={() => 'I am footer!!!'} |
| 159 | + ref={weekRef} |
| 160 | + /> |
| 161 | + |
| 162 | + <button |
| 163 | + type="button" |
| 164 | + onClick={() => { |
| 165 | + if (weekRef.current) { |
| 166 | + weekRef.current.focus(); |
| 167 | + } |
| 168 | + }} |
| 169 | + > |
| 170 | + Focus |
| 171 | + </button> |
| 172 | + </div> |
| 173 | + <div style={{ margin: '0 8px' }}> |
| 174 | + <h3>Week</h3> |
| 175 | + <Picker<Moment> |
| 176 | + generateConfig={momentGenerateConfig} |
| 177 | + locale={zhCN} |
| 178 | + picker="week" |
| 179 | + /> |
| 180 | + </div> |
| 181 | + <div style={{ margin: '0 8px' }}> |
| 182 | + <h3>Time</h3> |
| 183 | + <Picker<Moment> {...sharedProps} locale={zhCN} picker="time" /> |
| 184 | + </div> |
| 185 | + <div style={{ margin: '0 8px' }}> |
| 186 | + <h3>Time 12</h3> |
| 187 | + <Picker<Moment> |
| 188 | + {...sharedProps} |
| 189 | + locale={zhCN} |
| 190 | + picker="time" |
| 191 | + use12Hours |
| 192 | + /> |
| 193 | + </div> |
| 194 | + <div style={{ margin: '0 8px' }}> |
| 195 | + <h3>Year</h3> |
| 196 | + <Picker<Moment> {...sharedProps} locale={zhCN} picker="year" /> |
| 197 | + </div> |
| 198 | + </div> |
| 199 | + |
| 200 | + <div style={{ display: 'flex', flexWrap: 'wrap' }}> |
| 201 | + <div style={{ margin: '0 8px' }}> |
| 202 | + <h3>Basic RangePicker</h3> |
| 203 | + <RangePicker<Moment> |
| 204 | + {...sharedProps} |
| 205 | + value={undefined} |
| 206 | + locale={zhCN} |
| 207 | + allowClear |
| 208 | + ref={rangePickerRef} |
| 209 | + defaultValue={[moment('1990-09-03'), moment('1989-11-28')]} |
| 210 | + placeholder={['start...', 'end...']} |
| 211 | + /> |
| 212 | + </div> |
| 213 | + </div> |
| 214 | + </div> |
| 215 | + ); |
| 216 | +}; |
0 commit comments