@geomak/ui 5.4.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1800,8 +1800,8 @@ function CatalogCarousel({ items, buttonText, onOpen }) {
1800
1800
  )
1801
1801
  ] }) });
1802
1802
  }
1803
- function Catalog({ display = "grid", items = [], buttonText, onOpen }) {
1804
- return /* @__PURE__ */ jsx("div", { className: "w-full h-full", children: display === "grid" ? /* @__PURE__ */ jsx(CatalogGrid, { items, buttonText, onOpen }) : /* @__PURE__ */ jsx(CatalogCarousel, { items, buttonText, onOpen }) });
1803
+ function Catalog({ display: display2 = "grid", items = [], buttonText, onOpen }) {
1804
+ return /* @__PURE__ */ jsx("div", { className: "w-full h-full", children: display2 === "grid" ? /* @__PURE__ */ jsx(CatalogGrid, { items, buttonText, onOpen }) : /* @__PURE__ */ jsx(CatalogCarousel, { items, buttonText, onOpen }) });
1805
1805
  }
1806
1806
  function ContextMenu({ items, children }) {
1807
1807
  return /* @__PURE__ */ jsxs(ContextMenuPrimitive.Root, { children: [
@@ -5001,7 +5001,647 @@ function TagsInput({
5001
5001
  }
5002
5002
  );
5003
5003
  }
5004
+ var BOX_SIZE = {
5005
+ sm: "h-9 w-8 text-sm",
5006
+ md: "h-11 w-10 text-base",
5007
+ lg: "h-14 w-12 text-lg"
5008
+ };
5009
+ function OtpInput({
5010
+ length = 6,
5011
+ value = "",
5012
+ onChange,
5013
+ onComplete,
5014
+ label,
5015
+ htmlFor,
5016
+ name,
5017
+ mode = "numeric",
5018
+ masked = false,
5019
+ size = "md",
5020
+ disabled,
5021
+ errorMessage,
5022
+ required,
5023
+ groupAfter
5024
+ }) {
5025
+ const errorId = useId();
5026
+ const hasError = errorMessage != null;
5027
+ const refs = useRef([]);
5028
+ const chars = Array.from({ length }, (_, i) => value[i] ?? "");
5029
+ const pattern = mode === "numeric" ? /[0-9]/ : /[a-zA-Z0-9]/;
5030
+ const emit = (next) => {
5031
+ onChange?.(next);
5032
+ if (next.length === length && !next.includes(" ") && [...next].every(Boolean)) {
5033
+ onComplete?.(next);
5034
+ }
5035
+ };
5036
+ const setCharAt = (idx, char) => {
5037
+ const arr = chars.slice();
5038
+ arr[idx] = char;
5039
+ emit(arr.join(""));
5040
+ };
5041
+ const focusBox = (idx) => {
5042
+ const el = refs.current[Math.max(0, Math.min(length - 1, idx))];
5043
+ el?.focus();
5044
+ el?.select();
5045
+ };
5046
+ const onBoxChange = (idx, raw) => {
5047
+ const char = raw.slice(-1);
5048
+ if (char && !pattern.test(char)) return;
5049
+ setCharAt(idx, char);
5050
+ if (char) focusBox(idx + 1);
5051
+ };
5052
+ const onKeyDown = (idx, e) => {
5053
+ if (e.key === "Backspace") {
5054
+ if (chars[idx]) {
5055
+ setCharAt(idx, "");
5056
+ } else if (idx > 0) {
5057
+ setCharAt(idx - 1, "");
5058
+ focusBox(idx - 1);
5059
+ }
5060
+ } else if (e.key === "ArrowLeft") {
5061
+ e.preventDefault();
5062
+ focusBox(idx - 1);
5063
+ } else if (e.key === "ArrowRight") {
5064
+ e.preventDefault();
5065
+ focusBox(idx + 1);
5066
+ }
5067
+ };
5068
+ const onPaste = (e) => {
5069
+ e.preventDefault();
5070
+ const text = e.clipboardData.getData("text").trim();
5071
+ const valid = [...text].filter((c) => pattern.test(c)).slice(0, length);
5072
+ if (valid.length === 0) return;
5073
+ emit(valid.join(""));
5074
+ focusBox(valid.length);
5075
+ };
5076
+ return /* @__PURE__ */ jsx(Field, { label, htmlFor, errorId, errorMessage, required, children: /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", role: "group", "aria-label": typeof label === "string" ? label : "One-time code", children: chars.map((char, idx) => /* @__PURE__ */ jsxs(React8.Fragment, { children: [
5077
+ /* @__PURE__ */ jsx(
5078
+ "input",
5079
+ {
5080
+ ref: (el) => {
5081
+ refs.current[idx] = el;
5082
+ },
5083
+ id: idx === 0 ? htmlFor : void 0,
5084
+ name: idx === 0 ? name : void 0,
5085
+ value: char,
5086
+ disabled,
5087
+ inputMode: mode === "numeric" ? "numeric" : "text",
5088
+ autoComplete: idx === 0 ? "one-time-code" : "off",
5089
+ type: masked && char ? "password" : "text",
5090
+ maxLength: 1,
5091
+ "aria-label": `Digit ${idx + 1}`,
5092
+ "aria-invalid": hasError || void 0,
5093
+ "aria-describedby": hasError ? errorId : void 0,
5094
+ onChange: (e) => onBoxChange(idx, e.target.value),
5095
+ onKeyDown: (e) => onKeyDown(idx, e),
5096
+ onPaste,
5097
+ onFocus: (e) => e.target.select(),
5098
+ className: [
5099
+ BOX_SIZE[size],
5100
+ "text-center font-medium rounded-lg border bg-surface text-foreground",
5101
+ "transition-[border-color,box-shadow] duration-150",
5102
+ hasError ? "border-status-error" : "border-border",
5103
+ "hover:border-border-strong",
5104
+ "focus:outline-none focus:border-accent focus:ring-[3px] focus:ring-focus-ring",
5105
+ "disabled:bg-surface-raised disabled:text-foreground-muted disabled:cursor-not-allowed"
5106
+ ].join(" ")
5107
+ }
5108
+ ),
5109
+ groupAfter && (idx + 1) % groupAfter === 0 && idx < length - 1 && /* @__PURE__ */ jsx("span", { className: "w-2 text-center text-foreground-muted", "aria-hidden": "true", children: "\xB7" })
5110
+ ] }, idx)) }) });
5111
+ }
5112
+ var ICON_SIZE = { sm: "w-4 h-4", md: "w-5 h-5", lg: "w-7 h-7" };
5113
+ var Star = (filled) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", stroke: "currentColor", strokeWidth: filled ? 0 : 1.5, className: "w-full h-full", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M11.48 3.5a.56.56 0 011.04 0l2.13 4.77 5.18.5a.56.56 0 01.32.97l-3.9 3.46 1.15 5.1a.56.56 0 01-.83.6L12 16.8l-4.57 2.6a.56.56 0 01-.83-.6l1.15-5.1-3.9-3.46a.56.56 0 01.32-.97l5.18-.5L11.48 3.5z" }) });
5114
+ function Rating({
5115
+ value,
5116
+ defaultValue = 0,
5117
+ onChange,
5118
+ count = 5,
5119
+ allowHalf = false,
5120
+ readOnly = false,
5121
+ clearable = true,
5122
+ label,
5123
+ size = "md",
5124
+ disabled,
5125
+ icon = Star,
5126
+ errorMessage,
5127
+ name
5128
+ }) {
5129
+ const errorId = useId();
5130
+ const [internal, setInternal] = useState(defaultValue);
5131
+ const [hover, setHover] = useState(null);
5132
+ const current = value ?? internal;
5133
+ const display2 = hover ?? current;
5134
+ const interactive = !readOnly && !disabled;
5135
+ const commit = (next) => {
5136
+ const v = clearable && next === current ? 0 : next;
5137
+ setInternal(v);
5138
+ onChange?.(v);
5139
+ };
5140
+ const onKeyDown = (e) => {
5141
+ if (!interactive) return;
5142
+ const step = allowHalf ? 0.5 : 1;
5143
+ if (e.key === "ArrowRight" || e.key === "ArrowUp") {
5144
+ e.preventDefault();
5145
+ commit(Math.min(count, current + step));
5146
+ } else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
5147
+ e.preventDefault();
5148
+ commit(Math.max(0, current - step));
5149
+ } else if (e.key === "Home") {
5150
+ e.preventDefault();
5151
+ commit(0);
5152
+ } else if (e.key === "End") {
5153
+ e.preventDefault();
5154
+ commit(count);
5155
+ }
5156
+ };
5157
+ return /* @__PURE__ */ jsx(Field, { label, errorId, errorMessage, children: /* @__PURE__ */ jsxs(
5158
+ "div",
5159
+ {
5160
+ role: interactive ? "slider" : "img",
5161
+ "aria-label": typeof label === "string" ? label : "Rating",
5162
+ "aria-valuenow": interactive ? current : void 0,
5163
+ "aria-valuemin": interactive ? 0 : void 0,
5164
+ "aria-valuemax": interactive ? count : void 0,
5165
+ "aria-valuetext": `${current} of ${count}`,
5166
+ tabIndex: interactive ? 0 : -1,
5167
+ onKeyDown,
5168
+ onMouseLeave: () => setHover(null),
5169
+ className: "inline-flex items-center gap-1 text-accent focus:outline-none focus-visible:ring-[3px] focus-visible:ring-focus-ring rounded-md w-max",
5170
+ children: [
5171
+ name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: current }),
5172
+ Array.from({ length: count }, (_, i) => {
5173
+ const starValue = i + 1;
5174
+ const fillFraction = Math.max(0, Math.min(1, display2 - i));
5175
+ return /* @__PURE__ */ jsxs(
5176
+ "span",
5177
+ {
5178
+ className: `relative ${ICON_SIZE[size]} ${interactive ? "cursor-pointer" : ""} ${disabled ? "opacity-50" : ""}`,
5179
+ onMouseMove: (e) => {
5180
+ if (!interactive) return;
5181
+ if (allowHalf) {
5182
+ const rect = e.currentTarget.getBoundingClientRect();
5183
+ const half = e.clientX - rect.left < rect.width / 2;
5184
+ setHover(i + (half ? 0.5 : 1));
5185
+ } else {
5186
+ setHover(starValue);
5187
+ }
5188
+ },
5189
+ onClick: (e) => {
5190
+ if (!interactive) return;
5191
+ if (allowHalf) {
5192
+ const rect = e.currentTarget.getBoundingClientRect();
5193
+ const half = e.clientX - rect.left < rect.width / 2;
5194
+ commit(i + (half ? 0.5 : 1));
5195
+ } else {
5196
+ commit(starValue);
5197
+ }
5198
+ },
5199
+ children: [
5200
+ /* @__PURE__ */ jsx("span", { className: "absolute inset-0 text-foreground-muted", children: icon(false) }),
5201
+ /* @__PURE__ */ jsx(
5202
+ "span",
5203
+ {
5204
+ className: "absolute inset-0 overflow-hidden",
5205
+ style: { width: `${fillFraction * 100}%` },
5206
+ children: icon(true)
5207
+ }
5208
+ )
5209
+ ]
5210
+ },
5211
+ i
5212
+ );
5213
+ })
5214
+ ]
5215
+ }
5216
+ ) });
5217
+ }
5218
+ var pad = (n) => n.toString().padStart(2, "0");
5219
+ function parse(value) {
5220
+ if (!value) return null;
5221
+ const [h, m, s] = value.split(":").map(Number);
5222
+ if (Number.isNaN(h) || Number.isNaN(m)) return null;
5223
+ return { h, m, s: Number.isNaN(s) ? 0 : s };
5224
+ }
5225
+ function display(value, use12, withSeconds) {
5226
+ const p = parse(value);
5227
+ if (!p) return "";
5228
+ if (use12) {
5229
+ const period = p.h >= 12 ? "PM" : "AM";
5230
+ const h12 = p.h % 12 === 0 ? 12 : p.h % 12;
5231
+ return `${h12}:${pad(p.m)}${withSeconds ? `:${pad(p.s)}` : ""} ${period}`;
5232
+ }
5233
+ return `${pad(p.h)}:${pad(p.m)}${withSeconds ? `:${pad(p.s)}` : ""}`;
5234
+ }
5235
+ function TimePicker({
5236
+ value,
5237
+ onChange,
5238
+ label,
5239
+ htmlFor,
5240
+ name,
5241
+ placeholder = "Select a time\u2026",
5242
+ layout = "vertical",
5243
+ size = "md",
5244
+ use12Hours = false,
5245
+ withSeconds = false,
5246
+ minuteStep = 1,
5247
+ disabled,
5248
+ errorMessage,
5249
+ required,
5250
+ style
5251
+ }) {
5252
+ const errorId = useId();
5253
+ const hasError = errorMessage != null;
5254
+ const [open, setOpen] = useState(false);
5255
+ const parsed = parse(value) ?? { h: 0, m: 0, s: 0 };
5256
+ const update = (next) => {
5257
+ const merged = { ...parsed, ...next };
5258
+ onChange?.(`${pad(merged.h)}:${pad(merged.m)}${withSeconds ? `:${pad(merged.s)}` : ""}`);
5259
+ };
5260
+ const hours = use12Hours ? Array.from({ length: 12 }, (_, i) => i + 1) : Array.from({ length: 24 }, (_, i) => i);
5261
+ const minutes = Array.from({ length: Math.ceil(60 / minuteStep) }, (_, i) => i * minuteStep);
5262
+ const seconds = Array.from({ length: 60 }, (_, i) => i);
5263
+ const selectedHourCol = use12Hours ? parsed.h % 12 === 0 ? 12 : parsed.h % 12 : parsed.h;
5264
+ const period = parsed.h >= 12 ? "PM" : "AM";
5265
+ const setHour12 = (h12, p) => {
5266
+ const h24 = p === "AM" ? h12 === 12 ? 0 : h12 : h12 === 12 ? 12 : h12 + 12;
5267
+ update({ h: h24 });
5268
+ };
5269
+ const Column = ({ items, selected, onPick, fmt }) => /* @__PURE__ */ jsx("div", { className: "flex flex-col overflow-y-auto max-h-48 w-14 hidden-scrollbar", role: "listbox", children: items.map((n) => /* @__PURE__ */ jsx(
5270
+ "button",
5271
+ {
5272
+ type: "button",
5273
+ role: "option",
5274
+ "aria-selected": selected === n,
5275
+ onClick: () => onPick(n),
5276
+ className: `py-1.5 text-sm rounded-md text-center transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${selected === n ? "bg-accent text-accent-fg" : "text-foreground hover:bg-surface-raised"}`,
5277
+ children: fmt ? fmt(n) : pad(n)
5278
+ },
5279
+ n
5280
+ )) });
5281
+ return /* @__PURE__ */ jsxs(Field, { label, htmlFor, errorId, errorMessage, layout, required, children: [
5282
+ /* @__PURE__ */ jsxs(Popover.Root, { open: open && !disabled, onOpenChange: (o) => !disabled && setOpen(o), children: [
5283
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
5284
+ "button",
5285
+ {
5286
+ id: htmlFor,
5287
+ type: "button",
5288
+ disabled,
5289
+ style,
5290
+ "aria-invalid": hasError || void 0,
5291
+ "aria-describedby": hasError ? errorId : void 0,
5292
+ className: `flex items-center justify-between cursor-pointer select-none ${!style?.width ? "min-w-[160px]" : ""} ${fieldShell({ size, hasError, disabled })}`,
5293
+ children: [
5294
+ /* @__PURE__ */ jsx("span", { className: `text-sm truncate ${value ? "" : "text-foreground-muted"}`, children: display(value, use12Hours, withSeconds) || placeholder }),
5295
+ /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.75, className: "w-4 h-4 flex-shrink-0 text-foreground-muted ml-2", "aria-hidden": "true", children: [
5296
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
5297
+ /* @__PURE__ */ jsx("path", { d: "M12 7v5l3 2", strokeLinecap: "round" })
5298
+ ] })
5299
+ ]
5300
+ }
5301
+ ) }),
5302
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
5303
+ Popover.Content,
5304
+ {
5305
+ align: "start",
5306
+ sideOffset: 4,
5307
+ className: "bg-surface text-foreground border border-border rounded-lg shadow-md z-50 p-2 flex gap-1 animate-in fade-in-0 zoom-in-95",
5308
+ children: [
5309
+ /* @__PURE__ */ jsx(
5310
+ Column,
5311
+ {
5312
+ items: hours,
5313
+ selected: selectedHourCol,
5314
+ onPick: (h) => use12Hours ? setHour12(h, period) : update({ h }),
5315
+ fmt: use12Hours ? (n) => String(n) : pad
5316
+ }
5317
+ ),
5318
+ /* @__PURE__ */ jsx(Column, { items: minutes, selected: parsed.m, onPick: (m) => update({ m }) }),
5319
+ withSeconds && /* @__PURE__ */ jsx(Column, { items: seconds, selected: parsed.s, onPick: (s) => update({ s }) }),
5320
+ use12Hours && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1 w-12", children: ["AM", "PM"].map((p) => /* @__PURE__ */ jsx(
5321
+ "button",
5322
+ {
5323
+ type: "button",
5324
+ onClick: () => setHour12(selectedHourCol, p),
5325
+ className: `py-1.5 text-sm rounded-md transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${period === p ? "bg-accent text-accent-fg" : "text-foreground hover:bg-surface-raised"}`,
5326
+ children: p
5327
+ },
5328
+ p
5329
+ )) })
5330
+ ]
5331
+ }
5332
+ ) })
5333
+ ] }),
5334
+ name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: value ?? "" })
5335
+ ] });
5336
+ }
5337
+ var MONTH_NAMES2 = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
5338
+ var WEEKDAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
5339
+ var startOfMonth2 = (d) => new Date(d.getFullYear(), d.getMonth(), 1);
5340
+ var addMonths2 = (d, n) => new Date(d.getFullYear(), d.getMonth() + n, 1);
5341
+ var addDays2 = (d, n) => {
5342
+ const c = new Date(d);
5343
+ c.setDate(c.getDate() + n);
5344
+ return c;
5345
+ };
5346
+ var isSameDay2 = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
5347
+ var startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
5348
+ var defaultFmt = (d) => `${d.getFullYear()}-${`${d.getMonth() + 1}`.padStart(2, "0")}-${`${d.getDate()}`.padStart(2, "0")}`;
5349
+ function buildGrid2(viewMonth, weekStartsOn) {
5350
+ const first = startOfMonth2(viewMonth);
5351
+ const offset = (first.getDay() - weekStartsOn + 7) % 7;
5352
+ const gridStart = addDays2(first, -offset);
5353
+ return Array.from({ length: 42 }, (_, i) => {
5354
+ const d = addDays2(gridStart, i);
5355
+ return { date: d, outside: d.getMonth() !== viewMonth.getMonth() };
5356
+ });
5357
+ }
5358
+ function DateRangePicker({
5359
+ value = { start: null, end: null },
5360
+ onChange,
5361
+ label,
5362
+ htmlFor,
5363
+ placeholder = "Select a date range\u2026",
5364
+ layout = "vertical",
5365
+ size = "md",
5366
+ min,
5367
+ max,
5368
+ weekStartsOn = 0,
5369
+ presets,
5370
+ format = defaultFmt,
5371
+ disabled,
5372
+ errorMessage,
5373
+ required,
5374
+ style
5375
+ }) {
5376
+ const errorId = useId();
5377
+ const hasError = errorMessage != null;
5378
+ const [open, setOpen] = useState(false);
5379
+ const [leftMonth, setLeftMonth] = useState(() => startOfMonth2(value.start ?? /* @__PURE__ */ new Date()));
5380
+ const [pendingStart, setPendingStart] = useState(null);
5381
+ const [hoverDate, setHoverDate] = useState(null);
5382
+ const weekdays = useMemo(
5383
+ () => WEEKDAY.slice(weekStartsOn).concat(WEEKDAY.slice(0, weekStartsOn)),
5384
+ [weekStartsOn]
5385
+ );
5386
+ const isDisabled = (d) => min && d < startOfDay(min) || max && d > startOfDay(max);
5387
+ const effective = pendingStart ? { start: pendingStart, end: hoverDate } : value;
5388
+ const inRange = (d) => {
5389
+ const { start, end } = effective;
5390
+ if (!start || !end) return false;
5391
+ const [a, b] = start <= end ? [start, end] : [end, start];
5392
+ return d >= startOfDay(a) && d <= startOfDay(b);
5393
+ };
5394
+ const onDayClick = (d) => {
5395
+ if (isDisabled(d)) return;
5396
+ if (!pendingStart) {
5397
+ setPendingStart(d);
5398
+ setHoverDate(d);
5399
+ onChange?.({ start: d, end: null });
5400
+ } else {
5401
+ const [start, end] = pendingStart <= d ? [pendingStart, d] : [d, pendingStart];
5402
+ onChange?.({ start, end });
5403
+ setPendingStart(null);
5404
+ setHoverDate(null);
5405
+ setOpen(false);
5406
+ }
5407
+ };
5408
+ const triggerText = value.start && value.end ? `${format(value.start)} \u2013 ${format(value.end)}` : value.start ? `${format(value.start)} \u2013 \u2026` : "";
5409
+ const renderMonth = (viewMonth) => {
5410
+ const cells = buildGrid2(viewMonth, weekStartsOn);
5411
+ return /* @__PURE__ */ jsxs("div", { children: [
5412
+ /* @__PURE__ */ jsxs("div", { className: "text-sm font-semibold text-center mb-2 select-none", children: [
5413
+ MONTH_NAMES2[viewMonth.getMonth()],
5414
+ " ",
5415
+ viewMonth.getFullYear()
5416
+ ] }),
5417
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-7 gap-y-1", children: [
5418
+ weekdays.map((w) => /* @__PURE__ */ jsx("div", { className: "text-[11px] font-medium text-foreground-muted uppercase text-center", children: w }, w)),
5419
+ cells.map(({ date, outside }) => {
5420
+ const dis = isDisabled(date);
5421
+ const isStart = effective.start && isSameDay2(date, effective.start);
5422
+ const isEnd = effective.end && isSameDay2(date, effective.end);
5423
+ const within = inRange(date) && !isStart && !isEnd;
5424
+ return /* @__PURE__ */ jsx(
5425
+ "button",
5426
+ {
5427
+ type: "button",
5428
+ disabled: dis,
5429
+ onMouseEnter: () => pendingStart && setHoverDate(date),
5430
+ onClick: () => onDayClick(date),
5431
+ className: [
5432
+ "h-8 text-xs font-medium transition-colors",
5433
+ "focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
5434
+ "disabled:opacity-30 disabled:cursor-not-allowed",
5435
+ isStart || isEnd ? "bg-accent text-accent-fg rounded-md" : within ? "bg-surface-raised text-foreground rounded-none" : outside ? "text-foreground-muted hover:bg-surface-raised rounded-md" : "text-foreground hover:bg-surface-raised rounded-md"
5436
+ ].join(" "),
5437
+ children: date.getDate()
5438
+ },
5439
+ defaultFmt(date)
5440
+ );
5441
+ })
5442
+ ] })
5443
+ ] });
5444
+ };
5445
+ return /* @__PURE__ */ jsx(Field, { label, htmlFor, errorId, errorMessage, layout, required, children: /* @__PURE__ */ jsxs(Popover.Root, { open: open && !disabled, onOpenChange: (o) => {
5446
+ if (!disabled) {
5447
+ setOpen(o);
5448
+ if (!o) {
5449
+ setPendingStart(null);
5450
+ setHoverDate(null);
5451
+ }
5452
+ }
5453
+ }, children: [
5454
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
5455
+ "button",
5456
+ {
5457
+ id: htmlFor,
5458
+ type: "button",
5459
+ disabled,
5460
+ style,
5461
+ "aria-invalid": hasError || void 0,
5462
+ "aria-describedby": hasError ? errorId : void 0,
5463
+ className: `flex items-center justify-between cursor-pointer select-none ${!style?.width ? "min-w-[240px]" : ""} ${fieldShell({ size, hasError, disabled })}`,
5464
+ children: [
5465
+ /* @__PURE__ */ jsx("span", { className: `text-sm truncate ${triggerText ? "" : "text-foreground-muted"}`, children: triggerText || placeholder }),
5466
+ /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.75, className: "w-4 h-4 flex-shrink-0 text-foreground-muted ml-2", "aria-hidden": "true", children: [
5467
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "5", width: "18", height: "16", rx: "2" }),
5468
+ /* @__PURE__ */ jsx("path", { d: "M3 9h18M8 3v4M16 3v4", strokeLinecap: "round" })
5469
+ ] })
5470
+ ]
5471
+ }
5472
+ ) }),
5473
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
5474
+ Popover.Content,
5475
+ {
5476
+ align: "start",
5477
+ sideOffset: 4,
5478
+ className: "bg-surface text-foreground border border-border rounded-lg shadow-md z-50 p-3 flex gap-3 animate-in fade-in-0 zoom-in-95",
5479
+ children: [
5480
+ presets && presets.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1 pr-3 border-r border-border min-w-[120px]", children: presets.map((p) => /* @__PURE__ */ jsx(
5481
+ "button",
5482
+ {
5483
+ type: "button",
5484
+ onClick: () => {
5485
+ onChange?.(p.range());
5486
+ setOpen(false);
5487
+ },
5488
+ className: "text-left text-xs px-2 py-1.5 rounded-md text-foreground-secondary hover:bg-surface-raised hover:text-foreground transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
5489
+ children: p.label
5490
+ },
5491
+ p.label
5492
+ )) }),
5493
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
5494
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
5495
+ /* @__PURE__ */ jsx(
5496
+ "button",
5497
+ {
5498
+ type: "button",
5499
+ onClick: () => setLeftMonth(addMonths2(leftMonth, -1)),
5500
+ "aria-label": "Previous month",
5501
+ className: "absolute -top-1 left-0 w-7 h-7 inline-flex items-center justify-center rounded-md hover:bg-surface-raised focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
5502
+ children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "w-4 h-4", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15 19l-7-7 7-7" }) })
5503
+ }
5504
+ ),
5505
+ renderMonth(leftMonth)
5506
+ ] }),
5507
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
5508
+ /* @__PURE__ */ jsx(
5509
+ "button",
5510
+ {
5511
+ type: "button",
5512
+ onClick: () => setLeftMonth(addMonths2(leftMonth, 1)),
5513
+ "aria-label": "Next month",
5514
+ className: "absolute -top-1 right-0 w-7 h-7 inline-flex items-center justify-center rounded-md hover:bg-surface-raised focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
5515
+ children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "w-4 h-4", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) })
5516
+ }
5517
+ ),
5518
+ renderMonth(addMonths2(leftMonth, 1))
5519
+ ] })
5520
+ ] })
5521
+ ]
5522
+ }
5523
+ ) })
5524
+ ] }) });
5525
+ }
5526
+ var DEFAULT_SWATCHES = [
5527
+ "#0466c8",
5528
+ "#1e8449",
5529
+ "#d68910",
5530
+ "#c0392b",
5531
+ "#8e44ad",
5532
+ "#16a085",
5533
+ "#2c3e50",
5534
+ "#7f8c8d",
5535
+ "#e84393",
5536
+ "#00b894",
5537
+ "#fdcb6e",
5538
+ "#0a1929"
5539
+ ];
5540
+ var HEX_RE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
5541
+ function ColorPicker({
5542
+ value = "",
5543
+ onChange,
5544
+ label,
5545
+ htmlFor,
5546
+ name,
5547
+ layout = "vertical",
5548
+ size = "md",
5549
+ swatches = DEFAULT_SWATCHES,
5550
+ allowCustom = true,
5551
+ disabled,
5552
+ errorMessage,
5553
+ required,
5554
+ placeholder = "Pick a colour\u2026"
5555
+ }) {
5556
+ const errorId = useId();
5557
+ const hasError = errorMessage != null;
5558
+ const [open, setOpen] = useState(false);
5559
+ const [draft, setDraft] = useState(value);
5560
+ const valid = HEX_RE.test(value);
5561
+ const pick = (hex) => {
5562
+ onChange?.(hex);
5563
+ setDraft(hex);
5564
+ };
5565
+ const commitDraft = (raw) => {
5566
+ const hex = raw.startsWith("#") ? raw : `#${raw}`;
5567
+ setDraft(hex);
5568
+ if (HEX_RE.test(hex)) onChange?.(hex);
5569
+ };
5570
+ return /* @__PURE__ */ jsxs(Field, { label, htmlFor, errorId, errorMessage, layout, required, children: [
5571
+ /* @__PURE__ */ jsxs(Popover.Root, { open: open && !disabled, onOpenChange: (o) => !disabled && setOpen(o), children: [
5572
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
5573
+ "button",
5574
+ {
5575
+ id: htmlFor,
5576
+ type: "button",
5577
+ disabled,
5578
+ "aria-invalid": hasError || void 0,
5579
+ "aria-describedby": hasError ? errorId : void 0,
5580
+ className: `flex items-center gap-2 cursor-pointer select-none ${fieldShell({ size, hasError, disabled })}`,
5581
+ children: [
5582
+ /* @__PURE__ */ jsx(
5583
+ "span",
5584
+ {
5585
+ className: "h-4 w-4 flex-shrink-0 rounded border border-border",
5586
+ style: { backgroundColor: valid ? value : "transparent" },
5587
+ "aria-hidden": "true"
5588
+ }
5589
+ ),
5590
+ /* @__PURE__ */ jsx("span", { className: `flex-1 text-left text-sm truncate ${valid ? "text-foreground" : "text-foreground-muted"}`, children: valid ? value.toLowerCase() : placeholder })
5591
+ ]
5592
+ }
5593
+ ) }),
5594
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
5595
+ Popover.Content,
5596
+ {
5597
+ align: "start",
5598
+ sideOffset: 4,
5599
+ className: "bg-surface text-foreground border border-border rounded-lg shadow-md z-50 p-3 w-56 animate-in fade-in-0 zoom-in-95",
5600
+ children: [
5601
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-6 gap-2 mb-3", children: swatches.map((sw) => /* @__PURE__ */ jsx(
5602
+ "button",
5603
+ {
5604
+ type: "button",
5605
+ onClick: () => {
5606
+ pick(sw);
5607
+ setOpen(false);
5608
+ },
5609
+ "aria-label": sw,
5610
+ className: `h-7 w-7 rounded-md border transition-transform hover:scale-110 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${value.toLowerCase() === sw.toLowerCase() ? "border-accent ring-2 ring-focus-ring" : "border-border"}`,
5611
+ style: { backgroundColor: sw }
5612
+ },
5613
+ sw
5614
+ )) }),
5615
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
5616
+ /* @__PURE__ */ jsx(
5617
+ "input",
5618
+ {
5619
+ value: draft,
5620
+ onChange: (e) => commitDraft(e.target.value),
5621
+ placeholder: "#0466c8",
5622
+ "aria-label": "Hex colour",
5623
+ className: `flex-1 ${fieldShell({ size: "sm" })}`
5624
+ }
5625
+ ),
5626
+ allowCustom && /* @__PURE__ */ jsx(
5627
+ "input",
5628
+ {
5629
+ type: "color",
5630
+ value: valid ? value : "#000000",
5631
+ onChange: (e) => pick(e.target.value),
5632
+ "aria-label": "Custom colour",
5633
+ className: "h-7 w-9 rounded-md border border-border bg-surface cursor-pointer p-0.5"
5634
+ }
5635
+ )
5636
+ ] })
5637
+ ]
5638
+ }
5639
+ ) })
5640
+ ] }),
5641
+ name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: valid ? value : "" })
5642
+ ] });
5643
+ }
5004
5644
 
5005
- export { AppShell, AutoComplete, Avatar, Box, Button, Catalog, CatalogCarousel, CatalogGrid, Checkbox, ContextMenu, Drawer, Dropdown, FadingBase, Field, FileInput, Flex, Grid2 as Grid, GridCard, icons_default as Icon, IconButton, List2 as List, LoadingSpinner, Modal, NotificationProvider, NumberInput, OpaqueGridCard, Password, Portal, RadioGroup, ScalableContainer, SearchInput_default as SearchInput, SegmentedControl, Sidebar, SkeletonBox, SkeletonCard, SkeletonCircle, SkeletonText, Slider, Switch, Table, Tabs, TagsInput, DatePicker as Temporal, TextArea, TextInput, ThemeProvider, ThemeSwitch, ToggleButton, Tooltip, TooltipProvider, TopBar, Tree, TreeSelect, Typography, Wizard, fieldShell, useNotification };
5645
+ export { AppShell, AutoComplete, Avatar, Box, Button, Catalog, CatalogCarousel, CatalogGrid, Checkbox, ColorPicker, ContextMenu, DateRangePicker, Drawer, Dropdown, FadingBase, Field, FileInput, Flex, Grid2 as Grid, GridCard, icons_default as Icon, IconButton, List2 as List, LoadingSpinner, Modal, NotificationProvider, NumberInput, OpaqueGridCard, OtpInput, Password, Portal, RadioGroup, Rating, ScalableContainer, SearchInput_default as SearchInput, SegmentedControl, Sidebar, SkeletonBox, SkeletonCard, SkeletonCircle, SkeletonText, Slider, Switch, Table, Tabs, TagsInput, DatePicker as Temporal, TextArea, TextInput, ThemeProvider, ThemeSwitch, TimePicker, ToggleButton, Tooltip, TooltipProvider, TopBar, Tree, TreeSelect, Typography, Wizard, fieldShell, useNotification };
5006
5646
  //# sourceMappingURL=index.js.map
5007
5647
  //# sourceMappingURL=index.js.map