@cboxdk/cbox-ui 0.18.0 → 0.19.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/README.md +2 -0
- package/dist/index.d.ts +57 -1
- package/dist/index.js +281 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/tokens/controls.css +13 -0
package/README.md
CHANGED
|
@@ -134,6 +134,8 @@ below 768px so iOS does not zoom. The few words the components say themselves ("
|
|
|
134
134
|
| `Combobox` | The select (native `<select>` is not used). A 36px trigger that never changes size; the panel is portalled (into the Sheet it sits in, else `<body>`) and placed against the trigger, so an `overflow: hidden` parent never clips it, it opens upwards near the bottom of the screen, and it is at least 16rem wide (up to 22rem for long labels). Search, groups, avatars, `footerLink`, value mode (`value` + `onChange`) or navigation mode (`href` + `LinkComponent`). `onCreate(query)` adds a "Create “…”" row when what was typed matches no label; return a promise to show a spinner until it settles. `createLabel(query)` changes its text. Escape closes only the panel. |
|
|
135
135
|
| `TagInput` | Tags as chips in one field: Enter adds the highlighted suggestion or what was typed, a comma (or a pasted list) adds the text as typed, Backspace in the empty input removes the last chip, × removes one. `suggestions` (Combobox options) filter as the person types; `creatable={false}` allows suggestions only. `normalize` cleans what was typed into a tag (do the housekeeping there: lower case, spaces to dashes; the "Add “…”" row shows the result), `maxLength` cuts a longer tag to length, `validate(tag)` for what cannot be cleaned up, `maxTags`: a problem shows in the list's place and is announced, the field does not move. Takes its label, hint and error from a `Field`. |
|
|
136
136
|
| `DatePicker` | A calendar day as `YYYY-MM-DD` (or `null`), never a timestamp: a 36px trigger like the Combobox and a month calendar in a portalled panel sized to the calendar, not the trigger. Month and weekday names, the format and the first day of the week follow the host's locale. `min`/`max` refuse days outside, `presets` adds quick picks beside "Today", "Clear" empties it unless `required`. Arrows move a day or a week, Page Up/Down a month (Shift: a year), Home/End the week, Enter picks, Escape returns to the trigger; focus moves into the calendar with a keyboard or mouse, never on a tap. Takes its label, hint and error from a `Field`. |
|
|
137
|
+
| `TimePicker` | A time of day as `HH:MM` (24-hour) or `null`, shown in the locale (24-hour or AM/PM): a field to type in and the times at `step` minutes (default 15). Typing understands "930", "9.30", "21:30", "9pm"; Enter takes a typed time even off the step. `min`/`max`, `clearable`, `required`. |
|
|
138
|
+
| `DateTimePicker` | A DatePicker and a TimePicker side by side, valued as `YYYY-MM-DDTHH:MM` like `<input type="datetime-local">`. A day picked first gets `defaultTime` (09:00); `min`/`max` bound both. |
|
|
137
139
|
| `Spinner` | The indeterminate progress ring. Silent by default; `label` makes it a live status. |
|
|
138
140
|
|
|
139
141
|
### Charts
|
package/dist/index.d.ts
CHANGED
|
@@ -1608,6 +1608,62 @@ type DatePickerProps = Pick<AriaAttributes, 'aria-describedby' | 'aria-invalid'>
|
|
|
1608
1608
|
};
|
|
1609
1609
|
declare function DatePicker(props: DatePickerProps): react_jsx_runtime.JSX.Element;
|
|
1610
1610
|
|
|
1611
|
+
/**
|
|
1612
|
+
* TimePicker — a time of day as `HH:MM` (24-hour, or `null`), in place of `<input type="time">`.
|
|
1613
|
+
* The Combobox's trigger and a panel with a field to type in and the times at `step` minutes to
|
|
1614
|
+
* pick from. Typing understands how people write a time ("930", "9.30", "21:30", "9pm", "9:30 am");
|
|
1615
|
+
* Enter takes what was typed even off the step, and the list follows it. Shown in the host's
|
|
1616
|
+
* locale (24-hour or AM/PM), stored in 24-hour.
|
|
1617
|
+
*/
|
|
1618
|
+
type TimePickerProps = Pick<AriaAttributes, 'aria-describedby' | 'aria-invalid'> & {
|
|
1619
|
+
/** The time as `HH:MM`, or `null`. */
|
|
1620
|
+
value: string | null;
|
|
1621
|
+
onChange: (value: string | null) => void;
|
|
1622
|
+
/** Minutes between the times in the list. Default 15. */
|
|
1623
|
+
step?: number;
|
|
1624
|
+
/** The earliest time, `HH:MM`. */
|
|
1625
|
+
min?: string;
|
|
1626
|
+
/** The latest time, `HH:MM`. */
|
|
1627
|
+
max?: string;
|
|
1628
|
+
/** Shown in the trigger without a value. Default "Pick a time". */
|
|
1629
|
+
placeholder?: string;
|
|
1630
|
+
/** Offer "Clear" in the panel. Default true; ignored when `required`. */
|
|
1631
|
+
clearable?: boolean;
|
|
1632
|
+
disabled?: boolean;
|
|
1633
|
+
required?: boolean;
|
|
1634
|
+
ariaLabel?: string;
|
|
1635
|
+
triggerWidth?: 'auto' | 'full';
|
|
1636
|
+
id?: string;
|
|
1637
|
+
className?: string;
|
|
1638
|
+
};
|
|
1639
|
+
declare function TimePicker(props: TimePickerProps): react_jsx_runtime.JSX.Element;
|
|
1640
|
+
/**
|
|
1641
|
+
* DateTimePicker — a day and a time as `YYYY-MM-DDTHH:MM` in the reader's own clock (the value of
|
|
1642
|
+
* `<input type="datetime-local">`, so a form swaps one for the other), or `null`. A DatePicker and a
|
|
1643
|
+
* TimePicker side by side: a day picked first gets `defaultTime`, a time picked first gets today.
|
|
1644
|
+
*/
|
|
1645
|
+
type DateTimePickerProps = Pick<AriaAttributes, 'aria-describedby' | 'aria-invalid'> & {
|
|
1646
|
+
value: string | null;
|
|
1647
|
+
onChange: (value: string | null) => void;
|
|
1648
|
+
/** The earliest moment, `YYYY-MM-DDTHH:MM`. Days before it cannot be picked. */
|
|
1649
|
+
min?: string;
|
|
1650
|
+
/** The latest moment, `YYYY-MM-DDTHH:MM`. Days after it cannot be picked. */
|
|
1651
|
+
max?: string;
|
|
1652
|
+
/** The time a day gets when it is picked first. Default `09:00`. */
|
|
1653
|
+
defaultTime?: string;
|
|
1654
|
+
/** Minutes between the times in the list. Default 15. */
|
|
1655
|
+
step?: number;
|
|
1656
|
+
clearable?: boolean;
|
|
1657
|
+
disabled?: boolean;
|
|
1658
|
+
required?: boolean;
|
|
1659
|
+
ariaLabel?: string;
|
|
1660
|
+
id?: string;
|
|
1661
|
+
className?: string;
|
|
1662
|
+
};
|
|
1663
|
+
declare function DateTimePicker({ value, onChange, min, max, defaultTime, step, clearable, disabled, required, ariaLabel, id, className, ...aria }: DateTimePickerProps): react_jsx_runtime.JSX.Element;
|
|
1664
|
+
/** `HH:MM` from how people write a time: "9", "930", "0930", "9:30", "9.30", "9h30", "21 30", "9pm", "9:30 am". */
|
|
1665
|
+
declare function parseTime(text: string): string | null;
|
|
1666
|
+
|
|
1611
1667
|
type SheetSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
1612
1668
|
type SheetProps = {
|
|
1613
1669
|
open: boolean;
|
|
@@ -2085,4 +2141,4 @@ declare function Sparkline({ values, color, width, height }: {
|
|
|
2085
2141
|
height?: number;
|
|
2086
2142
|
}): react_jsx_runtime.JSX.Element | null;
|
|
2087
2143
|
|
|
2088
|
-
export { APP_HUES, AppContent, type AppKey, AppShell, Button, type ButtonProps, type ButtonSize, type ButtonVariant, CHART_PALETTE, CboxAppCatalog, type CboxAppCatalogProps, CboxAppIcon, type CboxAppIconProps, type CboxAppKey, type CboxAppLink, CboxBrand, type CboxBrandProps, type CboxIdContextValue, CboxIdProvider, CboxKnownApp, CboxLocalizationProvider, type CboxNotificationPreviewItem, type CboxNotificationsState, type CboxOrganization, CboxServiceMark, type CboxServiceMarkProps, CboxShell, type CboxShellProps, CboxSurfaces, type CboxSurfacesProps, type CboxTranslationValues, type CboxTranslator, type CboxUser, Checkbox, type CheckboxProps, Combobox, type ComboboxAvatar, type ComboboxGroup, type ComboboxOption, type ComboboxProps, type ContextItem, type ContextLevel, type ContextTone, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, DatePicker, type DatePickerProps, Dialog, DialogClose, type DialogProps, type DialogSize, EmptyState, Field, type FieldControlProps, type FieldProps, Heading, type HelpArticle, type HelpState, type HelpStore, type InboxState, type InferUrlState, Input, type InputProps, KeyValue, KeyValueList, type ListPage, type NavArea, type NavPage, PageHeader, type PageIntent, PageShell, type PageTabSpec, PageTabs, type PageTabsProps, type PageWidth, type PaletteAction, type PaletteRecord, PanelBody, RadioGroup, type RadioGroupProps, type RadioOption, type RealtimeState, type RealtimeStatus, RowLink, type RowLinkProps, SHELL_ICONS, SectionHeader, Sheet, SheetClose, type SheetProps, type SheetSize, type Shell, type ShellAccount, type Link as ShellActionLink, type ShellApp, type ShellBanner, type ShellCatalogState, type ShellCreatable, type ShellCreate, type ShellCreateForm, type ShellCreated, type ShellHelp, type ShellHelpArticle, type ShellIcon, type ShellLinkComponent, type ShellNavigate, type ShellNotifications, type ShellOption, type ShellPreferenceChange, type ShellPreferences, type ShellRecordSearch, type ShellRenderCreate, type ShellTheme, Slider, type SliderProps, Sparkline, Spinner, type SpinnerProps, StatTile, StatusPill, type SupportUpdate, type SurfaceArgs, type SurfaceConfig, type SurfaceController, type SurfaceId, Switch, type SwitchBody, type SwitchProps, TagInput, type TagInputProps, Textarea, type TextareaProps, type Transport, type UrlField, type UrlSchema, applyTheme, buildUrlSearch, buttonClassName, cn, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
2144
|
+
export { APP_HUES, AppContent, type AppKey, AppShell, Button, type ButtonProps, type ButtonSize, type ButtonVariant, CHART_PALETTE, CboxAppCatalog, type CboxAppCatalogProps, CboxAppIcon, type CboxAppIconProps, type CboxAppKey, type CboxAppLink, CboxBrand, type CboxBrandProps, type CboxIdContextValue, CboxIdProvider, CboxKnownApp, CboxLocalizationProvider, type CboxNotificationPreviewItem, type CboxNotificationsState, type CboxOrganization, CboxServiceMark, type CboxServiceMarkProps, CboxShell, type CboxShellProps, CboxSurfaces, type CboxSurfacesProps, type CboxTranslationValues, type CboxTranslator, type CboxUser, Checkbox, type CheckboxProps, Combobox, type ComboboxAvatar, type ComboboxGroup, type ComboboxOption, type ComboboxProps, type ContextItem, type ContextLevel, type ContextTone, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, DatePicker, type DatePickerProps, DateTimePicker, type DateTimePickerProps, Dialog, DialogClose, type DialogProps, type DialogSize, EmptyState, Field, type FieldControlProps, type FieldProps, Heading, type HelpArticle, type HelpState, type HelpStore, type InboxState, type InferUrlState, Input, type InputProps, KeyValue, KeyValueList, type ListPage, type NavArea, type NavPage, PageHeader, type PageIntent, PageShell, type PageTabSpec, PageTabs, type PageTabsProps, type PageWidth, type PaletteAction, type PaletteRecord, PanelBody, RadioGroup, type RadioGroupProps, type RadioOption, type RealtimeState, type RealtimeStatus, RowLink, type RowLinkProps, SHELL_ICONS, SectionHeader, Sheet, SheetClose, type SheetProps, type SheetSize, type Shell, type ShellAccount, type Link as ShellActionLink, type ShellApp, type ShellBanner, type ShellCatalogState, type ShellCreatable, type ShellCreate, type ShellCreateForm, type ShellCreated, type ShellHelp, type ShellHelpArticle, type ShellIcon, type ShellLinkComponent, type ShellNavigate, type ShellNotifications, type ShellOption, type ShellPreferenceChange, type ShellPreferences, type ShellRecordSearch, type ShellRenderCreate, type ShellTheme, Slider, type SliderProps, Sparkline, Spinner, type SpinnerProps, StatTile, StatusPill, type SupportUpdate, type SurfaceArgs, type SurfaceConfig, type SurfaceController, type SurfaceId, Switch, type SwitchBody, type SwitchProps, TagInput, type TagInputProps, Textarea, type TextareaProps, TimePicker, type TimePickerProps, type Transport, type UrlField, type UrlSchema, applyTheme, buildUrlSearch, buttonClassName, cn, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseTime, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
package/dist/index.js
CHANGED
|
@@ -6213,6 +6213,286 @@ function CalendarIcon() {
|
|
|
6213
6213
|
function Arrow({ direction }) {
|
|
6214
6214
|
return /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: direction === "left" ? "M8.5 3.5 5 7l3.5 3.5" : "M5.5 3.5 9 7l-3.5 3.5" }) });
|
|
6215
6215
|
}
|
|
6216
|
+
var useIsoLayoutEffect6 = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
6217
|
+
function TimePicker(props) {
|
|
6218
|
+
const { locale, t } = useCboxLocalization();
|
|
6219
|
+
const field = useFieldControl();
|
|
6220
|
+
const {
|
|
6221
|
+
value,
|
|
6222
|
+
onChange,
|
|
6223
|
+
step = 15,
|
|
6224
|
+
min,
|
|
6225
|
+
max,
|
|
6226
|
+
placeholder = t("Pick a time"),
|
|
6227
|
+
clearable = true,
|
|
6228
|
+
disabled = false,
|
|
6229
|
+
required = field.required ?? false,
|
|
6230
|
+
ariaLabel,
|
|
6231
|
+
triggerWidth = "auto",
|
|
6232
|
+
className
|
|
6233
|
+
} = props;
|
|
6234
|
+
const reactId = useId();
|
|
6235
|
+
const id = props.id ?? field.id ?? reactId;
|
|
6236
|
+
const listId = `${id}-times`;
|
|
6237
|
+
const picked = parseTime(value ?? "");
|
|
6238
|
+
const format = useMemo(() => timeFormat(locale), [locale]);
|
|
6239
|
+
const [open, setOpen] = useState(false);
|
|
6240
|
+
const [query2, setQuery] = useState("");
|
|
6241
|
+
const [highlight, setHighlight] = useState(-1);
|
|
6242
|
+
const containerRef = useRef(null);
|
|
6243
|
+
const triggerRef = useRef(null);
|
|
6244
|
+
const panelRef = useRef(null);
|
|
6245
|
+
const inputRef = useRef(null);
|
|
6246
|
+
const typedFocus = useRef(false);
|
|
6247
|
+
useAnchoredPanel(open, triggerRef, panelRef, void 0, true);
|
|
6248
|
+
const times = useMemo(() => {
|
|
6249
|
+
const every = Math.max(1, Math.min(720, Math.round(step)));
|
|
6250
|
+
return Array.from({ length: Math.ceil(1440 / every) }, (_, i) => fromMinutes(i * every));
|
|
6251
|
+
}, [step]);
|
|
6252
|
+
const allowed = useCallback((time) => (min === void 0 || time >= min) && (max === void 0 || time <= max), [min, max]);
|
|
6253
|
+
const typed = query2.trim() === "" ? null : parseTime(query2);
|
|
6254
|
+
const refused = query2.trim() !== "" && (typed === null || !allowed(typed));
|
|
6255
|
+
const anchor = typed ?? picked;
|
|
6256
|
+
useEffect(() => {
|
|
6257
|
+
if (!open) return;
|
|
6258
|
+
const at = anchor === null ? times.findIndex(allowed) : times.findIndex((time) => time >= anchor && allowed(time));
|
|
6259
|
+
setHighlight(at);
|
|
6260
|
+
if (at >= 0) requestAnimationFrame(() => centerInList(`${listId}-${at}`));
|
|
6261
|
+
}, [open, anchor, times, allowed, listId]);
|
|
6262
|
+
useIsoLayoutEffect6(() => {
|
|
6263
|
+
if (open) {
|
|
6264
|
+
if (typedFocus.current || finePointer2()) inputRef.current?.focus({ preventScroll: true });
|
|
6265
|
+
return;
|
|
6266
|
+
}
|
|
6267
|
+
setQuery("");
|
|
6268
|
+
}, [open]);
|
|
6269
|
+
useEffect(() => {
|
|
6270
|
+
if (!open) return;
|
|
6271
|
+
function onPointerDown(event) {
|
|
6272
|
+
const target = event.target;
|
|
6273
|
+
if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
|
|
6274
|
+
setOpen(false);
|
|
6275
|
+
}
|
|
6276
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
6277
|
+
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
|
6278
|
+
}, [open]);
|
|
6279
|
+
const choose = useCallback((time) => {
|
|
6280
|
+
onChange(time);
|
|
6281
|
+
setOpen(false);
|
|
6282
|
+
triggerRef.current?.focus();
|
|
6283
|
+
}, [onChange]);
|
|
6284
|
+
const move = (to) => {
|
|
6285
|
+
setHighlight(to);
|
|
6286
|
+
if (to >= 0) revealInList(`${listId}-${to}`);
|
|
6287
|
+
};
|
|
6288
|
+
const onKeyDown = (event) => {
|
|
6289
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
6290
|
+
event.preventDefault();
|
|
6291
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
6292
|
+
let next = highlight;
|
|
6293
|
+
do
|
|
6294
|
+
next += direction;
|
|
6295
|
+
while (next >= 0 && next < times.length && !allowed(times[next] ?? ""));
|
|
6296
|
+
if (next >= 0 && next < times.length) move(next);
|
|
6297
|
+
return;
|
|
6298
|
+
}
|
|
6299
|
+
if (event.key === "Enter") {
|
|
6300
|
+
event.preventDefault();
|
|
6301
|
+
if (typed !== null && allowed(typed)) choose(typed);
|
|
6302
|
+
else if (query2.trim() === "" && highlight >= 0 && times[highlight] !== void 0) choose(times[highlight] ?? null);
|
|
6303
|
+
return;
|
|
6304
|
+
}
|
|
6305
|
+
if (event.key === "Tab") {
|
|
6306
|
+
triggerRef.current?.focus();
|
|
6307
|
+
setOpen(false);
|
|
6308
|
+
}
|
|
6309
|
+
};
|
|
6310
|
+
const panel = open && typeof document !== "undefined" ? createPortal(
|
|
6311
|
+
/* @__PURE__ */ jsxs("div", { ref: panelRef, className: "cbx-ui-combo-panel cbx-ui-time-panel", "data-cbx-scroll-layer": "", children: [
|
|
6312
|
+
/* @__PURE__ */ jsxs("div", { className: "cbx-ui-combo-search-row", children: [
|
|
6313
|
+
/* @__PURE__ */ jsx(ClockIcon, { className: "cbx-ui-combo-search-icon" }),
|
|
6314
|
+
/* @__PURE__ */ jsx(
|
|
6315
|
+
"input",
|
|
6316
|
+
{
|
|
6317
|
+
ref: inputRef,
|
|
6318
|
+
type: "text",
|
|
6319
|
+
inputMode: "numeric",
|
|
6320
|
+
autoComplete: "off",
|
|
6321
|
+
value: query2,
|
|
6322
|
+
onChange: (event) => setQuery(event.target.value),
|
|
6323
|
+
onKeyDown,
|
|
6324
|
+
placeholder: t("Type a time"),
|
|
6325
|
+
"aria-label": t("Type a time"),
|
|
6326
|
+
"aria-invalid": refused || void 0,
|
|
6327
|
+
"aria-controls": listId,
|
|
6328
|
+
"aria-activedescendant": highlight >= 0 && query2.trim() === "" ? `${listId}-${highlight}` : void 0,
|
|
6329
|
+
className: "cbx-ui-combo-search"
|
|
6330
|
+
}
|
|
6331
|
+
)
|
|
6332
|
+
] }),
|
|
6333
|
+
refused ? /* @__PURE__ */ jsx("p", { className: "cbx-ui-combo-note", role: "status", children: typed === null ? t("Not a time. Try 9:30 or 21:30.") : t("Outside the times allowed here.") }) : typed !== null ? /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-ui-time-typed", onClick: () => choose(typed), children: [
|
|
6334
|
+
t("Use {time}", { time: format.format(asDate(typed)) }),
|
|
6335
|
+
/* @__PURE__ */ jsx("kbd", { children: "\u21B5" })
|
|
6336
|
+
] }) : null,
|
|
6337
|
+
/* @__PURE__ */ jsx("ul", { id: listId, role: "listbox", "aria-label": ariaLabel ?? placeholder, className: "cbx-ui-combo-list cbx-ui-time-list", children: times.map((time, index) => /* @__PURE__ */ jsx(
|
|
6338
|
+
"li",
|
|
6339
|
+
{
|
|
6340
|
+
id: `${listId}-${index}`,
|
|
6341
|
+
role: "option",
|
|
6342
|
+
tabIndex: -1,
|
|
6343
|
+
"aria-selected": time === picked,
|
|
6344
|
+
"aria-disabled": !allowed(time) || void 0,
|
|
6345
|
+
"data-highlighted": index === highlight ? "" : void 0,
|
|
6346
|
+
"data-active": time === picked ? "" : void 0,
|
|
6347
|
+
className: "cbx-ui-combo-option",
|
|
6348
|
+
onMouseEnter: () => setHighlight(index),
|
|
6349
|
+
onClick: () => allowed(time) && choose(time),
|
|
6350
|
+
children: /* @__PURE__ */ jsx("span", { className: "cbx-ui-combo-label", children: format.format(asDate(time)) })
|
|
6351
|
+
},
|
|
6352
|
+
time
|
|
6353
|
+
)) }),
|
|
6354
|
+
clearable && !required && picked !== null && /* @__PURE__ */ jsx("div", { className: "cbx-ui-date-foot", children: /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-ui-date-chip cbx-ui-date-clear", onClick: () => choose(null), children: t("Clear") }) })
|
|
6355
|
+
] }),
|
|
6356
|
+
panelContainer(containerRef.current)
|
|
6357
|
+
) : null;
|
|
6358
|
+
return /* @__PURE__ */ jsxs(
|
|
6359
|
+
"div",
|
|
6360
|
+
{
|
|
6361
|
+
ref: containerRef,
|
|
6362
|
+
className: cn("cbx-ui-combo", triggerWidth === "full" && "cbx-ui-combo--full", className),
|
|
6363
|
+
onKeyDown: (event) => {
|
|
6364
|
+
if (open && event.key === "Escape") {
|
|
6365
|
+
event.preventDefault();
|
|
6366
|
+
event.stopPropagation();
|
|
6367
|
+
setOpen(false);
|
|
6368
|
+
triggerRef.current?.focus();
|
|
6369
|
+
}
|
|
6370
|
+
},
|
|
6371
|
+
children: [
|
|
6372
|
+
/* @__PURE__ */ jsxs(
|
|
6373
|
+
"button",
|
|
6374
|
+
{
|
|
6375
|
+
ref: triggerRef,
|
|
6376
|
+
id,
|
|
6377
|
+
type: "button",
|
|
6378
|
+
disabled,
|
|
6379
|
+
"aria-haspopup": "dialog",
|
|
6380
|
+
"aria-expanded": open,
|
|
6381
|
+
"aria-required": required,
|
|
6382
|
+
"aria-label": ariaLabel !== void 0 ? picked !== null ? `${ariaLabel}: ${format.format(asDate(picked))}` : ariaLabel : void 0,
|
|
6383
|
+
"aria-describedby": props["aria-describedby"] ?? field["aria-describedby"],
|
|
6384
|
+
"aria-invalid": props["aria-invalid"] ?? field["aria-invalid"],
|
|
6385
|
+
className: "cbx-ui-combo-trigger cbx-ui-time-trigger",
|
|
6386
|
+
onClick: (event) => {
|
|
6387
|
+
typedFocus.current = event.detail === 0;
|
|
6388
|
+
setOpen((was) => !was);
|
|
6389
|
+
},
|
|
6390
|
+
onKeyDown: (event) => {
|
|
6391
|
+
if (!open && event.key === "ArrowDown") {
|
|
6392
|
+
event.preventDefault();
|
|
6393
|
+
typedFocus.current = true;
|
|
6394
|
+
setOpen(true);
|
|
6395
|
+
}
|
|
6396
|
+
},
|
|
6397
|
+
children: [
|
|
6398
|
+
/* @__PURE__ */ jsx(ClockIcon, { className: "cbx-ui-combo-icon" }),
|
|
6399
|
+
/* @__PURE__ */ jsx("span", { className: cn("cbx-ui-combo-value", picked === null && "is-placeholder"), children: picked !== null ? format.format(asDate(picked)) : placeholder })
|
|
6400
|
+
]
|
|
6401
|
+
}
|
|
6402
|
+
),
|
|
6403
|
+
panel
|
|
6404
|
+
]
|
|
6405
|
+
}
|
|
6406
|
+
);
|
|
6407
|
+
}
|
|
6408
|
+
function DateTimePicker({ value, onChange, min, max, defaultTime = "09:00", step, clearable = true, disabled, required, ariaLabel, id, className, ...aria }) {
|
|
6409
|
+
const { t } = useCboxLocalization();
|
|
6410
|
+
const [day, time] = splitMoment(value);
|
|
6411
|
+
const minDay = min?.slice(0, 10);
|
|
6412
|
+
const maxDay = max?.slice(0, 10);
|
|
6413
|
+
const minTime = min !== void 0 && day !== null && day === minDay ? min.slice(11, 16) : void 0;
|
|
6414
|
+
const maxTime = max !== void 0 && day !== null && day === maxDay ? max.slice(11, 16) : void 0;
|
|
6415
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("cbx-ui-datetime", className), role: "group", "aria-label": ariaLabel, children: [
|
|
6416
|
+
/* @__PURE__ */ jsx(
|
|
6417
|
+
DatePicker,
|
|
6418
|
+
{
|
|
6419
|
+
...aria,
|
|
6420
|
+
...id !== void 0 ? { id } : {},
|
|
6421
|
+
...minDay !== void 0 ? { min: minDay } : {},
|
|
6422
|
+
...maxDay !== void 0 ? { max: maxDay } : {},
|
|
6423
|
+
value: day,
|
|
6424
|
+
ariaLabel: t("Date"),
|
|
6425
|
+
clearable,
|
|
6426
|
+
...disabled !== void 0 ? { disabled } : {},
|
|
6427
|
+
...required !== void 0 ? { required } : {},
|
|
6428
|
+
onChange: (next) => onChange(next === null ? null : `${next}T${time ?? defaultTime}`)
|
|
6429
|
+
}
|
|
6430
|
+
),
|
|
6431
|
+
/* @__PURE__ */ jsx(
|
|
6432
|
+
TimePicker,
|
|
6433
|
+
{
|
|
6434
|
+
...aria,
|
|
6435
|
+
...minTime !== void 0 ? { min: minTime } : {},
|
|
6436
|
+
...maxTime !== void 0 ? { max: maxTime } : {},
|
|
6437
|
+
...step !== void 0 ? { step } : {},
|
|
6438
|
+
value: time,
|
|
6439
|
+
ariaLabel: t("Time"),
|
|
6440
|
+
clearable: false,
|
|
6441
|
+
...disabled !== void 0 ? { disabled } : {},
|
|
6442
|
+
onChange: (next) => next !== null && onChange(`${day ?? today2()}T${next}`)
|
|
6443
|
+
}
|
|
6444
|
+
)
|
|
6445
|
+
] });
|
|
6446
|
+
}
|
|
6447
|
+
function parseTime(text) {
|
|
6448
|
+
const match = /^\s*(\d{1,2})(?:\s*[:.h\s]\s*(\d{2})|(\d{2}))?\s*([ap])?\.?\s*m?\.?\s*$/i.exec(text);
|
|
6449
|
+
if (match === null) return null;
|
|
6450
|
+
let hours = Number(match[1]);
|
|
6451
|
+
const minutes = Number(match[2] ?? match[3] ?? "0");
|
|
6452
|
+
const half = match[4]?.toLowerCase();
|
|
6453
|
+
if (half !== void 0) {
|
|
6454
|
+
if (hours < 1 || hours > 12) return null;
|
|
6455
|
+
hours = hours % 12 + (half === "p" ? 12 : 0);
|
|
6456
|
+
}
|
|
6457
|
+
if (hours > 23 || minutes > 59) return null;
|
|
6458
|
+
return fromMinutes(hours * 60 + minutes);
|
|
6459
|
+
}
|
|
6460
|
+
function fromMinutes(total) {
|
|
6461
|
+
return `${String(Math.floor(total / 60)).padStart(2, "0")}:${String(total % 60).padStart(2, "0")}`;
|
|
6462
|
+
}
|
|
6463
|
+
function asDate(time) {
|
|
6464
|
+
return /* @__PURE__ */ new Date(`1970-01-01T${time}:00Z`);
|
|
6465
|
+
}
|
|
6466
|
+
function splitMoment(value) {
|
|
6467
|
+
const match = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(value ?? "");
|
|
6468
|
+
return match === null ? [null, null] : [match[1] ?? null, match[2] ?? null];
|
|
6469
|
+
}
|
|
6470
|
+
function today2() {
|
|
6471
|
+
const now = /* @__PURE__ */ new Date();
|
|
6472
|
+
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
6473
|
+
}
|
|
6474
|
+
function timeFormat(locale) {
|
|
6475
|
+
try {
|
|
6476
|
+
return new Intl.DateTimeFormat(locale.replace("_", "-") || void 0, { hour: "numeric", minute: "2-digit", timeZone: "UTC" });
|
|
6477
|
+
} catch {
|
|
6478
|
+
return new Intl.DateTimeFormat(void 0, { hour: "numeric", minute: "2-digit", timeZone: "UTC" });
|
|
6479
|
+
}
|
|
6480
|
+
}
|
|
6481
|
+
function centerInList(id) {
|
|
6482
|
+
const option = typeof document === "undefined" ? null : document.getElementById(id);
|
|
6483
|
+
const list = option?.closest('[role="listbox"]');
|
|
6484
|
+
if (option == null || list == null) return;
|
|
6485
|
+
list.scrollTop = option.offsetTop - list.clientHeight / 2 + option.offsetHeight / 2;
|
|
6486
|
+
}
|
|
6487
|
+
function finePointer2() {
|
|
6488
|
+
return typeof window !== "undefined" && window.matchMedia?.("(pointer: fine)").matches === true;
|
|
6489
|
+
}
|
|
6490
|
+
function ClockIcon({ className }) {
|
|
6491
|
+
return /* @__PURE__ */ jsxs("svg", { className, width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", "aria-hidden": "true", children: [
|
|
6492
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "5.75" }),
|
|
6493
|
+
/* @__PURE__ */ jsx("path", { d: "M8 4.75V8l2.25 1.5" })
|
|
6494
|
+
] });
|
|
6495
|
+
}
|
|
6216
6496
|
var Input = forwardRef(function Input2({ scale = "md", className, ...props }, ref) {
|
|
6217
6497
|
const field = useFieldControl();
|
|
6218
6498
|
return /* @__PURE__ */ jsx("input", { ref, className: cn("cbx-ui-input", scale === "lg" && "cbx-ui-input--lg", className), ...field, ...props });
|
|
@@ -7043,6 +7323,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
|
|
|
7043
7323
|
] });
|
|
7044
7324
|
}
|
|
7045
7325
|
|
|
7046
|
-
export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, DatePicker, Dialog, DialogClose, EmptyState, Field, Heading, Input, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RadioGroup, RowLink, SHELL_ICONS, SectionHeader, Sheet, SheetClose, Slider, Sparkline, Spinner, StatTile, StatusPill, Switch, TagInput, Textarea, applyTheme, buildUrlSearch, buttonClassName, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
7326
|
+
export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, DatePicker, DateTimePicker, Dialog, DialogClose, EmptyState, Field, Heading, Input, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RadioGroup, RowLink, SHELL_ICONS, SectionHeader, Sheet, SheetClose, Slider, Sparkline, Spinner, StatTile, StatusPill, Switch, TagInput, Textarea, TimePicker, applyTheme, buildUrlSearch, buttonClassName, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseTime, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
7047
7327
|
//# sourceMappingURL=index.js.map
|
|
7048
7328
|
//# sourceMappingURL=index.js.map
|