Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-mobile-datepicker

lanjingling051028.6kISC4.0.2

一个移动端时间选择器react组件

react-component, react-datepicker, date, datepicker, react, mobile, calendar

readme

react-mobile-datepicker

Travis npm package Coveralls

a lightweight react date picker for mobile, Not more than 4k

react-mobile-datepicker provides a component that can set year, month, day, hour, minute and second by sliding up or down.

Features

  • is only 4k.
  • It does not depend on moment.js

Theme

default

dark

ios

android

android-dark

Custom date unit

set dateConfig to configure year, month, day, hour, minute.

{
    'year': {
        format: 'YYYY',
        caption: 'Year',
        step: 1,
    },
    'month': {
        format: 'MM',
        caption: 'Mon',
        step: 1,
    },
    'date': {
        format: 'DD',
        caption: 'Day',
        step: 1,
    },
    'hour': {
        format: 'hh',
        caption: 'Hour',
        step: 1,
    },
    'minute': {
        format: 'mm',
        caption: 'Min',
        step: 1,
    },
    'second': {
        format: 'hh',
        caption: 'Sec',
        step: 1,
    },
}

set dateConfig to configure hour, minute and second.

{
    'hour': {
        format: 'hh',
        caption: 'Hour',
        step: 1,
    },
    'minute': {
        format: 'mm',
        caption: 'Min',
        step: 1,
    },
    'second': {
        format: 'hh',
        caption: 'Sec',
        step: 1,
    },
}

customize the content mapping shown in the month.


const monthMap = {
    '1': 'Jan',
    '2': 'Feb',
    '3': 'Mar',
    '4': 'Apr',
    '5': 'May',
    '6': 'Jun',
    '7': 'Jul',
    '8': 'Aug',
    '9': 'Sep',
    '10': 'Oct',
    '11': 'Nov',
    '12': 'Dec',
};

const dateConfig = {
    'year': {
        format: 'YYYY',
        caption: 'Year',
        step: 1,
    },
    'month': {
        format: value => monthMap[value.getMonth() + 1],
        caption: 'Mon',
        step: 1,
    },
    'date': {
        format: 'DD',
        caption: 'Day',
        step: 1,
    },
};

<DatePicker
    dateConfig={dateConfig}
/>

set showCaption to display date captions, matches the dateConfig property's caption.

const dateConfig = {
    'hour': {
        format: 'hh',
        caption: 'Hour',
        step: 1,
    },
    'minute': {
        format: 'mm',
        caption: 'Min',
        step: 1,
    },
    'second': {
        format: 'hh',
        caption: 'Sec',
        step: 1,
    },
}

<DatePicker
    showCaption={true}
    dateConfig={dateConfig}
/>

Getting Started

Install

Using npm:

$ npm install react-mobile-datepicker --save

Import what you need

The following guide assumes you have some sort of ES2015 build set up using babel and/or webpack/browserify/gulp/grunt/etc.

// Using an ES6 transpiler like Babel
import  React from 'react';
import ReactDOM from 'react-dom';
import DatePicker from 'react-mobile-datepicker';

Usage Example

class App extends React.Component {
    state = {
        time: new Date(),
        isOpen: false,
    }

    handleClick = () => {
        this.setState({ isOpen: true });
    }

    handleCancel = () => {
        this.setState({ isOpen: false });
    }

    handleSelect = (time) => {
        this.setState({ time, isOpen: false });
    }

    render() {
        return (
            <div className="App">
                <a
                    className="select-btn"
                    onClick={this.handleClick}>
                    select time
                </a>

                <DatePicker
                    value={this.state.time}
                    isOpen={this.state.isOpen}
                    onSelect={this.handleSelect}
                    onCancel={this.handleCancel} />
            </div>
        );
    }
}


ReactDOM.render(<App />, document.getElementById('react-box'));

PropTypes

Property Type Default Description
isPopup Boolean true whether as popup add a overlay
isOpen Boolean false whether to open datepicker
theme String default theme of datepicker, include 'default', 'dark', 'ios', 'android', 'android-dark'
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日']
dateSteps(deprecated), use dateConfig instead Array [1, 1, 1] set step for each time unit
dateConfig Object See DateConfig format for details configure date unit information
showFormat(deprecated, use headerFormat instead) String 'YYYY/MM/DD' customize the format of the display title
headerFormat String 'YYYY/MM/DD' customize the format of the display title
value Date new Date() date value
min Date new Date(1970, 0, 1) minimum date
max Date new Date(2050, 0, 1) maximum date
showHeader Boolean true whether to show the header
showFooter Boolean true whether to show the fotter
customHeader ReactElement undefined customize the header, if you set this property, it will replace showFormat
confirmText String 完成 customize the selection time button text
cancelText String 取消 customize the cancel button text
onSelect Function () => {} the callback function after click button of done, Date object as a parameter
onCancel Function () => {} the callback function after click button of cancel
onChange Function () => {} the callback function after date be changed

DateConfig

all default date configuration information, as follows

  • format: date unit display format
  • caption: date unit caption
  • step: date unit change interval
{
    'year': {
        format: 'YYYY',
        caption: 'Year',
        step: 1,
    },
    'month': {
        format: 'M',
        caption: 'Mon',
        step: 1,
    },
    'date': {
        format: 'D',
        caption: 'Day',
        step: 1,
    },
    'hour': {
        format: 'hh',
        caption: 'Hour',
        step: 1,
    },
    'minute': {
        format: 'mm',
        caption: 'Min',
        step: 1,
    },
    'second': {
        format: 'hh',
        caption: 'Sec',
        step: 1,
    },
}

Changelog

How to Contribute

Anyone and everyone is welcome to contribute to this project. The best way to start is by checking our open issues, submit a new issues or feature request, participate in discussions, upvote or downvote the issues you like or dislike.

changelog

4.0.2 2019-07-21 20:57:09

  • 01a3ec4 ✨ [feature] add characteristic of onchange and showFooter

4.0.1 2019-02-21 11:11:09

4.0.0 2018-10-26 12:39:53

3.0.12 2018-05-17 21:29:57

3.0.11 2018-05-12 10:57:46

3.0.10 2018-04-24 22:50:29

3.0.9 2018-04-23 10:48:04

  • 8508a7e ✨ [feature] add test case for dateSteps
  • 34ff8c6 ✨ [feature] Add characteristics of set a time step

3.0.8 2017-10-15 23:17:08

3.0.7 2017-10-12 08:11:11

3.0.6 2017-07-08 20:21:30

  • 1d847d8 📚 [document] edit readme document.
  • d2c3372 ✨ [feature] Add characteristics of automatic configuration Year, Month, Day, Hour, Minute, Second.

3.0.5 2017-07-03 20:47:51

3.0.4 2017-04-09 17:12:18

  • e2a2935 📦 [refact] edit test code for simulate event.
  • b743448 🐛 [bug]fix scrolling up will refresh page.

3.0.3 2017-01-05 15:06:48

3.0.2 2016-12-18 14:45:39

  • 45bcd3e 🐛 [bug]fix Cannot find module jsdom
  • a167120 ✨ [feature] Added an option (isPopup) (#2)

v3.0.1 - Sun, 18 Sep 2016 09:37:34 GMT

-

v3.0.0 - Sun, 18 Sep 2016 09:28:28 GMT

  • 14b868c [changed] ✅ update version,An increase of five theme,A slide can move multiple dates.

v2.0.7 - Tue, 13 Sep 2016 04:44:41 GMT

-

v2.0.7 - Sat, 10 Sep 2016 15:52:02 GMT

-

v2.0.6 - Sat, 10 Sep 2016 10:23:41 GMT

-

v2.0.5 - Sat, 10 Sep 2016 10:16:55 GMT

  • 9e2df2f [changed] add modal layer and add rollup for production

v2.0.4 - Tue, 12 Jul 2016 09:16:42 GMT

-

v2.0.3 - Tue, 12 Jul 2016 09:15:00 GMT

-

v2.0.2 - Tue, 05 Jul 2016 00:48:26 GMT

-

v2.0.1 - Mon, 04 Jul 2016 14:45:41 GMT

-

v2.0.0 - Mon, 04 Jul 2016 10:48:22 GMT

-

v1.0.16 - Mon, 27 Jun 2016 09:08:47 GMT

  • 4516b14 [changed] 修改finish-btn行高

v1.0.15 - Sun, 26 Jun 2016 04:09:49 GMT

-

v1.0.14 - Sun, 26 Jun 2016 03:38:28 GMT

  • 2025c43 [added] 添加README.md关键词

v1.0.13 - Sun, 26 Jun 2016 03:20:53 GMT

-

v1.0.12 - Sun, 26 Jun 2016 02:20:39 GMT

  • 37441d7 [added] 添加注释, 测试用例

v1.0.11 - Fri, 24 Jun 2016 02:35:43 GMT

-

v1.0.10 - Fri, 24 Jun 2016 01:55:02 GMT

  • 1687e8e [fixed] 取消isOpen, onCancel属性

v1.0.9 - Fri, 24 Jun 2016 01:33:47 GMT

-

v1.0.8 - Fri, 24 Jun 2016 01:32:53 GMT

-

v1.0.7 - Fri, 24 Jun 2016 01:29:41 GMT

v1.0.6 - Fri, 24 Jun 2016 01:25:40 GMT

  • a1f1db9 [fixed] 修复滚动快速出现的bug

v1.0.5 - Thu, 23 Jun 2016 13:37:16 GMT

-

v1.0.4 - Thu, 23 Jun 2016 13:34:36 GMT

-

v1.0.3 - Thu, 23 Jun 2016 13:22:13 GMT

  • 5a93fe9 [changed] 更新了READEME

v1.0.2 - Thu, 23 Jun 2016 13:12:08 GMT

-

v1.0.14 - Fri, 17 Jun 2016 07:30:27 GMT

-

v1.0.13 - Fri, 17 Jun 2016 06:26:17 GMT

-

v1.0.12 - Thu, 16 Jun 2016 15:42:47 GMT

-

v1.0.11 - Thu, 16 Jun 2016 14:15:13 GMT

-

v1.0.9 - Thu, 16 Jun 2016 12:47:16 GMT

-

v1.0.8 - Thu, 16 Jun 2016 12:10:32 GMT

-

v1.0.7 - Thu, 16 Jun 2016 09:09:24 GMT

v1.0.6 - Thu, 16 Jun 2016 08:54:53 GMT

  • 9be9fe6 [added] 添加.travis.yml

v1.0.5 - Thu, 16 Jun 2016 08:01:06 GMT

  • a2cd387 [fixed] 解决changlog无效的问题

v1.0.4 - Thu, 16 Jun 2016 07:40:50 GMT

-

v1.0.3 - Thu, 16 Jun 2016 07:40:47 GMT

-

1.0.3 - Thu, 16 Jun 2016 07:40:35 GMT

-

v1.0.4 - Thu, 16 Jun 2016 07:21:51 GMT

-

v1.0.3 - Thu, 16 Jun 2016 06:20:24 GMT

-

v1.0.2 - Thu, 16 Jun 2016 06:20:14 GMT

-

v1.0.2 - Thu, 16 Jun 2016 01:29:56 GMT

-

v1.0.1 - Thu, 16 Jun 2016 01:12:11 GMT

-