0.0.5 • Published 4 years ago

react-trip-date-arron v0.0.5

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
4 years ago

npm downloads dependencies dev dependencies

React-Trip-Date

A date/range picker for your React applications. it was a package for Tripema.com

  • Multiple Month, Custom Responsive, Number Of Selectable Days
  • Range Picker, Hoverable, Theme base
  • Support Jalali & Gregorian
  • Use Day.js (2KB immutable date and NO moment.js is needed)
  • Bundle size, 30kB (minified + GZipped 9.2 kB)

Demo

Online demo is also available!

OR

To run that demo on your own computer:

Getting started

Compatibility

Your project needs to use React 16 or later. If you use older version of React, please refer to the table below to find suitable React-Trip-Date version.

Installation

Add React-Trip-Date to your project by executing npm install react-trip-date or yarn add react-trip-date

if you don't installed styled-components and classnames, you need to install them. npm install styled-components classnames or yarn add styled-components classnames

Usage

Here's an example of basic usage:

import React, { Component } from 'react';
import { DatePicker, RangePicker, theme } from 'react-trip-date';
import {ThemeProvider} from 'styled-components';
const  handleResponsive  =  setNumberOfMonth  =>  {
	let  width  =  document.querySelector('.tp-calendar').clientWidth;
	if  (width  >  900)  {
		setNumberOfMonth(3);
	}  else  if  (width  <  900  &&  width  >  580)  {
		setNumberOfMonth(2);
	}  else  if  (width  <  580)  {
		setNumberOfMonth(1);
	}
};

const  Day = ({  day  }) => {
	return  (
		<>
			<p  className="date">{day.format('DD')}</p>
			<p  className="date">7</p>
		</>
		);
	};
	
class MyApp extends Component {

  onChange = date => console.log(date)

  render() {
    return (
      <ThemeProvider theme={theme}>
        <DatePicker
          handleChange={onChange}
		  selectedDays={['2019-11-06']} //initial selected days
		  jalali={false}
		  numberOfMonths={3}
		  numberOfSelectableDays={3} // number of days you need 
		  disabledDays={['2019-12-02']} //disabeld days
		  responsive={handleResponsive} // custom responsive, when using it, `numberOfMonths` props not working
		  disabledBeforToday={true} 
		  disabled={false} // disable calendar 
		  dayComponent={Day} //custom day component 
		  titleComponent={Title} // custom title of days
        />
      </ThemeProvider>
    );
  }
}

Custom styling

If you don't want to use default React-Trip-Date styling to build upon it, you can import theme by using import { theme } from 'react-trip-date instead and custom it.

User guide

DatePicker

Props

Prop nameDescriptionDefault valueExample values
handleChangeis a function that return an array of daysn/a(days) => console.log('selected days',days)
selectedDaysthe initial array of days[]['2019-10-01','2019-11-06']
jalalichoice jalali or gregorian calendarfalsefalse/true
numberOfMonthsnumber of months you need12
numberOfSelectableDaysnumber of days you need0/Infiniti3
disabledDaysthe disabled days that you don't want clickable[]['2019-11-04',2019-12-14]
responsivecustom responsive is function and have a argument for change number of month, when using it, numberOfMonths props not working(setNumberOfMonth => setNumberOfMonth(3))
disabledBeforTodaydisabled days before todaytruetrue/false
disableddisabled date pickerfalsetrue/false
dayComponentcustom day componentn/aDay = ({ day }) =><p>{day.format('DD')}</p>
titleComponentcustom title of days weekn/aconst Title=({source })=>{let titleDay = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']return ({titleDay.map(item=>(<p key={Math.random()}>{item}</p>))})}

RangePicker

Props

Prop nameDescriptionDefault valueExample values
handleChangeis a function that return an array of daysn/a(days) => console.log('selected days',days)
selectedDaysthe initial range date{from:'',to:''}{from:'2019-12-12',to:'2019-12-18'}
jalalichoice jalali or gregorian calendarfalsefalse/true
numberOfMonthsnumber of months you need12
hoverablechange range date when user hover daytruetrue/false
disabledDaysthe disabled days that you don't want clickable[]['2019-11-04',2019-12-14]
responsivecustom responsive is function and have a argument for change number of month, when using it, numberOfMonths props not workingn/a(setNumberOfMonth => setNumberOfMonth(3))
disabledBeforTodaydisabled days before todaytruetrue/false
disableddisabled date pickerfalsetrue/false
dayComponentcustom day componentn/aDay = ({ day }) =><p>{day.format('DD')}</p>
titleComponentcustom title of days weekn/aconst Title=({source })=>{let titleDay = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']return ({titleDay.map(item=>(<p key={Math.random()}>{item}</p>))})}

special thanks to:

Contributors

feel free to contribute.

License

The GNU GPLv3 License.