import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; export type DatePickerDateRule = string | Date | { from: string | Date; to: string | Date } | ((date: Date) => boolean); export type CarbonDatePickerContext = { range: import("svelte/store").Readable; multiple: import("svelte/store").Readable; inputValue: import("svelte/store").Writable; inputValueFrom: import("svelte/store").Writable; inputValueTo: import("svelte/store").Writable; inputIds: import("svelte/store").Readable>; hasCalendar: import("svelte/store").Readable; dateFormat: import("svelte/store").Writable; locale: import("svelte/store").Writable>; conjunction: import("svelte/store").Writable; clearable: import("svelte/store").Writable; clearButtonLabelText: import("svelte/store").Writable; /** * Empties the selection (both ends in range mode), then returns focus to * the input, which opens the calendar the same way a click would. */ clear: () => void; isFluid: import("svelte/store").Writable; add: (data: { id: string; labelText: string }) => void; setReadonly: (id: string, readonly: boolean) => void; setDisabled: (id: string, disabled: boolean) => void; setValidation: (id: string, invalid: boolean, warn: boolean) => void; declareRef: (data: { id: string; ref: HTMLInputElement }) => void; /** * `fromCalendar` marks the native `change` the calendar fires after its * `onChange`, which has already dispatched `change`. */ updateValue: (data: { type: "input" | "change"; value: string; fromCalendar?: boolean }) => void; handleFormReset: () => void; openCalendar: () => void; /** * Returns `false` when there is no calendar to focus (simple mode, or a * failed or pending calendar init). */ focusCalendar: () => boolean; }; type $RestProps = SvelteHTMLElements["div"]; type $Props = { /** * Specify the date picker type. * Changing it after mount rebuilds the calendar. * `"week"` selects a whole week: a picked day becomes the first day of its * week, so `value` is that date in `dateFormat`. A `value` set from outside * is kept as given. * @default "simple" */ datePickerType?: "simple" | "single" | "range" | "month" | "quarter" | "year" | "week" | "multiple"; /** * Specify the date picker input value. * Follows the inputs when the owning form resets. * @default "" */ value?: number | string; /** * Specify the date picker start date value (from). * Only works with the "range" date picker type. * Follows the inputs when the owning form resets. * @default "" */ valueFrom?: string; /** * Specify the date picker end date value (to). * Only works with the "range" date picker type. * Follows the inputs when the owning form resets. * @default "" */ valueTo?: string; /** * Specify the date format. * Use `"F Y"` or `"m/Y"` with `datePickerType="month"`, and `"Y"` with * `datePickerType="year"`. * @default "m/d/Y" */ dateFormat?: string; /** * Specify a separate format for the text shown in the input, using the * same tokens as `dateFormat`. `value` and the submitted form field keep * using `dateFormat`. * Not supported with the "simple" and "range" date picker types. */ displayFormat?: string | undefined; /** * Specify the maximum date. * Changing it drops selected dates that fall outside, updating `value` * (or `valueFrom`/`valueTo`) and `selectedDates` without a `change` event. * @default null */ maxDate?: null | string | Date; /** * Specify the minimum date. * Changing it drops selected dates that fall outside, updating `value` * (or `valueFrom`/`valueTo`) and `selectedDates` without a `change` event. * @default null */ minDate?: null | string | Date; /** * Specify dates to disable in the calendar. A date matches a rule when it * equals a string or `Date`, falls within a `{ from, to }` range, or a * predicate function returns `true`. Strings follow `dateFormat`. * When `enabledDates` is also non-empty, `enabledDates` takes priority and * `disabledDates` is ignored. * Reassign the array to update an open calendar; mutating it in place * (`push`) is not reactive. If the currently selected date becomes * disabled by a rule change, it stays selected. * Only works with the "single", "range", and "multiple" date picker types. * @default [] */ disabledDates?: ReadonlyArray; /** * Specify the only dates to enable in the calendar; every other date is * disabled. Takes the same rule shapes as `disabledDates`. When both are * non-empty, `enabledDates` takes priority and `disabledDates` is ignored. * Reassign the array to update an open calendar; mutating it in place * (`push`) is not reactive. If the currently selected date becomes * disabled by a rule change, it stays selected. * Only works with the "single", "range", and "multiple" date picker types. * @default [] */ enabledDates?: ReadonlyArray; /** * Specify the fewest days a range may span, counting both ends. * While the start is picked, days that would make a shorter range are * disabled. Typed and programmatic values are not checked. * Only works with the "range" date picker type. */ minRangeDays?: number | undefined; /** * Specify the most days a range may span, counting both ends. * While the start is picked, days that would make a longer range are * disabled. Typed and programmatic values are not checked. * Only works with the "range" date picker type. */ maxRangeDays?: number | undefined; /** * Specify the month to show when the calendar opens with no date * selected. Only the month and year are used; the day is ignored. * Values may be a Date, or a string in the same format as `dateFormat`. * Clamped into `minDate` / `maxDate` when it falls outside them. * Ignored once a date is selected, until the selection is cleared. * Only works with the "single", "range", and "multiple" date picker * types. * @default null */ initialMonth?: null | string | Date; /** * Specify the locale. * @default "en" */ locale?: string | Partial; /** * Specify the first day of the week, from 0 (Sunday) to 6 (Saturday). * Overrides the locale's own first day, which is used when unset. */ firstDayOfWeek?: undefined | 0 | 1 | 2 | 3 | 4 | 5 | 6; /** * Set to `true` to show each week's number beside it in the calendar. * Weeks are numbered per ISO 8601. The column is only shown with a * single month. * @default false */ weekNumbers?: boolean; /** * Set to `false` to allow picking from the calendar only: the field * stays focusable but can't be typed into. * @default true */ allowInput?: boolean; /** * Set to `false` to keep the calendar open after a date is picked. * @default true */ closeOnSelect?: boolean; /** * Parse typed text into a date. Receives the text and `dateFormat`; * return `undefined` for text that isn't a date. */ parseDate?: undefined | ((text: string, format: string) => Date | undefined); /** * Format a date for the field. Receives the date and the format in use. */ formatDate?: undefined | ((date: Date, format: string) => string); /** * Number of months the calendar shows side by side. * Not supported with the "week", "month", "quarter", and "year" types. * @default 1 */ months?: 1 | 2; /** * Separator between dates in the field, with `datePickerType="multiple"`. * @default ", " */ conjunction?: string; /** * Show the month in the calendar header in full ("September") or short * ("Sep"), from the active `locale`. * @default "long" */ monthLabel?: "long" | "short"; /** * Where a portalled calendar opens relative to its field: below, above, * or whichever fits. * @default "auto" */ direction?: "auto" | "bottom" | "top"; /** * How a portalled calendar lines up with its field. `"start"` and `"end"` * follow the writing direction: in RTL, `"start"` is the right edge. * @default "start" */ align?: "start" | "center" | "end"; /** * Position a portalled calendar against this element instead of the field. */ anchor?: undefined | HTMLElement; /** * Set to `true` to keep an initial value outside `minDate`/`maxDate` or * the enabled dates, instead of clearing it. * @default false */ keepOutOfRangeValue?: boolean; /** * Describe a day for screen readers, such as "2 events". The text is added * to the day's label, and the day gets a marker. */ dayDescription?: undefined | ((date: Date) => string | undefined); /** * Add a class to a day, such as for holidays. */ dayClass?: undefined | ((date: Date) => string | undefined); /** * Set to `true` to animate the calendar as it opens. * @default false */ animate?: boolean; /** * Elements that count as part of the calendar: focusing or clicking them * doesn't close it, such as a "Today" button beside the field. * @default [] */ keepOpenFor?: ReadonlyArray; /** * Accessible name of the calendar. Defaults to "Choose a date" (or a * month, quarter, or year, by `datePickerType`). */ calendarLabelText?: string | undefined; /** * Label of the button that shows the previous month. Defaults to * "Previous month" (or year, or decade, by `datePickerType`). */ previousLabelText?: string | undefined; /** * Label of the button that shows the next month. Defaults to "Next month" * (or year, or decade, by `datePickerType`). */ nextLabelText?: string | undefined; /** * Set to `true` to render the calendar permanently below the input * instead of in a popup. `open` and `close` events are not dispatched, * `portalMenu` is ignored, and the calendar stops accepting input while * the input is read-only or disabled. * Not supported with the "simple" date picker type. * @default false */ inline?: boolean; /** * Set to `true` to show a button that clears the date. It appears while * there is a value, and not while the input is read-only or disabled. * In range mode it sits on the end input and clears both dates. * @default false */ clearable?: boolean; /** * Specify the ARIA label for the clear button. * @default "Clear date" */ clearButtonLabelText?: string; /** * Set to `true` for a narrower field, sized for a short format such as * `dateFormat="m/y"`; a full date like `mm/dd/yyyy` is cut off. Only * applies to the `"simple"` type; on other types it logs a warning. * @default false */ short?: boolean; /** * Set to `true` to fill the parent's width instead of the fixed input width. * A range splits the width between its two inputs. * @default false */ fullWidth?: boolean; /** * Set to `true` to use the fluid variant. * Inherited from the parent `FluidForm` context, * so it does not need to be set when used inside `FluidForm`. * @default false */ fluid?: boolean; /** * Set to `true` to always render the calendar in a portal, or `false` to * keep it in place. Left unset, the calendar opens in a portal inside a * `Modal`, or when a box around it (`overflow` other than `visible`, such * as a `DataTable`) would cut it off. * * When the date picker is inside a native `` (opened with * `showModal()`) or an open `[popover]` element, the calendar auto-mounts * into that top-layer ancestor and uses `position: fixed` so it renders * above the backdrop instead of behind it. */ portalMenu?: boolean | undefined; /** * Set an id for the date picker element * @default uniqueId() */ id?: string; /** * Bind to the calendar for programmatic control: `open()`, `close()`, * `showMonth(date)`, `focusDate(date)`, `isOpen`, and `selectedDates`. * Available for every `datePickerType` except `"simple"`, where it stays * `null`. * @default null */ calendar?: import("./calendar-api.js").DatePickerCalendar | null; /** * Bind to the selected dates as `Date` objects, in the same order as * `calendar.selectedDates` (range: start, then end). Setting it selects * those dates and updates `value` (or `valueFrom`/`valueTo`). At mount, a * non-empty `value` takes precedence. Reassign the array to update; do not * mutate it. * Not supported with the "simple" date picker type. * @default [] */ selectedDates?: ReadonlyArray; /** * Set to `true` to open the calendar. Updates when the user opens or * closes it. Setting it to `false` closes the calendar and dispatches * `close` with the `"programmatic"` trigger, as Modal does. * Ignored by the "simple" type and inline calendars. * @default false */ open?: boolean; children?: (this: void) => void; [key: `data-${string}`]: unknown; }; export type DatePickerProps = Omit<$RestProps, keyof $Props> & $Props; export default class DatePicker extends SvelteComponentTyped< DatePickerProps, { change: CustomEvent; clear: CustomEvent; click: WindowEventMap["click"]; close: CustomEvent<{ trigger: "escape-key" | "outside-click" | "select" | "programmatic"; }>; error: CustomEvent<{ error: Error; value: string; }>; mouseenter: WindowEventMap["mouseenter"]; mouseleave: WindowEventMap["mouseleave"]; mouseover: WindowEventMap["mouseover"]; open: CustomEvent<{ selectedDates: Date[]; dateStr: string | { from: string; to: string; } }>; /** * Fires when the calendar is created and whenever it moves to another * month, year, or decade, with the first and last dates on show. Use it * to load data for the visible dates, such as `disabledDates`. */ view: CustomEvent<{ start: Date; end: Date; }>; }, { default: Record } > {}