DatePicker() → {JSX.Element}
Component that displays a date picker
Name | Type | Description |
---|---|---|
setModalIsOpen | Object | State function used to close the modal. |
clickedInput | String | The id of the input filed to attach the date picker modal to |
endYear | Number | (optionnal) The last year to display. Default : current year |
yearCount | Number | (optionnal) The number of years to display. Default : 100 |
- Source
A JSX.Element that contains the modal.
- Type:
- JSX.
Element
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.
Name | Type | Description |
---|---|---|
amount | number | The amount to change the month by. |
- Source
(inner) changeYear(year)
Change the selected year to a specific year.
Name | Type | Description |
---|---|---|
year | number | The year to set as the selected year. |
- Source
(inner) datePickerNavigator() → {JSX.Element}
Render the navigator for the date picker.
- Source
JSX elements for the date picker navigator.
- Type:
- JSX.
Element
(inner) generateDays() → {JSX.Element}
Generate the days to be displayed.
- Source
JSX elements representing the days.
- Type:
- JSX.
Element
(inner) generateMonths() → {JSX.Element}
Generate the months to be displayed.
- Source
JSX elements representing the months.
- Type:
- JSX.
Element
(inner) generateYears() → {JSX.Element}
Generate the years to be displayed.
- Source
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.
- Source
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.
Name | Type | Description |
---|---|---|
date | Date | The selected date. |
- Source
(inner) selectMonth(month)
Select a specific month.
Name | Type | Description |
---|---|---|
month | number | The month to select. |
- Source
(inner) toggleMonthScreen()
Toggle the month selection screen.
- Source
(inner) toggleYearScreen()
Toggle the year selection screen.
- Source