The calendar component is a web component that displays a calendar with the ability to select a date.
The calendar component is using the dayjs library to handle dates. The best way to use the calendar component if you are using the dayjs library in your project. The component settings are properties, not attributes, so you have to set them in JavaScript.
The calendar component can be used to select a date. The default date is the current date.
<dap-ds-calendar></dap-ds-calendar>
The value property can be used to set the selected date.
HTML
Js
const calendar = document.querySelector('dap-ds-calendar')
calendar.value = dayjs().add(1, 'day')
The currentDate
property can be used to set the current visible date. Only the month and year are considered.
HTML
Js
const calendar = document.querySelector('dap-ds-calendar')
calendar.currentDate = new Date('2022-08-15T22:00:00.000Z')
calendar.value = dayjs('2022-08-13T22:00:00.000Z')
The minDate
and maxDate
properties can be used to set the minimum and maximum date of the calendar. Only the month and year are considered.
In this example the minDate
is set to the previous month and the maxDate
is set to the next month, so you can do the paging only between the previous and next month.
HTML
Js
const calendar = document.querySelector('dap-ds-calendar')
calendar.minDate = dayjs().add(-1, 'month')
calendar.maxDate = dayjs().add(1, 'month')
calendar.value = dayjs()
The disabledDate
property can be used to set a function to determine if the date is disabled. The function should return true
if the date is disabled.
In this example the disabledDate
function is set to disable the weekends.
HTML
JS
const calendar = document.querySelector('dap-ds-calendar')
calendar.disabledDate = (date) => date.day() === 0 || date.day() === 6
The locale
property can be used to set the locale of the calendar. The default locale is the current locale of the browser.
The available locales are en
and hu
.
HTML
Hungarian locale
English locale
Js
const calendar = document.querySelector('dap-ds-calendar')
calendar.locale = 'hu'
calendar.value = dayjs().add(1, 'day')
import { DapDSCalendar } from 'dap-design-system/dist/dds'
import { DapDSCalendarReact } from 'dap-design-system/dist/react'
Property | Type | Default | Description |
---|---|---|---|
value | Dayjs | The value of the calendar. | |
currentDate | Dayjs | dayjs() | The current visible date of the calendar. Only the month and year are considered. |
minDate | Dayjs | dayjs('1901-01-01') | The minimum date of the calendar. Only the month and year are considered. |
maxDate | Dayjs | dayjs('2099-12-31') | The maximum date of the calendar. Only the month and year are considered. |
disabledDate | Function | () => false | The function to determine if the date is disabled. |
locale | string | dayjs.locale() | The locale of the calendar. |
Name | Description |
---|---|
(default) | The content of the calendar. |
Event Name | Description |
---|---|
dds-change | Fired when the calendar value changes. |
Part Name | Description |
---|---|
base | The main calendar container. |
header | The header of the calendar. |
body | The body of the calendar. |
Property Name | Description |
---|---|
--dds-calendar-display | The display property of the calendar container. Default is flex. |
--dds-calendar-isolation | The isolation property of the calendar. Default is isolate. |
--dds-calendar-block-display | The display property of the calendar block. Default is block. |
--dds-calendar-transition | The transition property for the calendar. Default is 'all 0.2s ease-in-out'. |
--dds-calendar-header-display | The display property of the calendar header. Default is grid. |
--dds-calendar-header-grid-flow | The grid-auto-flow property of the calendar header. Default is column. |
--dds-calendar-header-width | The width of the calendar header. Default is 100%. |
--dds-calendar-header-gap | The gap between header items. Default is the design system's spacing-100. |
--dds-calendar-select-min-height | The minimum height of the select trigger. Default is auto. |
--dds-calendar-select-max-height | The maximum height of the select trigger. Default is 32px. |
--dds-calendar-select-padding | The padding of the select trigger. Default is the design system's spacing-200. |
--dds-calendar-select-border-radius | The border radius of the select trigger. Default is the design system's radius-rounded. |
--dds-calendar-select-border-color | The border color of the select trigger. Default is the design system's border-neutral-transparent-interactive. |
--dds-calendar-select-background | The background color of the select trigger. Default is the design system's button-subtle-background-enabled. |
--dds-calendar-select-color | The text color of the select trigger. Default is the design system's button-subtle-text-enabled. |
--dds-calendar-select-font-size | The font size of the select trigger. Default is the design system's font-sm. |
--dds-calendar-select-font-style | The font style of the select trigger. Default is normal. |
--dds-calendar-select-font-weight | The font weight of the select trigger. Default is the design system's font-weight-bold. |
--dds-calendar-nav-button-margin | The margin of the navigation buttons. Default is the design system's spacing-200. |
--dds-calendar-nav-button-color | The color of the navigation button icons. Default is the design system's button-subtle-icon-enabled. |
Property | Type | Default | Description |
---|---|---|---|
value | Dayjs | The value of the calendar cell. | |
selected | boolean | false | Whether the calendar cell is selected. |
disabledDay | boolean | false | Whether the calendar cell is disabled. |
today | boolean | false | Whether the calendar cell is today. |
outOfRange | boolean | false | Whether the calendar cell is out of range. |
header | boolean | false | Whether the calendar cell is a date header. |
focused | boolean | false | Whether the calendar cell is focused. |
Name | Description |
---|---|
(default) | The content of the calendar cell. |
No custom events available.
Part Name | Description |
---|---|
base | The main calendar cell container. |
today-mark | The today mark of the calendar cell. |
No CSS custom properties available.