# RangeCalendar (@limerdev/zest) A month calendar to pick a range of dates: `bind:value` is `{ start, end }` of `DateValue`s (from `@limerdev/zest`). The first click sets the start, the second the end; the days between are highlighted. `minDays`, `maxDays`, `minValue`, `maxValue`, `isDateUnavailable`, `numberOfMonths`. With no children it draws the header and month grids; its parts are named like `Calendar`'s for custom layouts. - Category: Data input - Import: `import { RangeCalendar } from '@limerdev/zest'` - Bits UI: `RangeCalendar`, https://bits-ui.com/docs/components/range-calendar - Exports: `RangeCalendar.Root`, `RangeCalendar.Header`, `RangeCalendar.Heading`, `RangeCalendar.PrevButton`, `RangeCalendar.NextButton`, `RangeCalendar.Months`, `RangeCalendar.Grid`, `RangeCalendar.GridHead`, `RangeCalendar.GridBody`, `RangeCalendar.GridRow`, `RangeCalendar.HeadCell`, `RangeCalendar.Cell`, `RangeCalendar.Day` - Use for: Picking a period: a report's date range, an absence, a project phase. In a form, `DateRangePicker` puts it in a popover. - Don't: A single date: use `Calendar`. Dates people type: use `DateRangeField`. ```svelte ``` Props of `RangeCalendar.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. - `excludeDisabled` (`boolean`, default `false`): Whether to automatically reset the range if any date within the selected range becomes disabled. When true, the entire range will be cleared if a disabled date is found between the start and end dates. - `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. - `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 a range. - `maxValue` (`DateValue`): The maximum date that can be selected in the calendar. - `minDays` (`number`, default `undefined`): The minimum number of days that can be selected in a range. - `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. - `onEndValueChange` (`OnChangeFn`): A callback function called when the end value changes. This doesn't necessarily mean the `value` has updated and should be used to apply cosmetic changes to the calendar when only part of the value is changed/completed. - `onPlaceholderChange` (`OnChangeFn`): A callback function called when the placeholder value changes. - `onStartValueChange` (`OnChangeFn`): A callback function called when the start value changes. This doesn't necessarily mean the `value` has updated and should be used to apply cosmetic changes to the calendar when only part of the value is changed/completed. - `onValueChange` (`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. - `value` (`DateRange`, bindable): The value of the selected date range. - `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 `RangeCalendar.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 Click the first and last day of the period. ```svelte

{period.start?.toString() ?? '…'} – {period.end?.toString() ?? '…'}

```