@cboxdk/cbox-ui 0.17.1 → 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/dist/index.js CHANGED
@@ -4950,7 +4950,7 @@ var MAX_WIDTH = 352;
4950
4950
  function panelContainer(anchor) {
4951
4951
  return anchor?.closest("[data-cbx-dialog-layer], .cbx-overlay") ?? document.body;
4952
4952
  }
4953
- function useAnchoredPanel(open, anchor, panel, remeasure) {
4953
+ function useAnchoredPanel(open, anchor, panel, remeasure, ownWidth = false) {
4954
4954
  useIsoLayoutEffect3(() => {
4955
4955
  const element = panel.current;
4956
4956
  const target = anchor.current;
@@ -4960,8 +4960,8 @@ function useAnchoredPanel(open, anchor, panel, remeasure) {
4960
4960
  const measure = () => {
4961
4961
  const box = target.getBoundingClientRect();
4962
4962
  const room = document.documentElement.clientWidth - 2 * MARGIN2;
4963
- element.style.minWidth = `${Math.min(Math.max(box.width, MIN_WIDTH), room)}px`;
4964
- element.style.maxWidth = `${Math.min(Math.max(box.width, MAX_WIDTH), room)}px`;
4963
+ element.style.minWidth = ownWidth ? "0" : `${Math.min(Math.max(box.width, MIN_WIDTH), room)}px`;
4964
+ element.style.maxWidth = ownWidth ? `${room}px` : `${Math.min(Math.max(box.width, MAX_WIDTH), room)}px`;
4965
4965
  element.style.width = "max-content";
4966
4966
  element.style.maxHeight = "none";
4967
4967
  width = element.offsetWidth;
@@ -4999,7 +4999,7 @@ function useAnchoredPanel(open, anchor, panel, remeasure) {
4999
4999
  window.removeEventListener("resize", resize);
5000
5000
  window.removeEventListener("scroll", place2, true);
5001
5001
  };
5002
- }, [open, anchor, panel, remeasure]);
5002
+ }, [open, anchor, panel, remeasure, ownWidth]);
5003
5003
  }
5004
5004
  var CREATE = "\0create";
5005
5005
  var useIsoLayoutEffect4 = typeof window === "undefined" ? useEffect : useLayoutEffect;
@@ -5922,6 +5922,577 @@ function Checkbox({ checked, onCheckedChange, label, hint, disabled = false, req
5922
5922
  ] })
5923
5923
  ] });
5924
5924
  }
5925
+ var useIsoLayoutEffect5 = typeof window === "undefined" ? useEffect : useLayoutEffect;
5926
+ function DatePicker(props) {
5927
+ const { locale, t } = useCboxLocalization();
5928
+ const field = useFieldControl();
5929
+ const {
5930
+ value,
5931
+ onChange,
5932
+ min,
5933
+ max,
5934
+ placeholder = t("Pick a date"),
5935
+ clearable = true,
5936
+ presets = [],
5937
+ disabled = false,
5938
+ required = field.required ?? false,
5939
+ ariaLabel,
5940
+ triggerWidth = "auto",
5941
+ className
5942
+ } = props;
5943
+ const reactId = useId();
5944
+ const id = props.id ?? field.id ?? reactId;
5945
+ const gridLabelId = `${id}-month`;
5946
+ const picked = isDay(value) ? value : null;
5947
+ const [open, setOpen] = useState(false);
5948
+ const [focused, setFocused] = useState(() => clampDay(picked ?? today(), min, max));
5949
+ const moveFocus = useRef(false);
5950
+ const containerRef = useRef(null);
5951
+ const triggerRef = useRef(null);
5952
+ const panelRef = useRef(null);
5953
+ const gridRef = useRef(null);
5954
+ useAnchoredPanel(open, triggerRef, panelRef, void 0, true);
5955
+ const formats = useMemo(() => formatsFor(locale), [locale]);
5956
+ const firstDay = useMemo(() => firstDayOfWeek(locale), [locale]);
5957
+ const month = focused.slice(0, 7);
5958
+ const weeks = useMemo(() => monthGrid(month, firstDay), [month, firstDay]);
5959
+ const openPanel = useCallback((viaKeyboard) => {
5960
+ setFocused(clampDay(picked ?? today(), min, max));
5961
+ moveFocus.current = viaKeyboard || finePointer();
5962
+ setOpen(true);
5963
+ }, [picked, min, max]);
5964
+ const close = useCallback((refocus) => {
5965
+ setOpen(false);
5966
+ if (refocus) triggerRef.current?.focus();
5967
+ }, []);
5968
+ useIsoLayoutEffect5(() => {
5969
+ if (!open || !moveFocus.current) return;
5970
+ gridRef.current?.querySelector(`[data-day="${focused}"]`)?.focus({ preventScroll: true });
5971
+ }, [open, focused]);
5972
+ useEffect(() => {
5973
+ if (!open) return;
5974
+ function onPointerDown(event) {
5975
+ const target = event.target;
5976
+ if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
5977
+ setOpen(false);
5978
+ }
5979
+ document.addEventListener("pointerdown", onPointerDown, true);
5980
+ return () => document.removeEventListener("pointerdown", onPointerDown, true);
5981
+ }, [open]);
5982
+ const choose = useCallback((day) => {
5983
+ onChange(day);
5984
+ close(true);
5985
+ }, [onChange, close]);
5986
+ const move = useCallback((day) => {
5987
+ moveFocus.current = true;
5988
+ setFocused(clampDay(day, min, max));
5989
+ }, [min, max]);
5990
+ const onGridKeyDown = (event) => {
5991
+ const keys = {
5992
+ ArrowLeft: () => addDays(focused, -1),
5993
+ ArrowRight: () => addDays(focused, 1),
5994
+ ArrowUp: () => addDays(focused, -7),
5995
+ ArrowDown: () => addDays(focused, 7),
5996
+ PageUp: () => addMonths(focused, event.shiftKey ? -12 : -1),
5997
+ PageDown: () => addMonths(focused, event.shiftKey ? 12 : 1),
5998
+ Home: () => addDays(focused, -((weekday(focused) - firstDay + 7) % 7)),
5999
+ End: () => addDays(focused, 6 - (weekday(focused) - firstDay + 7) % 7)
6000
+ };
6001
+ const next = keys[event.key];
6002
+ if (next !== void 0) {
6003
+ event.preventDefault();
6004
+ move(next());
6005
+ }
6006
+ };
6007
+ const canPick = (day) => (min === void 0 || day >= min) && (max === void 0 || day <= max);
6008
+ const prevMonth = addMonths(`${month}-01`, -1);
6009
+ const nextMonth = addMonths(`${month}-01`, 1);
6010
+ const canPrev = min === void 0 || lastOfMonth(prevMonth) >= min;
6011
+ const canNext = max === void 0 || `${nextMonth.slice(0, 7)}-01` <= max;
6012
+ const todayDay = today();
6013
+ const panel = open && typeof document !== "undefined" ? createPortal(
6014
+ /* @__PURE__ */ jsxs(
6015
+ "div",
6016
+ {
6017
+ ref: panelRef,
6018
+ className: "cbx-ui-combo-panel cbx-ui-date-panel",
6019
+ role: "dialog",
6020
+ "aria-modal": "false",
6021
+ "aria-labelledby": gridLabelId,
6022
+ "data-cbx-scroll-layer": "",
6023
+ onBlur: (event) => {
6024
+ const next = event.relatedTarget;
6025
+ if (next !== null && !panelRef.current?.contains(next) && !containerRef.current?.contains(next)) setOpen(false);
6026
+ },
6027
+ children: [
6028
+ /* @__PURE__ */ jsxs("div", { className: "cbx-ui-date-head", children: [
6029
+ /* @__PURE__ */ jsx(
6030
+ "button",
6031
+ {
6032
+ type: "button",
6033
+ className: "cbx-ui-date-nav",
6034
+ "aria-label": t("Previous month"),
6035
+ disabled: !canPrev,
6036
+ onClick: () => setFocused(clampDay(addMonths(focused, -1), min, max)),
6037
+ children: /* @__PURE__ */ jsx(Arrow, { direction: "left" })
6038
+ }
6039
+ ),
6040
+ /* @__PURE__ */ jsx("span", { id: gridLabelId, className: "cbx-ui-date-month", "aria-live": "polite", children: formats.month.format(toDate(`${month}-01`)) }),
6041
+ /* @__PURE__ */ jsx(
6042
+ "button",
6043
+ {
6044
+ type: "button",
6045
+ className: "cbx-ui-date-nav",
6046
+ "aria-label": t("Next month"),
6047
+ disabled: !canNext,
6048
+ onClick: () => setFocused(clampDay(addMonths(focused, 1), min, max)),
6049
+ children: /* @__PURE__ */ jsx(Arrow, { direction: "right" })
6050
+ }
6051
+ )
6052
+ ] }),
6053
+ /* @__PURE__ */ jsxs("table", { ref: gridRef, role: "grid", className: "cbx-ui-date-grid", "aria-labelledby": gridLabelId, onKeyDown: onGridKeyDown, children: [
6054
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: weeks[0]?.map((day) => /* @__PURE__ */ jsx("th", { scope: "col", abbr: formats.weekdayLong.format(toDate(day)), children: formats.weekday.format(toDate(day)) }, day)) }) }),
6055
+ /* @__PURE__ */ jsx("tbody", { children: weeks.map((week) => /* @__PURE__ */ jsx("tr", { children: week.map((day) => {
6056
+ const outside = day.slice(0, 7) !== month;
6057
+ const selected = day === picked;
6058
+ return /* @__PURE__ */ jsx("td", { role: "gridcell", "aria-selected": selected || void 0, children: /* @__PURE__ */ jsx(
6059
+ "button",
6060
+ {
6061
+ type: "button",
6062
+ className: "cbx-ui-date-day",
6063
+ "data-day": day,
6064
+ "data-outside": outside || void 0,
6065
+ "data-today": day === todayDay || void 0,
6066
+ "data-selected": selected || void 0,
6067
+ tabIndex: day === focused ? 0 : -1,
6068
+ disabled: !canPick(day),
6069
+ "aria-label": formats.full.format(toDate(day)),
6070
+ "aria-current": day === todayDay ? "date" : void 0,
6071
+ onClick: () => choose(day),
6072
+ children: Number(day.slice(8))
6073
+ }
6074
+ ) }, day);
6075
+ }) }, week[0])) })
6076
+ ] }),
6077
+ /* @__PURE__ */ jsxs("div", { className: "cbx-ui-date-foot", children: [
6078
+ canPick(todayDay) && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-ui-date-chip", onClick: () => choose(todayDay), children: t("Today") }),
6079
+ presets.filter((preset) => isDay(preset.value) && canPick(preset.value)).map((preset) => /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-ui-date-chip", onClick: () => choose(preset.value), children: preset.label }, preset.label)),
6080
+ clearable && !required && picked !== null && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-ui-date-chip cbx-ui-date-clear", onClick: () => choose(null), children: t("Clear") })
6081
+ ] })
6082
+ ]
6083
+ }
6084
+ ),
6085
+ panelContainer(containerRef.current)
6086
+ ) : null;
6087
+ return /* @__PURE__ */ jsxs(
6088
+ "div",
6089
+ {
6090
+ ref: containerRef,
6091
+ className: cn("cbx-ui-combo", triggerWidth === "full" && "cbx-ui-combo--full", className),
6092
+ onKeyDown: (event) => {
6093
+ if (open && event.key === "Escape") {
6094
+ event.preventDefault();
6095
+ event.stopPropagation();
6096
+ close(true);
6097
+ }
6098
+ },
6099
+ children: [
6100
+ /* @__PURE__ */ jsxs(
6101
+ "button",
6102
+ {
6103
+ ref: triggerRef,
6104
+ id,
6105
+ type: "button",
6106
+ disabled,
6107
+ "aria-haspopup": "dialog",
6108
+ "aria-expanded": open,
6109
+ "aria-required": required,
6110
+ "aria-label": ariaLabel !== void 0 ? picked !== null ? `${ariaLabel}: ${formats.full.format(toDate(picked))}` : ariaLabel : void 0,
6111
+ "aria-describedby": props["aria-describedby"] ?? field["aria-describedby"],
6112
+ "aria-invalid": props["aria-invalid"] ?? field["aria-invalid"],
6113
+ className: "cbx-ui-combo-trigger cbx-ui-date-trigger",
6114
+ onClick: (event) => open ? close(false) : openPanel(event.detail === 0),
6115
+ onKeyDown: (event) => {
6116
+ if (!open && event.key === "ArrowDown") {
6117
+ event.preventDefault();
6118
+ openPanel(true);
6119
+ }
6120
+ },
6121
+ children: [
6122
+ /* @__PURE__ */ jsx(CalendarIcon, {}),
6123
+ /* @__PURE__ */ jsx("span", { className: cn("cbx-ui-combo-value", picked === null && "is-placeholder"), children: picked !== null ? formats.short.format(toDate(picked)) : placeholder })
6124
+ ]
6125
+ }
6126
+ ),
6127
+ panel
6128
+ ]
6129
+ }
6130
+ );
6131
+ }
6132
+ function isDay(value) {
6133
+ return typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(toDate(value).getTime());
6134
+ }
6135
+ function toDate(day) {
6136
+ return /* @__PURE__ */ new Date(`${day}T00:00:00Z`);
6137
+ }
6138
+ function fromDate(date) {
6139
+ return date.toISOString().slice(0, 10);
6140
+ }
6141
+ function today() {
6142
+ const now = /* @__PURE__ */ new Date();
6143
+ return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
6144
+ }
6145
+ function addDays(day, days) {
6146
+ const date = toDate(day);
6147
+ date.setUTCDate(date.getUTCDate() + days);
6148
+ return fromDate(date);
6149
+ }
6150
+ function addMonths(day, months) {
6151
+ const date = toDate(day);
6152
+ const wanted = date.getUTCDate();
6153
+ date.setUTCDate(1);
6154
+ date.setUTCMonth(date.getUTCMonth() + months);
6155
+ const last = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)).getUTCDate();
6156
+ date.setUTCDate(Math.min(wanted, last));
6157
+ return fromDate(date);
6158
+ }
6159
+ function lastOfMonth(day) {
6160
+ const date = toDate(day);
6161
+ return fromDate(new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)));
6162
+ }
6163
+ function weekday(day) {
6164
+ return toDate(day).getUTCDay();
6165
+ }
6166
+ function clampDay(day, min, max) {
6167
+ if (min !== void 0 && isDay(min) && day < min) return min;
6168
+ if (max !== void 0 && isDay(max) && day > max) return max;
6169
+ return day;
6170
+ }
6171
+ function monthGrid(month, firstDay) {
6172
+ const first = `${month}-01`;
6173
+ const start = addDays(first, -((weekday(first) - firstDay + 7) % 7));
6174
+ return Array.from({ length: 6 }, (_, week) => Array.from({ length: 7 }, (_2, day) => addDays(start, week * 7 + day)));
6175
+ }
6176
+ function firstDayOfWeek(locale) {
6177
+ try {
6178
+ const tag = new Intl.Locale(locale.replace("_", "-"));
6179
+ const info = tag.getWeekInfo?.() ?? tag.weekInfo;
6180
+ if (info !== void 0) return info.firstDay % 7;
6181
+ const region = tag.maximize().region;
6182
+ return region !== void 0 && SUNDAY_FIRST.has(region) ? 0 : 1;
6183
+ } catch {
6184
+ return 1;
6185
+ }
6186
+ }
6187
+ var SUNDAY_FIRST = /* @__PURE__ */ new Set(["US", "CA", "MX", "BR", "JP", "KR", "TW", "HK", "IL", "PH", "AU", "ZA", "IN", "SA"]);
6188
+ function formatsFor(locale) {
6189
+ const make = (options) => {
6190
+ try {
6191
+ return new Intl.DateTimeFormat(locale.replace("_", "-") || void 0, { ...options, timeZone: "UTC" });
6192
+ } catch {
6193
+ return new Intl.DateTimeFormat(void 0, { ...options, timeZone: "UTC" });
6194
+ }
6195
+ };
6196
+ return {
6197
+ short: make({ day: "numeric", month: "short", year: "numeric" }),
6198
+ full: make({ weekday: "long", day: "numeric", month: "long", year: "numeric" }),
6199
+ month: make({ month: "long", year: "numeric" }),
6200
+ weekday: make({ weekday: "narrow" }),
6201
+ weekdayLong: make({ weekday: "long" })
6202
+ };
6203
+ }
6204
+ function finePointer() {
6205
+ return typeof window !== "undefined" && window.matchMedia?.("(pointer: fine)").matches === true;
6206
+ }
6207
+ function CalendarIcon() {
6208
+ return /* @__PURE__ */ jsxs("svg", { className: "cbx-ui-combo-icon", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", "aria-hidden": "true", children: [
6209
+ /* @__PURE__ */ jsx("rect", { x: "2.5", y: "3.5", width: "11", height: "10", rx: "2" }),
6210
+ /* @__PURE__ */ jsx("path", { d: "M2.5 6.5h11M5.5 2v3M10.5 2v3" })
6211
+ ] });
6212
+ }
6213
+ function Arrow({ direction }) {
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
+ }
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
+ }
5925
6496
  var Input = forwardRef(function Input2({ scale = "md", className, ...props }, ref) {
5926
6497
  const field = useFieldControl();
5927
6498
  return /* @__PURE__ */ jsx("input", { ref, className: cn("cbx-ui-input", scale === "lg" && "cbx-ui-input--lg", className), ...field, ...props });
@@ -6752,6 +7323,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
6752
7323
  ] });
6753
7324
  }
6754
7325
 
6755
- export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, 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 };
6756
7327
  //# sourceMappingURL=index.js.map
6757
7328
  //# sourceMappingURL=index.js.map