@schedule-x/date-picker
A demo can be found at: https://schedule-x.dev/demos/date-picker
Install
npm install @schedule-x/date-picker @schedule-x/theme-default
Setup
import { createDatePicker } from '@schedule-x/date-picker'
import '@schedule-x/theme-default/dist/date-picker.css'
const datePicker = createDatePicker({
listeners: {
onChange: (date) => {
console.log('date changed', date)
},
},
})
datePicker.render(document.getElementById('date-picker'))
First, we create a date picker instance with the createDatePicker
function. This function takes a configuration
object as its only argument. With the onChange
listener, this sets us up to react to the selection of a date.
Finally, the render
method is called, rendering the date picker into the element specified as the single argument.
Methods and properties
value
(string property)
The value
property is used to get or set the selected date. It needs to have the format YYYY-MM-DD
.
disabled
(boolean property)
The disabled
property is used to get or set the disabled state of the date picker.
setTheme(theme: 'light' | 'dark')
The setTheme
method is used to set the theme of the date picker
getTheme(): 'light' | 'dark'
The getTheme
method is used to get the current theme of the date picker
Configuration
Below is an example of how to configure the date picker, containing all the currently available options.
import { createDatePicker } from '@schedule-x/date-picker'
import '@schedule-x/theme-default/dist/date-picker.css'
const config = {
locale: 'zh-CN',
firstDayOfWeek: 0,
selectedDate: '2023-12-24',
label: 'Select a date',
name: 'date-picker',
teleportTo: document.body,
placement: 'bottom-end',
min: '2020-01-01',
max: '2025-01-01',
style: {
isDark: true,
fullWidth: true,
},
listeners: {
onChange: (date) => {
console.log('date changed', date)
},
onEscapeKeyDown: ($app) => {
$app.timePickerState.isOpen.value = false
},
},
}
const datePicker = createDatePicker(config)
datePicker.render(document.getElementById('date-picker'))