5.1.0 • Published 9 months ago

ftc-datepicker v5.1.0

Weekly downloads
6
License
ISC
Repository
github
Last release
9 months ago

��# ftc-datepicker

  • Ultimate calendar for your React app.
  • Supports range selection

tl;dr

  • Install by executing npm install ftc-datepicker or yarn add ftc-datepicker
  • Import by adding import DatePicker from 'ftc-datepicker';
  • Use by adding <DatePicker />
  • For getting selected date/range use this prop: selectCallbackFN

Getting started

Installation

Add ftc-datepicker to your project by executing

npm install ftc-datepicker

or

yarn add ftc-datepicker

Usage

Here's an example of basic usage:

import React, { Component } from 'react';
import DatePicker from 'ftc-datepicker';

class MyApp extends Component {
  constructor() {
    super();
    this.state = {
      startDate: new Date(2020, 5, 1),
      endDate: new Date(2020, 6, 4)
    }
  }
  
  onSelect = ({startDate, endDate}) => this.setState({
    startDate: startDate,
    endDate: endDate
  });

  render() {
    return (
      <div>
        <div>{this.state.startDate} - {this.state.endDate}</div>
        <DatePicker
          startDate={new Date(2020, 5, 1)}
          endDate={new Date(2020, 6, 4)}
          onSelect={this.onSelect}
        />
      </div>
    );
  }
}

User guide

Props

Prop nameProp descriptionProp typeDefault valueExample values
isPopUpA boolean determines whether it will be a popup or notBooleanfalsetrue or false
isRangePickerA boolean determines whether it will be a date range selector or not (It cannot be used in combination with isFlexibleDate)Booleanfalsetrue or false
isFlexibleDateA boolean determines whether it will be a flexible selector or not (It cannot be used in combination with isRangePicker)Booleanfalsetrue or false
showDateRangeDetailsA boolean determines whether it will show the selected date/range details in the date pickerBooleanfalsetrue or false
showTitleDropDownA boolean determines whether it will show a dropdown with a list of months in each month title or not.Booleanfalsetrue or false
showInputLabelOnly activated if isPopUp is true, and it determines whether it will show the label of the date picker input or notBooleanfalsetrue or false
selectedDateCanBeOutOfAllowedRangeA boolean determines whether selected date can be (before minDate or after maxDate) or not.Booleanfalsetrue or false
flexibleDateRangesOnly activated if isFlexibleDate is set to true. It is an array of all flexible date rangesArray of Numbers[][1, 2, 3]
flexibleDateRangesLabelsOnly activated if isFlexibleDate is set to true. It is an array of all flexible date ranges labelsArray of Strings['� 1 day', '� 2 days', ...]['� 1 day', '� 2 days', '� 3 days']
flexibleDateRangeOnly activated if isFlexibleDate is set to true. It is the default flexible date range. It should be one of the flexibleDateRanges array.Number02
flexibleDateTitleOnly activated if isFlexibleDate is set to true. It is a title that will be shown above the flexible date ranges buttonsString'Arrival day earlier or later''Any title ...'
flexibleDateSelectButtonLabelOnly activated if isFlexibleDate is set to true.String'Select''Any label ...'
firstDayInWeekShiftA number between 0 and 6 sets the beginning of the week. 0 is for Monday and 6 is for SundayNumber04
monthsInDatePickerA number sets how many months to showNumber12
monthStepA number sets the value of the months change step when the previous or next buttons are pressedNumber12
selectedDaysInOneClickOnly activated if isRangePicker is set to false. And by giving it a value more than 1 you can select more than one day in one clickNumber13
dayNameLengthA number that sets the length of day names in the month table headerNumber39
weekEndsAn array that sets the indexes of the weekends. Monday's index is is 0 and Sunday's index is 6Array of Numbers[5, 6][6]
inputDateFormatOnly activated when isPopUp is set to true and it can be a function or a string specifies how the selected date in the date picker input will be shown. For example 8/March/2019:yyyy: 2019yy: 19MMMM: MarchMMM: MarMM: MaM: Mmm: 03m: 3DDDD: FridayDDD: FriDD: FrD: Fdd: 08d: 8String OR Function(Date) => String'DDD, MMM dd yyyy''d/m/yyyy'
headerDateFormatPIt can be a function or a string specifies how the month header will be shown. The same format pattern used in inputDateFormatString OR Function(Date) => String'MMMM yyyy''mm-yyyy'
datePickerRangeFormatPIt can be a function or a string specifies how the selected date/range will be shown. The same format pattern used in inputDateFormatString OR Function(Date) => String'dd/mm/yyyy''d-m-yyyy'
inputPlaceholderOnly activated if isPopUp is true, and it sets the placeholder text for the date picker inputString'Click here to select date''Select date'
inputLabelOnly activated if both isPopUp & showInputLabel are true, and it sets the label text for the date picker inputString'Click here to select date''Select date'
monthNamesUse it to provide your own month namesArray of Strings['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
dayNamesUse it to provide your own day names. Please note that the array should start with Monday's nameArray of Strings['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
minDateTo prevent showing or selecting dates before this date. If not provided, there will be no minimum limitDatenullnew Date(2010, 2, 4)
maxDateTo prevent showing or selecting dates after this date. If not provided, there will be no maximum limitDatenullnew Date(2025, 3, 2)
startDateIf isRangePicker is set to true then this will be the initial start date, if not then it will be the initial selected dateDatenullnew Date(2019, 2, 9)
endDateOnly activated when isRangePicker is set to true and it represents the initial end dateDatenullnew Date(2019, 5, 4)
shownMonthThe initial shown monthDatenullnew Date()
firstMonthInMonthsDropDownOnly activated if showTitleDropDown is set to true, It sets the first month in the month title dropdownDateCurrent monthnew Date(2019, 2, 17)
lastMonthInMonthsDropDownOnly activated if showTitleDropDown is set to true, It sets the last month in the month title dropdownDateAfter 2 years from current monthnew Date(2021, 5, 21)
blackListArray of dates/ranges that you want to prevent the user from selecting themDate, {start: Date, end: Date}, Date, ...[][new Date(2019, 9, 30), new Date(2019, 11, 1), {start: new Date(2020, 2, 3), end: new Date(2020, 8, 1)}, ...]
onSelectA callback function that will be called each time the user selects a dateFunctionnull({startDate, endDate, shownMonth, flexibleDateRange}) => this.setState({start: startDate, end: endDate})
onMonthChangeA callback function that will be called each time the user shows a different monthFunctionnull({startDate, endDate, shownMonth}) => this.setState({start: startDate, end: endDate})
onToggleOnly activated if isPopUp is true. It ia a callback function that will be called each time the popup togglesFunctionnull(isOpen) => console.log('popup is ' + (isOpen ? 'open' : 'closed'))
dayTileTemplateTo provide your own template for day tilesFunctionnull({startDate, endDate, shownMonth, dayDate, dayLabel}) => <div><h1>{dayDate.getDate()}</h1><p>Some text</p></div>
inputPlaceholderIconTemplateTo add a template for the input placeholder iconFunctionnull({isOpen, startDate, endDate, shownMonth, flexibleDateRange}) => (isOpen ? <Some open icon /> : <Some closed icon />)
inputTemplateA template for the date picker input buttonFunctionnull({startDate, endDate, shownMonth, flexibleDateRange}) => <Some button />
inputClearButtonTemplateThis is a template to add a clear selection button to the date picker inputFunctionnull({startDate, endDate, shownMonth, flexibleDateRange}) => (startDate ? <Some clear icon /> : <Some picker icon />)
footerTemplateTo add a template for the date picker footerFunctionnull({startDate, endDate, shownMonth}) => <div></div>
previousButtonTemplateTo provide your own template for previous month buttonFunctionnull({startDate, endDate, shownMonth}) => <button>Previous</button>
nextButtonTemplateTo provide your own template for next month buttonFunctionnull({startDate, endDate, shownMonth}) => <button>Next</button>
monthTitleDropDownIconTemplateTo provide a template for the icon of the month dropdown titleFunctionnull({startDate, endDate, shownMonth, open}) => (open ? <Some icon /> : <Other icon />)

Authors

Mustapha Idrissi & Yaser Somaf
m.idrissi@freetimecompany.nl
y.somaf@freetimecompany.nl

5.1.0

9 months ago

5.0.0

9 months ago

3.3.1

10 months ago

3.3.0

10 months ago

4.1.0

10 months ago

4.0.1

10 months ago

4.0.0

10 months ago

4.1.1

10 months ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago