@eqtylab/equality 4.11.0 → 4.12.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.d.cts CHANGED
@@ -937,7 +937,8 @@ declare const TabsTrigger: React$1.ForwardRefExoticComponent<Omit<TabsPrimitive.
937
937
  declare const TabsContent: React$1.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsContentProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & React$1.RefAttributes<HTMLDivElement>>;
938
938
 
939
939
  interface TabsProps {
940
- id: string;
940
+ /** @deprecated No longer used. The active indicator is positioned without it. */
941
+ id?: string;
941
942
  items: {
942
943
  label: string;
943
944
  value: string;
@@ -954,7 +955,7 @@ interface TabsProps {
954
955
  onValueChange?: (value: string) => void;
955
956
  staticRender?: boolean;
956
957
  }
957
- declare const Tabs: ({ id, items, className, tabsListBackground, defaultValue, onValueChange, staticRender, }: TabsProps) => react_jsx_runtime.JSX.Element;
958
+ declare const Tabs: ({ items, className, tabsListBackground, defaultValue, onValueChange, staticRender, }: TabsProps) => react_jsx_runtime.JSX.Element;
958
959
 
959
960
  declare const Textarea: React$1.ForwardRefExoticComponent<Omit<React$1.DetailedHTMLProps<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React$1.RefAttributes<HTMLTextAreaElement>>;
960
961
 
package/dist/index.d.ts CHANGED
@@ -937,7 +937,8 @@ declare const TabsTrigger: React$1.ForwardRefExoticComponent<Omit<TabsPrimitive.
937
937
  declare const TabsContent: React$1.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsContentProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & React$1.RefAttributes<HTMLDivElement>>;
938
938
 
939
939
  interface TabsProps {
940
- id: string;
940
+ /** @deprecated No longer used. The active indicator is positioned without it. */
941
+ id?: string;
941
942
  items: {
942
943
  label: string;
943
944
  value: string;
@@ -954,7 +955,7 @@ interface TabsProps {
954
955
  onValueChange?: (value: string) => void;
955
956
  staticRender?: boolean;
956
957
  }
957
- declare const Tabs: ({ id, items, className, tabsListBackground, defaultValue, onValueChange, staticRender, }: TabsProps) => react_jsx_runtime.JSX.Element;
958
+ declare const Tabs: ({ items, className, tabsListBackground, defaultValue, onValueChange, staticRender, }: TabsProps) => react_jsx_runtime.JSX.Element;
958
959
 
959
960
  declare const Textarea: React$1.ForwardRefExoticComponent<Omit<React$1.DetailedHTMLProps<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React$1.RefAttributes<HTMLTextAreaElement>>;
960
961
 
package/dist/index.js CHANGED
@@ -3829,6 +3829,7 @@ var SectionHeading = ({
3829
3829
  hasRightContent && renderRightContent()
3830
3830
  ] });
3831
3831
  };
3832
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
3832
3833
  var SegmentedControls = ({
3833
3834
  options,
3834
3835
  value,
@@ -3856,14 +3857,14 @@ var SegmentedControls = ({
3856
3857
  setIndicator({ left: activeSegment.offsetLeft, width: activeSegment.offsetWidth });
3857
3858
  }
3858
3859
  }, [value]);
3859
- useLayoutEffect(() => {
3860
+ useIsomorphicLayoutEffect(() => {
3860
3861
  updateIndicator();
3861
3862
  }, [updateIndicator, options, effectiveDisplay, size]);
3862
3863
  useEffect(() => {
3863
3864
  const frame = requestAnimationFrame(() => setAnimateIndicator(true));
3864
3865
  return () => cancelAnimationFrame(frame);
3865
3866
  }, []);
3866
- useLayoutEffect(() => {
3867
+ useIsomorphicLayoutEffect(() => {
3867
3868
  const container = containerRef.current;
3868
3869
  if (!container) return;
3869
3870
  const observer = new ResizeObserver(updateIndicator);
@@ -4190,7 +4191,6 @@ TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
4190
4191
  var TabsContent = React15.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(TabsPrimitive.Content, { ref, className: cn(styles57["tabs-content"], className), ...props }));
4191
4192
  TabsContent.displayName = TabsPrimitive.Content.displayName;
4192
4193
  var Tabs = ({
4193
- id,
4194
4194
  items,
4195
4195
  className,
4196
4196
  tabsListBackground = "transparent",
@@ -4200,6 +4200,43 @@ var Tabs = ({
4200
4200
  }) => {
4201
4201
  const [activeTab, setActiveTab] = useState(defaultValue ?? items[0].value);
4202
4202
  const isFilled = tabsListBackground === "filled";
4203
+ const listRef = useRef(null);
4204
+ const triggerRefs = useRef({});
4205
+ const [indicator, setIndicator] = useState(null);
4206
+ const [animateIndicator, setAnimateIndicator] = useState(false);
4207
+ const itemValues = items.map((item) => item.value).join("\0");
4208
+ const updateIndicator = useCallback(() => {
4209
+ const activeTrigger = triggerRefs.current[activeTab];
4210
+ const width = activeTrigger?.offsetWidth ?? 0;
4211
+ if (!activeTrigger || width === 0) {
4212
+ setIndicator(null);
4213
+ return;
4214
+ }
4215
+ const left = activeTrigger.offsetLeft;
4216
+ setIndicator((previous) => {
4217
+ if (previous?.left === left && previous.width === width) return previous;
4218
+ const hops = previous ? Math.abs(left + width / 2 - (previous.left + previous.width / 2)) / ((width + previous.width) / 2) : 0;
4219
+ const duration = Math.min(400, Math.max(250, 250 + (hops - 1) * 100));
4220
+ return { left, width, duration };
4221
+ });
4222
+ }, [activeTab]);
4223
+ useIsomorphicLayoutEffect(() => {
4224
+ if (!staticRender) updateIndicator();
4225
+ }, [updateIndicator, itemValues, staticRender]);
4226
+ useEffect(() => {
4227
+ const frame = requestAnimationFrame(() => setAnimateIndicator(true));
4228
+ return () => cancelAnimationFrame(frame);
4229
+ }, []);
4230
+ useIsomorphicLayoutEffect(() => {
4231
+ const list = listRef.current;
4232
+ if (!list || staticRender) return;
4233
+ const observer = new ResizeObserver(updateIndicator);
4234
+ observer.observe(list);
4235
+ for (const trigger of Object.values(triggerRefs.current)) {
4236
+ if (trigger) observer.observe(trigger);
4237
+ }
4238
+ return () => observer.disconnect();
4239
+ }, [updateIndicator, itemValues, staticRender]);
4203
4240
  const handleValueChange = (newTab) => {
4204
4241
  setActiveTab(newTab);
4205
4242
  onValueChange?.(newTab);
@@ -4214,20 +4251,20 @@ var Tabs = ({
4214
4251
  styles58["active-tab-indicator"],
4215
4252
  isFilled ? styles58["active-tab-indicator--filled"] : styles58["active-tab-indicator--transparent"]
4216
4253
  );
4217
- const renderActiveStyle = (isActive) => {
4254
+ const renderTriggerIndicator = (value) => {
4218
4255
  if (staticRender) {
4219
- return /* @__PURE__ */ jsx("span", { className: cn(indicatorClass, styles58["active-tab-indicator--static"]) });
4220
- }
4221
- if (isActive) {
4222
4256
  return /* @__PURE__ */ jsx(
4223
- motion.span,
4257
+ "span",
4224
4258
  {
4225
- className: indicatorClass,
4226
- initial: false,
4227
- layoutId: `${id}-active-tab-indicator`
4259
+ "aria-hidden": true,
4260
+ "data-slot": "tabs-indicator",
4261
+ className: cn(indicatorClass, styles58["active-tab-indicator--static"])
4228
4262
  }
4229
4263
  );
4230
4264
  }
4265
+ if (!indicator && value === activeTab) {
4266
+ return /* @__PURE__ */ jsx("span", { "aria-hidden": true, "data-slot": "tabs-indicator", className: indicatorClass });
4267
+ }
4231
4268
  return null;
4232
4269
  };
4233
4270
  return /* @__PURE__ */ jsxs(
@@ -4237,33 +4274,55 @@ var Tabs = ({
4237
4274
  onValueChange: handleValueChange,
4238
4275
  className: cn(styles58["tabs"], className),
4239
4276
  children: [
4240
- /* @__PURE__ */ jsx(
4277
+ /* @__PURE__ */ jsxs(
4241
4278
  TabsList,
4242
4279
  {
4280
+ ref: listRef,
4243
4281
  className: cn(
4244
4282
  styles58["tabs-list"],
4245
4283
  isFilled ? styles58["tabs-list--filled"] : styles58["tabs-list--transparent"]
4246
4284
  ),
4247
- children: items.map(({ label, value, icon, suffix, triggerProps }) => {
4248
- const isActive = activeTab === value;
4249
- return /* @__PURE__ */ createElement(
4250
- TabsTrigger,
4285
+ children: [
4286
+ items.map(({ label, value, icon, suffix, triggerProps }) => {
4287
+ return /* @__PURE__ */ createElement(
4288
+ TabsTrigger,
4289
+ {
4290
+ ...triggerProps,
4291
+ key: value,
4292
+ ref: (el) => {
4293
+ triggerRefs.current[value] = el;
4294
+ },
4295
+ value,
4296
+ className: cn(
4297
+ styles58["tabs-trigger"],
4298
+ isFilled ? styles58["tabs-trigger--filled"] : styles58["tabs-trigger--transparent"],
4299
+ triggerProps?.className
4300
+ )
4301
+ },
4302
+ renderIcon(icon),
4303
+ label,
4304
+ suffix,
4305
+ renderTriggerIndicator(value)
4306
+ );
4307
+ }),
4308
+ !staticRender && indicator && /* @__PURE__ */ jsx(
4309
+ "span",
4251
4310
  {
4252
- ...triggerProps,
4253
- key: value,
4254
- value,
4311
+ "aria-hidden": true,
4312
+ "data-slot": "tabs-indicator",
4255
4313
  className: cn(
4256
- styles58["tabs-trigger"],
4257
- isFilled ? styles58["tabs-trigger--filled"] : styles58["tabs-trigger--transparent"],
4258
- triggerProps?.className
4259
- )
4260
- },
4261
- renderIcon(icon),
4262
- label,
4263
- suffix,
4264
- renderActiveStyle(isActive)
4265
- );
4266
- })
4314
+ indicatorClass,
4315
+ styles58["active-tab-indicator--shared"],
4316
+ animateIndicator && styles58["active-tab-indicator--animated"]
4317
+ ),
4318
+ style: {
4319
+ transform: `translateX(${indicator.left}px)`,
4320
+ "--indicator-width": `${indicator.width}px`,
4321
+ "--indicator-duration": `${indicator.duration}ms`
4322
+ }
4323
+ }
4324
+ )
4325
+ ]
4267
4326
  }
4268
4327
  ),
4269
4328
  items.map(({ value, content }) => /* @__PURE__ */ jsx(