@calcifer-design/ui 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
  2. package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
  3. package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
  4. package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
  5. package/dist/components/CardList/CardList.d.ts +30 -0
  6. package/dist/components/CardList/CardList.js +35 -0
  7. package/dist/components/CardList/CardList.module.js +7 -0
  8. package/dist/components/CardList/CardList_module.css +20 -0
  9. package/dist/components/Checkbox/Checkbox.d.ts +23 -0
  10. package/dist/components/Checkbox/Checkbox.js +33 -0
  11. package/dist/components/Checkbox/Checkbox.module.js +6 -0
  12. package/dist/components/Checkbox/Checkbox_module.css +16 -0
  13. package/dist/components/DatePicker/Calendar.d.ts +19 -0
  14. package/dist/components/DatePicker/Calendar.js +207 -0
  15. package/dist/components/DatePicker/DatePicker.d.ts +72 -0
  16. package/dist/components/DatePicker/DatePicker.js +116 -0
  17. package/dist/components/DatePicker/DatePicker.module.js +14 -0
  18. package/dist/components/DatePicker/DatePicker_module.css +112 -0
  19. package/dist/components/DatePicker/calendarDate.d.ts +46 -0
  20. package/dist/components/DatePicker/calendarDate.js +117 -0
  21. package/dist/components/Descriptions/Descriptions.d.ts +25 -0
  22. package/dist/components/Descriptions/Descriptions.js +44 -0
  23. package/dist/components/Descriptions/Descriptions.module.js +8 -0
  24. package/dist/components/Descriptions/Descriptions_module.css +47 -0
  25. package/dist/components/Field/Field.d.ts +118 -0
  26. package/dist/components/Field/Field.js +90 -0
  27. package/dist/components/Field/PickerField.d.ts +41 -0
  28. package/dist/components/Field/PickerField.js +115 -0
  29. package/dist/components/Field/PickerField.module.js +8 -0
  30. package/dist/components/Field/PickerField_module.css +36 -0
  31. package/dist/components/FilterBar/FilterBar.d.ts +55 -0
  32. package/dist/components/FilterBar/FilterBar.js +138 -0
  33. package/dist/components/FilterBar/FilterBar.module.js +13 -0
  34. package/dist/components/FilterBar/FilterBar_module.css +98 -0
  35. package/dist/components/Form/Form.d.ts +48 -0
  36. package/dist/components/Form/Form.js +38 -0
  37. package/dist/components/Form/Form.module.js +5 -0
  38. package/dist/components/Form/FormContext.d.ts +15 -0
  39. package/dist/components/Form/FormContext.js +20 -0
  40. package/dist/components/Form/Form_module.css +6 -0
  41. package/dist/components/PageShell/PageShell.d.ts +27 -0
  42. package/dist/components/PageShell/PageShell.js +35 -0
  43. package/dist/components/PageShell/PageShell.module.js +9 -0
  44. package/dist/components/PageShell/PageShell_module.css +56 -0
  45. package/dist/components/RadioGroup/RadioGroup.d.ts +35 -0
  46. package/dist/components/RadioGroup/RadioGroup.js +64 -0
  47. package/dist/components/RadioGroup/RadioGroup.module.js +6 -0
  48. package/dist/components/RadioGroup/RadioGroup_module.css +13 -0
  49. package/dist/components/Segmented/Segmented.d.ts +49 -0
  50. package/dist/components/Segmented/Segmented.js +55 -0
  51. package/dist/components/Segmented/Segmented.module.js +7 -0
  52. package/dist/components/Segmented/Segmented_module.css +75 -0
  53. package/dist/components/Select/Select.d.ts +42 -0
  54. package/dist/components/Select/Select.js +90 -0
  55. package/dist/components/Select/Select.module.js +9 -0
  56. package/dist/components/Select/Select_module.css +70 -0
  57. package/dist/components/Steps/Steps.d.ts +30 -0
  58. package/dist/components/Steps/Steps.js +63 -0
  59. package/dist/components/Steps/Steps.module.js +10 -0
  60. package/dist/components/Steps/Steps_module.css +126 -0
  61. package/dist/components/Switch/Switch.d.ts +23 -0
  62. package/dist/components/Switch/Switch.js +25 -0
  63. package/dist/components/Switch/Switch.module.js +6 -0
  64. package/dist/components/Switch/Switch_module.css +41 -0
  65. package/dist/components/TextArea/TextArea.d.ts +16 -0
  66. package/dist/components/TextArea/TextArea.js +28 -0
  67. package/dist/components/TextArea/TextArea.module.js +5 -0
  68. package/dist/components/TextArea/TextArea_module.css +12 -0
  69. package/dist/components/TextInput/TextInput.d.ts +17 -0
  70. package/dist/components/TextInput/TextInput.js +18 -0
  71. package/dist/components/TimePicker/TimePicker.d.ts +19 -0
  72. package/dist/components/TimePicker/TimePicker.js +17 -0
  73. package/dist/components/Timeline/Timeline.d.ts +39 -0
  74. package/dist/components/Timeline/Timeline.js +109 -0
  75. package/dist/components/Timeline/Timeline.module.js +12 -0
  76. package/dist/components/Timeline/Timeline_module.css +99 -0
  77. package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
  78. package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
  79. package/dist/components/Toolbar/Toolbar.d.ts +46 -0
  80. package/dist/components/Toolbar/Toolbar.js +43 -0
  81. package/dist/components/Toolbar/Toolbar.module.js +7 -0
  82. package/dist/components/Toolbar/Toolbar_module.css +26 -0
  83. package/dist/components/Tree/Tree.d.ts +81 -0
  84. package/dist/components/Tree/Tree.js +232 -0
  85. package/dist/components/Tree/Tree.module.js +12 -0
  86. package/dist/components/Tree/Tree_module.css +124 -0
  87. package/dist/components/Tree/treeIndex.d.ts +23 -0
  88. package/dist/components/Tree/treeIndex.js +33 -0
  89. package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
  90. package/dist/components/TreeSelect/TreeSelect.js +117 -0
  91. package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
  92. package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
  93. package/dist/components/Upload/Upload.d.ts +66 -0
  94. package/dist/components/Upload/Upload.js +287 -0
  95. package/dist/components/Upload/Upload.module.js +12 -0
  96. package/dist/components/Upload/Upload_module.css +96 -0
  97. package/dist/components/ViewField/ViewField.d.ts +26 -0
  98. package/dist/components/ViewField/ViewField.js +29 -0
  99. package/dist/components/ViewField/ViewField.module.js +6 -0
  100. package/dist/components/ViewField/ViewField_module.css +17 -0
  101. package/dist/hooks/useFormReset.d.ts +10 -0
  102. package/dist/hooks/useFormReset.js +34 -0
  103. package/dist/icons/CalendarIcon.d.ts +2 -0
  104. package/dist/icons/CalendarIcon.js +26 -0
  105. package/dist/icons/CheckIcon.d.ts +6 -0
  106. package/dist/icons/CheckIcon.js +17 -0
  107. package/dist/icons/ChevronDownIcon.d.ts +6 -0
  108. package/dist/icons/ChevronDownIcon.js +17 -0
  109. package/dist/icons/MinusIcon.d.ts +5 -0
  110. package/dist/icons/MinusIcon.js +16 -0
  111. package/dist/index.d.ts +46 -0
  112. package/dist/index.js +23 -0
  113. package/dist/styles/field.module.js +15 -0
  114. package/dist/styles/field_module.css +133 -0
  115. package/dist/styles/pair.module.js +6 -0
  116. package/dist/styles/pair_module.css +18 -0
  117. package/dist/styles/popup_module.css +6 -0
  118. package/package.json +2 -2
@@ -0,0 +1,24 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { LinkRenderProps } from '../NavMenu/NavMenu.js';
3
+ export interface BreadcrumbItem {
4
+ label: string;
5
+ /**
6
+ * Makes the item a link. Ignored on the last item, which is the page the reader is on, and
7
+ * optional before it for a level with no page of its own.
8
+ */
9
+ href?: string;
10
+ }
11
+ export interface BreadcrumbProps {
12
+ /** The trail, outermost first. The last item is the current page. */
13
+ items: BreadcrumbItem[];
14
+ /** The navigation landmark's name. */
15
+ 'aria-label'?: string;
16
+ /**
17
+ * Lets the app render router links; defaults to a plain anchor. Called only for an item that
18
+ * is a link, so `href` is always there.
19
+ */
20
+ renderLink?: (item: BreadcrumbItem & {
21
+ href: string;
22
+ }, props: LinkRenderProps) => ReactElement;
23
+ }
24
+ export declare function Breadcrumb({ items, 'aria-label': ariaLabel, renderLink, }: BreadcrumbProps): import("react").JSX.Element | null;
@@ -0,0 +1,48 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import Breadcrumb_module from "./Breadcrumb.module.js";
3
+ function defaultRenderLink(item, { children, ...linkProps }) {
4
+ return /*#__PURE__*/ jsx("a", {
5
+ href: item.href,
6
+ ...linkProps,
7
+ children: children
8
+ });
9
+ }
10
+ function renderItemContent(item, isLast, renderLink) {
11
+ if (isLast) return /*#__PURE__*/ jsx("span", {
12
+ className: Breadcrumb_module.current,
13
+ "aria-current": "page",
14
+ children: item.label
15
+ });
16
+ if (void 0 === item.href) return /*#__PURE__*/ jsx("span", {
17
+ className: Breadcrumb_module.text,
18
+ children: item.label
19
+ });
20
+ return renderLink({
21
+ ...item,
22
+ href: item.href
23
+ }, {
24
+ className: Breadcrumb_module.link,
25
+ children: item.label
26
+ });
27
+ }
28
+ function Breadcrumb({ items, 'aria-label': ariaLabel = 'Breadcrumb', renderLink = defaultRenderLink }) {
29
+ if (0 === items.length) return null;
30
+ return /*#__PURE__*/ jsx("nav", {
31
+ "aria-label": ariaLabel,
32
+ children: /*#__PURE__*/ jsx("ol", {
33
+ className: Breadcrumb_module.list,
34
+ children: items.map((item, index)=>/*#__PURE__*/ jsxs("li", {
35
+ className: Breadcrumb_module.item,
36
+ children: [
37
+ index > 0 ? /*#__PURE__*/ jsx("span", {
38
+ className: Breadcrumb_module.separator,
39
+ "aria-hidden": "true",
40
+ children: "/"
41
+ }) : null,
42
+ renderItemContent(item, index === items.length - 1, renderLink)
43
+ ]
44
+ }, index))
45
+ })
46
+ });
47
+ }
48
+ export { Breadcrumb };
@@ -0,0 +1,10 @@
1
+ import "./Breadcrumb_module.css";
2
+ const Breadcrumb_module = {
3
+ list: "list-eDbWY",
4
+ item: "item-yKtE5",
5
+ separator: "separator-pHrdE",
6
+ link: "link-l4Wbt",
7
+ text: "text-F4Upa",
8
+ current: "current-rfbM_"
9
+ };
10
+ export default Breadcrumb_module;
@@ -0,0 +1,49 @@
1
+ .list-eDbWY {
2
+ align-items: center;
3
+ gap: var(--space-1) var(--space-2);
4
+ font-size: var(--text-sm);
5
+ line-height: var(--leading-snug);
6
+ flex-wrap: wrap;
7
+ margin: 0;
8
+ padding: 0;
9
+ list-style: none;
10
+ display: flex;
11
+ }
12
+
13
+ .item-yKtE5 {
14
+ align-items: center;
15
+ gap: var(--space-2);
16
+ overflow-wrap: anywhere;
17
+ min-width: 0;
18
+ display: inline-flex;
19
+ }
20
+
21
+ .separator-pHrdE {
22
+ color: var(--color-text-subtle);
23
+ flex: none;
24
+ }
25
+
26
+ .link-l4Wbt {
27
+ border-radius: var(--radius-sm);
28
+ min-height: 1.5rem;
29
+ color: var(--color-link);
30
+ align-items: center;
31
+ text-decoration: underline;
32
+ display: inline-flex;
33
+ }
34
+
35
+ @media (hover: hover) {
36
+ .link-l4Wbt:hover {
37
+ text-decoration: none;
38
+ }
39
+ }
40
+
41
+ .text-F4Upa {
42
+ color: var(--color-text-muted);
43
+ }
44
+
45
+ .current-rfbM_ {
46
+ color: var(--color-text);
47
+ font-weight: 500;
48
+ }
49
+
@@ -0,0 +1,30 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface CardListProps<Item> {
3
+ items: readonly Item[];
4
+ /** What tells one item from another across renders. */
5
+ getKey: (item: Item) => string | number;
6
+ /** One card. A `Card` is the usual answer, and any node will do. */
7
+ renderItem: (item: Item) => ReactNode;
8
+ /**
9
+ * The narrowest a column may get, as any CSS length, before the list drops to fewer columns.
10
+ * Defaults to `16rem`. A width greater than the list's own takes the list's own, so no value can
11
+ * overflow a phone.
12
+ */
13
+ minColumnWidth?: string;
14
+ /**
15
+ * Sets `aria-busy`. Items already here stay, so that a refresh loses nobody's focus or place, and
16
+ * skeletons stand in only for an empty list. To show skeletons, pass no items.
17
+ */
18
+ loading?: boolean;
19
+ /** How many skeletons stand in, up to 100. */
20
+ skeletonCount?: number;
21
+ /** Shown when there are no items and nothing is loading. Without it, nothing is drawn. */
22
+ emptyState?: ReactNode;
23
+ /** Names the list. */
24
+ 'aria-label': string;
25
+ }
26
+ /**
27
+ * A responsive list of cards: as many columns as fit, down to one. Each skeleton's item is hidden
28
+ * from assistive technology, so a list still loading reads as a busy list and not as blank rows.
29
+ */
30
+ export declare function CardList<Item>({ items, getKey, renderItem, minColumnWidth, loading, skeletonCount, emptyState, 'aria-label': ariaLabel, }: CardListProps<Item>): import("react").JSX.Element | null;
@@ -0,0 +1,35 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Skeleton } from "../Skeleton/Skeleton.js";
3
+ import CardList_module from "./CardList.module.js";
4
+ function CardList({ items, getKey, renderItem, minColumnWidth, loading = false, skeletonCount = 6, emptyState, 'aria-label': ariaLabel }) {
5
+ if (0 === items.length && !loading) return void 0 === emptyState ? null : /*#__PURE__*/ jsx("div", {
6
+ className: CardList_module.empty,
7
+ children: emptyState
8
+ });
9
+ const standIns = 0 === items.length && Number.isFinite(skeletonCount) ? Math.min(Math.max(0, Math.trunc(skeletonCount)), 100) : 0;
10
+ return /*#__PURE__*/ jsxs("ul", {
11
+ role: "list",
12
+ className: CardList_module.list,
13
+ style: void 0 === minColumnWidth ? void 0 : {
14
+ '--card-list-min-column': minColumnWidth
15
+ },
16
+ "aria-label": ariaLabel,
17
+ "aria-busy": loading ? true : void 0,
18
+ children: [
19
+ items.map((item)=>/*#__PURE__*/ jsx("li", {
20
+ className: CardList_module.item,
21
+ children: renderItem(item)
22
+ }, getKey(item))),
23
+ Array.from({
24
+ length: standIns
25
+ }, (_unused, position)=>/*#__PURE__*/ jsx("li", {
26
+ className: CardList_module.item,
27
+ "aria-hidden": "true",
28
+ children: /*#__PURE__*/ jsx(Skeleton, {
29
+ variant: "block"
30
+ })
31
+ }, position))
32
+ ]
33
+ });
34
+ }
35
+ export { CardList };
@@ -0,0 +1,7 @@
1
+ import "./CardList_module.css";
2
+ const CardList_module = {
3
+ list: "list-sqMJI",
4
+ item: "item-b8vTh",
5
+ empty: "empty-G1gXX"
6
+ };
7
+ export default CardList_module;
@@ -0,0 +1,20 @@
1
+ .list-sqMJI {
2
+ --card-list-track: minmax(min(var(--card-list-min-column, 16rem), 100%), 1fr);
3
+ grid-template-columns: repeat(auto-fill, var(--card-list-track));
4
+ gap: var(--space-4);
5
+ margin: 0;
6
+ padding: 0;
7
+ list-style: none;
8
+ display: grid;
9
+ }
10
+
11
+ .item-b8vTh {
12
+ min-width: 0;
13
+ }
14
+
15
+ .empty-G1gXX {
16
+ color: var(--color-text-muted);
17
+ font-size: var(--text-md);
18
+ line-height: var(--leading-prose);
19
+ }
20
+
@@ -0,0 +1,23 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type FieldFrameProps } from '../Field/Field.js';
3
+ export interface CheckboxProps extends FieldFrameProps {
4
+ /** The text beside the box, and the checkbox's accessible name. */
5
+ label: string;
6
+ /** Sits under the row and joins the checkbox's `aria-describedby`. */
7
+ description?: ReactNode;
8
+ /** Controlled. Pair it with `onCheckedChange`; use `defaultChecked` for an uncontrolled box. */
9
+ checked?: boolean;
10
+ defaultChecked?: boolean;
11
+ /**
12
+ * Neither ticked nor unticked: `aria-checked="mixed"`, and a bar instead of a tick. The
13
+ * "select all" state above a list of boxes.
14
+ */
15
+ indeterminate?: boolean;
16
+ /**
17
+ * The new checked state. One argument, as on every other control in the tier: Base UI calls
18
+ * its own callback `(checked, eventDetails)` and this wrapper drops the second, which no
19
+ * consumer can read without a cast.
20
+ */
21
+ onCheckedChange?: (checked: boolean) => void;
22
+ }
23
+ export declare function Checkbox({ label, name, description, error, checked, defaultChecked, indeterminate, onCheckedChange, required, disabled, }: CheckboxProps): import("react").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Checkbox } from "@base-ui/react/checkbox";
3
+ import { CheckIcon } from "../../icons/CheckIcon.js";
4
+ import { MinusIcon } from "../../icons/MinusIcon.js";
5
+ import field_module from "../../styles/field.module.js";
6
+ import { InlineField } from "../Field/Field.js";
7
+ import Checkbox_module from "./Checkbox.module.js";
8
+ function Checkbox_Checkbox({ label, name, description, error, checked, defaultChecked, indeterminate = false, onCheckedChange, required = false, disabled = false }) {
9
+ return /*#__PURE__*/ jsx(InlineField, {
10
+ label: label,
11
+ name: name,
12
+ description: description,
13
+ error: error,
14
+ required: required,
15
+ disabled: disabled,
16
+ children: /*#__PURE__*/ jsx(Checkbox.Root, {
17
+ className: [
18
+ field_module.controlBox,
19
+ Checkbox_module.box
20
+ ].join(' '),
21
+ checked: checked,
22
+ defaultChecked: defaultChecked,
23
+ indeterminate: indeterminate,
24
+ onCheckedChange: (nextChecked)=>onCheckedChange?.(nextChecked),
25
+ required: required,
26
+ children: /*#__PURE__*/ jsx(Checkbox.Indicator, {
27
+ className: Checkbox_module.indicator,
28
+ children: indeterminate ? /*#__PURE__*/ jsx(MinusIcon, {}) : /*#__PURE__*/ jsx(CheckIcon, {})
29
+ })
30
+ })
31
+ });
32
+ }
33
+ export { Checkbox_Checkbox as Checkbox };
@@ -0,0 +1,6 @@
1
+ import "./Checkbox_module.css";
2
+ const Checkbox_module = {
3
+ box: "box-DHMQq",
4
+ indicator: "indicator-g_8JY"
5
+ };
6
+ export default Checkbox_module;
@@ -0,0 +1,16 @@
1
+ .box-DHMQq {
2
+ border-radius: var(--radius-sm);
3
+ width: 1.25rem;
4
+ height: 1.25rem;
5
+ color: var(--color-accent-text);
6
+ }
7
+
8
+ .indicator-g_8JY {
9
+ display: inline-flex;
10
+ }
11
+
12
+ .indicator-g_8JY > svg {
13
+ width: .875rem;
14
+ height: .875rem;
15
+ }
16
+
@@ -0,0 +1,19 @@
1
+ import { type RefObject } from 'react';
2
+ import { type DateAvailability } from './calendarDate.js';
3
+ export interface CalendarProps extends DateAvailability {
4
+ gridRef: RefObject<HTMLTableElement | null>;
5
+ chosen: string | null;
6
+ locale: string | undefined;
7
+ weekStartsOn: number;
8
+ previousMonthLabel: string;
9
+ nextMonthLabel: string;
10
+ onSelect: (date: string) => void;
11
+ }
12
+ /**
13
+ * The month grid inside `DatePicker`'s dialog, mounted only while it is open. Internal.
14
+ *
15
+ * Roving focus, per the WAI-ARIA date picker dialog pattern: one date is the tab stop, the opening
16
+ * focus and the origin of the arrow keys. Unavailable dates can be focused and read out, as the
17
+ * pattern says, but not chosen; months wholly outside `min` and `max` cannot be reached at all.
18
+ */
19
+ export declare function Calendar({ gridRef, chosen, min, max, isDateDisabled, locale, weekStartsOn, previousMonthLabel, nextMonthLabel, onSelect, }: CalendarProps): import("react").JSX.Element;
@@ -0,0 +1,207 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
4
+ import { IconButton } from "../IconButton/IconButton.js";
5
+ import { addDays, addMonths, dateFormatter, endOfWeek, firstOfMonth, isDateUnavailable, startOfWeek, todayIn, weeksOfMonth } from "./calendarDate.js";
6
+ import DatePicker_module from "./DatePicker.module.js";
7
+ const A_SUNDAY = '2023-01-01';
8
+ const SEARCH_LIMIT_IN_DAYS = 800;
9
+ function monthOf(date) {
10
+ return date.slice(0, 7);
11
+ }
12
+ function readingDirectionOf(element) {
13
+ return getComputedStyle(element).direction;
14
+ }
15
+ function Calendar({ gridRef, chosen, min, max, isDateDisabled, locale, weekStartsOn, previousMonthLabel, nextMonthLabel, onSelect }) {
16
+ const monthId = useId();
17
+ const [today] = useState(()=>todayIn(new Date()));
18
+ const gridHasFocus = useRef(false);
19
+ const headerRef = useRef(null);
20
+ const isUnavailable = (date)=>isDateUnavailable(date, {
21
+ min,
22
+ max,
23
+ isDateDisabled
24
+ });
25
+ const isReachable = (date)=>(null === min || monthOf(date) >= monthOf(min)) && (null === max || monthOf(date) <= monthOf(max));
26
+ const firstAvailableFrom = (start)=>{
27
+ let candidate = start;
28
+ for(let step = 0; step < SEARCH_LIMIT_IN_DAYS && isReachable(candidate); step += 1){
29
+ if (!isUnavailable(candidate)) return candidate;
30
+ candidate = addDays(candidate, 1);
31
+ }
32
+ return start;
33
+ };
34
+ const restingDate = ()=>{
35
+ if (null !== chosen && isReachable(chosen)) return chosen;
36
+ if (!isUnavailable(today)) return today;
37
+ if (null !== min && today < min) return firstAvailableFrom(min);
38
+ if (null !== max && today > max) {
39
+ const monthStart = firstOfMonth(max);
40
+ return firstAvailableFrom(null !== min && min > monthStart ? min : monthStart);
41
+ }
42
+ return firstAvailableFrom(firstOfMonth(today));
43
+ };
44
+ const restingDateIn = (month)=>{
45
+ if (null !== chosen && monthOf(chosen) === monthOf(month) && !isUnavailable(chosen)) return chosen;
46
+ if (monthOf(today) === monthOf(month) && !isUnavailable(today)) return today;
47
+ const available = firstAvailableFrom(firstOfMonth(month));
48
+ return monthOf(available) === monthOf(month) ? available : firstOfMonth(month);
49
+ };
50
+ const [movedDate, setMovedDate] = useState(null);
51
+ const [lastChosen, setLastChosen] = useState(chosen);
52
+ if (chosen !== lastChosen) {
53
+ setLastChosen(chosen);
54
+ setMovedDate(null);
55
+ }
56
+ const activeDate = null !== movedDate && isReachable(movedDate) ? movedDate : restingDate();
57
+ useLayoutEffect(()=>{
58
+ if (gridHasFocus.current) gridRef.current?.querySelector(`[data-date="${activeDate}"]`)?.focus();
59
+ }, [
60
+ activeDate,
61
+ gridRef
62
+ ]);
63
+ useLayoutEffect(()=>{
64
+ if (null !== headerRef.current) headerRef.current.dataset.direction = readingDirectionOf(headerRef.current);
65
+ });
66
+ const formatters = useMemo(()=>({
67
+ month: dateFormatter(locale, {
68
+ month: 'long',
69
+ year: 'numeric'
70
+ }),
71
+ day: dateFormatter(locale, {
72
+ day: 'numeric'
73
+ }),
74
+ fullDate: dateFormatter(locale, {
75
+ dateStyle: 'full'
76
+ }),
77
+ shortWeekday: dateFormatter(locale, {
78
+ weekday: 'short'
79
+ }),
80
+ longWeekday: dateFormatter(locale, {
81
+ weekday: 'long'
82
+ })
83
+ }), [
84
+ locale
85
+ ]);
86
+ const moveTo = (target)=>{
87
+ if (isReachable(target)) setMovedDate(target);
88
+ };
89
+ const handleKeyDown = (event)=>{
90
+ const inRightToLeft = 'rtl' === readingDirectionOf(event.currentTarget);
91
+ const monthStep = event.shiftKey ? 12 : 1;
92
+ const targets = {
93
+ ArrowLeft: ()=>addDays(activeDate, inRightToLeft ? 1 : -1),
94
+ ArrowRight: ()=>addDays(activeDate, inRightToLeft ? -1 : 1),
95
+ ArrowUp: ()=>addDays(activeDate, -7),
96
+ ArrowDown: ()=>addDays(activeDate, 7),
97
+ Home: ()=>startOfWeek(activeDate, weekStartsOn),
98
+ End: ()=>endOfWeek(activeDate, weekStartsOn),
99
+ PageUp: ()=>addMonths(activeDate, -monthStep),
100
+ PageDown: ()=>addMonths(activeDate, monthStep)
101
+ };
102
+ const target = targets[event.key];
103
+ if (target) {
104
+ event.preventDefault();
105
+ moveTo(target());
106
+ } else if ('Enter' === event.key || ' ' === event.key) {
107
+ event.preventDefault();
108
+ if (!isUnavailable(activeDate)) onSelect(activeDate);
109
+ }
110
+ };
111
+ const previousMonth = addMonths(firstOfMonth(activeDate), -1);
112
+ const nextMonth = addMonths(firstOfMonth(activeDate), 1);
113
+ const hasPreviousMonth = isReachable(previousMonth);
114
+ const hasNextMonth = isReachable(nextMonth);
115
+ return /*#__PURE__*/ jsxs(Fragment, {
116
+ children: [
117
+ /*#__PURE__*/ jsxs("div", {
118
+ ref: headerRef,
119
+ className: DatePicker_module.header,
120
+ children: [
121
+ /*#__PURE__*/ jsx(IconButton, {
122
+ className: DatePicker_module.previous,
123
+ size: "sm",
124
+ label: previousMonthLabel,
125
+ "aria-disabled": hasPreviousMonth ? void 0 : true,
126
+ onClick: ()=>{
127
+ if (hasPreviousMonth) setMovedDate(restingDateIn(previousMonth));
128
+ },
129
+ children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
130
+ }),
131
+ /*#__PURE__*/ jsx("div", {
132
+ id: monthId,
133
+ className: DatePicker_module.month,
134
+ "aria-live": "polite",
135
+ "aria-atomic": "true",
136
+ children: formatters.month.format(activeDate)
137
+ }),
138
+ /*#__PURE__*/ jsx(IconButton, {
139
+ className: DatePicker_module.next,
140
+ size: "sm",
141
+ label: nextMonthLabel,
142
+ "aria-disabled": hasNextMonth ? void 0 : true,
143
+ onClick: ()=>{
144
+ if (hasNextMonth) setMovedDate(restingDateIn(nextMonth));
145
+ },
146
+ children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
147
+ })
148
+ ]
149
+ }),
150
+ /*#__PURE__*/ jsx("div", {
151
+ className: DatePicker_module.gridSlot,
152
+ children: /*#__PURE__*/ jsxs("table", {
153
+ ref: gridRef,
154
+ role: "grid",
155
+ className: DatePicker_module.grid,
156
+ "aria-labelledby": monthId,
157
+ onKeyDown: handleKeyDown,
158
+ onFocus: ()=>{
159
+ gridHasFocus.current = true;
160
+ },
161
+ onBlur: (event)=>{
162
+ gridHasFocus.current = event.currentTarget.contains(event.relatedTarget);
163
+ },
164
+ children: [
165
+ /*#__PURE__*/ jsx("thead", {
166
+ children: /*#__PURE__*/ jsx("tr", {
167
+ children: Array.from({
168
+ length: 7
169
+ }, (_unused, offset)=>{
170
+ const weekday = addDays(A_SUNDAY, (weekStartsOn + offset) % 7);
171
+ return /*#__PURE__*/ jsx("th", {
172
+ scope: "col",
173
+ className: DatePicker_module.weekday,
174
+ "aria-label": formatters.longWeekday.format(weekday),
175
+ children: formatters.shortWeekday.format(weekday)
176
+ }, weekday);
177
+ })
178
+ })
179
+ }),
180
+ /*#__PURE__*/ jsx("tbody", {
181
+ children: weeksOfMonth(activeDate, weekStartsOn).map((week, weekIndex)=>/*#__PURE__*/ jsx("tr", {
182
+ children: week.map((date, dayIndex)=>null === date ? /*#__PURE__*/ jsx("td", {
183
+ role: "gridcell"
184
+ }, dayIndex) : /*#__PURE__*/ jsx("td", {
185
+ role: "gridcell",
186
+ className: DatePicker_module.day,
187
+ "data-date": date,
188
+ tabIndex: date === activeDate ? 0 : -1,
189
+ "aria-label": formatters.fullDate.format(date),
190
+ "aria-selected": date === chosen,
191
+ "aria-current": date === today ? 'date' : void 0,
192
+ "aria-disabled": isUnavailable(date) ? true : void 0,
193
+ onClick: ()=>{
194
+ if (isUnavailable(date)) setMovedDate(date);
195
+ else onSelect(date);
196
+ },
197
+ children: formatters.day.format(date)
198
+ }, date))
199
+ }, weekIndex))
200
+ })
201
+ ]
202
+ })
203
+ })
204
+ ]
205
+ });
206
+ }
207
+ export { Calendar };
@@ -0,0 +1,72 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { FieldFrameProps } from '../Field/Field.js';
3
+ export interface DatePickerLabels {
4
+ /** The month button's name. */
5
+ previousMonth: string;
6
+ nextMonth: string;
7
+ /** The button that closes the calendar without choosing. */
8
+ close: string;
9
+ /** Joins the trigger's accessible name when the field is `required`. */
10
+ required: string;
11
+ /** Shown when `Form` submits a `required` picker with nothing chosen. */
12
+ requiredMessage: string;
13
+ /** Shown when `Form` submits a date that `min`, `max` or `isDateDisabled` refuses. */
14
+ unavailableMessage: string;
15
+ /** The clear button's name. Defaults to "Clear" and the field's own label. */
16
+ clear: string;
17
+ }
18
+ export interface DatePickerProps extends FieldFrameProps {
19
+ /** The visible label, and the start of the trigger's accessible name. */
20
+ label: string;
21
+ /** Sits under the trigger and joins its `aria-describedby`. */
22
+ description?: ReactNode;
23
+ /**
24
+ * Draws the required mark and adds the word to the trigger's name. `Form` refuses to submit while
25
+ * nothing is chosen, with `labels.requiredMessage` on the frame. A plain `<form>` is not blocked:
26
+ * the value travels in a hidden input, which has no constraints, so the app validates.
27
+ */
28
+ required?: boolean;
29
+ /**
30
+ * Controlled: `YYYY-MM-DD`, or `null` for nothing chosen. A string that does not name a real date
31
+ * (`''`, `2026-02-30`) reads as nothing chosen, and nothing is reported for it. A real date
32
+ * outside `min` and `max` or refused by `isDateDisabled` is still shown, because it is the app's
33
+ * value, and `Form` refuses to submit it, with `labels.unavailableMessage` on the frame. That
34
+ * covers a default value too, and a date a moved `min` has overtaken. A plain `<form>` is not
35
+ * blocked, for the reason `required` gives.
36
+ */
37
+ value?: string | null;
38
+ /**
39
+ * Uncontrolled: the first value, and the one a native reset of the surrounding form goes back to,
40
+ * with `onValueChange` told. A controlled `value` stays through a reset, as the parent's to change.
41
+ */
42
+ defaultValue?: string | null;
43
+ /** The chosen date or `null` once cleared, in one argument, and only for a real change. */
44
+ onValueChange?: (value: string | null) => void;
45
+ /** Called when focus leaves the trigger, for a form library's "touched". */
46
+ onBlur?: () => void;
47
+ /** The earliest date that can be chosen. Months entirely before it cannot be reached. */
48
+ min?: string;
49
+ /** The latest date that can be chosen. Months entirely after it cannot be reached. */
50
+ max?: string;
51
+ /** Marks more dates unavailable. They can still be reached by arrow key and read out. */
52
+ isDateDisabled?: (date: string) => boolean;
53
+ /**
54
+ * A BCP 47 tag for the month and day names, the digits and the calendar's direction. Left out,
55
+ * the browser's own; a tag it cannot read counts as left out. That default can differ between a
56
+ * server's render and the browser's, which passing `locale` avoids.
57
+ */
58
+ locale?: string;
59
+ /** The first column, 0 for Sunday to 6 for Saturday. Left out, what `locale` says. */
60
+ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
61
+ /** Shows a button that clears the date, while there is one. */
62
+ clearable?: boolean;
63
+ /** Shown on the trigger while nothing is chosen. */
64
+ placeholder?: string;
65
+ /** The words the control says itself, for an app that is not in English. */
66
+ labels?: Partial<DatePickerLabels>;
67
+ }
68
+ /**
69
+ * A date field: a button showing the formatted date opens the WAI-ARIA date picker dialog, whose
70
+ * grid is ours because Base UI has no public calendar. Submits `YYYY-MM-DD` through a hidden input.
71
+ */
72
+ export declare function DatePicker({ label, name, description, error, required, disabled, value, defaultValue, onValueChange, onBlur, min, max, isDateDisabled, locale, weekStartsOn, clearable, placeholder, labels, }: DatePickerProps): import("react").JSX.Element;