|
1 | 1 | # react-mobile-datepicker |
2 | 2 | [![Travis][build-badge]][build] [![npm package][npm-badge]][npm] [![Coveralls][coveralls-badge]][coveralls] |
3 | 3 |
|
4 | | -一个移动端时间选择器react组件 |
5 | | ---------------------------------------- |
| 4 | + |
| 5 | +**a lightweight react date picker for mobile, Not more than 4k** |
| 6 | + |
| 7 | +react-mobile-datepicker provides a component that can set year, month and day by sliding up or down. |
| 8 | + |
| 9 | + |
6 | 10 |
|
7 | 11 | <div style="padding:30px"> |
8 | 12 | <img src="https://raw.githubusercontent.com/lanjingling0510/react-mobile-datepicker/master/.github/preview.gif" width="300" /> |
9 | 13 | </div> |
10 | 14 |
|
11 | 15 |
|
12 | 16 |
|
13 | | -安装 |
14 | | ------------- |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +### Install |
| 21 | + |
15 | 22 | Using [npm](https://www.npmjs.com/): |
16 | 23 |
|
17 | 24 | $ npm install react-mobile-datepicker --save |
18 | 25 |
|
| 26 | +### Import what you need |
| 27 | +The following guide assumes you have some sort of ES2015 build set up using babel and/or webpack/browserify/gulp/grunt/etc. |
19 | 28 |
|
20 | | -然后,使用模块加载工具流,支持common.js或ES2015模块,例如[webpack](https://github.com/webpack/webpack) |
21 | 29 |
|
22 | 30 | ```js |
23 | 31 | // Using an ES6 transpiler like Babel |
| 32 | +import React from 'react'; |
| 33 | +import ReactDOM from 'react-dom'; |
24 | 34 | import DatePicker from 'react-mobile-datepicker'; |
25 | | -import 'react-mobile-datepicker/dist/mobile-datepicker.css'; // Make sure to import the default stylesheet |
26 | | - |
27 | | -// Not using an ES6 transpiler |
28 | | -var DatePicker = require('react-mobile-datepicker'); |
29 | | -require('react-mobile-datepicker/dist/mobile-datepicker.css'); |
30 | 35 | ``` |
31 | 36 |
|
32 | | -使用 |
33 | | ------------- |
34 | | -### 例子 |
35 | 37 |
|
36 | | -```js |
37 | | -import React, { Component } from 'react'; |
38 | | -import { render } from 'react-dom'; |
39 | | -import DatePicker from 'mobile-datepicker'; |
40 | | -import 'react-mobile-datepicker/dist/mobile-datepicker.css'; // only needs to be imported once |
41 | | - |
42 | | -// Render the Calendar |
43 | | -var today = new Date(); |
44 | | -var minDate = Number(new Date()) - (24*60*60*1000) * 7; // One week before today |
| 38 | +### Usage Example |
45 | 39 |
|
46 | 40 |
|
47 | | - |
48 | | -render( |
49 | | - <DatePicker |
50 | | - startDate={today} |
51 | | - minDate={minDate} |
52 | | - onSelect={(time) => { console.log(time); }} />, |
53 | | - document.getElementById('root') |
54 | | -); |
| 41 | +```js |
| 42 | +class App extends React.Component { |
| 43 | + state = { |
| 44 | + time: new Date(), |
| 45 | + isOpen: false, |
| 46 | + } |
| 47 | + |
| 48 | + handleClick = () => { |
| 49 | + this.setState({ isOpen: true }); |
| 50 | + } |
| 51 | + |
| 52 | + handleSelect = (time) => { |
| 53 | + this.setState({ time, isOpen: false }); |
| 54 | + } |
| 55 | + |
| 56 | + render() { |
| 57 | + return ( |
| 58 | + <div className="App"> |
| 59 | + <a |
| 60 | + className="select-btn" |
| 61 | + onClick={this.handleClick}> |
| 62 | + select time |
| 63 | + </a> |
| 64 | + <p className="select-time "> |
| 65 | + {convertDate(this.state.time, 'YYYY-MM-DD')} |
| 66 | + </p> |
| 67 | + |
| 68 | + <DatePicker |
| 69 | + date={this.state.time} |
| 70 | + isOpen={this.state.isOpen} |
| 71 | + onSelect={this.handleSelect} /> |
| 72 | + </div> |
| 73 | + ); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +ReactDOM.render(<App />, document.getElementById('react-box')); |
55 | 79 | ``` |
56 | 80 |
|
57 | 81 |
|
58 | | -Prop Types |
59 | | ------------- |
| 82 | +## PropTypes |
60 | 83 |
|
61 | 84 | | Property | Type | Default | Description | |
62 | 85 | |:------------- |:------------- |:-------------- |:---------- | |
63 | | -| btnColor | String | #fff | 完成按钮颜色 | |
64 | | -| dateColor | String | #fff | 日期文字颜色 | |
65 | | -| layerBackground | String | #ffa70b | 背景颜色 | |
66 | | -| date | Date | new Date() | 初始日期 | |
67 | | -| minDate | Date | 前一周 | 最小日期 | |
68 | | -| maxDate | Date | new Date() | 最大日期 | |
69 | | -| onSelect | Function | () => {} | 点击完成后的回调函数, Date对象作为参数 | |
70 | | - |
71 | | -Changelog |
72 | | -------------- |
73 | | - |
74 | | -v1.0.3 - Thu, 23 Jun 2016 13:22:13 GMT |
75 | | --------------------------------------- |
76 | | - |
77 | | -- [5a93fe9](../../commit/5a93fe9) [changed] 更新了READEME |
78 | | - |
| 86 | +| btnColor | String | #fff | done button color | |
| 87 | +| dateColor | String | #fff | date of text color | |
| 88 | +| layerBackground | String | #ffa70b | background color | |
| 89 | +| date | Date | new Date() | date value | |
| 90 | +| minDate | Date | new Date(1970, 0, 1) | minimum date | |
| 91 | +| maxDate | Date | new Date(2050, 0, 1) | maximum date | |
| 92 | +| onSelect | Function | () => {} | the callback function after click button of done, Date object as a parameter | |
| 93 | + |
| 94 | +## Changelog |
| 95 | +* [Changelog](CHANGELOG.md) |
| 96 | + |
| 97 | +## How to Contribute |
| 98 | + |
| 99 | +Anyone and everyone is welcome to contribute to this project. The best way to |
| 100 | +start is by checking our [open issues](https://github.com/lanjingling0510/react-mobile-datepicker/issues), |
| 101 | +[submit a new issues](https://github.com/lanjingling0510/react-mobile-datepicker/issues/new?labels=bug) or |
| 102 | +[feature request](https://github.com/lanjingling0510/react-mobile-datepicker/issues/new?labels=enhancement), |
| 103 | +participate in discussions, upvote or downvote the issues you like or dislike. |
79 | 104 |
|
80 | 105 |
|
81 | 106 |
|
|
0 commit comments