@geomak/ui 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -16,6 +16,7 @@ var Popover = require('@radix-ui/react-popover');
16
16
  var SwitchPrimitive = require('@radix-ui/react-switch');
17
17
  var CheckboxPrimitive = require('@radix-ui/react-checkbox');
18
18
  var RadioGroupPrimitive = require('@radix-ui/react-radio-group');
19
+ var SliderPrimitive = require('@radix-ui/react-slider');
19
20
 
20
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
21
22
 
@@ -49,6 +50,7 @@ var Popover__namespace = /*#__PURE__*/_interopNamespace(Popover);
49
50
  var SwitchPrimitive__namespace = /*#__PURE__*/_interopNamespace(SwitchPrimitive);
50
51
  var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
51
52
  var RadioGroupPrimitive__namespace = /*#__PURE__*/_interopNamespace(RadioGroupPrimitive);
53
+ var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
52
54
 
53
55
  var Moon = ({ color = "gray" }) => /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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" }) });
54
56
  var Sun = ({ color = "yellow" }) => /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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" }) });
@@ -4663,6 +4665,377 @@ function ChevronLeft() {
4663
4665
  function ChevronRight3() {
4664
4666
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "w-4 h-4", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) });
4665
4667
  }
4668
+ var LINE_HEIGHT_PX = 21;
4669
+ function TextArea({
4670
+ value,
4671
+ onChange,
4672
+ onBlur,
4673
+ disabled,
4674
+ label,
4675
+ htmlFor,
4676
+ placeholder,
4677
+ name,
4678
+ layout = "vertical",
4679
+ size = "md",
4680
+ rows = 4,
4681
+ autoGrow = false,
4682
+ maxRows = 12,
4683
+ maxLength,
4684
+ showCount = false,
4685
+ resize,
4686
+ errorMessage,
4687
+ required,
4688
+ style,
4689
+ inputStyle
4690
+ }) {
4691
+ const errorId = React8.useId();
4692
+ const hasError = errorMessage != null;
4693
+ const ref = React8.useRef(null);
4694
+ React8.useLayoutEffect(() => {
4695
+ if (!autoGrow) return;
4696
+ const el = ref.current;
4697
+ if (!el) return;
4698
+ el.style.height = "auto";
4699
+ const maxH = maxRows * LINE_HEIGHT_PX + 16;
4700
+ el.style.height = `${Math.min(el.scrollHeight, maxH)}px`;
4701
+ el.style.overflowY = el.scrollHeight > maxH ? "auto" : "hidden";
4702
+ }, [value, autoGrow, maxRows]);
4703
+ const count = typeof value === "string" ? value.length : 0;
4704
+ const resizeClass = (resize ?? (autoGrow ? "none" : "vertical")) === "none" ? "resize-none" : (resize ?? "vertical") === "horizontal" ? "resize-x" : (resize ?? "vertical") === "both" ? "resize" : "resize-y";
4705
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4706
+ Field,
4707
+ {
4708
+ label,
4709
+ htmlFor,
4710
+ errorId,
4711
+ errorMessage,
4712
+ layout,
4713
+ required,
4714
+ children: [
4715
+ /* @__PURE__ */ jsxRuntime.jsx(
4716
+ "textarea",
4717
+ {
4718
+ ref,
4719
+ disabled,
4720
+ value,
4721
+ onChange,
4722
+ onBlur,
4723
+ name,
4724
+ id: htmlFor,
4725
+ rows,
4726
+ maxLength,
4727
+ placeholder: placeholder ?? "",
4728
+ "aria-invalid": hasError || void 0,
4729
+ "aria-describedby": hasError ? errorId : void 0,
4730
+ className: `${fieldShell({ size, hasError, disabled, sized: false })} px-3 py-2 leading-normal ${resizeClass}`,
4731
+ style: { ...style, ...inputStyle }
4732
+ }
4733
+ ),
4734
+ showCount && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-right text-xs text-foreground-muted tabular-nums", children: maxLength != null ? `${count} / ${maxLength}` : count })
4735
+ ]
4736
+ }
4737
+ );
4738
+ }
4739
+ var SIZE = {
4740
+ sm: { h: "h-control-sm", text: "text-xs", pad: "px-2.5" },
4741
+ md: { h: "h-control-md", text: "text-sm", pad: "px-3.5" },
4742
+ lg: { h: "h-control-lg", text: "text-sm", pad: "px-4" }
4743
+ };
4744
+ function SegmentedControl({
4745
+ options,
4746
+ value,
4747
+ defaultValue,
4748
+ onChange,
4749
+ size = "md",
4750
+ fullWidth = false,
4751
+ disabled,
4752
+ "aria-label": ariaLabel
4753
+ }) {
4754
+ const sz = SIZE[size];
4755
+ return /* @__PURE__ */ jsxRuntime.jsx(
4756
+ ToggleGroup__namespace.Root,
4757
+ {
4758
+ type: "single",
4759
+ value,
4760
+ defaultValue,
4761
+ onValueChange: (v) => {
4762
+ if (v) onChange?.(v);
4763
+ },
4764
+ disabled,
4765
+ "aria-label": ariaLabel,
4766
+ className: [
4767
+ "inline-flex items-center gap-1 rounded-lg border border-border bg-surface-raised p-1",
4768
+ sz.h,
4769
+ fullWidth ? "flex w-full" : "",
4770
+ disabled ? "opacity-60 cursor-not-allowed" : ""
4771
+ ].filter(Boolean).join(" "),
4772
+ children: options.map((opt) => /* @__PURE__ */ jsxRuntime.jsxs(
4773
+ ToggleGroup__namespace.Item,
4774
+ {
4775
+ value: opt.value,
4776
+ disabled: opt.disabled,
4777
+ className: [
4778
+ "inline-flex items-center justify-center gap-1.5 rounded-md select-none whitespace-nowrap",
4779
+ "transition-colors duration-150 h-full",
4780
+ sz.text,
4781
+ sz.pad,
4782
+ fullWidth ? "flex-1" : "",
4783
+ // Resting: muted text, transparent. Hover lifts the text.
4784
+ "text-foreground-secondary hover:text-foreground",
4785
+ // Active: surface-white pill + accent text + subtle shadow.
4786
+ "data-[state=on]:bg-surface data-[state=on]:text-accent data-[state=on]:shadow-sm",
4787
+ "focus:outline-none focus-visible:ring-[3px] focus-visible:ring-focus-ring",
4788
+ "disabled:opacity-40 disabled:cursor-not-allowed"
4789
+ ].filter(Boolean).join(" "),
4790
+ children: [
4791
+ opt.icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-shrink-0", children: opt.icon }),
4792
+ opt.label
4793
+ ]
4794
+ },
4795
+ opt.value
4796
+ ))
4797
+ }
4798
+ );
4799
+ }
4800
+ var TRACK_H = { sm: "h-1", md: "h-1.5", lg: "h-2" };
4801
+ var THUMB = { sm: "h-3.5 w-3.5", md: "h-4 w-4", lg: "h-5 w-5" };
4802
+ var toArray = (v) => v == null ? void 0 : Array.isArray(v) ? v : [v];
4803
+ function Slider({
4804
+ value,
4805
+ defaultValue,
4806
+ onChange,
4807
+ onChangeEnd,
4808
+ min = 0,
4809
+ max = 100,
4810
+ step = 1,
4811
+ label,
4812
+ showValue = false,
4813
+ formatValue = (n) => String(n),
4814
+ marks,
4815
+ tooltip = false,
4816
+ size = "md",
4817
+ disabled,
4818
+ errorMessage,
4819
+ name,
4820
+ htmlFor
4821
+ }) {
4822
+ const errorId = React8.useId();
4823
+ const hasError = errorMessage != null;
4824
+ const isRange = Array.isArray(value ?? defaultValue);
4825
+ const [internal, setInternal] = React8.useState(
4826
+ () => toArray(value) ?? toArray(defaultValue) ?? [min]
4827
+ );
4828
+ const current = toArray(value) ?? internal;
4829
+ const [dragging, setDragging] = React8.useState(false);
4830
+ const emit = (arr) => {
4831
+ setInternal(arr);
4832
+ const next = isRange ? [arr[0], arr[1]] : arr[0];
4833
+ onChange?.(next);
4834
+ };
4835
+ const valueText = current.map(formatValue).join(" \u2013 ");
4836
+ return /* @__PURE__ */ jsxRuntime.jsxs(Field, { label: void 0, errorId, errorMessage, children: [
4837
+ (label || showValue) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-2", children: [
4838
+ label && /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor, className: "text-sm font-medium text-foreground select-none", children: label }),
4839
+ showValue && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-foreground-secondary tabular-nums", children: valueText })
4840
+ ] }),
4841
+ /* @__PURE__ */ jsxRuntime.jsxs(
4842
+ SliderPrimitive__namespace.Root,
4843
+ {
4844
+ id: htmlFor,
4845
+ name,
4846
+ value: toArray(value),
4847
+ defaultValue: toArray(defaultValue),
4848
+ min,
4849
+ max,
4850
+ step,
4851
+ disabled,
4852
+ "aria-invalid": hasError || void 0,
4853
+ "aria-describedby": hasError ? errorId : void 0,
4854
+ onValueChange: (v) => {
4855
+ emit(v);
4856
+ setDragging(true);
4857
+ },
4858
+ onValueCommit: (v) => {
4859
+ setDragging(false);
4860
+ onChangeEnd?.(isRange ? [v[0], v[1]] : v[0]);
4861
+ },
4862
+ className: "relative flex items-center select-none touch-none w-full h-5",
4863
+ children: [
4864
+ /* @__PURE__ */ jsxRuntime.jsx(SliderPrimitive__namespace.Track, { className: `relative grow rounded-full bg-surface-raised border border-border ${TRACK_H[size]}`, children: /* @__PURE__ */ jsxRuntime.jsx(SliderPrimitive__namespace.Range, { className: "absolute h-full rounded-full bg-accent" }) }),
4865
+ current.map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
4866
+ SliderPrimitive__namespace.Thumb,
4867
+ {
4868
+ className: `group relative block ${THUMB[size]} rounded-full border-2 border-accent bg-surface shadow-sm transition-shadow
4869
+ focus:outline-none focus-visible:ring-[3px] focus-visible:ring-focus-ring
4870
+ disabled:cursor-not-allowed`,
4871
+ children: tooltip && /* @__PURE__ */ jsxRuntime.jsx(
4872
+ "span",
4873
+ {
4874
+ 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"}`,
4875
+ children: formatValue(current[i])
4876
+ }
4877
+ )
4878
+ },
4879
+ i
4880
+ ))
4881
+ ]
4882
+ }
4883
+ ),
4884
+ marks && marks.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative mt-2 h-4", children: marks.map((m) => {
4885
+ const pct = (m.value - min) / (max - min) * 100;
4886
+ return /* @__PURE__ */ jsxRuntime.jsx(
4887
+ "span",
4888
+ {
4889
+ className: "absolute -translate-x-1/2 text-xs text-foreground-muted tabular-nums",
4890
+ style: { left: `${pct}%` },
4891
+ children: m.label ?? m.value
4892
+ },
4893
+ m.value
4894
+ );
4895
+ }) })
4896
+ ] });
4897
+ }
4898
+ function TagsInput({
4899
+ value,
4900
+ defaultValue,
4901
+ onChange,
4902
+ label,
4903
+ htmlFor,
4904
+ name,
4905
+ placeholder = "Add and press Enter",
4906
+ layout = "vertical",
4907
+ size = "md",
4908
+ disabled,
4909
+ errorMessage,
4910
+ required,
4911
+ maxTags,
4912
+ dedupe = true,
4913
+ validate,
4914
+ separators = ["Enter", ","]
4915
+ }) {
4916
+ const errorId = React8.useId();
4917
+ const inputRef = React8.useRef(null);
4918
+ const [internal, setInternal] = React8.useState(defaultValue ?? []);
4919
+ const [draft, setDraft] = React8.useState("");
4920
+ const [localError, setLocalError] = React8.useState(null);
4921
+ const tags = value ?? internal;
4922
+ const hasError = errorMessage != null || localError != null;
4923
+ const errorText = errorMessage ?? localError ?? void 0;
4924
+ const commitTags = (next) => {
4925
+ setInternal(next);
4926
+ onChange?.(next);
4927
+ };
4928
+ const addTag = (raw) => {
4929
+ const tag = raw.trim();
4930
+ if (!tag) return false;
4931
+ if (maxTags != null && tags.length >= maxTags) return false;
4932
+ if (dedupe && tags.some((t) => t.toLowerCase() === tag.toLowerCase())) {
4933
+ setLocalError(`"${tag}" is already added`);
4934
+ return false;
4935
+ }
4936
+ if (validate) {
4937
+ const res = validate(tag, tags);
4938
+ if (res !== true) {
4939
+ setLocalError(typeof res === "string" ? res : `"${tag}" is not valid`);
4940
+ return false;
4941
+ }
4942
+ }
4943
+ setLocalError(null);
4944
+ commitTags([...tags, tag]);
4945
+ return true;
4946
+ };
4947
+ const removeTag = (idx) => {
4948
+ commitTags(tags.filter((_, i) => i !== idx));
4949
+ setLocalError(null);
4950
+ };
4951
+ const onKeyDown = (e) => {
4952
+ if (separators.includes(e.key)) {
4953
+ e.preventDefault();
4954
+ if (addTag(draft)) setDraft("");
4955
+ } else if (e.key === "Backspace" && draft === "" && tags.length > 0) {
4956
+ removeTag(tags.length - 1);
4957
+ }
4958
+ };
4959
+ const onPaste = (e) => {
4960
+ const text = e.clipboardData.getData("text");
4961
+ const parts = text.split(/[\n,;]+/).map((p) => p.trim()).filter(Boolean);
4962
+ if (parts.length > 1) {
4963
+ e.preventDefault();
4964
+ let added = false;
4965
+ for (const p of parts) added = addTag(p) || added;
4966
+ if (added) setDraft("");
4967
+ }
4968
+ };
4969
+ const atMax = maxTags != null && tags.length >= maxTags;
4970
+ return /* @__PURE__ */ jsxRuntime.jsx(
4971
+ Field,
4972
+ {
4973
+ label,
4974
+ htmlFor,
4975
+ errorId,
4976
+ errorMessage: errorText,
4977
+ layout,
4978
+ required,
4979
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
4980
+ "div",
4981
+ {
4982
+ 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`,
4983
+ onClick: () => inputRef.current?.focus(),
4984
+ children: [
4985
+ tags.map((tag, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
4986
+ "span",
4987
+ {
4988
+ 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",
4989
+ children: [
4990
+ tag,
4991
+ /* @__PURE__ */ jsxRuntime.jsx(
4992
+ "button",
4993
+ {
4994
+ type: "button",
4995
+ disabled,
4996
+ onClick: (e) => {
4997
+ e.stopPropagation();
4998
+ removeTag(idx);
4999
+ },
5000
+ "aria-label": `Remove ${tag}`,
5001
+ 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",
5002
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "10", height: "10", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 5L5 15M5 5l10 10", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) })
5003
+ }
5004
+ )
5005
+ ]
5006
+ },
5007
+ `${tag}-${idx}`
5008
+ )),
5009
+ /* @__PURE__ */ jsxRuntime.jsx(
5010
+ "input",
5011
+ {
5012
+ ref: inputRef,
5013
+ id: htmlFor,
5014
+ name,
5015
+ disabled: disabled || atMax,
5016
+ value: draft,
5017
+ onChange: (e) => {
5018
+ setDraft(e.target.value);
5019
+ if (localError) setLocalError(null);
5020
+ },
5021
+ onKeyDown,
5022
+ onPaste,
5023
+ onBlur: () => {
5024
+ if (addTag(draft)) setDraft("");
5025
+ },
5026
+ placeholder: atMax ? "" : tags.length === 0 ? placeholder : "",
5027
+ "aria-invalid": hasError || void 0,
5028
+ "aria-describedby": hasError ? errorId : void 0,
5029
+ autoComplete: "off",
5030
+ className: "flex-1 min-w-[6rem] bg-transparent outline-none text-sm placeholder:text-foreground-muted disabled:cursor-not-allowed"
5031
+ }
5032
+ )
5033
+ ]
5034
+ }
5035
+ )
5036
+ }
5037
+ );
5038
+ }
4666
5039
 
4667
5040
  Object.defineProperty(exports, "COLORS", {
4668
5041
  enumerable: true,
@@ -4711,15 +5084,19 @@ exports.Portal = Portal;
4711
5084
  exports.RadioGroup = RadioGroup;
4712
5085
  exports.ScalableContainer = ScalableContainer;
4713
5086
  exports.SearchInput = SearchInput_default;
5087
+ exports.SegmentedControl = SegmentedControl;
4714
5088
  exports.Sidebar = Sidebar;
4715
5089
  exports.SkeletonBox = SkeletonBox;
4716
5090
  exports.SkeletonCard = SkeletonCard;
4717
5091
  exports.SkeletonCircle = SkeletonCircle;
4718
5092
  exports.SkeletonText = SkeletonText;
5093
+ exports.Slider = Slider;
4719
5094
  exports.Switch = Switch;
4720
5095
  exports.Table = Table;
4721
5096
  exports.Tabs = Tabs;
5097
+ exports.TagsInput = TagsInput;
4722
5098
  exports.Temporal = DatePicker;
5099
+ exports.TextArea = TextArea;
4723
5100
  exports.TextInput = TextInput;
4724
5101
  exports.ThemeProvider = ThemeProvider;
4725
5102
  exports.ThemeSwitch = ThemeSwitch;