@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.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" }) });
@@ -4629,7 +4630,378 @@ 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
+ }
4632
5004
 
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 };
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 };
4634
5006
  //# sourceMappingURL=index.js.map
4635
5007
  //# sourceMappingURL=index.js.map