@geomak/ui 5.3.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
@@ -15,6 +15,7 @@ import * as Popover from '@radix-ui/react-popover';
15
15
  import * as SwitchPrimitive from '@radix-ui/react-switch';
16
16
  import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
17
17
  import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
18
+ import * as SliderPrimitive from '@radix-ui/react-slider';
18
19
 
19
20
  var Moon = ({ color = "gray" }) => /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: color, viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: color, className: "w-8 h-8", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M21.752 15.002A9.718 9.718 0 0118 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 003 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 009.002-5.998z" }) });
20
21
  var Sun = ({ color = "yellow" }) => /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: color, viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: color, className: "w-8 h-8", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 3v2.25m6.364.386l-1.591 1.591M21 12h-2.25m-.386 6.364l-1.591-1.591M12 18.75V21m-4.773-4.227l-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0z" }) });
@@ -1799,8 +1800,8 @@ function CatalogCarousel({ items, buttonText, onOpen }) {
1799
1800
  )
1800
1801
  ] }) });
1801
1802
  }
1802
- function Catalog({ display = "grid", items = [], buttonText, onOpen }) {
1803
- 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 }) });
1804
1805
  }
1805
1806
  function ContextMenu({ items, children }) {
1806
1807
  return /* @__PURE__ */ jsxs(ContextMenuPrimitive.Root, { children: [
@@ -4629,7 +4630,1018 @@ function ChevronLeft() {
4629
4630
  function ChevronRight3() {
4630
4631
  return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "w-4 h-4", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) });
4631
4632
  }
4633
+ var LINE_HEIGHT_PX = 21;
4634
+ function TextArea({
4635
+ value,
4636
+ onChange,
4637
+ onBlur,
4638
+ disabled,
4639
+ label,
4640
+ htmlFor,
4641
+ placeholder,
4642
+ name,
4643
+ layout = "vertical",
4644
+ size = "md",
4645
+ rows = 4,
4646
+ autoGrow = false,
4647
+ maxRows = 12,
4648
+ maxLength,
4649
+ showCount = false,
4650
+ resize,
4651
+ errorMessage,
4652
+ required,
4653
+ style,
4654
+ inputStyle
4655
+ }) {
4656
+ const errorId = useId();
4657
+ const hasError = errorMessage != null;
4658
+ const ref = useRef(null);
4659
+ useLayoutEffect(() => {
4660
+ if (!autoGrow) return;
4661
+ const el = ref.current;
4662
+ if (!el) return;
4663
+ el.style.height = "auto";
4664
+ const maxH = maxRows * LINE_HEIGHT_PX + 16;
4665
+ el.style.height = `${Math.min(el.scrollHeight, maxH)}px`;
4666
+ el.style.overflowY = el.scrollHeight > maxH ? "auto" : "hidden";
4667
+ }, [value, autoGrow, maxRows]);
4668
+ const count = typeof value === "string" ? value.length : 0;
4669
+ const resizeClass = (resize ?? (autoGrow ? "none" : "vertical")) === "none" ? "resize-none" : (resize ?? "vertical") === "horizontal" ? "resize-x" : (resize ?? "vertical") === "both" ? "resize" : "resize-y";
4670
+ return /* @__PURE__ */ jsxs(
4671
+ Field,
4672
+ {
4673
+ label,
4674
+ htmlFor,
4675
+ errorId,
4676
+ errorMessage,
4677
+ layout,
4678
+ required,
4679
+ children: [
4680
+ /* @__PURE__ */ jsx(
4681
+ "textarea",
4682
+ {
4683
+ ref,
4684
+ disabled,
4685
+ value,
4686
+ onChange,
4687
+ onBlur,
4688
+ name,
4689
+ id: htmlFor,
4690
+ rows,
4691
+ maxLength,
4692
+ placeholder: placeholder ?? "",
4693
+ "aria-invalid": hasError || void 0,
4694
+ "aria-describedby": hasError ? errorId : void 0,
4695
+ className: `${fieldShell({ size, hasError, disabled, sized: false })} px-3 py-2 leading-normal ${resizeClass}`,
4696
+ style: { ...style, ...inputStyle }
4697
+ }
4698
+ ),
4699
+ showCount && /* @__PURE__ */ jsx("div", { className: "mt-1 text-right text-xs text-foreground-muted tabular-nums", children: maxLength != null ? `${count} / ${maxLength}` : count })
4700
+ ]
4701
+ }
4702
+ );
4703
+ }
4704
+ var SIZE = {
4705
+ sm: { h: "h-control-sm", text: "text-xs", pad: "px-2.5" },
4706
+ md: { h: "h-control-md", text: "text-sm", pad: "px-3.5" },
4707
+ lg: { h: "h-control-lg", text: "text-sm", pad: "px-4" }
4708
+ };
4709
+ function SegmentedControl({
4710
+ options,
4711
+ value,
4712
+ defaultValue,
4713
+ onChange,
4714
+ size = "md",
4715
+ fullWidth = false,
4716
+ disabled,
4717
+ "aria-label": ariaLabel
4718
+ }) {
4719
+ const sz = SIZE[size];
4720
+ return /* @__PURE__ */ jsx(
4721
+ ToggleGroup.Root,
4722
+ {
4723
+ type: "single",
4724
+ value,
4725
+ defaultValue,
4726
+ onValueChange: (v) => {
4727
+ if (v) onChange?.(v);
4728
+ },
4729
+ disabled,
4730
+ "aria-label": ariaLabel,
4731
+ className: [
4732
+ "inline-flex items-center gap-1 rounded-lg border border-border bg-surface-raised p-1",
4733
+ sz.h,
4734
+ fullWidth ? "flex w-full" : "",
4735
+ disabled ? "opacity-60 cursor-not-allowed" : ""
4736
+ ].filter(Boolean).join(" "),
4737
+ children: options.map((opt) => /* @__PURE__ */ jsxs(
4738
+ ToggleGroup.Item,
4739
+ {
4740
+ value: opt.value,
4741
+ disabled: opt.disabled,
4742
+ className: [
4743
+ "inline-flex items-center justify-center gap-1.5 rounded-md select-none whitespace-nowrap",
4744
+ "transition-colors duration-150 h-full",
4745
+ sz.text,
4746
+ sz.pad,
4747
+ fullWidth ? "flex-1" : "",
4748
+ // Resting: muted text, transparent. Hover lifts the text.
4749
+ "text-foreground-secondary hover:text-foreground",
4750
+ // Active: surface-white pill + accent text + subtle shadow.
4751
+ "data-[state=on]:bg-surface data-[state=on]:text-accent data-[state=on]:shadow-sm",
4752
+ "focus:outline-none focus-visible:ring-[3px] focus-visible:ring-focus-ring",
4753
+ "disabled:opacity-40 disabled:cursor-not-allowed"
4754
+ ].filter(Boolean).join(" "),
4755
+ children: [
4756
+ opt.icon && /* @__PURE__ */ jsx("span", { className: "flex-shrink-0", children: opt.icon }),
4757
+ opt.label
4758
+ ]
4759
+ },
4760
+ opt.value
4761
+ ))
4762
+ }
4763
+ );
4764
+ }
4765
+ var TRACK_H = { sm: "h-1", md: "h-1.5", lg: "h-2" };
4766
+ var THUMB = { sm: "h-3.5 w-3.5", md: "h-4 w-4", lg: "h-5 w-5" };
4767
+ var toArray = (v) => v == null ? void 0 : Array.isArray(v) ? v : [v];
4768
+ function Slider({
4769
+ value,
4770
+ defaultValue,
4771
+ onChange,
4772
+ onChangeEnd,
4773
+ min = 0,
4774
+ max = 100,
4775
+ step = 1,
4776
+ label,
4777
+ showValue = false,
4778
+ formatValue = (n) => String(n),
4779
+ marks,
4780
+ tooltip = false,
4781
+ size = "md",
4782
+ disabled,
4783
+ errorMessage,
4784
+ name,
4785
+ htmlFor
4786
+ }) {
4787
+ const errorId = useId();
4788
+ const hasError = errorMessage != null;
4789
+ const isRange = Array.isArray(value ?? defaultValue);
4790
+ const [internal, setInternal] = useState(
4791
+ () => toArray(value) ?? toArray(defaultValue) ?? [min]
4792
+ );
4793
+ const current = toArray(value) ?? internal;
4794
+ const [dragging, setDragging] = useState(false);
4795
+ const emit = (arr) => {
4796
+ setInternal(arr);
4797
+ const next = isRange ? [arr[0], arr[1]] : arr[0];
4798
+ onChange?.(next);
4799
+ };
4800
+ const valueText = current.map(formatValue).join(" \u2013 ");
4801
+ return /* @__PURE__ */ jsxs(Field, { label: void 0, errorId, errorMessage, children: [
4802
+ (label || showValue) && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-2", children: [
4803
+ label && /* @__PURE__ */ jsx("label", { htmlFor, className: "text-sm font-medium text-foreground select-none", children: label }),
4804
+ showValue && /* @__PURE__ */ jsx("span", { className: "text-sm text-foreground-secondary tabular-nums", children: valueText })
4805
+ ] }),
4806
+ /* @__PURE__ */ jsxs(
4807
+ SliderPrimitive.Root,
4808
+ {
4809
+ id: htmlFor,
4810
+ name,
4811
+ value: toArray(value),
4812
+ defaultValue: toArray(defaultValue),
4813
+ min,
4814
+ max,
4815
+ step,
4816
+ disabled,
4817
+ "aria-invalid": hasError || void 0,
4818
+ "aria-describedby": hasError ? errorId : void 0,
4819
+ onValueChange: (v) => {
4820
+ emit(v);
4821
+ setDragging(true);
4822
+ },
4823
+ onValueCommit: (v) => {
4824
+ setDragging(false);
4825
+ onChangeEnd?.(isRange ? [v[0], v[1]] : v[0]);
4826
+ },
4827
+ className: "relative flex items-center select-none touch-none w-full h-5",
4828
+ children: [
4829
+ /* @__PURE__ */ jsx(SliderPrimitive.Track, { className: `relative grow rounded-full bg-surface-raised border border-border ${TRACK_H[size]}`, children: /* @__PURE__ */ jsx(SliderPrimitive.Range, { className: "absolute h-full rounded-full bg-accent" }) }),
4830
+ current.map((_, i) => /* @__PURE__ */ jsx(
4831
+ SliderPrimitive.Thumb,
4832
+ {
4833
+ className: `group relative block ${THUMB[size]} rounded-full border-2 border-accent bg-surface shadow-sm transition-shadow
4834
+ focus:outline-none focus-visible:ring-[3px] focus-visible:ring-focus-ring
4835
+ disabled:cursor-not-allowed`,
4836
+ children: tooltip && /* @__PURE__ */ jsx(
4837
+ "span",
4838
+ {
4839
+ className: `pointer-events-none absolute -top-8 left-1/2 -translate-x-1/2 rounded-md bg-foreground px-1.5 py-0.5 text-xs text-background tabular-nums whitespace-nowrap transition-opacity ${dragging ? "opacity-100" : "opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"}`,
4840
+ children: formatValue(current[i])
4841
+ }
4842
+ )
4843
+ },
4844
+ i
4845
+ ))
4846
+ ]
4847
+ }
4848
+ ),
4849
+ marks && marks.length > 0 && /* @__PURE__ */ jsx("div", { className: "relative mt-2 h-4", children: marks.map((m) => {
4850
+ const pct = (m.value - min) / (max - min) * 100;
4851
+ return /* @__PURE__ */ jsx(
4852
+ "span",
4853
+ {
4854
+ className: "absolute -translate-x-1/2 text-xs text-foreground-muted tabular-nums",
4855
+ style: { left: `${pct}%` },
4856
+ children: m.label ?? m.value
4857
+ },
4858
+ m.value
4859
+ );
4860
+ }) })
4861
+ ] });
4862
+ }
4863
+ function TagsInput({
4864
+ value,
4865
+ defaultValue,
4866
+ onChange,
4867
+ label,
4868
+ htmlFor,
4869
+ name,
4870
+ placeholder = "Add and press Enter",
4871
+ layout = "vertical",
4872
+ size = "md",
4873
+ disabled,
4874
+ errorMessage,
4875
+ required,
4876
+ maxTags,
4877
+ dedupe = true,
4878
+ validate,
4879
+ separators = ["Enter", ","]
4880
+ }) {
4881
+ const errorId = useId();
4882
+ const inputRef = useRef(null);
4883
+ const [internal, setInternal] = useState(defaultValue ?? []);
4884
+ const [draft, setDraft] = useState("");
4885
+ const [localError, setLocalError] = useState(null);
4886
+ const tags = value ?? internal;
4887
+ const hasError = errorMessage != null || localError != null;
4888
+ const errorText = errorMessage ?? localError ?? void 0;
4889
+ const commitTags = (next) => {
4890
+ setInternal(next);
4891
+ onChange?.(next);
4892
+ };
4893
+ const addTag = (raw) => {
4894
+ const tag = raw.trim();
4895
+ if (!tag) return false;
4896
+ if (maxTags != null && tags.length >= maxTags) return false;
4897
+ if (dedupe && tags.some((t) => t.toLowerCase() === tag.toLowerCase())) {
4898
+ setLocalError(`"${tag}" is already added`);
4899
+ return false;
4900
+ }
4901
+ if (validate) {
4902
+ const res = validate(tag, tags);
4903
+ if (res !== true) {
4904
+ setLocalError(typeof res === "string" ? res : `"${tag}" is not valid`);
4905
+ return false;
4906
+ }
4907
+ }
4908
+ setLocalError(null);
4909
+ commitTags([...tags, tag]);
4910
+ return true;
4911
+ };
4912
+ const removeTag = (idx) => {
4913
+ commitTags(tags.filter((_, i) => i !== idx));
4914
+ setLocalError(null);
4915
+ };
4916
+ const onKeyDown = (e) => {
4917
+ if (separators.includes(e.key)) {
4918
+ e.preventDefault();
4919
+ if (addTag(draft)) setDraft("");
4920
+ } else if (e.key === "Backspace" && draft === "" && tags.length > 0) {
4921
+ removeTag(tags.length - 1);
4922
+ }
4923
+ };
4924
+ const onPaste = (e) => {
4925
+ const text = e.clipboardData.getData("text");
4926
+ const parts = text.split(/[\n,;]+/).map((p) => p.trim()).filter(Boolean);
4927
+ if (parts.length > 1) {
4928
+ e.preventDefault();
4929
+ let added = false;
4930
+ for (const p of parts) added = addTag(p) || added;
4931
+ if (added) setDraft("");
4932
+ }
4933
+ };
4934
+ const atMax = maxTags != null && tags.length >= maxTags;
4935
+ return /* @__PURE__ */ jsx(
4936
+ Field,
4937
+ {
4938
+ label,
4939
+ htmlFor,
4940
+ errorId,
4941
+ errorMessage: errorText,
4942
+ layout,
4943
+ required,
4944
+ children: /* @__PURE__ */ jsxs(
4945
+ "div",
4946
+ {
4947
+ className: `flex flex-wrap items-center gap-1.5 min-h-[36px] ${fieldShell({ size, hasError, disabled, focusWithin: true, sized: false })} px-2 py-1.5`,
4948
+ onClick: () => inputRef.current?.focus(),
4949
+ children: [
4950
+ tags.map((tag, idx) => /* @__PURE__ */ jsxs(
4951
+ "span",
4952
+ {
4953
+ className: "inline-flex items-center gap-1 rounded-md bg-surface-raised text-foreground text-xs pl-2 pr-1 py-0.5 border border-border",
4954
+ children: [
4955
+ tag,
4956
+ /* @__PURE__ */ jsx(
4957
+ "button",
4958
+ {
4959
+ type: "button",
4960
+ disabled,
4961
+ onClick: (e) => {
4962
+ e.stopPropagation();
4963
+ removeTag(idx);
4964
+ },
4965
+ "aria-label": `Remove ${tag}`,
4966
+ className: "inline-flex items-center justify-center w-4 h-4 rounded text-foreground-muted hover:text-status-error hover:bg-surface transition-colors focus:outline-none focus-visible:ring-1 focus-visible:ring-accent",
4967
+ children: /* @__PURE__ */ jsx("svg", { width: "10", height: "10", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M15 5L5 15M5 5l10 10", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) })
4968
+ }
4969
+ )
4970
+ ]
4971
+ },
4972
+ `${tag}-${idx}`
4973
+ )),
4974
+ /* @__PURE__ */ jsx(
4975
+ "input",
4976
+ {
4977
+ ref: inputRef,
4978
+ id: htmlFor,
4979
+ name,
4980
+ disabled: disabled || atMax,
4981
+ value: draft,
4982
+ onChange: (e) => {
4983
+ setDraft(e.target.value);
4984
+ if (localError) setLocalError(null);
4985
+ },
4986
+ onKeyDown,
4987
+ onPaste,
4988
+ onBlur: () => {
4989
+ if (addTag(draft)) setDraft("");
4990
+ },
4991
+ placeholder: atMax ? "" : tags.length === 0 ? placeholder : "",
4992
+ "aria-invalid": hasError || void 0,
4993
+ "aria-describedby": hasError ? errorId : void 0,
4994
+ autoComplete: "off",
4995
+ className: "flex-1 min-w-[6rem] bg-transparent outline-none text-sm placeholder:text-foreground-muted disabled:cursor-not-allowed"
4996
+ }
4997
+ )
4998
+ ]
4999
+ }
5000
+ )
5001
+ }
5002
+ );
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
+ }
4632
5644
 
4633
- 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, Sidebar, SkeletonBox, SkeletonCard, SkeletonCircle, SkeletonText, Switch, Table, Tabs, DatePicker as Temporal, 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 };
4634
5646
  //# sourceMappingURL=index.js.map
4635
5647
  //# sourceMappingURL=index.js.map