@geomak/ui 5.10.0 → 6.0.1

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
@@ -958,131 +958,229 @@ function Tooltip({
958
958
  ] }) });
959
959
  }
960
960
  var TooltipProvider = TooltipPrimitive__namespace.Provider;
961
+ var TabsContext = React8.createContext(null);
962
+ function useTabsContext() {
963
+ const ctx = React8.useContext(TabsContext);
964
+ if (!ctx) throw new Error("Tabs.List / Tabs.Trigger / Tabs.Panel must be rendered inside <Tabs>.");
965
+ return ctx;
966
+ }
967
+ var SIZE = {
968
+ sm: { trigger: "h-8 text-xs px-2.5", icon: "h-3.5 w-3.5", add: "h-8 w-8" },
969
+ md: { trigger: "h-10 text-sm px-3", icon: "h-4 w-4", add: "h-10 w-9" },
970
+ lg: { trigger: "h-12 text-sm px-4", icon: "h-[18px] w-[18px]", add: "h-12 w-10" }
971
+ };
972
+ var MARKER_TRANSITION = { duration: 0.26, ease: [0.16, 1, 0.3, 1] };
961
973
  function Tabs({
962
- tabs = [],
963
- onTabChange,
964
- onTabClose,
965
- isLazy,
966
- tabsClosable = true,
967
- defaultActiveTab
974
+ value,
975
+ defaultValue,
976
+ onValueChange,
977
+ variant = "underline",
978
+ size = "md",
979
+ orientation = "horizontal",
980
+ className = "",
981
+ style,
982
+ children
968
983
  }) {
969
- const [value, setValue] = React8.useState(() => defaultActiveTab ?? tabs[0]?.key ?? "");
970
- React8.useEffect(() => {
971
- if (defaultActiveTab) setValue(defaultActiveTab);
972
- }, [defaultActiveTab]);
973
- React8.useEffect(() => {
974
- if (tabs.length === 0) {
975
- setValue("");
976
- return;
977
- }
978
- const exists = tabs.find((t) => t.key === value);
979
- if (!exists) {
980
- setValue(tabs[tabs.length - 1].key);
981
- }
982
- }, [tabs, value]);
983
- const handleValueChange = (newValue) => {
984
- const prev = tabs.find((t) => t.key === value);
985
- const next = tabs.find((t) => t.key === newValue);
986
- onTabChange?.(prev, next);
987
- setValue(newValue);
988
- };
989
- const toPreviousTab = () => {
990
- const idx = tabs.findIndex((t) => t.key === value);
991
- if (idx > 0) handleValueChange(tabs[idx - 1].key);
992
- };
993
- const toNextTab = () => {
994
- const idx = tabs.findIndex((t) => t.key === value);
995
- if (idx < tabs.length - 1) handleValueChange(tabs[idx + 1].key);
984
+ const isControlled = value !== void 0;
985
+ const [internal, setInternal] = React8.useState(defaultValue);
986
+ const current = isControlled ? value : internal;
987
+ const reduced = !!framerMotion.useReducedMotion();
988
+ const indicatorId = React8.useId();
989
+ const handle = (next) => {
990
+ if (!isControlled) setInternal(next);
991
+ onValueChange?.(next);
996
992
  };
997
- if (tabs.length === 0) return null;
998
- return /* @__PURE__ */ jsxRuntime.jsxs(
993
+ return /* @__PURE__ */ jsxRuntime.jsx(TabsContext.Provider, { value: { value: current, variant, size, orientation, indicatorId, reduced }, children: /* @__PURE__ */ jsxRuntime.jsx(
999
994
  TabsPrimitive__namespace.Root,
995
+ {
996
+ value: current,
997
+ onValueChange: handle,
998
+ orientation,
999
+ className: [
1000
+ "flex min-w-0",
1001
+ orientation === "vertical" ? "flex-row gap-4" : "flex-col gap-3",
1002
+ className
1003
+ ].filter(Boolean).join(" "),
1004
+ style,
1005
+ children
1006
+ }
1007
+ ) });
1008
+ }
1009
+ function TabsList({ children, "aria-label": ariaLabel, className = "" }) {
1010
+ const { variant, orientation, reduced } = useTabsContext();
1011
+ const horizontal = orientation === "horizontal";
1012
+ const scrollRef = React8.useRef(null);
1013
+ const [edges, setEdges] = React8.useState({ start: false, end: false });
1014
+ const scrollable = variant !== "segmented";
1015
+ React8.useLayoutEffect(() => {
1016
+ const el = scrollRef.current;
1017
+ if (!el || !scrollable) return;
1018
+ const update = () => {
1019
+ if (horizontal) {
1020
+ setEdges({
1021
+ start: el.scrollLeft > 1,
1022
+ end: el.scrollLeft + el.clientWidth < el.scrollWidth - 1
1023
+ });
1024
+ } else {
1025
+ setEdges({
1026
+ start: el.scrollTop > 1,
1027
+ end: el.scrollTop + el.clientHeight < el.scrollHeight - 1
1028
+ });
1029
+ }
1030
+ };
1031
+ update();
1032
+ el.addEventListener("scroll", update, { passive: true });
1033
+ const ro = new ResizeObserver(update);
1034
+ ro.observe(el);
1035
+ return () => {
1036
+ el.removeEventListener("scroll", update);
1037
+ ro.disconnect();
1038
+ };
1039
+ }, [horizontal, scrollable, children]);
1040
+ const nudge = React8.useCallback((dir) => {
1041
+ const el = scrollRef.current;
1042
+ if (!el) return;
1043
+ const amount = (horizontal ? el.clientWidth : el.clientHeight) * 0.7 * dir;
1044
+ el.scrollBy({ [horizontal ? "left" : "top"]: amount, behavior: reduced ? "auto" : "smooth" });
1045
+ }, [horizontal, reduced]);
1046
+ const maskStyle = scrollable && (edges.start || edges.end) ? (() => {
1047
+ const dir = horizontal ? "to right" : "to bottom";
1048
+ const a = edges.start ? "transparent, black 36px" : "black";
1049
+ const b = edges.end ? "black calc(100% - 36px), transparent" : "black";
1050
+ const img = `linear-gradient(${dir}, ${a}, ${b})`;
1051
+ return { maskImage: img, WebkitMaskImage: img };
1052
+ })() : {};
1053
+ const trackClass = (() => {
1054
+ if (variant === "segmented") {
1055
+ return horizontal ? "inline-flex items-center gap-1 rounded-lg border border-border bg-surface-raised p-1 w-fit" : "inline-flex flex-col items-stretch gap-1 rounded-lg border border-border bg-surface-raised p-1 w-fit";
1056
+ }
1057
+ const hairline = horizontal ? "border-b border-border" : "border-r border-border";
1058
+ const align = variant === "enclosed" && horizontal ? "items-end" : "items-stretch";
1059
+ return `flex ${horizontal ? "flex-row" : "flex-col"} ${align} gap-1 ${hairline}`;
1060
+ })();
1061
+ const scrollClass = scrollable ? horizontal ? "overflow-x-auto overflow-y-hidden hidden-scrollbar" : "overflow-y-auto overflow-x-hidden hidden-scrollbar" : "";
1062
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ["relative flex min-w-0", horizontal ? "flex-row items-stretch" : "flex-col items-stretch", className].filter(Boolean).join(" "), children: [
1063
+ scrollable && edges.start && /* @__PURE__ */ jsxRuntime.jsx(Chevron, { side: "start", orientation, onClick: () => nudge(-1) }),
1064
+ /* @__PURE__ */ jsxRuntime.jsx(
1065
+ TabsPrimitive__namespace.List,
1066
+ {
1067
+ ref: scrollRef,
1068
+ "aria-label": ariaLabel,
1069
+ className: [scrollClass, trackClass, "min-w-0 flex-1"].filter(Boolean).join(" "),
1070
+ style: maskStyle,
1071
+ children
1072
+ }
1073
+ ),
1074
+ scrollable && edges.end && /* @__PURE__ */ jsxRuntime.jsx(Chevron, { side: "end", orientation, onClick: () => nudge(1) })
1075
+ ] });
1076
+ }
1077
+ function Chevron({ side, orientation, onClick }) {
1078
+ const horizontal = orientation === "horizontal";
1079
+ const rotate = horizontal ? side === "start" ? "rotate-180" : "" : side === "start" ? "-rotate-90" : "rotate-90";
1080
+ const pos = horizontal ? side === "start" ? "left-0 top-1/2 -translate-y-1/2" : "right-0 top-1/2 -translate-y-1/2" : side === "start" ? "top-0 left-1/2 -translate-x-1/2" : "bottom-0 left-1/2 -translate-x-1/2";
1081
+ return /* @__PURE__ */ jsxRuntime.jsx(
1082
+ "button",
1083
+ {
1084
+ type: "button",
1085
+ "aria-label": side === "start" ? "Scroll tabs backward" : "Scroll tabs forward",
1086
+ onClick,
1087
+ className: `absolute z-20 ${pos} flex h-7 w-7 items-center justify-center rounded-full border border-border bg-surface text-foreground-secondary shadow-sm hover:text-foreground hover:bg-surface-raised transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,
1088
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: `h-4 w-4 ${rotate}`, "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) })
1089
+ }
1090
+ );
1091
+ }
1092
+ function TabsTrigger({ value, icon, badge, closeable, onClose, disabled, className = "", children }) {
1093
+ const { value: active, variant, size, orientation, indicatorId, reduced } = useTabsContext();
1094
+ const isActive = active === value;
1095
+ const horizontal = orientation === "horizontal";
1096
+ const sz = SIZE[size];
1097
+ const base = "group/trigger relative inline-flex items-center justify-center whitespace-nowrap font-medium select-none transition-colors duration-150 focus:outline-none disabled:opacity-40 disabled:cursor-not-allowed flex-shrink-0";
1098
+ const variantCls = variant === "segmented" ? `rounded-md ${isActive ? "text-accent" : "text-foreground-secondary hover:text-foreground"} focus-visible:text-accent` : variant === "enclosed" ? `${horizontal ? "rounded-t-md border border-b-0 -mb-px" : "rounded-l-md border border-r-0 -mr-px"} ${isActive ? "bg-surface border-border text-foreground" : "border-transparent text-foreground-secondary hover:text-foreground hover:bg-surface-raised"} focus-visible:text-accent` : `${isActive ? "text-accent" : "text-foreground-secondary hover:text-foreground"} focus-visible:text-accent`;
1099
+ const trigger = /* @__PURE__ */ jsxRuntime.jsxs(
1100
+ TabsPrimitive__namespace.Trigger,
1000
1101
  {
1001
1102
  value,
1002
- onValueChange: handleValueChange,
1003
- className: "h-full max-w-full flex flex-col gap-2",
1103
+ disabled,
1104
+ className: [base, sz.trigger, closeable ? "pr-8" : "", variantCls, className].filter(Boolean).join(" "),
1004
1105
  children: [
1005
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-surface border border-border rounded-lg flex items-center justify-between flex-shrink-0 w-full p-1 overflow-hidden", children: [
1006
- /* @__PURE__ */ jsxRuntime.jsx(
1007
- "button",
1008
- {
1009
- type: "button",
1010
- onClick: toPreviousTab,
1011
- "aria-label": "Previous tab",
1012
- className: "cursor-pointer rounded-lg transition-colors duration-150 hover:bg-surface-raised text-foreground-secondary hover:text-foreground rotate-180 flex-shrink-0 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
1013
- children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "h-6 w-6", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) })
1014
- }
1015
- ),
1016
- /* @__PURE__ */ jsxRuntime.jsx(
1017
- TabsPrimitive__namespace.List,
1018
- {
1019
- "aria-label": "Tabs",
1020
- className: "flex-1 flex items-center gap-1 overflow-x-auto overflow-y-hidden rounded-lg scroll-smooth snap-x snap-mandatory hidden-scrollbar",
1021
- children: tabs.map((tab) => (
1022
- // Trigger + close button are SIBLINGS, not nested.
1023
- // Nesting a clickable element inside <button> is invalid
1024
- // HTML and breaks keyboard activation of the inner one.
1025
- // The wrapper carries `group` so the close button can
1026
- // react to the trigger's `data-state=active` for styling.
1027
- /* @__PURE__ */ jsxRuntime.jsxs(
1028
- "div",
1029
- {
1030
- className: "snap-start snap-always relative flex items-center flex-1 min-w-[120px] max-w-[220px] flex-shrink-0 group",
1031
- children: [
1032
- /* @__PURE__ */ jsxRuntime.jsx(
1033
- TabsPrimitive__namespace.Trigger,
1034
- {
1035
- value: tab.key,
1036
- className: `w-full ${tabsClosable ? "pr-8" : "pr-3"} pl-3 py-2 rounded-3xl cursor-pointer transition-all duration-200 select-none h-10 text-left
1037
- text-foreground-secondary bg-surface-raised
1038
- hover:bg-surface hover:text-foreground
1039
- data-[state=active]:bg-accent data-[state=active]:text-accent-foreground
1040
- focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,
1041
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm block", children: tab.title })
1042
- }
1043
- ),
1044
- tabsClosable && /* @__PURE__ */ jsxRuntime.jsx(
1045
- "button",
1046
- {
1047
- type: "button",
1048
- "aria-label": `Close ${tab.title}`,
1049
- onClick: (e) => {
1050
- e.stopPropagation();
1051
- onTabClose?.(tab.key);
1052
- },
1053
- className: "absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-secondary group-data-[state=active]:text-accent-foreground hover:bg-black/10 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
1054
- children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "14", height: "14", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 5L5 15M5 5l10 10", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
1055
- }
1056
- )
1057
- ]
1058
- },
1059
- tab.key
1060
- )
1061
- ))
1062
- }
1063
- ),
1064
- /* @__PURE__ */ jsxRuntime.jsx(
1065
- "button",
1066
- {
1067
- type: "button",
1068
- onClick: toNextTab,
1069
- "aria-label": "Next tab",
1070
- className: "cursor-pointer rounded-lg transition-colors duration-150 hover:bg-surface-raised text-foreground-secondary hover:text-foreground flex-shrink-0 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",
1071
- children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "h-6 w-6", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) })
1072
- }
1073
- )
1106
+ variant === "segmented" && isActive && /* @__PURE__ */ jsxRuntime.jsx(
1107
+ framerMotion.motion.span,
1108
+ {
1109
+ layoutId: `${indicatorId}-seg`,
1110
+ className: "absolute inset-0 rounded-md bg-surface shadow-sm",
1111
+ transition: reduced ? { duration: 0 } : MARKER_TRANSITION,
1112
+ "aria-hidden": "true"
1113
+ }
1114
+ ),
1115
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "relative z-[1] inline-flex items-center gap-2 min-w-0", children: [
1116
+ icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: `flex-shrink-0 inline-flex items-center justify-center ${sz.icon}`, children: icon }),
1117
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children }),
1118
+ badge != null && // Unopinionated count chip: a subtle blue-tinted slate pill
1119
+ // with near-white text, consistent across active/inactive.
1120
+ // Both tokens are theme-relative, so it self-inverts in dark
1121
+ // mode (light pill + dark text) and always stays legible.
1122
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-0.5 inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-foreground-secondary px-1.5 text-[11px] font-semibold leading-none text-background", children: badge })
1074
1123
  ] }),
1075
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2 rounded-lg w-full flex-1 min-h-0 bg-surface border border-border overflow-hidden", children: isLazy ? (
1076
- // Mount only the active content
1077
- tabs.filter((t) => t.key === value).map((t) => /* @__PURE__ */ jsxRuntime.jsx(TabsPrimitive__namespace.Content, { value: t.key, className: "w-full h-full focus:outline-none", children: t.content }, t.key))
1078
- ) : (
1079
- // Pre-mount all, hide non-active via Radix
1080
- tabs.map((t) => /* @__PURE__ */ jsxRuntime.jsx(TabsPrimitive__namespace.Content, { value: t.key, className: "w-full h-full focus:outline-none", forceMount: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full h-full ${t.key === value ? "block" : "hidden"}`, children: t.content }) }, t.key))
1081
- ) })
1124
+ variant === "underline" && isActive && /* @__PURE__ */ jsxRuntime.jsx(
1125
+ framerMotion.motion.span,
1126
+ {
1127
+ layoutId: `${indicatorId}-line`,
1128
+ className: horizontal ? "absolute left-2 right-2 bottom-0 h-0.5 rounded-full bg-accent" : "absolute top-1.5 bottom-1.5 right-0 w-0.5 rounded-full bg-accent",
1129
+ transition: reduced ? { duration: 0 } : MARKER_TRANSITION,
1130
+ "aria-hidden": "true"
1131
+ }
1132
+ )
1082
1133
  ]
1083
1134
  }
1084
1135
  );
1136
+ if (!closeable) return trigger;
1137
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "relative inline-flex items-center flex-shrink-0", children: [
1138
+ trigger,
1139
+ /* @__PURE__ */ jsxRuntime.jsx(
1140
+ "button",
1141
+ {
1142
+ type: "button",
1143
+ "aria-label": "Close tab",
1144
+ onClick: (e) => {
1145
+ e.stopPropagation();
1146
+ onClose?.();
1147
+ },
1148
+ className: "absolute right-1.5 top-1/2 z-[2] -translate-y-1/2 inline-flex h-5 w-5 items-center justify-center rounded text-foreground-muted hover:text-status-error hover:bg-surface-raised transition-colors focus:outline-none focus-visible:ring-1 focus-visible:ring-accent",
1149
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "12", height: "12", 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", strokeLinejoin: "round" }) })
1150
+ }
1151
+ )
1152
+ ] });
1085
1153
  }
1154
+ function TabsAdd({ onClick, "aria-label": ariaLabel = "Add tab", className = "" }) {
1155
+ const { size } = useTabsContext();
1156
+ return /* @__PURE__ */ jsxRuntime.jsx(
1157
+ "button",
1158
+ {
1159
+ type: "button",
1160
+ onClick,
1161
+ "aria-label": ariaLabel,
1162
+ className: `flex-shrink-0 inline-flex items-center justify-center rounded-md text-foreground-muted hover:text-foreground hover:bg-surface-raised transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${SIZE[size].add} ${className}`.trim(),
1163
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "h-4 w-4", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 5v14M5 12h14" }) })
1164
+ }
1165
+ );
1166
+ }
1167
+ function TabsPanel({ value, keepMounted, className = "", style, children }) {
1168
+ return /* @__PURE__ */ jsxRuntime.jsx(
1169
+ TabsPrimitive__namespace.Content,
1170
+ {
1171
+ value,
1172
+ forceMount: keepMounted || void 0,
1173
+ className: ["min-w-0 flex-1 focus:outline-none data-[state=inactive]:hidden", className].filter(Boolean).join(" "),
1174
+ style,
1175
+ children
1176
+ }
1177
+ );
1178
+ }
1179
+ Tabs.List = TabsList;
1180
+ Tabs.Trigger = TabsTrigger;
1181
+ Tabs.Panel = TabsPanel;
1182
+ Tabs.Add = TabsAdd;
1183
+ var Tabs_default = Tabs;
1086
1184
  var isParent = (item) => Boolean(item.children && item.children.length > 0);
1087
1185
  function TreeNodeItem({
1088
1186
  item,
@@ -5013,7 +5111,7 @@ function TextArea({
5013
5111
  }
5014
5112
  );
5015
5113
  }
5016
- var SIZE = {
5114
+ var SIZE2 = {
5017
5115
  sm: { h: "h-control-sm", text: "text-xs", pad: "px-2.5" },
5018
5116
  md: { h: "h-control-md", text: "text-sm", pad: "px-3.5" },
5019
5117
  lg: { h: "h-control-lg", text: "text-sm", pad: "px-4" }
@@ -5035,7 +5133,7 @@ function SegmentedControl({
5035
5133
  errorMessage,
5036
5134
  "aria-label": ariaLabel
5037
5135
  }) {
5038
- const sz = SIZE[size];
5136
+ const sz = SIZE2[size];
5039
5137
  const groupId = React8.useId();
5040
5138
  const errorId = React8.useId();
5041
5139
  const hasError = errorMessage != null;
@@ -6704,7 +6802,7 @@ exports.SkeletonText = SkeletonText;
6704
6802
  exports.Slider = Slider;
6705
6803
  exports.Switch = Switch;
6706
6804
  exports.Table = Table;
6707
- exports.Tabs = Tabs;
6805
+ exports.Tabs = Tabs_default;
6708
6806
  exports.TagsInput = TagsInput;
6709
6807
  exports.Temporal = DatePicker;
6710
6808
  exports.TextArea = TextArea;