All Projects → talentedandrew → react-modern-datepicker

talentedandrew / react-modern-datepicker

Licence: Apache-2.0 license
A modern date picker for react library

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to react-modern-datepicker

nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (+36.84%)
Mutual labels:  date, datepicker
Brpickerview
BRPickerView 封装的是iOS中常用的选择器组件,主要包括:日期选择器(支持年月日、年月等15种日期样式选择,支持设置星期、至今等)、地址选择器(支持省市区、省市、省三种地区选择)、自定义字符串选择器(支持单列、多列、二级联动、三级联动选择)。支持自定义主题样式,适配深色模式,支持将选择器组件添加到指定容器视图。
Stars: ✭ 2,149 (+11210.53%)
Mutual labels:  date, datepicker
Horizontalpicker
DatePicker horizontal con selección smooth por día para Android.
Stars: ✭ 116 (+510.53%)
Mutual labels:  date, datepicker
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (+5510.53%)
Mutual labels:  date, datepicker
Vuejs Datepicker
A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations
Stars: ✭ 2,529 (+13210.53%)
Mutual labels:  date, datepicker
Rc Datetime Picker
React component for datetime picker by Moment.js
Stars: ✭ 85 (+347.37%)
Mutual labels:  date, datepicker
Things Calendar
Simple but elegant datepicker for the web — inspired by Things for mac
Stars: ✭ 165 (+768.42%)
Mutual labels:  date, datepicker
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+196600%)
Mutual labels:  date, dayjs
Datepicker
Get a date with JavaScript! A datepicker with no dependencies.
Stars: ✭ 212 (+1015.79%)
Mutual labels:  date, datepicker
Lightpick
(deprecated) Check out the new date picker Litepicker
Stars: ✭ 204 (+973.68%)
Mutual labels:  date, datepicker
Intl Date Time
International DateTime for Laravel Nova
Stars: ✭ 50 (+163.16%)
Mutual labels:  date, datepicker
Flatpickr
lightweight, powerful javascript datetimepicker with no dependencies
Stars: ✭ 14,575 (+76610.53%)
Mutual labels:  date, datepicker
Persianrangedatepicker
Persian range date picker for android.
Stars: ✭ 48 (+152.63%)
Mutual labels:  date, datepicker
Datepicker
A Date Picker with Calendar for iPhone and iPad Apps.
Stars: ✭ 103 (+442.11%)
Mutual labels:  date, datepicker
React Picky Date Time
A react component for date time picker. Online demo examples
Stars: ✭ 31 (+63.16%)
Mutual labels:  date, datepicker
Calendar
📆 calendar 日历
Stars: ✭ 119 (+526.32%)
Mutual labels:  date, datepicker
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (+4784.21%)
Mutual labels:  date, datepicker
Rsdayflow
iOS 7+ Calendar (Date Picker) with Infinite Scrolling.
Stars: ✭ 843 (+4336.84%)
Mutual labels:  date, datepicker
Vuetify Daterange Picker
The missing date range picker for Vuetify JS you have been looking for.
Stars: ✭ 192 (+910.53%)
Mutual labels:  date, datepicker
Calendarview
A highly customizable calendar library for Android, powered by RecyclerView.
Stars: ✭ 2,862 (+14963.16%)
Mutual labels:  date, datepicker

react-modern-datepicker

npm (scoped)

A modern date picker for react library. (Now customizable) . Built using React, Dayjs and styled-components

Date view

Date view Date view Date view

Customizable

Date view Date view Date view Date view Date view Date view Date view Date view

Installation

The package can be installed via NPM:

npm install react-modern-datepicker --save

This package doesn't come with any dependency other than dayjs (momentjs deprecated) & styled-components. Threfore, You’ll need to install React, PropTypes separately since those dependencies aren’t included in the package. Below is a simple example of how to use the ModernDatepicker in a React view.

import React from 'react';
import ModernDatepicker from 'react-modern-datepicker';

class Example extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			startDate: new Date(), // can be any of these ['dayjs()', '', null, new Date(2018,12,1)]
		};
		this.handleChange = this.handleChange.bind(this);
	}

	handleChange(date) {
		this.setState({
			startDate: date,
		});
	}

	render() {
		return (
			<ModernDatepicker
				date={this.state.startDate}
				format={'DD-MM-YYYY'}
				showBorder
				onChange={date => this.handleChange(date)}
				placeholder={'Select a date'}
			/>
		);
	}
}

Important Note

The previous versions of this library ( < v0.8) were using momentjs as a dependency which has been replaced by dayjs (mostly due to the bundle size). Since momentjs has been removed, the support for locale i.e lang has also been removed.

Adding your own theme

You can now add your own theme to customize the ModernDatepicker.You can do this with the help of primaryColor, secondaryColor, primaryTextColor, secondaryTextColor props. The following example shows how to customize the ModernDatepicker.

import React from 'react';
import ModernDatepicker from 'react-modern-datepicker';
import dayjs from 'dayjs';
import './App.css';
import icon from '../assets/icon.png'; // if you want to show an icon

class Example extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			startDate: new Date(), // can be any of these ['dayjs()', '', null, new Date(2018,12,1)]
		};
		this.handleChange = this.handleChange.bind(this);
	}

	handleChange(date) {
		this.setState({
			startDate: date,
		});
	}

	render() {
		return (
			<ModernDatepicker
				date={this.state.startDate}
				format={'DD-MM-YYYY'}
				showBorder
				allowEdit
				className="color"
				id="someId"
				icon={icon}
				maxDate={dayjs().add('1', 'day')} // can be a javascript date object also (new Date(2018,12,12))
				minDate={dayjs().subtract('2', 'day')}// can be a javascript date object also (new Date(2018,12,1))
				onChange={date => this.handleChange(date)}
				placeholder={'Select a date'}
				primaryColor={'#d9b44a'}
				secondaryColor={'#75b1a9'}
				primaryTextColor={'#4f6457'}
				secondaryTextColor={'#acd0c0'}
			/>
		);
	}
}

Please note that these props (primaryColor, secondaryColor, primaryTextColor, secondaryTextColor) , takes a valid color scheme as a string.(like HEX or RGB format).

Adding your own CSS

You can also pass your own css to style the input element.The following example shows how to style the input element using your own css.

./App.css

//Please  note that, for this class to take the precedence over the
//default css, we should repeat the class name like below (instead of .color, we are
// using .color.color)
.color.color {
	border-radius: 0;
	-moz-border-radius: 0;
	-webkit-border-radius: 0;
	font-size: 15px;
	font-weight: 600;
	padding: 10px 10px 10px 5px;
	border-bottom: 1px solid #ebebeb !important;
	border: none;
	box-sizing: border-box;
	margin-top: 22px;
	box-shadow: none;
	font-family: Open Sans, sans-serif;
}

./App.js

import React from 'react';
import ModernDatepicker from 'react-modern-datepicker';
import dayjs from 'dayjs';
import './App.css';
import icon from '../assets/icon.png'; // if you want to show an icon

class Example extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			startDate: dayjs(),
		};
		this.handleChange = this.handleChange.bind(this);
	}

	handleChange(date) {
		this.setState({
			startDate: date,
		});
	}

	render() {
		return (
			<ModernDatepicker
				date={this.state.startDate}
				format={'DD-MM-YYYY'}
				showBorder
				className="color"
				icon={icon}
				onChange={date => this.handleChange(date)}
				placeholder={'Select a date'}
			/>
		);
	}
}

Passing min and max date

You can also pass min and max date to the component.The following example shows how to pass min and max date.

import React from 'react';
import ModernDatepicker from 'react-modern-datepicker';
import dayjs from 'dayjs';
import './App.css';
import icon from '../assets/icon.png'; // if you want to show an icon

class Example extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			startDate: dayjs(),
		};
		this.handleChange = this.handleChange.bind(this);
	}

	handleChange(date) {
		this.setState({
			startDate: date,
		});
	}

	render() {
		return (
			<ModernDatepicker
				date={this.state.startDate}
				format={'DD-MM-YYYY'}
				showBorder
				allowEdit
				className="color"
				id="someId"
				icon={icon}
				maxDate={dayjs().add('1', 'day')}
				minDate={dayjs().subtract('2', 'day')}
				onChange={date => this.handleChange(date)}
				placeholder={'Select a date'}
			/>
		);
	}
}

If you pass invalid min or max date, it will show the corresponding error.

Passing Language and Label (This feature has been deprecated as of now.)

You can also pass language and label to the component.The following example shows how to pass language and label, using props lang and label.

Configuration

The most basic use of the ModernDatepicker can be described with:

<ModernDatepicker date={this.state.date} onChange={this.handleChange} showBorder />

The default format prop is DD-MM-YYYY if not specified.

Options

The following are the props that you can pass to ModernDatepicker Component :

props Default Optional Description
date null true This prop takes the date that you want to show, in string format, a javascript date object(new Date()) or as an instance of dayjs
format 'DD-MM-YYYY' true This prop takes the format you want to set for your date
showBorder false true This prop takes a boolean to show or not to show borders around the input
allowEdit false true This prop takes a boolean to edit the input field manually
onChange null false This props takes a function, with the date passed to its parameters
placeholder null true This props takes a string to show when no date is selected
className null true This props takes any external css/scss you want to use to override the default one.
icon null true This props takes an image you want to add as an icon.
iconClass null true This props takes any external css/scss, that you want to use to style your icon
maxDate null true This props takes the maximum date. (expects you to provide the same format as the date)
minDate null true This props takes the minimum date. (expects you to provide the same format as the date)
id null true This props takes the id as a string, that you want to pass to the input element
label null true This props takes the label as a string, that you want to show for the input element
labelClass null true This props takes any external css/scss, that you want to use to style your label
lang en true This props takes the language as a string, that you want to show in the calendar
onFocus null true This props takes the function to call on onFocus event
onBlur null true This props takes the function to call on onBlur event
primaryColor null true This props takes the color code in string format, and applies it to the selected date section
secondaryColor null true This props takes the color code in string format, and applies it to the body of the datepicker
primaryTextColor null true This props takes the color code in string format, and applies it to the text of the body of the datepicker
secondaryTextColor null true This props takes the color code in string format, and applies it to the selected text of the body of the datepicker

Compatibility

React

Compatible with the latest version of react i.e v16.X.X

Latest compatible versions:

  • React 16.0.0 or newer: All above React-datepicker v.0.2.0

Browser Support

The date picker is compatible with the latest versions of Chrome, Firefox, and IE10+.

License

Apache License see LICENSE for the full license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].