DatePicker

DatePicker() → {JSX.Element}

Component that displays a date picker

Properties
NameTypeDescription
setModalIsOpenObject

State function used to close the modal.

clickedInputString

The id of the input filed to attach the date picker modal to

endYearNumber

(optionnal) The last year to display. Default : current year

yearCountNumber

(optionnal) The number of years to display. Default : 100

Returns:

A JSX.Element that contains the modal.

Type: 
JSX.Element
Example
import { DatePicker } from 'date-picker-nextjs'
import { useState } from 'react'

const Example = () => {
  const [modalDateIsOpen, setModalDateIsOpen] = useState(false)
  const [clickedInput, setClickedInput] = useState(null)

  const handleDatePicker = (e) => {
    setClickedInput(e.target.id)
    setModalDateIsOpen(true)
  }

  const submit = (e) => {
    e.preventDefault()
    // your logic
  }

  return (
    <form
      className='test'
      onSubmit={submit}
    >
      <label htmlFor='birthdate'>Birthdate</label>
      <input
        className='input-field outline-none'
        type='text'
        id='dateOfBirth'
        placeholder='Date of birth'
        onClick={handleDatePicker}
      />

      <input
        type='submit'
        value='Submit'
      />
    </form>
    {modalDateIsOpen && (
        <DatePicker
          setModalDateIsOpen={setModalDateIsOpen}
          clickedInput={clickedInput}
        />
      )}
  )
}

export default Example

Methods

(inner) changeMonth(amount)

Change the selected month by a specified amount.

Parameters:
NameTypeDescription
amountnumber

The amount to change the month by.

(inner) changeYear(year)

Change the selected year to a specific year.

Parameters:
NameTypeDescription
yearnumber

The year to set as the selected year.

(inner) datePickerNavigator() → {JSX.Element}

Render the navigator for the date picker.

Returns:

JSX elements for the date picker navigator.

Type: 
JSX.Element

(inner) generateDays() → {JSX.Element}

Generate the days to be displayed.

Returns:

JSX elements representing the days.

Type: 
JSX.Element

(inner) generateMonths() → {JSX.Element}

Generate the months to be displayed.

Returns:

JSX elements representing the months.

Type: 
JSX.Element

(inner) generateYears() → {JSX.Element}

Generate the years to be displayed.

Returns:

JSX elements representing the years.

Type: 
JSX.Element

(inner) getFirstDayOfWeek() → {number}

Get the day of the week for the first day of the selected month.

Returns:

The day of the week for the first day.

Type: 
number

(inner) selectDate(date)

Select a specific date and set it as the input value.

Parameters:
NameTypeDescription
dateDate

The selected date.

(inner) selectMonth(month)

Select a specific month.

Parameters:
NameTypeDescription
monthnumber

The month to select.

(inner) toggleMonthScreen()

Toggle the month selection screen.

(inner) toggleYearScreen()

Toggle the year selection screen.