Skip to main content
K
Last modified: 24/Jun/2024

Datepicker

Use the Datepicker component to allow users pick a single date or a date range.

#Usage

#Only date picker

import { useState } from 'react' import { Datepicker } from '@kinsta/stratus' export const MyComponent = () => { const [date, setDate] = useState<Date>(new Date(Date.now())) return <Datepicker currentDate={date} onDateChange={setDate} /> }

#Date and time picker

import { useState } from 'react' import { Datepicker } from '@kinsta/stratus' export const MyComponent = () => { const [date, setDate] = useState<Date>(new Date(Date.now())) return <Datepicker currentDate={date} onDateChange={setDate} hasTimeSelector /> }

#Only time picker

import { useState } from 'react' import { Datepicker } from '@kinsta/stratus' export const MyComponent = () => { const [date, setDate] = useState<Date>(new Date(Date.now())) return ( <Datepicker currentDate={date} onDateChange={setDate} hasTimeSelector hasDateSelector={false} /> }

#Props

The Datepicker components interface extends the HTMLElement interface. So you can use any props which documented there. Also, you can utilize all the React Synthetic events (on*), and props related to styling (className, style). These will all be applied to the Datepicker's wrapper except for placeholder, which will change the placeholder of the Date input.

#currentDate
Date
The current date and time
#minDate
Date
The minimum of the selectable date
#maxDate
Date
The maximum of the selectable date
#firstDayOfWeek
Day
First day of the week
0
#dateLabel
string
Title of the date field
#timeLabel
string
Title of the time field
#prevLabel
string
Text to the previous arrow in the date selector
#nextLabel
string
Text to the next arrow in the date selector
#hasTimeSelector
boolean
If it is set to true it renders the Time selector field
false
#hasDateSelector
boolean
If it is set to true it renders the Date selector field
true
#isMonthShort
boolean
It renders the month in short format
false
#onDateChange
(date: Date) => void
The function to be called if the date is selected
#placeholder
string
Placeholder of the date field

#Types

  • DatepickerProps: props of the Datepicker component processed by stratus
  • DatepickerInterface: DatepickerProps extended by HTMLAttributes<HTMLElement>

Read more about types here