@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.
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
- package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
- package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
- package/dist/components/CardList/CardList.d.ts +30 -0
- package/dist/components/CardList/CardList.js +35 -0
- package/dist/components/CardList/CardList.module.js +7 -0
- package/dist/components/CardList/CardList_module.css +20 -0
- package/dist/components/Checkbox/Checkbox.d.ts +23 -0
- package/dist/components/Checkbox/Checkbox.js +33 -0
- package/dist/components/Checkbox/Checkbox.module.js +6 -0
- package/dist/components/Checkbox/Checkbox_module.css +16 -0
- package/dist/components/DatePicker/Calendar.d.ts +19 -0
- package/dist/components/DatePicker/Calendar.js +207 -0
- package/dist/components/DatePicker/DatePicker.d.ts +72 -0
- package/dist/components/DatePicker/DatePicker.js +116 -0
- package/dist/components/DatePicker/DatePicker.module.js +14 -0
- package/dist/components/DatePicker/DatePicker_module.css +112 -0
- package/dist/components/DatePicker/calendarDate.d.ts +46 -0
- package/dist/components/DatePicker/calendarDate.js +117 -0
- package/dist/components/Descriptions/Descriptions.d.ts +25 -0
- package/dist/components/Descriptions/Descriptions.js +44 -0
- package/dist/components/Descriptions/Descriptions.module.js +8 -0
- package/dist/components/Descriptions/Descriptions_module.css +47 -0
- package/dist/components/Field/Field.d.ts +118 -0
- package/dist/components/Field/Field.js +90 -0
- package/dist/components/Field/PickerField.d.ts +41 -0
- package/dist/components/Field/PickerField.js +115 -0
- package/dist/components/Field/PickerField.module.js +8 -0
- package/dist/components/Field/PickerField_module.css +36 -0
- package/dist/components/FilterBar/FilterBar.d.ts +55 -0
- package/dist/components/FilterBar/FilterBar.js +138 -0
- package/dist/components/FilterBar/FilterBar.module.js +13 -0
- package/dist/components/FilterBar/FilterBar_module.css +98 -0
- package/dist/components/Form/Form.d.ts +48 -0
- package/dist/components/Form/Form.js +38 -0
- package/dist/components/Form/Form.module.js +5 -0
- package/dist/components/Form/FormContext.d.ts +15 -0
- package/dist/components/Form/FormContext.js +20 -0
- package/dist/components/Form/Form_module.css +6 -0
- package/dist/components/PageShell/PageShell.d.ts +27 -0
- package/dist/components/PageShell/PageShell.js +35 -0
- package/dist/components/PageShell/PageShell.module.js +9 -0
- package/dist/components/PageShell/PageShell_module.css +56 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +35 -0
- package/dist/components/RadioGroup/RadioGroup.js +64 -0
- package/dist/components/RadioGroup/RadioGroup.module.js +6 -0
- package/dist/components/RadioGroup/RadioGroup_module.css +13 -0
- package/dist/components/Segmented/Segmented.d.ts +49 -0
- package/dist/components/Segmented/Segmented.js +55 -0
- package/dist/components/Segmented/Segmented.module.js +7 -0
- package/dist/components/Segmented/Segmented_module.css +75 -0
- package/dist/components/Select/Select.d.ts +42 -0
- package/dist/components/Select/Select.js +90 -0
- package/dist/components/Select/Select.module.js +9 -0
- package/dist/components/Select/Select_module.css +70 -0
- package/dist/components/Steps/Steps.d.ts +30 -0
- package/dist/components/Steps/Steps.js +63 -0
- package/dist/components/Steps/Steps.module.js +10 -0
- package/dist/components/Steps/Steps_module.css +126 -0
- package/dist/components/Switch/Switch.d.ts +23 -0
- package/dist/components/Switch/Switch.js +25 -0
- package/dist/components/Switch/Switch.module.js +6 -0
- package/dist/components/Switch/Switch_module.css +41 -0
- package/dist/components/TextArea/TextArea.d.ts +16 -0
- package/dist/components/TextArea/TextArea.js +28 -0
- package/dist/components/TextArea/TextArea.module.js +5 -0
- package/dist/components/TextArea/TextArea_module.css +12 -0
- package/dist/components/TextInput/TextInput.d.ts +17 -0
- package/dist/components/TextInput/TextInput.js +18 -0
- package/dist/components/TimePicker/TimePicker.d.ts +19 -0
- package/dist/components/TimePicker/TimePicker.js +17 -0
- package/dist/components/Timeline/Timeline.d.ts +39 -0
- package/dist/components/Timeline/Timeline.js +109 -0
- package/dist/components/Timeline/Timeline.module.js +12 -0
- package/dist/components/Timeline/Timeline_module.css +99 -0
- package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
- package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
- package/dist/components/Toolbar/Toolbar.d.ts +46 -0
- package/dist/components/Toolbar/Toolbar.js +43 -0
- package/dist/components/Toolbar/Toolbar.module.js +7 -0
- package/dist/components/Toolbar/Toolbar_module.css +26 -0
- package/dist/components/Tree/Tree.d.ts +81 -0
- package/dist/components/Tree/Tree.js +232 -0
- package/dist/components/Tree/Tree.module.js +12 -0
- package/dist/components/Tree/Tree_module.css +124 -0
- package/dist/components/Tree/treeIndex.d.ts +23 -0
- package/dist/components/Tree/treeIndex.js +33 -0
- package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
- package/dist/components/TreeSelect/TreeSelect.js +117 -0
- package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
- package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
- package/dist/components/Upload/Upload.d.ts +66 -0
- package/dist/components/Upload/Upload.js +287 -0
- package/dist/components/Upload/Upload.module.js +12 -0
- package/dist/components/Upload/Upload_module.css +96 -0
- package/dist/components/ViewField/ViewField.d.ts +26 -0
- package/dist/components/ViewField/ViewField.js +29 -0
- package/dist/components/ViewField/ViewField.module.js +6 -0
- package/dist/components/ViewField/ViewField_module.css +17 -0
- package/dist/hooks/useFormReset.d.ts +10 -0
- package/dist/hooks/useFormReset.js +34 -0
- package/dist/icons/CalendarIcon.d.ts +2 -0
- package/dist/icons/CalendarIcon.js +26 -0
- package/dist/icons/CheckIcon.d.ts +6 -0
- package/dist/icons/CheckIcon.js +17 -0
- package/dist/icons/ChevronDownIcon.d.ts +6 -0
- package/dist/icons/ChevronDownIcon.js +17 -0
- package/dist/icons/MinusIcon.d.ts +5 -0
- package/dist/icons/MinusIcon.js +16 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +23 -0
- package/dist/styles/field.module.js +15 -0
- package/dist/styles/field_module.css +133 -0
- package/dist/styles/pair.module.js +6 -0
- package/dist/styles/pair_module.css +18 -0
- package/dist/styles/popup_module.css +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Popover } from "@base-ui/react/popover";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { CalendarIcon } from "../../icons/CalendarIcon.js";
|
|
5
|
+
import popup_module from "../../styles/popup.module.js";
|
|
6
|
+
import { Button } from "../Button/Button.js";
|
|
7
|
+
import { PickerField } from "../Field/PickerField.js";
|
|
8
|
+
import { Calendar } from "./Calendar.js";
|
|
9
|
+
import { dateFormatter, directionOf, isDateUnavailable, parseIsoDate, usableLocale, weekStartOf } from "./calendarDate.js";
|
|
10
|
+
import DatePicker_module from "./DatePicker.module.js";
|
|
11
|
+
const DEFAULT_LABELS = {
|
|
12
|
+
previousMonth: 'Previous month',
|
|
13
|
+
nextMonth: 'Next month',
|
|
14
|
+
close: 'Close',
|
|
15
|
+
required: 'required',
|
|
16
|
+
requiredMessage: 'Choose a date.',
|
|
17
|
+
unavailableMessage: 'Choose an available date.'
|
|
18
|
+
};
|
|
19
|
+
function DatePicker({ label, name, description, error, required = false, disabled = false, value, defaultValue, onValueChange, onBlur, min, max, isDateDisabled, locale, weekStartsOn, clearable = false, placeholder = 'Choose a date', labels }) {
|
|
20
|
+
const gridRef = useRef(null);
|
|
21
|
+
const [heldValue, setHeldValue] = useState(()=>parseIsoDate(defaultValue));
|
|
22
|
+
const [open, setOpen] = useState(false);
|
|
23
|
+
if (open && disabled) setOpen(false);
|
|
24
|
+
const chosen = void 0 === value ? heldValue : parseIsoDate(value);
|
|
25
|
+
const words = {
|
|
26
|
+
...DEFAULT_LABELS,
|
|
27
|
+
clear: `Clear ${label}`,
|
|
28
|
+
...labels
|
|
29
|
+
};
|
|
30
|
+
const resolvedLocale = usableLocale(locale);
|
|
31
|
+
const firstWeekday = weekStartsOn ?? weekStartOf(resolvedLocale);
|
|
32
|
+
const earliest = parseIsoDate(min);
|
|
33
|
+
const latest = parseIsoDate(max);
|
|
34
|
+
const commit = (nextValue)=>{
|
|
35
|
+
setHeldValue(nextValue);
|
|
36
|
+
if (nextValue !== chosen) onValueChange?.(nextValue);
|
|
37
|
+
};
|
|
38
|
+
return /*#__PURE__*/ jsx(PickerField, {
|
|
39
|
+
label: label,
|
|
40
|
+
name: name,
|
|
41
|
+
description: description,
|
|
42
|
+
error: error,
|
|
43
|
+
required: required,
|
|
44
|
+
disabled: disabled,
|
|
45
|
+
value: chosen,
|
|
46
|
+
valueText: null === chosen ? placeholder : dateFormatter(resolvedLocale, {
|
|
47
|
+
dateStyle: 'medium'
|
|
48
|
+
}).format(chosen),
|
|
49
|
+
icon: /*#__PURE__*/ jsx(CalendarIcon, {}),
|
|
50
|
+
requiredWord: words.required,
|
|
51
|
+
validate: ()=>{
|
|
52
|
+
if (null === chosen) return required ? words.requiredMessage : null;
|
|
53
|
+
return isDateUnavailable(chosen, {
|
|
54
|
+
min: earliest,
|
|
55
|
+
max: latest,
|
|
56
|
+
isDateDisabled
|
|
57
|
+
}) ? words.unavailableMessage : null;
|
|
58
|
+
},
|
|
59
|
+
onReset: ()=>{
|
|
60
|
+
if (void 0 === value) commit(parseIsoDate(defaultValue));
|
|
61
|
+
},
|
|
62
|
+
clearable: clearable,
|
|
63
|
+
clearLabel: words.clear,
|
|
64
|
+
onClear: ()=>commit(null),
|
|
65
|
+
onBlur: onBlur,
|
|
66
|
+
open: open,
|
|
67
|
+
onOpenChange: setOpen,
|
|
68
|
+
modal: "trap-focus",
|
|
69
|
+
children: /*#__PURE__*/ jsx(Popover.Portal, {
|
|
70
|
+
children: /*#__PURE__*/ jsx(Popover.Positioner, {
|
|
71
|
+
className: popup_module.layer,
|
|
72
|
+
align: "start",
|
|
73
|
+
sideOffset: 8,
|
|
74
|
+
children: /*#__PURE__*/ jsxs(Popover.Popup, {
|
|
75
|
+
className: [
|
|
76
|
+
popup_module.surface,
|
|
77
|
+
DatePicker_module.popup
|
|
78
|
+
].join(' '),
|
|
79
|
+
"data-popup": "popover",
|
|
80
|
+
"aria-label": label,
|
|
81
|
+
"aria-modal": "true",
|
|
82
|
+
dir: void 0 === resolvedLocale ? void 0 : directionOf(resolvedLocale),
|
|
83
|
+
initialFocus: ()=>gridRef.current?.querySelector('[tabindex="0"]') ?? true,
|
|
84
|
+
children: [
|
|
85
|
+
/*#__PURE__*/ jsx(Calendar, {
|
|
86
|
+
gridRef: gridRef,
|
|
87
|
+
chosen: chosen,
|
|
88
|
+
min: earliest,
|
|
89
|
+
max: latest,
|
|
90
|
+
isDateDisabled: isDateDisabled,
|
|
91
|
+
locale: resolvedLocale,
|
|
92
|
+
weekStartsOn: firstWeekday,
|
|
93
|
+
previousMonthLabel: words.previousMonth,
|
|
94
|
+
nextMonthLabel: words.nextMonth,
|
|
95
|
+
onSelect: (date)=>{
|
|
96
|
+
commit(date);
|
|
97
|
+
setOpen(false);
|
|
98
|
+
}
|
|
99
|
+
}),
|
|
100
|
+
/*#__PURE__*/ jsx("div", {
|
|
101
|
+
className: DatePicker_module.footer,
|
|
102
|
+
children: /*#__PURE__*/ jsx(Popover.Close, {
|
|
103
|
+
render: /*#__PURE__*/ jsx(Button, {
|
|
104
|
+
variant: "ghost",
|
|
105
|
+
size: "sm"
|
|
106
|
+
}),
|
|
107
|
+
children: words.close
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
export { DatePicker };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./DatePicker_module.css";
|
|
2
|
+
const DatePicker_module = {
|
|
3
|
+
popup: "popup-KehYf",
|
|
4
|
+
header: "header-zwN0_",
|
|
5
|
+
month: "month-kmJCd",
|
|
6
|
+
previous: "previous-zWGPB",
|
|
7
|
+
next: "next-caCSG",
|
|
8
|
+
gridSlot: "gridSlot-XSqqc",
|
|
9
|
+
grid: "grid-OEI6m",
|
|
10
|
+
weekday: "weekday-BLI2K",
|
|
11
|
+
day: "day-DOQIC",
|
|
12
|
+
footer: "footer-rvxzg"
|
|
13
|
+
};
|
|
14
|
+
export default DatePicker_module;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
.popup-KehYf {
|
|
2
|
+
width: 22rem;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.header-zwN0_ {
|
|
6
|
+
justify-content: space-between;
|
|
7
|
+
align-items: center;
|
|
8
|
+
gap: var(--space-2);
|
|
9
|
+
display: flex;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.month-kmJCd {
|
|
13
|
+
color: var(--color-text);
|
|
14
|
+
font-size: var(--text-md);
|
|
15
|
+
font-weight: 500;
|
|
16
|
+
line-height: var(--leading-snug);
|
|
17
|
+
text-align: center;
|
|
18
|
+
flex: 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.previous-zWGPB svg {
|
|
22
|
+
transform: rotate(90deg);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.next-caCSG svg, .header-zwN0_[data-direction="rtl"] .previous-zWGPB svg {
|
|
26
|
+
transform: rotate(-90deg);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.header-zwN0_[data-direction="rtl"] .next-caCSG svg {
|
|
30
|
+
transform: rotate(90deg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.previous-zWGPB[aria-disabled="true"], .next-caCSG[aria-disabled="true"] {
|
|
34
|
+
cursor: not-allowed;
|
|
35
|
+
opacity: .45;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.gridSlot-XSqqc {
|
|
39
|
+
min-height: calc(7 * var(--size-touch));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.grid-OEI6m {
|
|
43
|
+
border-collapse: separate;
|
|
44
|
+
border-spacing: 0;
|
|
45
|
+
table-layout: fixed;
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.weekday-BLI2K {
|
|
50
|
+
height: var(--size-touch);
|
|
51
|
+
color: var(--color-text-muted);
|
|
52
|
+
font-size: var(--text-sm);
|
|
53
|
+
text-align: center;
|
|
54
|
+
padding: 0;
|
|
55
|
+
font-weight: 500;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.day-DOQIC {
|
|
59
|
+
height: var(--size-touch);
|
|
60
|
+
border-radius: var(--radius-md);
|
|
61
|
+
color: var(--color-text);
|
|
62
|
+
font-size: var(--text-md);
|
|
63
|
+
text-align: center;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
transition-property: background-color, color;
|
|
66
|
+
transition-duration: var(--motion-duration-1);
|
|
67
|
+
transition-timing-function: var(--motion-ease);
|
|
68
|
+
-webkit-tap-highlight-color: transparent;
|
|
69
|
+
padding: 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@media (hover: hover) {
|
|
73
|
+
.day-DOQIC:hover:not([aria-disabled="true"], [aria-selected="true"]) {
|
|
74
|
+
background: var(--color-surface-2);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.day-DOQIC[aria-current="date"] {
|
|
79
|
+
border: 1px solid var(--color-accent);
|
|
80
|
+
font-weight: 600;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.day-DOQIC[aria-selected="true"] {
|
|
84
|
+
background: var(--color-accent);
|
|
85
|
+
color: var(--color-accent-text);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.day-DOQIC[aria-disabled="true"] {
|
|
89
|
+
cursor: not-allowed;
|
|
90
|
+
opacity: .45;
|
|
91
|
+
text-decoration: line-through;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@media (forced-colors: active) {
|
|
95
|
+
.day-DOQIC[aria-selected="true"] {
|
|
96
|
+
forced-color-adjust: none;
|
|
97
|
+
color: highlighttext;
|
|
98
|
+
background: highlight;
|
|
99
|
+
outline-color: canvastext;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.day-DOQIC[aria-disabled="true"] {
|
|
103
|
+
opacity: 1;
|
|
104
|
+
color: graytext;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.footer-rvxzg {
|
|
109
|
+
justify-content: flex-end;
|
|
110
|
+
display: flex;
|
|
111
|
+
}
|
|
112
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar arithmetic on `YYYY-MM-DD` strings, which is what `DatePicker` speaks in and which sort
|
|
3
|
+
* correctly as text. A date here is a day on a calendar, not an instant, so every calculation runs
|
|
4
|
+
* on UTC fields, where no day is ever 23 or 25 hours long and no midnight is ever skipped, and
|
|
5
|
+
* `Intl.DateTimeFormat` formats it back with `timeZone: 'UTC'`. The one place the local zone
|
|
6
|
+
* belongs is `todayIn`, because "today" is the user's. `toISOString` appears nowhere: on a local
|
|
7
|
+
* `Date` it is the classic way to shift a value by a day.
|
|
8
|
+
*/
|
|
9
|
+
/** The date if `value` names a real one, else `null`: `2026-02-30`, `''` and `'soon'` do not. */
|
|
10
|
+
export declare function parseIsoDate(value: string | null | undefined): string | null;
|
|
11
|
+
/** What makes a date impossible to choose. Bounds are real dates or `null`, as `parseIsoDate` gives. */
|
|
12
|
+
export interface DateAvailability {
|
|
13
|
+
min: string | null;
|
|
14
|
+
max: string | null;
|
|
15
|
+
isDateDisabled: ((date: string) => boolean) | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The one test of a date against the bounds, for the grid and for validating a chosen value. */
|
|
18
|
+
export declare function isDateUnavailable(date: string, { min, max, isDateDisabled }: DateAvailability): boolean;
|
|
19
|
+
/** The date on the user's own calendar at `now`. */
|
|
20
|
+
export declare function todayIn(now: Date): string;
|
|
21
|
+
export declare function addDays(date: string, amount: number): string;
|
|
22
|
+
export declare function firstOfMonth(date: string): string;
|
|
23
|
+
export declare function lastOfMonth(date: string): string;
|
|
24
|
+
/** Moves whole months, and lands on the last day when the target month is too short. */
|
|
25
|
+
export declare function addMonths(date: string, amount: number): string;
|
|
26
|
+
/** 0 is Sunday, as `Date` and the prop have it. */
|
|
27
|
+
export declare function weekdayOf(date: string): number;
|
|
28
|
+
export declare function startOfWeek(date: string, weekStartsOn: number): string;
|
|
29
|
+
export declare function endOfWeek(date: string, weekStartsOn: number): string;
|
|
30
|
+
/** The month holding `date` as rows of seven, with `null` for the cells outside the month. */
|
|
31
|
+
export declare function weeksOfMonth(date: string, weekStartsOn: number): (string | null)[][];
|
|
32
|
+
/**
|
|
33
|
+
* A `DateTimeFormat` for calendar dates. Keep it the only way a date here becomes text. Always the
|
|
34
|
+
* Gregorian calendar, because that is what the arithmetic above lays out: a locale's own calendar,
|
|
35
|
+
* Persian for `fa-IR` or one named in the tag as `en-US-u-ca-hebrew`, would label those cells with
|
|
36
|
+
* the wrong month. The language and the digits stay the locale's.
|
|
37
|
+
*/
|
|
38
|
+
export declare function dateFormatter(locale: string | undefined, options: Intl.DateTimeFormatOptions): {
|
|
39
|
+
format: (date: string) => string;
|
|
40
|
+
};
|
|
41
|
+
/** The locale if the platform can read it, else `undefined`: `''` and `en_US` would throw. */
|
|
42
|
+
export declare function usableLocale(locale: string | undefined): string | undefined;
|
|
43
|
+
/** Worked out from the script because `Intl.Locale`'s own text info is not in every browser. */
|
|
44
|
+
export declare function directionOf(locale: string): 'ltr' | 'rtl';
|
|
45
|
+
/** The locale's first day of the week where the platform knows it, 0 to 6; else Sunday. */
|
|
46
|
+
export declare function weekStartOf(locale: string | undefined): number;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const DAY_IN_MILLISECONDS = 86400000;
|
|
2
|
+
const EARLIEST_DATE = '0000-01-01';
|
|
3
|
+
const LATEST_DATE = '9999-12-31';
|
|
4
|
+
function toInstant(date) {
|
|
5
|
+
const instant = new Date(0);
|
|
6
|
+
instant.setUTCFullYear(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1, Number(date.slice(8, 10)));
|
|
7
|
+
return instant;
|
|
8
|
+
}
|
|
9
|
+
function formatFields(year, month, day) {
|
|
10
|
+
return [
|
|
11
|
+
String(year).padStart(4, '0'),
|
|
12
|
+
String(month).padStart(2, '0'),
|
|
13
|
+
String(day).padStart(2, '0')
|
|
14
|
+
].join('-');
|
|
15
|
+
}
|
|
16
|
+
function fromInstant(instant) {
|
|
17
|
+
const year = instant.getUTCFullYear();
|
|
18
|
+
if (year < 0) return EARLIEST_DATE;
|
|
19
|
+
if (year > 9999) return LATEST_DATE;
|
|
20
|
+
return formatFields(year, instant.getUTCMonth() + 1, instant.getUTCDate());
|
|
21
|
+
}
|
|
22
|
+
function parseIsoDate(value) {
|
|
23
|
+
if ('string' != typeof value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
24
|
+
return fromInstant(toInstant(value)) === value ? value : null;
|
|
25
|
+
}
|
|
26
|
+
function isDateUnavailable(date, { min, max, isDateDisabled }) {
|
|
27
|
+
return null !== min && date < min || null !== max && date > max || Boolean(isDateDisabled?.(date));
|
|
28
|
+
}
|
|
29
|
+
function todayIn(now) {
|
|
30
|
+
return formatFields(now.getFullYear(), now.getMonth() + 1, now.getDate());
|
|
31
|
+
}
|
|
32
|
+
function addDays(date, amount) {
|
|
33
|
+
return fromInstant(new Date(toInstant(date).getTime() + amount * DAY_IN_MILLISECONDS));
|
|
34
|
+
}
|
|
35
|
+
function firstOfMonth(date) {
|
|
36
|
+
return `${date.slice(0, 7)}-01`;
|
|
37
|
+
}
|
|
38
|
+
function lastOfMonth(date) {
|
|
39
|
+
const instant = toInstant(firstOfMonth(date));
|
|
40
|
+
instant.setUTCMonth(instant.getUTCMonth() + 1, 0);
|
|
41
|
+
return fromInstant(instant);
|
|
42
|
+
}
|
|
43
|
+
function daysInMonth(date) {
|
|
44
|
+
return Number(lastOfMonth(date).slice(8, 10));
|
|
45
|
+
}
|
|
46
|
+
function withDay(date, day) {
|
|
47
|
+
return `${date.slice(0, 8)}${String(day).padStart(2, '0')}`;
|
|
48
|
+
}
|
|
49
|
+
function addMonths(date, amount) {
|
|
50
|
+
const instant = toInstant(firstOfMonth(date));
|
|
51
|
+
instant.setUTCMonth(instant.getUTCMonth() + amount);
|
|
52
|
+
const first = fromInstant(instant);
|
|
53
|
+
return withDay(first, Math.min(Number(date.slice(8, 10)), daysInMonth(first)));
|
|
54
|
+
}
|
|
55
|
+
function weekdayOf(date) {
|
|
56
|
+
return toInstant(date).getUTCDay();
|
|
57
|
+
}
|
|
58
|
+
function daysIntoWeek(date, weekStartsOn) {
|
|
59
|
+
return (weekdayOf(date) - weekStartsOn + 7) % 7;
|
|
60
|
+
}
|
|
61
|
+
function startOfWeek(date, weekStartsOn) {
|
|
62
|
+
return addDays(date, -daysIntoWeek(date, weekStartsOn));
|
|
63
|
+
}
|
|
64
|
+
function endOfWeek(date, weekStartsOn) {
|
|
65
|
+
return addDays(startOfWeek(date, weekStartsOn), 6);
|
|
66
|
+
}
|
|
67
|
+
function weeksOfMonth(date, weekStartsOn) {
|
|
68
|
+
const first = firstOfMonth(date);
|
|
69
|
+
const dayCount = daysInMonth(date);
|
|
70
|
+
const leadingCells = daysIntoWeek(first, weekStartsOn);
|
|
71
|
+
const weekCount = Math.ceil((leadingCells + dayCount) / 7);
|
|
72
|
+
return Array.from({
|
|
73
|
+
length: weekCount
|
|
74
|
+
}, (_unusedWeek, week)=>Array.from({
|
|
75
|
+
length: 7
|
|
76
|
+
}, (_unusedDay, column)=>{
|
|
77
|
+
const day = 7 * week + column - leadingCells + 1;
|
|
78
|
+
return day >= 1 && day <= dayCount ? withDay(first, day) : null;
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
function dateFormatter(locale, options) {
|
|
82
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
83
|
+
...options,
|
|
84
|
+
calendar: 'gregory',
|
|
85
|
+
timeZone: 'UTC'
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
format: (date)=>formatter.format(toInstant(date))
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function usableLocale(locale) {
|
|
92
|
+
try {
|
|
93
|
+
return void 0 === locale ? void 0 : Intl.getCanonicalLocales(locale)[0];
|
|
94
|
+
} catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const RIGHT_TO_LEFT_SCRIPTS = new Set([
|
|
99
|
+
'Adlm',
|
|
100
|
+
'Arab',
|
|
101
|
+
'Hebr',
|
|
102
|
+
'Mand',
|
|
103
|
+
'Nkoo',
|
|
104
|
+
'Rohg',
|
|
105
|
+
'Syrc',
|
|
106
|
+
'Thaa'
|
|
107
|
+
]);
|
|
108
|
+
function directionOf(locale) {
|
|
109
|
+
const script = new Intl.Locale(locale).maximize().script ?? '';
|
|
110
|
+
return RIGHT_TO_LEFT_SCRIPTS.has(script) ? 'rtl' : 'ltr';
|
|
111
|
+
}
|
|
112
|
+
function weekStartOf(locale) {
|
|
113
|
+
const resolved = locale ?? new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
114
|
+
const details = new Intl.Locale(resolved);
|
|
115
|
+
return (details.getWeekInfo?.().firstDay ?? details.weekInfo?.firstDay ?? 0) % 7;
|
|
116
|
+
}
|
|
117
|
+
export { addDays, addMonths, dateFormatter, directionOf, endOfWeek, firstOfMonth, isDateUnavailable, lastOfMonth, parseIsoDate, startOfWeek, todayIn, usableLocale, weekStartOf, weekdayOf, weeksOfMonth };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface DescriptionsItem {
|
|
3
|
+
/** Identifies the item across renders. */
|
|
4
|
+
id: string;
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
value?: ReactNode;
|
|
7
|
+
/** How many columns it takes. Limited to `columns`, and ignored at narrow widths. */
|
|
8
|
+
span?: 1 | 2 | 3;
|
|
9
|
+
}
|
|
10
|
+
export interface DescriptionsProps {
|
|
11
|
+
items: DescriptionsItem[];
|
|
12
|
+
/**
|
|
13
|
+
* The columns from the `sm` breakpoint up; below it there is one. The breakpoint is the
|
|
14
|
+
* viewport's, so in a narrow place on a wide screen, such as a sidebar, pass `1`.
|
|
15
|
+
*/
|
|
16
|
+
columns?: 1 | 2 | 3;
|
|
17
|
+
/** Rendered above the list, and names it through `aria-labelledby`. */
|
|
18
|
+
heading?: ReactNode;
|
|
19
|
+
/** `4` is the extra step `Card` does not have: this often sits inside a card's own `h3`. */
|
|
20
|
+
headingLevel?: 2 | 3 | 4;
|
|
21
|
+
/** Shown instead of a value that is `undefined`, `null`, `false` or `''`. */
|
|
22
|
+
emptyText?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/** A set of label and value pairs in one `<dl>`. For a single pair use `ViewField`. */
|
|
25
|
+
export declare function Descriptions({ items, columns, heading, headingLevel, emptyText, }: DescriptionsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import pair_module from "../../styles/pair.module.js";
|
|
4
|
+
import { DEFAULT_EMPTY_TEXT, isEmptyValue } from "../ViewField/ViewField.js";
|
|
5
|
+
import Descriptions_module from "./Descriptions.module.js";
|
|
6
|
+
function Descriptions({ items, columns = 2, heading, headingLevel = 3, emptyText = DEFAULT_EMPTY_TEXT }) {
|
|
7
|
+
const headingId = useId();
|
|
8
|
+
const Heading = `h${headingLevel}`;
|
|
9
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
10
|
+
className: Descriptions_module.root,
|
|
11
|
+
children: [
|
|
12
|
+
heading ? /*#__PURE__*/ jsx(Heading, {
|
|
13
|
+
id: headingId,
|
|
14
|
+
className: Descriptions_module.heading,
|
|
15
|
+
children: heading
|
|
16
|
+
}) : null,
|
|
17
|
+
/*#__PURE__*/ jsx("dl", {
|
|
18
|
+
className: Descriptions_module.list,
|
|
19
|
+
"data-columns": columns,
|
|
20
|
+
"aria-labelledby": heading ? headingId : void 0,
|
|
21
|
+
children: items.map((item)=>{
|
|
22
|
+
const isEmpty = isEmptyValue(item.value);
|
|
23
|
+
const span = Math.min(item.span ?? 1, columns);
|
|
24
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
25
|
+
className: Descriptions_module.group,
|
|
26
|
+
"data-span": span > 1 ? span : void 0,
|
|
27
|
+
children: [
|
|
28
|
+
/*#__PURE__*/ jsx("dt", {
|
|
29
|
+
className: pair_module.label,
|
|
30
|
+
children: item.label
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ jsx("dd", {
|
|
33
|
+
className: pair_module.value,
|
|
34
|
+
"data-empty": isEmpty ? '' : void 0,
|
|
35
|
+
children: isEmpty ? emptyText : item.value
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
}, item.id);
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export { Descriptions };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
.root-bQlQQ {
|
|
2
|
+
gap: var(--space-3);
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
display: flex;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.heading-aHnDT {
|
|
8
|
+
color: var(--color-text);
|
|
9
|
+
font-size: var(--text-h3);
|
|
10
|
+
line-height: var(--leading-snug);
|
|
11
|
+
letter-spacing: var(--tracking-heading);
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.list-Qwuyt {
|
|
16
|
+
gap: var(--space-4);
|
|
17
|
+
grid-template-columns: minmax(0, 1fr);
|
|
18
|
+
margin: 0;
|
|
19
|
+
display: grid;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.group-fd_ih {
|
|
23
|
+
gap: var(--space-1);
|
|
24
|
+
overflow-wrap: anywhere;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
min-width: 0;
|
|
27
|
+
display: flex;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@media (width >= 40rem) {
|
|
31
|
+
.list-Qwuyt[data-columns="2"] {
|
|
32
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.list-Qwuyt[data-columns="3"] {
|
|
36
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.group-fd_ih[data-span="2"] {
|
|
40
|
+
grid-column: span 2;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.group-fd_ih[data-span="3"] {
|
|
44
|
+
grid-column: span 3;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/** Internal. Read by `TextInput`, `TextArea` and `TimePicker`; not exported from the barrel. */
|
|
3
|
+
export declare function useFieldRequired(): boolean;
|
|
4
|
+
export interface FieldMessagesProps {
|
|
5
|
+
/** Sits under the control and joins the control's `aria-describedby`. */
|
|
6
|
+
description: ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* The description node's own id. Left `undefined` lets Base UI generate one; a later
|
|
9
|
+
* component's own frame passes an id of its own when something else needs to point at the
|
|
10
|
+
* same node.
|
|
11
|
+
*/
|
|
12
|
+
descriptionId?: string;
|
|
13
|
+
/** The validation message. Its presence — not its content — is the error state. */
|
|
14
|
+
error: string | undefined;
|
|
15
|
+
/** The error node's own id, on the same terms as `descriptionId`. */
|
|
16
|
+
errorId?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The description/error block every Tier 3 field frame renders: a description that shows
|
|
20
|
+
* whenever one is given, and an error that only shows once one is given. Exported, but
|
|
21
|
+
* deliberately absent from `src/index.ts` — not part of the barrel, exactly as
|
|
22
|
+
* `useFieldRequired` above and `icons/CloseIcon` are reachable across modules without being
|
|
23
|
+
* published. `Field` is the first of six components that render this exact pair; `Select`,
|
|
24
|
+
* `Checkbox`, `RadioGroup` and `Switch` import it from here in later tasks, each supplying its
|
|
25
|
+
* own frame's `description` and `error` and, where its frame does not already sit inside a
|
|
26
|
+
* `Field.Root` whose context wires `aria-describedby` on its own, the ids that frame needs the
|
|
27
|
+
* nodes to carry.
|
|
28
|
+
*/
|
|
29
|
+
export declare function FieldMessages({ description, descriptionId, error, errorId }: FieldMessagesProps): import("react").JSX.Element;
|
|
30
|
+
export interface RequiredMarkProps {
|
|
31
|
+
/** Draws the mark when true. Every frame passes its own `required` prop straight in. */
|
|
32
|
+
when: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The required mark every Tier 3 frame draws after its label. Childless and `aria-hidden` on
|
|
36
|
+
* purpose: the control's own `required` attribute is what carries the requirement into the
|
|
37
|
+
* accessibility tree, and the asterisk is generated content, because a text child would join
|
|
38
|
+
* the label's raw text content — which is what Testing Library's `getByLabelText` matches
|
|
39
|
+
* against. `field.module.css`'s `.required` has the long version. One line written five times
|
|
40
|
+
* before this, and written wrong in two of them. Internal, like `FieldMessages`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function RequiredMark({ when }: RequiredMarkProps): import("react").JSX.Element | null;
|
|
43
|
+
/**
|
|
44
|
+
* The prop set every Tier 3 field frame takes. `Field`, `Select`, `Checkbox`, `RadioGroup`,
|
|
45
|
+
* `Switch` and the `InlineField` below all extend it and restate only the members their own
|
|
46
|
+
* anatomy rewords — a checkbox's label sits beside its box, a radio group's description sits
|
|
47
|
+
* under its options, and `Field` is the one frame whose control is a real `<input>`, so its
|
|
48
|
+
* `required` behaves differently on submit. `TextInput` is the tier's exception: it has no
|
|
49
|
+
* frame of its own and reads `name`, `disabled` and `required` off the one around it.
|
|
50
|
+
*/
|
|
51
|
+
export interface FieldFrameProps {
|
|
52
|
+
/** The visible label, and the control's accessible name. */
|
|
53
|
+
label: string;
|
|
54
|
+
/** Identifies the field when a form is submitted. */
|
|
55
|
+
name?: string;
|
|
56
|
+
/** Sits under the control and joins the control's `aria-describedby`. */
|
|
57
|
+
description?: ReactNode;
|
|
58
|
+
/**
|
|
59
|
+
* The validation message. Its presence — not its content — is the error state: the frame
|
|
60
|
+
* becomes `invalid`, the control gets `aria-invalid="true"` and the message joins the
|
|
61
|
+
* control's `aria-describedby`. Validation itself belongs to the consuming app; the library
|
|
62
|
+
* owns only how an error looks and how it is announced.
|
|
63
|
+
*/
|
|
64
|
+
error?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Draws the required mark and puts `required` on the control. Base UI carries it on the
|
|
67
|
+
* visually hidden, `aria-hidden`, `tabindex="-1"` companion input it submits with — the exact
|
|
68
|
+
* shape a browser refuses to report a validation message on, so the native bubble blocks the
|
|
69
|
+
* submit silently instead. A form driven by a form library must carry `noValidate` on the
|
|
70
|
+
* `<form>`, as `Field`'s own `required` documents and the composed example does.
|
|
71
|
+
*/
|
|
72
|
+
required?: boolean;
|
|
73
|
+
disabled?: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface FieldProps extends FieldFrameProps {
|
|
76
|
+
/**
|
|
77
|
+
* Identifies the field when a form is submitted. It takes precedence over any `name` the
|
|
78
|
+
* control carries, which is why no control in this tier has one.
|
|
79
|
+
*/
|
|
80
|
+
name?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Draws the required mark and puts `required` on the control. Note that a native `required`
|
|
83
|
+
* also arms the browser's own validation bubble on submit; a form driven by TanStack Form or
|
|
84
|
+
* any other library should carry `noValidate` on the `<form>`, as such forms normally do.
|
|
85
|
+
* `Field`'s control is a real `<input>`, so the browser reports the message rather than
|
|
86
|
+
* blocking the submit in silence, which is what the other four frames' `required` documents.
|
|
87
|
+
*/
|
|
88
|
+
required?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* The control. `TextInput` is the one this tier ships for it; anything else Base UI's field
|
|
91
|
+
* context reaches works too, and `TextInput`'s `render` prop is how a caller's own element —
|
|
92
|
+
* a `<textarea>`, an `<input type="file">` — gets the same wiring and the same skin.
|
|
93
|
+
*
|
|
94
|
+
* `Select`, `Checkbox`, `RadioGroup` and `Switch` are **not** composed in here: each owns its
|
|
95
|
+
* own field frame, because a `<label for>` above a control is not the anatomy any of them has.
|
|
96
|
+
*/
|
|
97
|
+
children: ReactNode;
|
|
98
|
+
}
|
|
99
|
+
export declare function Field({ label, name, description, error, required, disabled, children, }: FieldProps): import("react").JSX.Element;
|
|
100
|
+
export interface InlineFieldProps extends FieldFrameProps {
|
|
101
|
+
/** The text beside the control, and the control's accessible name. */
|
|
102
|
+
label: string;
|
|
103
|
+
/** Sits under the row and joins the control's `aria-describedby`. */
|
|
104
|
+
description?: ReactNode;
|
|
105
|
+
/** Draws the required mark. The control in the row still takes its own `required`. */
|
|
106
|
+
required?: boolean;
|
|
107
|
+
/** The control that sits at the head of the row: a `Checkbox.Root`, a `Switch.Root`. */
|
|
108
|
+
children: ReactNode;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The frame `Checkbox` and `Switch` share: a row whose label wraps the control and the text,
|
|
112
|
+
* with the description and the error beneath it. That is the whole difference between this
|
|
113
|
+
* frame and `Field`'s — the label sits beside the control rather than above it — and it is why
|
|
114
|
+
* neither of those two is composed inside `Field`. Exported, but deliberately absent from
|
|
115
|
+
* `src/index.ts`, on the same terms as `FieldMessages` and `useFieldRequired` above: a
|
|
116
|
+
* consumer composes a `Checkbox` or a `Switch`, not the frame under them.
|
|
117
|
+
*/
|
|
118
|
+
export declare function InlineField({ label, name, description, error, required, disabled, children, }: InlineFieldProps): import("react").JSX.Element;
|