@jcsoftdev/ui 0.3.0 → 0.4.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/CHANGELOG.md +103 -1
- package/README.md +55 -2
- package/bin/ui-theme.mjs +13 -2
- package/dist/atoms/checkbox/checkbox.js +3 -1
- package/dist/atoms/chip/chip.d.ts +11 -3
- package/dist/atoms/chip/chip.js +8 -1
- package/dist/atoms/chip/index.d.ts +1 -1
- package/dist/atoms/chip/index.js +2 -0
- package/dist/atoms/due-chip/due-chip.d.ts +31 -0
- package/dist/atoms/due-chip/due-chip.js +41 -0
- package/dist/atoms/due-chip/index.d.ts +2 -0
- package/dist/atoms/due-chip/index.js +6 -0
- package/dist/atoms/due-chip/model.d.ts +25 -0
- package/dist/atoms/due-chip/model.js +44 -0
- package/dist/atoms/icon-button/icon-button.d.ts +22 -0
- package/dist/atoms/icon-button/icon-button.js +38 -0
- package/dist/atoms/icon-button/index.d.ts +1 -0
- package/dist/atoms/icon-button/index.js +8 -0
- package/dist/atoms/index.d.ts +5 -0
- package/dist/atoms/index.js +5 -0
- package/dist/atoms/internal/hit-area.d.ts +6 -0
- package/dist/atoms/internal/hit-area.js +4 -0
- package/dist/atoms/kbd/index.d.ts +1 -0
- package/dist/atoms/kbd/index.js +4 -0
- package/dist/atoms/kbd/kbd.d.ts +7 -0
- package/dist/atoms/kbd/kbd.js +17 -0
- package/dist/atoms/radio-group/radio-group.js +6 -2
- package/dist/atoms/seal/index.d.ts +1 -0
- package/dist/atoms/seal/index.js +4 -0
- package/dist/atoms/seal/seal.d.ts +30 -0
- package/dist/atoms/seal/seal.js +71 -0
- package/dist/atoms/spinner/index.d.ts +1 -0
- package/dist/atoms/spinner/index.js +5 -0
- package/dist/atoms/spinner/spinner.d.ts +19 -0
- package/dist/atoms/spinner/spinner.js +31 -0
- package/dist/atoms/switch/switch.js +3 -1
- package/dist/calendar/date-calendar/date-calendar.d.ts +32 -0
- package/dist/calendar/date-calendar/date-calendar.js +189 -0
- package/dist/calendar/date-calendar/index.d.ts +1 -0
- package/dist/calendar/date-calendar/index.js +6 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/internal/date-utils.d.ts +26 -0
- package/dist/calendar/internal/date-utils.js +95 -1
- package/dist/containers/aside/aside.d.ts +14 -0
- package/dist/containers/aside/aside.js +25 -0
- package/dist/containers/aside/index.d.ts +1 -0
- package/dist/containers/aside/index.js +5 -0
- package/dist/containers/banner/banner.d.ts +4 -1
- package/dist/containers/banner/banner.js +9 -1
- package/dist/containers/description-list/description-list.d.ts +29 -6
- package/dist/containers/description-list/description-list.js +47 -6
- package/dist/containers/feed/feed.d.ts +23 -0
- package/dist/containers/feed/feed.js +77 -0
- package/dist/containers/feed/index.d.ts +2 -0
- package/dist/containers/feed/index.js +10 -0
- package/dist/containers/feed/model.d.ts +19 -0
- package/dist/containers/feed/model.js +38 -0
- package/dist/containers/index.d.ts +6 -0
- package/dist/containers/index.js +6 -0
- package/dist/containers/kpi/kpi.d.ts +50 -8
- package/dist/containers/kpi/kpi.js +91 -39
- package/dist/containers/list-detail/index.d.ts +1 -0
- package/dist/containers/list-detail/index.js +20 -0
- package/dist/containers/list-detail/list-detail.d.ts +55 -0
- package/dist/containers/list-detail/list-detail.js +221 -0
- package/dist/containers/note/index.d.ts +1 -0
- package/dist/containers/note/index.js +4 -0
- package/dist/containers/note/note.d.ts +13 -0
- package/dist/containers/note/note.js +27 -0
- package/dist/containers/section/index.d.ts +1 -0
- package/dist/containers/section/index.js +6 -0
- package/dist/containers/section/section.d.ts +68 -0
- package/dist/containers/section/section.js +198 -0
- package/dist/containers/shortcuts/index.d.ts +1 -0
- package/dist/containers/shortcuts/index.js +8 -0
- package/dist/containers/shortcuts/shortcuts.d.ts +18 -0
- package/dist/containers/shortcuts/shortcuts.js +50 -0
- package/dist/containers/table/selection.d.ts +9 -0
- package/dist/containers/table/selection.js +20 -0
- package/dist/containers/table/table.d.ts +66 -4
- package/dist/containers/table/table.js +128 -7
- package/dist/containers/timeline/index.d.ts +1 -1
- package/dist/containers/timeline/index.js +4 -2
- package/dist/containers/timeline/timeline.d.ts +32 -5
- package/dist/containers/timeline/timeline.js +154 -90
- package/dist/forms/chip-group/chip-group.d.ts +54 -0
- package/dist/forms/chip-group/chip-group.js +114 -0
- package/dist/forms/chip-group/index.d.ts +1 -0
- package/dist/forms/chip-group/index.js +6 -0
- package/dist/forms/combobox/combobox.d.ts +60 -0
- package/dist/forms/combobox/combobox.js +281 -0
- package/dist/forms/combobox/index.d.ts +1 -0
- package/dist/forms/combobox/index.js +6 -0
- package/dist/forms/date-picker/date-picker.d.ts +40 -0
- package/dist/forms/date-picker/date-picker.js +183 -0
- package/dist/forms/date-picker/date-time-picker.d.ts +43 -0
- package/dist/forms/date-picker/date-time-picker.js +121 -0
- package/dist/forms/date-picker/index.d.ts +2 -0
- package/dist/forms/date-picker/index.js +10 -0
- package/dist/forms/date-picker/model.d.ts +35 -0
- package/dist/forms/date-picker/model.js +83 -0
- package/dist/forms/dropzone/dropzone.d.ts +30 -2
- package/dist/forms/dropzone/dropzone.js +153 -23
- package/dist/forms/field/field.d.ts +16 -10
- package/dist/forms/field/field.js +41 -5
- package/dist/forms/index.d.ts +4 -0
- package/dist/forms/index.js +4 -0
- package/dist/forms/input/index.d.ts +1 -1
- package/dist/forms/input/index.js +4 -1
- package/dist/forms/input/input.d.ts +21 -5
- package/dist/forms/input/input.js +74 -9
- package/dist/forms/input-icon/input-icon.d.ts +1 -1
- package/dist/forms/internal/listbox-items.d.ts +18 -0
- package/dist/forms/internal/listbox-items.js +88 -0
- package/dist/forms/internal/listbox.d.ts +44 -0
- package/dist/forms/internal/listbox.js +74 -0
- package/dist/forms/number-stepper/model.d.ts +16 -0
- package/dist/forms/number-stepper/model.js +23 -0
- package/dist/forms/number-stepper/number-stepper.d.ts +36 -6
- package/dist/forms/number-stepper/number-stepper.js +86 -37
- package/dist/forms/select-menu/index.d.ts +1 -0
- package/dist/forms/select-menu/index.js +6 -0
- package/dist/forms/select-menu/select-menu.d.ts +35 -0
- package/dist/forms/select-menu/select-menu.js +230 -0
- package/dist/i18n/strings.d.ts +89 -0
- package/dist/i18n/strings.js +54 -2
- package/dist/i18n/ui-strings-provider.d.ts +1 -1
- package/dist/i18n/ui-strings-provider.js +6 -2
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/stepper/index.d.ts +1 -1
- package/dist/navigation/stepper/index.js +3 -1
- package/dist/navigation/stepper/stepper.d.ts +8 -0
- package/dist/navigation/stepper/stepper.js +68 -45
- package/dist/navigation/tabs/index.d.ts +1 -0
- package/dist/navigation/tabs/index.js +6 -0
- package/dist/navigation/tabs/tabs-nav.d.ts +37 -0
- package/dist/navigation/tabs/tabs-nav.js +57 -0
- package/dist/navigation/wizard/index.d.ts +1 -0
- package/dist/navigation/wizard/index.js +6 -0
- package/dist/navigation/wizard/model.d.ts +33 -0
- package/dist/navigation/wizard/model.js +34 -0
- package/dist/navigation/wizard/wizard.d.ts +45 -0
- package/dist/navigation/wizard/wizard.js +169 -0
- package/dist/overlays/alert-dialog/alert-dialog.d.ts +103 -0
- package/dist/overlays/alert-dialog/alert-dialog.js +342 -0
- package/dist/overlays/alert-dialog/index.d.ts +1 -0
- package/dist/overlays/alert-dialog/index.js +26 -0
- package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +17 -1
- package/dist/overlays/dropdown-menu/dropdown-menu.js +12 -4
- package/dist/overlays/dropdown-menu/index.d.ts +1 -1
- package/dist/overlays/dropdown-menu/index.js +8 -2
- package/dist/overlays/index.d.ts +2 -0
- package/dist/overlays/index.js +2 -0
- package/dist/overlays/testing/index.d.ts +5 -0
- package/dist/overlays/testing/index.js +4 -0
- package/dist/overlays/toaster/index.d.ts +2 -1
- package/dist/overlays/toaster/index.js +4 -2
- package/dist/overlays/toaster/toast-store.d.ts +6 -2
- package/dist/overlays/toaster/toast.d.ts +3 -0
- package/dist/overlays/toaster/toast.js +3 -0
- package/dist/overlays/toaster/toaster.d.ts +3 -0
- package/dist/overlays/toaster/toaster.js +36 -3
- package/dist/overlays/tooltip/index.d.ts +1 -0
- package/dist/overlays/tooltip/index.js +4 -0
- package/dist/overlays/tooltip/model.d.ts +10 -0
- package/dist/overlays/tooltip/model.js +13 -0
- package/dist/overlays/tooltip/tooltip.d.ts +41 -0
- package/dist/overlays/tooltip/tooltip.js +116 -0
- package/dist/primitives/use-dismissable-layer.js +1 -1
- package/dist/states/error-state/error-state.d.ts +6 -1
- package/dist/states/error-state/error-state.js +13 -9
- package/dist/states/skeleton/skeleton.d.ts +8 -2
- package/dist/states/skeleton/skeleton.js +44 -2
- package/package.json +2 -2
- package/scripts/build-theme.mjs +12 -1
- package/src/atoms/checkbox/checkbox.tsx +3 -1
- package/src/atoms/chip/chip.tsx +18 -3
- package/src/atoms/chip/index.ts +2 -0
- package/src/atoms/due-chip/due-chip.tsx +75 -0
- package/src/atoms/due-chip/index.ts +2 -0
- package/src/atoms/due-chip/model.ts +67 -0
- package/src/atoms/icon-button/icon-button.tsx +58 -0
- package/src/atoms/icon-button/index.ts +6 -0
- package/src/atoms/index.ts +5 -0
- package/src/atoms/internal/hit-area.ts +7 -0
- package/src/atoms/kbd/index.ts +1 -0
- package/src/atoms/kbd/kbd.tsx +20 -0
- package/src/atoms/radio-group/radio-group.tsx +8 -2
- package/src/atoms/seal/index.ts +1 -0
- package/src/atoms/seal/seal.tsx +107 -0
- package/src/atoms/spinner/index.ts +1 -0
- package/src/atoms/spinner/spinner.tsx +49 -0
- package/src/atoms/switch/switch.tsx +3 -1
- package/src/calendar/date-calendar/date-calendar.tsx +230 -0
- package/src/calendar/date-calendar/index.ts +5 -0
- package/src/calendar/index.ts +1 -0
- package/src/calendar/internal/date-utils.ts +115 -0
- package/src/containers/aside/aside.tsx +40 -0
- package/src/containers/aside/index.ts +1 -0
- package/src/containers/banner/banner.tsx +18 -1
- package/src/containers/description-list/description-list.tsx +85 -9
- package/src/containers/feed/feed.tsx +99 -0
- package/src/containers/feed/index.ts +8 -0
- package/src/containers/feed/model.ts +54 -0
- package/src/containers/index.ts +6 -0
- package/src/containers/kpi/kpi.tsx +161 -62
- package/src/containers/list-detail/index.ts +15 -0
- package/src/containers/list-detail/list-detail.tsx +293 -0
- package/src/containers/note/index.ts +1 -0
- package/src/containers/note/note.tsx +38 -0
- package/src/containers/section/index.ts +11 -0
- package/src/containers/section/section.tsx +281 -0
- package/src/containers/shortcuts/index.ts +6 -0
- package/src/containers/shortcuts/shortcuts.tsx +92 -0
- package/src/containers/table/selection.ts +26 -0
- package/src/containers/table/table.tsx +215 -13
- package/src/containers/timeline/index.ts +3 -0
- package/src/containers/timeline/timeline.tsx +204 -93
- package/src/forms/chip-group/chip-group.tsx +184 -0
- package/src/forms/chip-group/index.ts +8 -0
- package/src/forms/combobox/combobox.tsx +359 -0
- package/src/forms/combobox/index.ts +7 -0
- package/src/forms/date-picker/date-picker.tsx +239 -0
- package/src/forms/date-picker/date-time-picker.tsx +178 -0
- package/src/forms/date-picker/index.ts +10 -0
- package/src/forms/date-picker/model.ts +108 -0
- package/src/forms/dropzone/dropzone.tsx +217 -35
- package/src/forms/field/field.tsx +72 -7
- package/src/forms/index.ts +4 -0
- package/src/forms/input/index.ts +8 -1
- package/src/forms/input/input.tsx +97 -12
- package/src/forms/input-icon/input-icon.tsx +1 -1
- package/src/forms/internal/listbox-items.tsx +103 -0
- package/src/forms/internal/listbox.ts +124 -0
- package/src/forms/number-stepper/model.ts +35 -0
- package/src/forms/number-stepper/number-stepper.tsx +132 -42
- package/src/forms/select-menu/index.ts +7 -0
- package/src/forms/select-menu/select-menu.tsx +280 -0
- package/src/i18n/strings.ts +89 -0
- package/src/i18n/ui-strings-provider.tsx +15 -4
- package/src/navigation/index.ts +1 -0
- package/src/navigation/stepper/index.ts +7 -1
- package/src/navigation/stepper/stepper.tsx +41 -5
- package/src/navigation/tabs/index.ts +7 -0
- package/src/navigation/tabs/tabs-nav.tsx +131 -0
- package/src/navigation/wizard/index.ts +7 -0
- package/src/navigation/wizard/model.ts +61 -0
- package/src/navigation/wizard/wizard.tsx +222 -0
- package/src/overlays/alert-dialog/alert-dialog.tsx +486 -0
- package/src/overlays/alert-dialog/index.ts +19 -0
- package/src/overlays/dropdown-menu/dropdown-menu.tsx +29 -4
- package/src/overlays/dropdown-menu/index.ts +3 -0
- package/src/overlays/index.ts +2 -0
- package/src/overlays/testing/index.ts +5 -0
- package/src/overlays/toaster/index.ts +2 -0
- package/src/overlays/toaster/toast-store.ts +6 -2
- package/src/overlays/toaster/toast.ts +6 -0
- package/src/overlays/toaster/toaster.tsx +44 -2
- package/src/overlays/tooltip/index.ts +1 -0
- package/src/overlays/tooltip/model.ts +18 -0
- package/src/overlays/tooltip/tooltip.tsx +166 -0
- package/src/primitives/use-dismissable-layer.ts +7 -2
- package/src/states/error-state/error-state.tsx +19 -8
- package/src/states/skeleton/skeleton.tsx +68 -2
- package/styles/tailwind.css +33 -30
- package/styles/theme.css +33 -30
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState
|
|
9
|
+
} from "react";
|
|
10
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
11
|
+
import { X } from "../../icons/index.js";
|
|
12
|
+
import * as PopoverPrimitive from "../../primitives/popover/popover.js";
|
|
13
|
+
import { cn } from "../../utils/cn.js";
|
|
14
|
+
import { useComposedRefs } from "../../utils/compose.js";
|
|
15
|
+
import { materialClass } from "../../utils/material.js";
|
|
16
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
17
|
+
import {
|
|
18
|
+
filterItems,
|
|
19
|
+
flattenItems,
|
|
20
|
+
matchesQuery,
|
|
21
|
+
moveActive
|
|
22
|
+
} from "../internal/listbox.js";
|
|
23
|
+
import { LISTBOX_SURFACE, ListboxItems, optionDomId } from "../internal/listbox-items.js";
|
|
24
|
+
function Combobox({
|
|
25
|
+
options,
|
|
26
|
+
value: valueProp,
|
|
27
|
+
defaultValue = "",
|
|
28
|
+
onValueChange,
|
|
29
|
+
onSearchChange,
|
|
30
|
+
filter = true,
|
|
31
|
+
maxVisible = 50,
|
|
32
|
+
loading = false,
|
|
33
|
+
loadingText,
|
|
34
|
+
emptyText,
|
|
35
|
+
clearable = true,
|
|
36
|
+
clearLabel,
|
|
37
|
+
valueLabel,
|
|
38
|
+
name,
|
|
39
|
+
invalid,
|
|
40
|
+
required,
|
|
41
|
+
nativeRequired = false,
|
|
42
|
+
size = "md",
|
|
43
|
+
container,
|
|
44
|
+
material,
|
|
45
|
+
disabled,
|
|
46
|
+
className,
|
|
47
|
+
classNames,
|
|
48
|
+
ref,
|
|
49
|
+
id,
|
|
50
|
+
onFocus,
|
|
51
|
+
onClick,
|
|
52
|
+
onBlur,
|
|
53
|
+
onKeyDown,
|
|
54
|
+
"aria-label": ariaLabel,
|
|
55
|
+
"aria-labelledby": ariaLabelledBy,
|
|
56
|
+
"aria-invalid": ariaInvalid,
|
|
57
|
+
...props
|
|
58
|
+
}) {
|
|
59
|
+
const strings = useUiStrings();
|
|
60
|
+
const autoId = useId();
|
|
61
|
+
const inputId = id ?? autoId;
|
|
62
|
+
const listId = `${inputId}-listbox`;
|
|
63
|
+
const rootRef = useRef(null);
|
|
64
|
+
const inputRef = useRef(null);
|
|
65
|
+
const composedRef = useComposedRefs(ref, inputRef);
|
|
66
|
+
const allOptions = useMemo(() => flattenItems(options), [options]);
|
|
67
|
+
const [value, setValue] = useControllableState({
|
|
68
|
+
prop: valueProp,
|
|
69
|
+
defaultProp: defaultValue,
|
|
70
|
+
onChange: (next) => onValueChange?.(next, allOptions.find((option) => option.value === next) ?? null)
|
|
71
|
+
});
|
|
72
|
+
const [query, setQuery] = useState(null);
|
|
73
|
+
const [open, setOpen] = useState(false);
|
|
74
|
+
const [active, setActive] = useState(0);
|
|
75
|
+
const text = query ?? "";
|
|
76
|
+
const items = useMemo(() => {
|
|
77
|
+
const predicate = filter === false ? () => true : typeof filter === "function" ? (option) => filter(option, text) : (option) => matchesQuery(option, text);
|
|
78
|
+
return filterItems(options, predicate, maxVisible);
|
|
79
|
+
}, [options, filter, text, maxVisible]);
|
|
80
|
+
const flat = useMemo(() => flattenItems(items), [items]);
|
|
81
|
+
const selected = value === "" ? void 0 : allOptions.find((option) => option.value === value);
|
|
82
|
+
const selectedLabel = selected?.label ?? (value === "" ? "" : valueLabel ?? "");
|
|
83
|
+
const isOpen = open && !disabled;
|
|
84
|
+
const showList = isOpen && flat.length > 0;
|
|
85
|
+
const showEmpty = isOpen && !loading && flat.length === 0;
|
|
86
|
+
const activeIndex = flat[active] && !flat[active]?.disabled ? active : moveActive(flat, -1, "first");
|
|
87
|
+
useEffect(() => setActive(0), [query, isOpen]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!showList || activeIndex < 0) return;
|
|
90
|
+
document.getElementById(optionDomId(listId, activeIndex))?.scrollIntoView?.({ block: "nearest" });
|
|
91
|
+
}, [showList, activeIndex, listId]);
|
|
92
|
+
const resetSearch = () => {
|
|
93
|
+
if (query !== null) onSearchChange?.("");
|
|
94
|
+
setQuery(null);
|
|
95
|
+
};
|
|
96
|
+
const pick = (option) => {
|
|
97
|
+
if (!option || option.disabled) return;
|
|
98
|
+
setValue(option.value);
|
|
99
|
+
resetSearch();
|
|
100
|
+
setOpen(false);
|
|
101
|
+
};
|
|
102
|
+
const clear = () => {
|
|
103
|
+
setValue("");
|
|
104
|
+
resetSearch();
|
|
105
|
+
setOpen(false);
|
|
106
|
+
inputRef.current?.focus();
|
|
107
|
+
};
|
|
108
|
+
const handleKeyDown = (event) => {
|
|
109
|
+
onKeyDown?.(event);
|
|
110
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
111
|
+
const { key } = event;
|
|
112
|
+
if (key === "ArrowDown") {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
if (!isOpen) setOpen(true);
|
|
115
|
+
else setActive(moveActive(flat, activeIndex, "next"));
|
|
116
|
+
} else if (key === "ArrowUp") {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
if (!isOpen) setOpen(true);
|
|
119
|
+
else setActive(moveActive(flat, activeIndex, "prev"));
|
|
120
|
+
} else if (key === "Enter") {
|
|
121
|
+
if (showList && flat[activeIndex]) {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
pick(flat[activeIndex]);
|
|
124
|
+
}
|
|
125
|
+
} else if (key === "Escape") {
|
|
126
|
+
if (isOpen) {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
setOpen(false);
|
|
129
|
+
} else if (query !== null) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
resetSearch();
|
|
132
|
+
}
|
|
133
|
+
} else if (key === "Backspace" && clearable && text === "" && query !== null && selected) {
|
|
134
|
+
clear();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const hasClear = clearable && !disabled && value !== "";
|
|
138
|
+
return /* @__PURE__ */ jsxs(PopoverPrimitive.Root, { open: isOpen, onOpenChange: setOpen, children: [
|
|
139
|
+
/* @__PURE__ */ jsx(PopoverPrimitive.Anchor, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
140
|
+
"div",
|
|
141
|
+
{
|
|
142
|
+
ref: rootRef,
|
|
143
|
+
className: cn("relative flex w-full min-w-0", classNames?.root, className),
|
|
144
|
+
children: [
|
|
145
|
+
/* @__PURE__ */ jsx(
|
|
146
|
+
"input",
|
|
147
|
+
{
|
|
148
|
+
...props,
|
|
149
|
+
ref: composedRef,
|
|
150
|
+
id: inputId,
|
|
151
|
+
type: "text",
|
|
152
|
+
role: "combobox",
|
|
153
|
+
"data-ui-layer": "",
|
|
154
|
+
autoComplete: "off",
|
|
155
|
+
"aria-expanded": isOpen,
|
|
156
|
+
"aria-controls": isOpen ? listId : void 0,
|
|
157
|
+
"aria-autocomplete": "list",
|
|
158
|
+
"aria-activedescendant": showList && activeIndex >= 0 ? optionDomId(listId, activeIndex) : void 0,
|
|
159
|
+
"aria-label": ariaLabel,
|
|
160
|
+
"aria-labelledby": ariaLabelledBy,
|
|
161
|
+
"aria-invalid": ariaInvalid ?? (invalid || void 0),
|
|
162
|
+
"aria-required": required || void 0,
|
|
163
|
+
required: nativeRequired ? required : void 0,
|
|
164
|
+
disabled,
|
|
165
|
+
value: query ?? selectedLabel,
|
|
166
|
+
onFocus: (event) => {
|
|
167
|
+
onFocus?.(event);
|
|
168
|
+
event.currentTarget.select();
|
|
169
|
+
setOpen(true);
|
|
170
|
+
},
|
|
171
|
+
onClick: (event) => {
|
|
172
|
+
onClick?.(event);
|
|
173
|
+
setOpen(true);
|
|
174
|
+
},
|
|
175
|
+
onChange: (event) => {
|
|
176
|
+
setQuery(event.target.value);
|
|
177
|
+
onSearchChange?.(event.target.value);
|
|
178
|
+
setOpen(true);
|
|
179
|
+
},
|
|
180
|
+
onBlur: (event) => {
|
|
181
|
+
onBlur?.(event);
|
|
182
|
+
setOpen(false);
|
|
183
|
+
resetSearch();
|
|
184
|
+
},
|
|
185
|
+
onKeyDown: handleKeyDown,
|
|
186
|
+
className: cn(
|
|
187
|
+
"w-full min-w-0 rounded-input border-control bg-surface-control pl-3 text-control text-ink placeholder:text-ink-3 focus:border-transparent focus:outline-2 focus:outline-accent-ink focus:-outline-offset-1 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-danger",
|
|
188
|
+
size === "sm" ? "h-control-sm" : "h-input min-h-(--touch-target)",
|
|
189
|
+
hasClear ? "pr-8" : "pr-3",
|
|
190
|
+
classNames?.input
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
),
|
|
194
|
+
hasClear ? /* @__PURE__ */ jsx(
|
|
195
|
+
"button",
|
|
196
|
+
{
|
|
197
|
+
type: "button",
|
|
198
|
+
"aria-label": clearLabel ?? strings.clear,
|
|
199
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
200
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
201
|
+
onClick: clear,
|
|
202
|
+
className: cn(
|
|
203
|
+
"absolute inset-y-0 right-0 flex w-8 items-center justify-center rounded-input text-ink-3 outline-none hover:text-ink focus-visible:focus-ring",
|
|
204
|
+
classNames?.clear
|
|
205
|
+
),
|
|
206
|
+
children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true", className: "size-3.5" })
|
|
207
|
+
}
|
|
208
|
+
) : null,
|
|
209
|
+
name ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value, disabled }) : null
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
) }),
|
|
213
|
+
/* @__PURE__ */ jsx(PopoverPrimitive.Portal, { container, children: /* @__PURE__ */ jsxs(
|
|
214
|
+
PopoverPrimitive.Content,
|
|
215
|
+
{
|
|
216
|
+
role: "presentation",
|
|
217
|
+
sideOffset: 4,
|
|
218
|
+
collisionPadding: 8,
|
|
219
|
+
align: "start",
|
|
220
|
+
onOpenAutoFocus: (event) => event.preventDefault(),
|
|
221
|
+
onCloseAutoFocus: (event) => event.preventDefault(),
|
|
222
|
+
onInteractOutside: (event) => {
|
|
223
|
+
if (rootRef.current?.contains(event.detail.originalEvent.target)) {
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
className: cn(
|
|
228
|
+
LISTBOX_SURFACE,
|
|
229
|
+
materialClass(material, "surface-solid"),
|
|
230
|
+
classNames?.content
|
|
231
|
+
),
|
|
232
|
+
children: [
|
|
233
|
+
loading ? /* @__PURE__ */ jsx(
|
|
234
|
+
"p",
|
|
235
|
+
{
|
|
236
|
+
role: "status",
|
|
237
|
+
className: cn("px-2.5 py-1.5 text-ink-3 text-meta", classNames?.status),
|
|
238
|
+
children: loadingText ?? strings.loading
|
|
239
|
+
}
|
|
240
|
+
) : null,
|
|
241
|
+
showEmpty ? /* @__PURE__ */ jsx(
|
|
242
|
+
"p",
|
|
243
|
+
{
|
|
244
|
+
role: "status",
|
|
245
|
+
className: cn("px-2.5 py-1.5 text-ink-3 text-meta", classNames?.status),
|
|
246
|
+
children: emptyText ?? strings.noResults
|
|
247
|
+
}
|
|
248
|
+
) : null,
|
|
249
|
+
/* @__PURE__ */ jsx(
|
|
250
|
+
"div",
|
|
251
|
+
{
|
|
252
|
+
id: listId,
|
|
253
|
+
role: "listbox",
|
|
254
|
+
"data-ui-layer": "",
|
|
255
|
+
hidden: !showList,
|
|
256
|
+
"aria-label": ariaLabelledBy ? void 0 : ariaLabel,
|
|
257
|
+
"aria-labelledby": ariaLabelledBy,
|
|
258
|
+
children: showList ? /* @__PURE__ */ jsx(
|
|
259
|
+
ListboxItems,
|
|
260
|
+
{
|
|
261
|
+
items,
|
|
262
|
+
flat,
|
|
263
|
+
idBase: listId,
|
|
264
|
+
isSelected: (option) => option.value === value,
|
|
265
|
+
activeIndex,
|
|
266
|
+
onActivate: setActive,
|
|
267
|
+
onPick: pick,
|
|
268
|
+
optionClassName: classNames?.option,
|
|
269
|
+
groupClassName: classNames?.group
|
|
270
|
+
}
|
|
271
|
+
) : null
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
) })
|
|
277
|
+
] });
|
|
278
|
+
}
|
|
279
|
+
export {
|
|
280
|
+
Combobox
|
|
281
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Combobox, type ComboboxGroup, type ComboboxOption, type ComboboxPart, type ComboboxProps, } from "./combobox.js";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
import { type WeekStart } from "../../calendar/internal/date-utils.js";
|
|
3
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
4
|
+
import { type Material } from "../../utils/material.js";
|
|
5
|
+
export type DatePickerPart = "root" | "input" | "clear" | "trigger" | "content" | "calendar";
|
|
6
|
+
export interface DatePickerProps extends Omit<ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "type" | "min" | "max" | "size" | "inputMode" | "maxLength"> {
|
|
7
|
+
/** Selected date as "YYYY-MM-DD" (controlled); `""` means none. Never converted through a time zone. */
|
|
8
|
+
value?: string;
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
/** Called with a valid "YYYY-MM-DD" date, or `""` when the field is cleared. */
|
|
11
|
+
onValueChange?: (value: string) => void;
|
|
12
|
+
/** Earliest allowed date, "YYYY-MM-DD". */
|
|
13
|
+
min?: string;
|
|
14
|
+
/** Latest allowed date, "YYYY-MM-DD". */
|
|
15
|
+
max?: string;
|
|
16
|
+
/** Extra dates that cannot be picked or typed (holidays, taken days). */
|
|
17
|
+
isDateDisabled?: (date: string) => boolean;
|
|
18
|
+
/** BCP 47 locale for labels and the typed format. Defaults to the `locale` UI string (es-PE: dd/mm/aaaa). */
|
|
19
|
+
locale?: string;
|
|
20
|
+
/** First day of the week in the calendar, 0 (Sunday) to 6. Defaults from the locale (es-PE: Monday). */
|
|
21
|
+
weekStartsOn?: WeekStart;
|
|
22
|
+
/** Shows a button that clears the date. Default `true`. */
|
|
23
|
+
clearable?: boolean;
|
|
24
|
+
clearLabel?: string;
|
|
25
|
+
/** Submits the "YYYY-MM-DD" value with a surrounding `<form>` through a hidden input. */
|
|
26
|
+
name?: string;
|
|
27
|
+
invalid?: boolean;
|
|
28
|
+
/** Portal target for the calendar popover. Defaults to `document.body`. */
|
|
29
|
+
container?: HTMLElement | null;
|
|
30
|
+
/** Popover surface material; see `PopoverContent`. */
|
|
31
|
+
material?: Material;
|
|
32
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the input and is merged last. */
|
|
33
|
+
classNames?: ClassNames<DatePickerPart>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Typed date field plus a calendar popover. The value is an ISO "YYYY-MM-DD" string end to end,
|
|
37
|
+
* so it never shifts with the time zone. The person types in the locale's order ("07/09/2026" in
|
|
38
|
+
* es-PE) or picks from the calendar; Alt+ArrowDown opens it from the keyboard.
|
|
39
|
+
*/
|
|
40
|
+
export declare function DatePicker({ value: valueProp, defaultValue, onValueChange, min, max, isDateDisabled, locale: localeProp, weekStartsOn, clearable, clearLabel, name, invalid, container, material, disabled, placeholder, className, classNames, ref, onBlur, onKeyDown, "aria-invalid": ariaInvalid, ...props }: DatePickerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useRef, useState } from "react";
|
|
4
|
+
import { DateCalendar } from "../../calendar/date-calendar/date-calendar.js";
|
|
5
|
+
import { isIsoDate } from "../../calendar/internal/date-utils.js";
|
|
6
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
7
|
+
import { Calendar as CalendarIcon, X } from "../../icons/index.js";
|
|
8
|
+
import * as PopoverPrimitive from "../../primitives/popover/popover.js";
|
|
9
|
+
import { cn } from "../../utils/cn.js";
|
|
10
|
+
import { useComposedRefs } from "../../utils/compose.js";
|
|
11
|
+
import { materialClass } from "../../utils/material.js";
|
|
12
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
13
|
+
import {
|
|
14
|
+
dateFormatFor,
|
|
15
|
+
displayPlaceholder,
|
|
16
|
+
formatDisplay,
|
|
17
|
+
maskDisplay,
|
|
18
|
+
parseDisplay
|
|
19
|
+
} from "./model.js";
|
|
20
|
+
const ICON_BUTTON = "flex w-8 items-center justify-center rounded-input text-ink-3 outline-none hover:text-ink focus-visible:focus-ring disabled:pointer-events-none disabled:opacity-50";
|
|
21
|
+
function DatePicker({
|
|
22
|
+
value: valueProp,
|
|
23
|
+
defaultValue = "",
|
|
24
|
+
onValueChange,
|
|
25
|
+
min,
|
|
26
|
+
max,
|
|
27
|
+
isDateDisabled,
|
|
28
|
+
locale: localeProp,
|
|
29
|
+
weekStartsOn,
|
|
30
|
+
clearable = true,
|
|
31
|
+
clearLabel,
|
|
32
|
+
name,
|
|
33
|
+
invalid,
|
|
34
|
+
container,
|
|
35
|
+
material,
|
|
36
|
+
disabled,
|
|
37
|
+
placeholder,
|
|
38
|
+
className,
|
|
39
|
+
classNames,
|
|
40
|
+
ref,
|
|
41
|
+
onBlur,
|
|
42
|
+
onKeyDown,
|
|
43
|
+
"aria-invalid": ariaInvalid,
|
|
44
|
+
...props
|
|
45
|
+
}) {
|
|
46
|
+
const strings = useUiStrings();
|
|
47
|
+
const locale = localeProp || strings.locale;
|
|
48
|
+
const format = useMemo(() => dateFormatFor(locale), [locale]);
|
|
49
|
+
const inputRef = useRef(null);
|
|
50
|
+
const composedRef = useComposedRefs(ref, inputRef);
|
|
51
|
+
const [current, setCurrent] = useControllableState({
|
|
52
|
+
prop: valueProp,
|
|
53
|
+
defaultProp: defaultValue,
|
|
54
|
+
onChange: onValueChange
|
|
55
|
+
});
|
|
56
|
+
const date = isIsoDate(current) ? current : "";
|
|
57
|
+
const [draft, setDraft] = useState(null);
|
|
58
|
+
const [open, setOpen] = useState(false);
|
|
59
|
+
const allowed = (iso) => !(min && iso < min) && !(max && iso > max) && !isDateDisabled?.(iso);
|
|
60
|
+
const typed = draft === null ? null : parseDisplay(draft, format);
|
|
61
|
+
const rejected = typed !== null && !allowed(typed);
|
|
62
|
+
const onChange = (raw) => {
|
|
63
|
+
const masked = maskDisplay(raw, format);
|
|
64
|
+
const iso = parseDisplay(masked, format);
|
|
65
|
+
if (iso && allowed(iso)) {
|
|
66
|
+
setCurrent(iso);
|
|
67
|
+
setDraft(null);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
setDraft(masked);
|
|
71
|
+
if (masked === "") setCurrent("");
|
|
72
|
+
};
|
|
73
|
+
const handleKeyDown = (event) => {
|
|
74
|
+
onKeyDown?.(event);
|
|
75
|
+
if (event.defaultPrevented) return;
|
|
76
|
+
if (event.key === "ArrowDown" && event.altKey && !disabled) {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
setOpen(true);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const hasClear = clearable && !disabled && date !== "";
|
|
82
|
+
return /* @__PURE__ */ jsxs(PopoverPrimitive.Root, { open, onOpenChange: setOpen, children: [
|
|
83
|
+
/* @__PURE__ */ jsx(PopoverPrimitive.Anchor, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: cn("relative flex w-full min-w-0", classNames?.root), children: [
|
|
84
|
+
/* @__PURE__ */ jsx(
|
|
85
|
+
"input",
|
|
86
|
+
{
|
|
87
|
+
...props,
|
|
88
|
+
ref: composedRef,
|
|
89
|
+
type: "text",
|
|
90
|
+
inputMode: "numeric",
|
|
91
|
+
autoComplete: "off",
|
|
92
|
+
maxLength: 10,
|
|
93
|
+
disabled,
|
|
94
|
+
placeholder: placeholder ?? displayPlaceholder(format, {
|
|
95
|
+
day: strings.dayPlaceholder,
|
|
96
|
+
month: strings.monthPlaceholder,
|
|
97
|
+
year: strings.yearPlaceholder
|
|
98
|
+
}),
|
|
99
|
+
"aria-invalid": ariaInvalid ?? (invalid || rejected || void 0),
|
|
100
|
+
value: draft ?? formatDisplay(date, format),
|
|
101
|
+
onChange: (event) => onChange(event.target.value),
|
|
102
|
+
onBlur: (event) => {
|
|
103
|
+
onBlur?.(event);
|
|
104
|
+
setDraft(null);
|
|
105
|
+
},
|
|
106
|
+
onKeyDown: handleKeyDown,
|
|
107
|
+
className: cn(
|
|
108
|
+
"h-input min-h-(--touch-target) w-full min-w-0 rounded-input border-control bg-surface-control pl-3 text-control text-ink tabular-nums placeholder:text-ink-3 focus:border-transparent focus:outline-2 focus:outline-accent-ink focus:-outline-offset-1 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-danger",
|
|
109
|
+
hasClear ? "pr-16" : "pr-9",
|
|
110
|
+
classNames?.input,
|
|
111
|
+
className
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "absolute inset-y-0 right-0 flex items-center", children: [
|
|
116
|
+
hasClear ? /* @__PURE__ */ jsx(
|
|
117
|
+
"button",
|
|
118
|
+
{
|
|
119
|
+
type: "button",
|
|
120
|
+
"aria-label": clearLabel ?? strings.clear,
|
|
121
|
+
onClick: () => {
|
|
122
|
+
setCurrent("");
|
|
123
|
+
setDraft(null);
|
|
124
|
+
inputRef.current?.focus();
|
|
125
|
+
},
|
|
126
|
+
className: cn(ICON_BUTTON, classNames?.clear),
|
|
127
|
+
children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true", className: "size-3.5" })
|
|
128
|
+
}
|
|
129
|
+
) : null,
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
PopoverPrimitive.Trigger,
|
|
132
|
+
{
|
|
133
|
+
disabled,
|
|
134
|
+
"aria-label": strings.openCalendar,
|
|
135
|
+
className: cn(ICON_BUTTON, classNames?.trigger),
|
|
136
|
+
children: /* @__PURE__ */ jsx(CalendarIcon, { "aria-hidden": "true", className: "size-4" })
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
] }),
|
|
140
|
+
name ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: date, disabled }) : null
|
|
141
|
+
] }) }),
|
|
142
|
+
/* @__PURE__ */ jsx(PopoverPrimitive.Portal, { container, children: /* @__PURE__ */ jsx(
|
|
143
|
+
PopoverPrimitive.Content,
|
|
144
|
+
{
|
|
145
|
+
"aria-label": strings.calendar,
|
|
146
|
+
sideOffset: 4,
|
|
147
|
+
collisionPadding: 8,
|
|
148
|
+
align: "start",
|
|
149
|
+
onOpenAutoFocus: (event) => event.preventDefault(),
|
|
150
|
+
onCloseAutoFocus: (event) => {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
inputRef.current?.focus({ preventScroll: true });
|
|
153
|
+
},
|
|
154
|
+
className: cn(
|
|
155
|
+
"z-85 max-w-(--ui-popper-available-width) overflow-y-auto rounded-popover surface-overlay p-3 text-ink shadow-overlay",
|
|
156
|
+
materialClass(material, "surface-solid"),
|
|
157
|
+
classNames?.content
|
|
158
|
+
),
|
|
159
|
+
children: /* @__PURE__ */ jsx(
|
|
160
|
+
DateCalendar,
|
|
161
|
+
{
|
|
162
|
+
autoFocus: true,
|
|
163
|
+
value: date || void 0,
|
|
164
|
+
min,
|
|
165
|
+
max,
|
|
166
|
+
isDateDisabled,
|
|
167
|
+
locale,
|
|
168
|
+
weekStartsOn,
|
|
169
|
+
className: classNames?.calendar,
|
|
170
|
+
onSelect: (next) => {
|
|
171
|
+
setCurrent(next);
|
|
172
|
+
setDraft(null);
|
|
173
|
+
setOpen(false);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
) })
|
|
179
|
+
] });
|
|
180
|
+
}
|
|
181
|
+
export {
|
|
182
|
+
DatePicker
|
|
183
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
import { type WeekStart } from "../../calendar/internal/date-utils.js";
|
|
3
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
4
|
+
import type { Material } from "../../utils/material.js";
|
|
5
|
+
export type DateTimePickerPart = "root" | "date" | "time";
|
|
6
|
+
export interface DateTimePickerProps extends Omit<ComponentProps<"div">, "defaultValue" | "onChange" | "children" | "role" | "id" | "aria-label" | "aria-labelledby"> {
|
|
7
|
+
/**
|
|
8
|
+
* "YYYY-MM-DDTHH:mm" (controlled), a wall-clock date and time with no zone: the component never
|
|
9
|
+
* converts it, so "2026-09-07T09:30" stays that string whatever the browser's time zone is.
|
|
10
|
+
* `""` while either half is missing or the pair is outside `min`/`max`.
|
|
11
|
+
*/
|
|
12
|
+
value?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
/** Earliest allowed value: a date ("2026-09-07", whole day) or a date-time. */
|
|
16
|
+
min?: string;
|
|
17
|
+
/** Latest allowed value: a date (whole day) or a date-time. */
|
|
18
|
+
max?: string;
|
|
19
|
+
isDateDisabled?: (date: string) => boolean;
|
|
20
|
+
locale?: string;
|
|
21
|
+
weekStartsOn?: WeekStart;
|
|
22
|
+
/** Minutes moved by ArrowUp / ArrowDown on the minutes of the time half. Default 5. */
|
|
23
|
+
step?: number;
|
|
24
|
+
/** Submits the combined value with a surrounding `<form>` through a hidden input. */
|
|
25
|
+
name?: string;
|
|
26
|
+
id?: string;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
invalid?: boolean;
|
|
30
|
+
"aria-label"?: string;
|
|
31
|
+
"aria-labelledby"?: string;
|
|
32
|
+
"aria-describedby"?: string;
|
|
33
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
34
|
+
container?: HTMLElement | null;
|
|
35
|
+
material?: Material;
|
|
36
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
37
|
+
classNames?: ClassNames<DateTimePickerPart>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Date field with calendar plus a 24h time field, as one value. Replaces
|
|
41
|
+
* `<input type="datetime-local">`; the value is "YYYY-MM-DDTHH:mm" without a time zone.
|
|
42
|
+
*/
|
|
43
|
+
export declare function DateTimePicker({ value: valueProp, defaultValue, onValueChange, min, max, isDateDisabled, locale, weekStartsOn, step, name, id, disabled, required, invalid, container, material, className, classNames, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: DateTimePickerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useMemo, useState } from "react";
|
|
4
|
+
import { isIsoDate } from "../../calendar/internal/date-utils.js";
|
|
5
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
6
|
+
import { cn } from "../../utils/cn.js";
|
|
7
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
8
|
+
import { TimeInput } from "../time-input/time-input.js";
|
|
9
|
+
import { DatePicker } from "./date-picker.js";
|
|
10
|
+
import { dateTimeInRange, joinDateTime, splitDateTime } from "./model.js";
|
|
11
|
+
const EMPTY = { date: "", time: "" };
|
|
12
|
+
function DateTimePicker({
|
|
13
|
+
value: valueProp,
|
|
14
|
+
defaultValue = "",
|
|
15
|
+
onValueChange,
|
|
16
|
+
min,
|
|
17
|
+
max,
|
|
18
|
+
isDateDisabled,
|
|
19
|
+
locale,
|
|
20
|
+
weekStartsOn,
|
|
21
|
+
step,
|
|
22
|
+
name,
|
|
23
|
+
id,
|
|
24
|
+
disabled,
|
|
25
|
+
required,
|
|
26
|
+
invalid,
|
|
27
|
+
container,
|
|
28
|
+
material,
|
|
29
|
+
className,
|
|
30
|
+
classNames,
|
|
31
|
+
"aria-label": ariaLabel,
|
|
32
|
+
"aria-labelledby": ariaLabelledBy,
|
|
33
|
+
"aria-describedby": ariaDescribedBy,
|
|
34
|
+
"aria-invalid": ariaInvalid,
|
|
35
|
+
...props
|
|
36
|
+
}) {
|
|
37
|
+
const strings = useUiStrings();
|
|
38
|
+
const autoId = useId();
|
|
39
|
+
const dateId = id ?? autoId;
|
|
40
|
+
const [current, setCurrent] = useControllableState({
|
|
41
|
+
prop: valueProp,
|
|
42
|
+
defaultProp: defaultValue,
|
|
43
|
+
onChange: onValueChange
|
|
44
|
+
});
|
|
45
|
+
const [parts, setParts] = useState(() => splitDateTime(current) ?? EMPTY);
|
|
46
|
+
const [synced, setSynced] = useState(current);
|
|
47
|
+
const [timeLabel, setTimeLabel] = useState(strings.time);
|
|
48
|
+
const suffix = strings.time.toLowerCase();
|
|
49
|
+
if (synced !== current) {
|
|
50
|
+
setSynced(current);
|
|
51
|
+
if (joinDateTime(parts) !== current) setParts(splitDateTime(current) ?? EMPTY);
|
|
52
|
+
}
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const label = ariaLabel ?? ariaLabelledBy?.split(" ").map((labelId) => document.getElementById(labelId)?.textContent ?? "").join(" ").trim() ?? document.getElementById(dateId)?.labels?.[0]?.textContent?.trim();
|
|
55
|
+
setTimeLabel(label ? `${label}, ${suffix}` : strings.time);
|
|
56
|
+
}, [ariaLabel, ariaLabelledBy, dateId, strings.time, suffix]);
|
|
57
|
+
const joined = joinDateTime(parts);
|
|
58
|
+
const outOfRange = joined !== "" && !dateTimeInRange(joined, min, max);
|
|
59
|
+
const dateMin = min && isIsoDate(min.slice(0, 10)) ? min.slice(0, 10) : void 0;
|
|
60
|
+
const dateMax = max && isIsoDate(max.slice(0, 10)) ? max.slice(0, 10) : void 0;
|
|
61
|
+
const update = useMemo(
|
|
62
|
+
() => (next) => {
|
|
63
|
+
setParts(next);
|
|
64
|
+
const value = joinDateTime(next);
|
|
65
|
+
const committed = value && dateTimeInRange(value, min, max) ? value : "";
|
|
66
|
+
setCurrent(committed);
|
|
67
|
+
},
|
|
68
|
+
[min, max, setCurrent]
|
|
69
|
+
);
|
|
70
|
+
const shared = {
|
|
71
|
+
disabled,
|
|
72
|
+
"aria-describedby": ariaDescribedBy,
|
|
73
|
+
"aria-invalid": ariaInvalid ?? (invalid || void 0)
|
|
74
|
+
};
|
|
75
|
+
return /* @__PURE__ */ jsxs(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
...props,
|
|
79
|
+
className: cn("flex w-full min-w-0 flex-wrap gap-2", classNames?.root, className),
|
|
80
|
+
children: [
|
|
81
|
+
/* @__PURE__ */ jsx(
|
|
82
|
+
DatePicker,
|
|
83
|
+
{
|
|
84
|
+
...shared,
|
|
85
|
+
id: dateId,
|
|
86
|
+
value: parts.date,
|
|
87
|
+
onValueChange: (date) => update({ ...parts, date }),
|
|
88
|
+
min: dateMin,
|
|
89
|
+
max: dateMax,
|
|
90
|
+
isDateDisabled,
|
|
91
|
+
locale,
|
|
92
|
+
weekStartsOn,
|
|
93
|
+
required,
|
|
94
|
+
"aria-label": ariaLabel,
|
|
95
|
+
"aria-labelledby": ariaLabelledBy,
|
|
96
|
+
container,
|
|
97
|
+
material,
|
|
98
|
+
className: void 0,
|
|
99
|
+
classNames: { root: cn("flex-[3_1_10rem]", classNames?.date) }
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
/* @__PURE__ */ jsx("div", { className: cn("flex min-w-0 flex-[2_1_6rem]", classNames?.time), children: /* @__PURE__ */ jsx(
|
|
103
|
+
TimeInput,
|
|
104
|
+
{
|
|
105
|
+
...shared,
|
|
106
|
+
"aria-invalid": outOfRange ? true : shared["aria-invalid"],
|
|
107
|
+
"aria-label": timeLabel,
|
|
108
|
+
value: parts.time,
|
|
109
|
+
onValueChange: (time) => update({ ...parts, time }),
|
|
110
|
+
required,
|
|
111
|
+
step
|
|
112
|
+
}
|
|
113
|
+
) }),
|
|
114
|
+
name ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: current, disabled }) : null
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
DateTimePicker
|
|
121
|
+
};
|