Skip to content

Commit 88e8b68

Browse files
📚 [document] edit readme document.
1 parent daf0b98 commit 88e8b68

5 files changed

Lines changed: 219 additions & 31 deletions

File tree

.github/caption.png

18.8 KB
Loading

README.md

Lines changed: 171 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,150 @@ react-mobile-datepicker provides a component that can set year, month, day, hour
3939

4040
## Custom date unit
4141

42-
set dateFormat for `['YYYY', 'MM', 'DD', 'hh', 'mm']` to configure year, month, day, hour, minute.
42+
set `dateConfig` to configure year, month, day, hour, minute.
43+
44+
```javascript
45+
{
46+
'year': {
47+
format: 'YYYY',
48+
caption: 'Year',
49+
step: 1,
50+
},
51+
'month': {
52+
format: 'MM',
53+
caption: 'Mon',
54+
step: 1,
55+
},
56+
'date': {
57+
format: 'DD',
58+
caption: 'Day',
59+
step: 1,
60+
},
61+
'hour': {
62+
format: 'hh',
63+
caption: 'Hour',
64+
step: 1,
65+
},
66+
'minute': {
67+
format: 'mm',
68+
caption: 'Min',
69+
step: 1,
70+
},
71+
'second': {
72+
format: 'hh',
73+
caption: 'Sec',
74+
step: 1,
75+
},
76+
}
77+
```
4378

4479
<div style="padding:30px">
4580
<img src="https://raw.githubusercontent.com/lanjingling0510/react-mobile-datepicker/master/.github/year-month-day-hour-minute.png" width="300" />
4681
</div>
4782

4883

49-
set dateFormat for `['hh', 'mm', 'ss']` to configure hour, minute and second.
84+
set `dateConfig` to configure hour, minute and second.
85+
86+
```javascript
87+
{
88+
'hour': {
89+
format: 'hh',
90+
caption: 'Hour',
91+
step: 1,
92+
},
93+
'minute': {
94+
format: 'mm',
95+
caption: 'Min',
96+
step: 1,
97+
},
98+
'second': {
99+
format: 'hh',
100+
caption: 'Sec',
101+
step: 1,
102+
},
103+
}
104+
```
50105

51106
<div style="padding:30px">
52107
<img src="https://raw.githubusercontent.com/lanjingling0510/react-mobile-datepicker/master/.github/hour-minute-second.png" width="300" />
53108
</div>
54109

55110
customize the content mapping shown in the month.
56111

57-
```js
112+
```javascript
113+
58114
const monthMap = {
59-
'01': 'Jan',
60-
'02': 'Feb',
61-
'03': 'Mar',
62-
'04': 'Apr',
63-
'05': 'May',
64-
'06': 'Jun',
65-
'07': 'Jul',
66-
'08': 'Aug',
67-
'09': 'Sep',
115+
'1': 'Jan',
116+
'2': 'Feb',
117+
'3': 'Mar',
118+
'4': 'Apr',
119+
'5': 'May',
120+
'6': 'Jun',
121+
'7': 'Jul',
122+
'8': 'Aug',
123+
'9': 'Sep',
68124
'10': 'Oct',
69125
'11': 'Nov',
70126
'12': 'Dec',
71127
};
72128

129+
const dateConfig = {
130+
'year': {
131+
format: 'YYYY',
132+
caption: 'Year',
133+
step: 1,
134+
},
135+
'month': {
136+
format: value => monthMap[value.getMonth() + 1],
137+
caption: 'Mon',
138+
step: 1,
139+
},
140+
'date': {
141+
format: 'DD',
142+
caption: 'Day',
143+
step: 1,
144+
},
145+
};
146+
73147
<DatePicker
74-
dateFormat={['YYYY', ['MM', (month) => monthMap[month]], 'DD']}
148+
dateConfig={dateConfig}
75149
/>
76150

77151
```
78-
152+
<div style="padding:30px">
79153
<img src="https://raw.githubusercontent.com/lanjingling0510/react-mobile-datepicker/master/.github/year-custom_month-day.png" width="300" />
80154
</div>
81155

156+
set `showCaption` to display date captions, matches the dateConfig property's caption.
157+
158+
```javascript
159+
const dateConfig = {
160+
'hour': {
161+
format: 'hh',
162+
caption: 'Hour',
163+
step: 1,
164+
},
165+
'minute': {
166+
format: 'mm',
167+
caption: 'Min',
168+
step: 1,
169+
},
170+
'second': {
171+
format: 'hh',
172+
caption: 'Sec',
173+
step: 1,
174+
},
175+
}
176+
177+
<DatePicker
178+
showCaption={true}
179+
dateConfig={dateConfig}
180+
/>
181+
```
182+
183+
<div style="padding:30px">
184+
<img src="https://raw.githubusercontent.com/lanjingling0510/react-mobile-datepicker/master/.github/caption.png" width="300" />
185+
</div>
82186

83187

84188
## Getting Started
@@ -93,7 +197,7 @@ Using [npm](https://www.npmjs.com/):
93197
The following guide assumes you have some sort of ES2015 build set up using babel and/or webpack/browserify/gulp/grunt/etc.
94198

95199

96-
```js
200+
```javascript
97201
// Using an ES6 transpiler like Babel
98202
import React from 'react';
99203
import ReactDOM from 'react-dom';
@@ -104,7 +208,7 @@ import DatePicker from 'react-mobile-datepicker';
104208
### Usage Example
105209

106210

107-
```js
211+
```javascript
108212
class App extends React.Component {
109213
state = {
110214
time: new Date(),
@@ -154,9 +258,11 @@ ReactDOM.render(<App />, document.getElementById('react-box'));
154258
| isPopup | Boolean | true | whether as popup add a overlay |
155259
| isOpen | Boolean | false | whether to open datepicker |
156260
| theme | String | default | theme of datepicker, include 'default', 'dark', 'ios', 'android', 'android-dark' |
157-
| dateFormat | Array | ['YYYY', 'M', 'D'] | according to year, month, day, hour, minute, second format specified display text. E.g ['YYYY年', 'MM月', 'DD日']|
158-
| dateSteps | Array | [1, 1, 1] | set step for each time unit |
159-
|showFormat | String | 'YYYY/MM/DD' | customize the format of the display title |
261+
| ~~dateFormat~~(deprecated, use `dateConfig` instead) | Array | ['YYYY', 'M', 'D'] | according to year, month, day, hour, minute, second format specified display text. E.g ['YYYY年', 'MM月', 'DD日']|
262+
| ~~dateSteps~~(deprecated), use `dateConfig` instead | Array | [1, 1, 1] | set step for each time unit |
263+
| dateConfig | Object | [See `DateConfig` format for details](#dateconfig) | configure date unit information |
264+
|~~showFormat~~(deprecated, use `headerFormat` instead) | String | 'YYYY/MM/DD' | customize the format of the display title |
265+
|headerFormat | String | 'YYYY/MM/DD' | customize the format of the display title |
160266
| value | Date | new Date() | date value |
161267
| min | Date | new Date(1970, 0, 1) | minimum date |
162268
| max | Date | new Date(2050, 0, 1) | maximum date |
@@ -167,6 +273,52 @@ ReactDOM.render(<App />, document.getElementById('react-box'));
167273
| onSelect | Function | () => {} | the callback function after click button of done, Date object as a parameter |
168274
| onCancel | Function | () => {} | the callback function after click button of cancel |
169275

276+
277+
## DateConfig
278+
279+
all default date configuration information, as follows
280+
281+
- format: date unit display format
282+
- caption: date unit caption
283+
- step: date unit change interval
284+
285+
```javascript
286+
{
287+
'year': {
288+
format: 'YYYY',
289+
caption: 'Year',
290+
step: 1,
291+
},
292+
'month': {
293+
format: 'M',
294+
caption: 'Mon',
295+
step: 1,
296+
},
297+
'date': {
298+
format: 'D',
299+
caption: 'Day',
300+
step: 1,
301+
},
302+
'hour': {
303+
format: 'hh',
304+
caption: 'Hour',
305+
step: 1,
306+
},
307+
'minute': {
308+
format: 'mm',
309+
caption: 'Min',
310+
step: 1,
311+
},
312+
'second': {
313+
format: 'hh',
314+
caption: 'Sec',
315+
step: 1,
316+
},
317+
}
318+
319+
```
320+
321+
170322
## Changelog
171323
* [Changelog](CHANGELOG.md)
172324

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function ModalDatePicker<T: *>({ isPopup, ...props }: ModalDatePickerProps<T>) {
4141
);
4242
}
4343

44+
ModalDatePicker.displayName = 'MobileDatePicker';
4445
ModalDatePicker.defaultProps = defaultProps;
4546

4647
export default ModalDatePicker;

stories/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.datepicker {
2+
width: 375px;
3+
position: relative;
4+
}

stories/index.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,17 @@ import { storiesOf } from '@storybook/react';
55
// import { linkTo } from '@storybook/addon-links';
66

77
import DatePicker from '../lib/index.js';
8+
import './index.css';
89

910
const props = {
1011
value: new Date(),
1112
isPopup: false,
1213
theme: 'android'
1314
};
1415

15-
const wrapStyle = {
16-
width: 375,
17-
height: 294,
18-
position: 'relative',
19-
};
20-
2116
const getComponent = (options) => {
2217
return (
23-
<div style={wrapStyle}>
24-
<DatePicker {...props} {...options} />
25-
</div>
18+
<DatePicker {...props} {...options} />
2619
);
2720
};
2821

@@ -34,11 +27,49 @@ storiesOf('Theme', module)
3427
.addWithInfo('android', () => getComponent({theme: 'android'}))
3528
.addWithInfo('android-dark', () => getComponent({theme: 'android-dark'}))
3629

37-
storiesOf('dateFormat', module)
30+
31+
const dateConfigMap = {
32+
'year': {
33+
format: 'YYYY',
34+
caption: '年',
35+
step: 1,
36+
},
37+
'month': {
38+
format: 'M',
39+
caption: '月',
40+
step: 1,
41+
},
42+
'date': {
43+
format: 'D',
44+
caption: '日',
45+
step: 1,
46+
},
47+
'hour': {
48+
format: 'hh',
49+
caption: '时',
50+
step: 1,
51+
},
52+
'minute': {
53+
format: 'mm',
54+
caption: '分',
55+
step: 1,
56+
},
57+
'second': {
58+
format: 'hh',
59+
caption: '秒',
60+
step: 1,
61+
},
62+
};
63+
64+
storiesOf('dateConfig', module)
3865
.addWithInfo('YYYY,MM,DD', () => getComponent())
39-
.addWithInfo('YYYY,MM,DD hh:mm', () => getComponent({dateFormat: ['YYYY', 'MM', 'DD', 'hh', 'mm'], showFormat: 'YYYY/MM/DD hh:mm'}))
40-
.addWithInfo('hh:mm:ss', () => getComponent({dateFormat: ['hh', 'mm', 'ss'], showFormat: 'hh:mm:ss'}))
66+
.addWithInfo('YYYY,MM,DD hh:mm', () => getComponent({dateConfig: dateConfigMap, showFormat: 'YYYY/MM/DD hh:mm'}))
67+
.addWithInfo('hh:mm:ss', () => getComponent({dateConfig: ['hour', 'minute', 'second'], showFormat: 'hh:mm:ss'}))
4168

4269
storiesOf('dateLimit', module)
4370
.addWithInfo('min', () => getComponent({ min: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000) }))
4471
.addWithInfo('max', () => getComponent({ max: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000) }))
72+
73+
storiesOf('dateCaption', module)
74+
.addWithInfo('default caption', () => getComponent({dateConfig: ['year', 'month', 'date', 'hour', 'minute', 'second'], showCaption: true}))
75+
.addWithInfo('custom caption', () => getComponent({dateConfig: dateConfigMap, showCaption: true}))

0 commit comments

Comments
 (0)