GithubHelp home page GithubHelp logo

lanjingling0510 / react-mobile-datepicker Goto Github PK

View Code? Open in Web Editor NEW
300.0 16.0 142.0 1.12 MB

🙊 👻 look a demo, Please imitate mobile environment.

Home Page: https://codepen.io/lanjingling0510/pen/LRpOYp?editors=1010

License: MIT License

JavaScript 89.29% CSS 10.71%

react-mobile-datepicker's Introduction

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 footer
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.

react-mobile-datepicker's People

Contributors

kerminate avatar lanjingling0510 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-mobile-datepicker's Issues

Allow for Caption/Headers

As a user, I want to know what I am actually selecting. Would be good to have a bar at the top indicating whether it's a day, hour or year.

See example:
image

As opposed to:
image

use on-page instead of as popup?

Hi.. is it possible to use this component as a widget directly on the page, without having to use it as a popup / overlay on the page?

scrolling up will update the page

hi
i have installed you package, ui is very nice. However, when i scroll up for the past time such as 2000-12-11. this behavior will result in updating the page and can not select the time.

hope your response.
thanks

Unable to select date in chrome

It is working in android mobile but not able to select date while using in chrome in Mac book.

Here is version details:

"react-mobile-datepicker": "^4.0.2",
"react": "^16.9.0",

Can you please help me on this

Here is my code:

<DatePicker value={dateOfBirth || new Date()} isOpen={isPickerOpen} confirmText="Confirm" cancelText="Cancel" min={new Date(1900, 0, 1)} onSelect={handleDateChange} onChange={handleDatePickerChange} onCancel={handleCancelDate} />

[Feature] 12 Hour AM/PM Support?

This library is awesome except for one flaw. There doesn't seem to be a way to set 12 hour time. rmc-date-picker supports this but has a lack of themes and the time doesn't seem to roll over continuously like this library. I was wondering if there is already support for this I'm just overlooking?

isPopup bug

isPopup 属性会跟isOpen属性有冲突

set time step

It's better to allow user to set a time step like 5 or 10 minutes when specifying dateFormat that contains time info. In most cases we prefer to set time points like "10:30", "12:45" etc.

[Feature] Keyboard navigation

Hello, I really like this component, but it lacks keyboard navigation, which could be a major accessibility issue!

Any chance you'll add it soon-ish?

scroll problems

I have tested on ios & android, both platform have the problem: can't scroll smoothly.

even can't scroll on desktop

how to disabled auto change month and year?

when I scroll day list, if it from 31 to 1, month will auto add 1. If it from 1 to 31, month will auto substract 1.
but I don't want to it auto change month list and year list.
is there someone who can help me?

onSelect事件中参数错误

onSelect事件中获取的参数是永远是初始时的时间,这导致组件完全失去意义。这bug也太夸张了吧?

datepicker can't update by F5

after importing the datepicker component, when i first render the component , a problem that document is not defined occurs in line 134 in 'react-mobile-datepicker.js' of dist. all in one word, i hope you can give me some advise to solve this. thanks.

麻烦支持一下react16

image
这里就算改成react 16的写法应该也不会影响到react 15 的正常使用的吧,但react 16会报错

无法选择低于时间戳起始年(1970)的日期

javascript 可通过负数来表明低于 1970 年的日期,如:

const time = new Date(- 10 * 9999999999);
-> Mon Oct 31 1966 22:13:20 GMT+0800 (**标准时间)
time.getFullYear();
-> 1966

但该时间控件无法识别

npm could not install this package

npm ERR! path D:\ReactNavigation\H5\node_modules\react-mobile-datepicker
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'D:\ReactNavigation\H5\node_modules\react-mobile-datepicker' -> 'D:\ReactNavigation\H5\node_modules.react-mobile-datepicker.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xiaooming\AppData\Roaming\npm-cache_logs\2018-03-08T07_56_01_675Z-debug.log

Map month number to month name

Need to add an option to convert month number to month name.

E.g.:

const monthMap = {
0: 'Jan',
1: 'Feb',
2: 'March',
}

<DatePicker
dateFormat={['YYYY', ['MM', (month) => monthMap(month)], 'DD']}
/>

IE 11不兼容

能支持IE11 的兼容吗?在IE11,可以用鼠标滑动,但是在平板不能用手滑动

flexible冲突问题

您好,我们的h5用到了flexible组件,在metaEl.setAttribute('name', 'viewport'); metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');,此处会改变viewport的scale,在iPhone X手机上看到的scale是0.3333,而咋们这个时间控件是根据scale=1来做的,导致整个时间插件的缩小了1/3,这个问题怎么办?

bundle error

@lanjingling0510

thanks for your library.

use latest version,
and when i do react-native run-ios
got this:

error: bundling failed: Error: Couldn't find preset "stage-0" relative to directory "/Users/apps/node_modules/react-mobile-datepicker"

When scrolling 2 wheels at the same it is possible to set a date outside min/maxDate

Hi!

We found an issue with the datepicker. It is possible to set a date outside the min/max boundary by scrolling two wheels at the same time. In this case the whole component becomes disabled and it is impossible to change date.

I suggest you add a check to the componentDidUpdate() life cycle:
if value > max => set value to max
if value < min => set value to min

Thank You for the feedback!

Arkady

Relative positioning

Thanks for this nice widget. I'm building a progressive web app and finding a calendar picker that would be mobile friendly is very hard. I really like this library, however, it would be useful if we could have some control over its positioning. Currently, it has position:absolute and it's always placed at the bottom of the screen. That may not always suit the design. Is there a way to modify the positioning now?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.