# Calendar (@limerdev/zest) A month calendar to pick a date: `type="single"` binds a `DateValue` (a `CalendarDate` from `@limerdev/zest/date`, all of `@internationalized/date`), `type="multiple"` a `DateValue[]`. `minValue`, `maxValue`, `isDateDisabled`, `isDateUnavailable`, `numberOfMonths`, `weekStartsOn`, `locale`. With no children it draws the header and month grids; the parts (`Header`, `Heading`, `PrevButton`, `NextButton`, `Months`, `Grid`, `GridHead`, `GridBody`, `GridRow`, `HeadCell`, `Cell`, `Day`) are there for custom layouts. Arrow keys move between days, Page Up and Down between months, Enter or Space picks. - Category: Data input - Import: `import { Calendar } from '@limerdev/zest'` - Bits UI: `Calendar`, https://bits-ui.com/docs/components/calendar - Exports: `Calendar.Root`, `Calendar.Header`, `Calendar.Heading`, `Calendar.PrevButton`, `Calendar.NextButton`, `Calendar.Months`, `Calendar.Grid`, `Calendar.GridHead`, `Calendar.GridBody`, `Calendar.GridRow`, `Calendar.HeadCell`, `Calendar.Cell`, `Calendar.Day` - Use for: Picking a date where seeing the month helps: a deadline, an absence day, a delivery date. In a form, `DatePicker` puts it in a popover. - Don't: A date people know and type (a birth date): use `DateField`. A range of dates: use `RangeCalendar`. ```svelte ``` Props of `Calendar.Root`: - `calendarLabel` (`string`): This label is exclusively used for accessibility, remaining hidden from the page. It's read by screen readers when the calendar is opened. The current month and year are automatically appended to the label, so you only need to provide the base label. For instance: - 'Date of birth' will be read as 'Date of birth, January 2021' if the current month is January 2021. - 'Appointment date' will be read as 'Appointment date, January 2021' if the current month is January 2021. - 'Booking date' will be read as 'Booking date, January 2021' if the current month is January 2021. - `disabled` (`boolean`, default `false`): Whether or not the calendar is disabled. - `disableDaysOutsideMonth` (`boolean`, default `false`): Whether to disable the selection of days outside the current month. By default, days outside the current month are rendered to fill the calendar grid, but they are not selectable. Setting this prop to `true` will disable this behavior. - `fixedWeeks` (`boolean`, default `false`): Display 6 weeks per month, regardless the month's number of weeks. This is useful for displaying a consistent calendar, where the size of the calendar doesn't change month to month. To display 6 weeks per month, you will need to render out the previous and next month's dates in the calendar as well. - `initialFocus` (`boolean`): If `true`, the calendar will focus the selected day, today, or the first day of the month in that order depending on what is visible when the calendar is mounted. - `isDateDisabled` (`DateMatcher`): A function that receives a date and returns `true` or `false` to indicate whether the date is disabled. - `isDateUnavailable` (`DateMatcher`): Dates matching the provided matchers are marked as "unavailable." Unlike disabled dates, users can still focus and select unavailable dates. However, selecting an unavailable date renders the date picker as invalid. For example, in a calendar for booking appointments, you might mark already booked dates as unavailable. These dates could become available again before the appointment date, allowing users to select them to learn more about the appointment. `[data-unavailable]` - applied to unavailable dates - `locale` (`string`, default `'en'`): The default locale setting. - `maxDays` (`number`, default `undefined`): The maximum number of days that can be selected in multiple mode. When set, users cannot select more dates than this number. - `maxValue` (`DateValue`): The maximum date that can be selected in the calendar. - `minValue` (`DateValue`): The minimum date that can be selected in the calendar. - `monthFormat` (`"numeric" | "long" | "short" | "narrow" | "2-digit" | ((month: number) => string)`, default `"long"`): The format of the month names in the calendar. - `numberOfMonths` (`number`, default `1`): Determines the number of months to display on the calendar simultaneously. For navigation between months, refer to the `pagedNavigation` prop. - `onPlaceholderChange` (`OnChangeFn`): A callback function called when the placeholder value changes. - `onValueChange` (`OnChangeFn | OnChangeFn`): A callback function called when the value changes. - `pagedNavigation` (`boolean`, default `false`): Applicable only when `numberOfMonths` is greater than 1. Controls whether to use paged navigation for the next and previous buttons in the date picker. With paged navigation set to `true`, clicking the next/prev buttons changes all months in view. When set to `false`, it shifts the view by a single month. For example, with `pagedNavigation` set to `true` and 2 months displayed (January and February), clicking the next button changes the view to March and April. If `pagedNavigation` is `false`, the view shifts to February and March. - `placeholder` (`DateValue`, default `the current date`, bindable): The placeholder date, used to control the view of the calendar when no value is present. - `preventDeselect` (`boolean`, default `false`): Whether or not users can deselect a date once selected without selecting another date. - `readonly` (`boolean`, default `false`): Whether the calendar is readonly. When true, the user will be able to focus and navigate the calendar, but will not be able to select dates. - `type` (`"multiple" | "single"`, required): The type of calendar. If set to `'single'`, the calendar will only allow a single date to be selected. If set to `'multiple'`, the calendar will allow multiple dates to be selected. - `value` (`DateValue | DateValue[]`, bindable): The value of the selected date in the calendar. The value of the selected dates in the calendar. - `weekdayFormat` (`"long" | "short" | "narrow"`, default `'short'`): How the string representation of the weekdays provided via the `weekdays` state store should be formatted. ```md - "long": "Sunday", "Monday", "Tuesday", etc. - "short": "Sun", "Mon", "Tue", etc. - "narrow": "S", "M", "T", etc. ``` - `weekStartsOn` (`0 | 1 | 2 | 3 | 4 | 5 | 6`, default `0 (Sunday)`): The day of the week to start the calendar on, which must be a number between 0 and 6, where 0 is Sunday and 6 is Saturday. - `yearFormat` (`"numeric" | "2-digit" | ((year: number) => string)`, default `"numeric"`): The format of the year names in the calendar. Props of `Calendar.Cell`: - `date` (`DateValue`, required): The date value of the cell. - `month` (`DateValue`, required): The month DateValue that this cell is being rendered in. Example: Basic A single date. Arrow keys move between days, Page Up and Down between months. ```svelte

Picked: {date?.toString() ?? 'nothing'}

``` Example: Two months and limits numberOfMonths shows several; minValue and isDateUnavailable limit the choice. Date helpers such as isWeekend come from @limerdev/zest/date, all of @internationalized/date. ```svelte isWeekend(value, 'en-GB')} class="rounded-box border-(length:--border) border-border bg-base-100 shadow-field" /> ```