@frontify/fondue 12.0.0-beta.374 → 12.0.0-beta.376

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.
@@ -1,71 +1,76 @@
1
- import { jsx as p, Fragment as I } from "react/jsx-runtime";
2
- import { useState as i, useLayoutEffect as L, Children as N, isValidElement as x } from "react";
3
- import { Trigger as u } from "../../utilities/dialogs/Trigger.es.js";
1
+ import { jsx as n, Fragment as D } from "react/jsx-runtime";
2
+ import { useState as i, useLayoutEffect as F, Children as I, isValidElement as N } from "react";
3
+ import { Trigger as E } from "../../utilities/dialogs/Trigger.es.js";
4
4
  import { Content as y } from "../../utilities/dialogs/Content.es.js";
5
- import { usePopper as D } from "react-popper";
5
+ import { usePopper as x } from "react-popper";
6
6
  import { Portal as H } from "../Portal/Portal.es.js";
7
- const S = 200, v = 400, C = "100px", R = ({ dimension: n, isVerticalAlignedToTop: r }) => ({
8
- left: `${(window.innerWidth - n.width) / 2}px`,
9
- top: r ? C : `${(window.innerHeight - n.height) / 2}px`,
7
+ const S = 200, C = 400, R = "100px", U = ({ dimension: p, isVerticalAlignedToTop: r }) => ({
8
+ left: `${(window.innerWidth - p.width) / 2}px`,
9
+ top: r ? R : `${(window.innerHeight - p.height) / 2}px`,
10
10
  transform: "none"
11
11
  }), m = ({
12
- children: n,
12
+ children: p,
13
13
  open: r,
14
- placement: E = "bottom-start",
15
- offset: P = [0, 8],
16
- flip: h = !0,
14
+ placement: P = "bottom-start",
15
+ offset: h = [0, 8],
16
+ flip: w = !0,
17
17
  enablePortal: g = !0,
18
- zIndex: l = "auto",
18
+ zIndex: a = "auto",
19
19
  isDetached: s = !1,
20
20
  verticalAlignment: T,
21
- strategy: w = "absolute"
21
+ strategy: L = "absolute"
22
22
  }) => {
23
- const [_, b] = i(null), [O, a] = i(null), [A, F] = i({
23
+ const [_, b] = i(null), [v, l] = i(null), [O, A] = i({
24
24
  width: S,
25
- height: v
26
- }), t = D(s ? document.body : _, O, {
27
- placement: E,
25
+ height: C
26
+ }), t = x(s ? document.body : _, v, {
27
+ placement: P,
28
28
  modifiers: [
29
- { name: "offset", options: { offset: P } },
29
+ { name: "offset", options: { offset: h } },
30
30
  {
31
31
  name: "flip",
32
- enabled: h
32
+ enabled: w
33
33
  }
34
34
  ],
35
- strategy: w
35
+ strategy: L
36
36
  });
37
- L(() => {
38
- var e, o, d, c;
39
- s && t.state && r && F({
40
- width: (o = (e = t.state.rects) == null ? void 0 : e.popper) == null ? void 0 : o.width,
41
- height: (c = (d = t.state.rects) == null ? void 0 : d.popper) == null ? void 0 : c.height
42
- });
37
+ F(() => {
38
+ const e = () => {
39
+ var o, d, u, c;
40
+ s && t.state && r && A({
41
+ width: (d = (o = t.state.rects) == null ? void 0 : o.popper) == null ? void 0 : d.width,
42
+ height: (c = (u = t.state.rects) == null ? void 0 : u.popper) == null ? void 0 : c.height
43
+ });
44
+ };
45
+ return e(), window.addEventListener("resize", e), () => {
46
+ window.removeEventListener("resize", e);
47
+ };
43
48
  }, [s, r, t.state]);
44
- const f = s ? R({ dimension: A, isVerticalAlignedToTop: T === "top" }) : {};
45
- return /* @__PURE__ */ p(I, { children: N.map(n, (e) => {
46
- if (x(e) && typeof e.type == "function") {
49
+ const f = s ? U({ dimension: O, isVerticalAlignedToTop: T === "top" }) : {};
50
+ return /* @__PURE__ */ n(D, { children: I.map(p, (e) => {
51
+ if (N(e) && typeof e.type == "function") {
47
52
  const { displayName: o } = e.type;
48
- if (o === u.displayName)
49
- return /* @__PURE__ */ p("div", { ref: b, children: e });
53
+ if (o === E.displayName)
54
+ return /* @__PURE__ */ n("div", { ref: b, children: e });
50
55
  if (o === y.displayName && r)
51
- return g ? /* @__PURE__ */ p(H, { children: /* @__PURE__ */ p(
56
+ return g ? /* @__PURE__ */ n(H, { children: /* @__PURE__ */ n(
52
57
  "div",
53
58
  {
54
- ref: a,
59
+ ref: l,
55
60
  style: {
56
- zIndex: l,
61
+ zIndex: a,
57
62
  ...t.styles.popper,
58
63
  ...f
59
64
  },
60
65
  ...t.attributes.popper,
61
66
  children: e
62
67
  }
63
- ) }) : /* @__PURE__ */ p(
68
+ ) }) : /* @__PURE__ */ n(
64
69
  "div",
65
70
  {
66
- ref: a,
71
+ ref: l,
67
72
  style: {
68
- zIndex: l,
73
+ zIndex: a,
69
74
  ...t.styles.popper,
70
75
  ...f
71
76
  },
@@ -77,7 +82,7 @@ const S = 200, v = 400, C = "100px", R = ({ dimension: n, isVerticalAlignedToTop
77
82
  }) });
78
83
  };
79
84
  m.displayName = "FonduePopper";
80
- m.Trigger = u;
85
+ m.Trigger = E;
81
86
  m.Content = y;
82
87
  export {
83
88
  m as Popper
@@ -1 +1 @@
1
- {"version":3,"file":"Popper.es.js","sources":["../../../src/components/Popper/Popper.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Children, isValidElement, useLayoutEffect, useState } from 'react';\nimport { Trigger } from '@utilities/dialogs/Trigger';\nimport { Content } from '@utilities/dialogs/Content';\nimport { usePopper } from 'react-popper';\nimport { Portal } from '@components/Portal';\nimport { PopperDimension, PopperProps, PrepareElementStyleProps } from '@components/Popper/types';\n\nconst DEFAULT_POPPER_WIDTH = 200;\nconst DEFAULT_POPPER_HEIGHT = 400;\nconst DEFAULT_DIALOG_TOP_POSITION = '100px';\n\nconst prepareElementStyle = ({ dimension, isVerticalAlignedToTop }: PrepareElementStyleProps) => ({\n left: `${(window.innerWidth - dimension.width) / 2}px`,\n top: isVerticalAlignedToTop ? DEFAULT_DIALOG_TOP_POSITION : `${(window.innerHeight - dimension.height) / 2}px`,\n transform: 'none',\n});\n\nexport const Popper = ({\n children,\n open,\n placement = 'bottom-start',\n offset = [0, 8],\n flip = true,\n enablePortal = true,\n zIndex = 'auto',\n isDetached = false,\n verticalAlignment,\n strategy = 'absolute',\n}: PopperProps) => {\n const [referenceElement, setReferenceElement] = useState<HTMLDivElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n const [popperDimensions, setPopperDimensions] = useState<PopperDimension>({\n width: DEFAULT_POPPER_WIDTH,\n height: DEFAULT_POPPER_HEIGHT,\n });\n\n const popperInstance = usePopper(isDetached ? document.body : referenceElement, popperElement, {\n placement,\n modifiers: [\n { name: 'offset', options: { offset } },\n {\n name: 'flip',\n enabled: flip,\n },\n ],\n strategy,\n });\n\n useLayoutEffect(() => {\n if (isDetached && popperInstance.state && open) {\n setPopperDimensions({\n width: popperInstance.state.rects?.popper?.width,\n height: popperInstance.state.rects?.popper?.height,\n });\n }\n }, [isDetached, open, popperInstance.state]);\n\n const detachedElementStyles = isDetached\n ? prepareElementStyle({ dimension: popperDimensions, isVerticalAlignedToTop: verticalAlignment === 'top' })\n : {};\n\n return (\n <>\n {Children.map(children, (child) => {\n if (isValidElement(child) && typeof child.type === 'function') {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Property 'displayName' does not exist on type 'JSXElementConstructor<any>'.ts(2339)\n const { displayName } = child.type;\n\n if (displayName === Trigger.displayName) {\n return <div ref={setReferenceElement}>{child}</div>;\n }\n\n if (displayName === Content.displayName && open) {\n return enablePortal ? (\n <Portal>\n <div\n ref={setPopperElement}\n style={{\n zIndex,\n ...popperInstance.styles.popper,\n ...detachedElementStyles,\n }}\n {...popperInstance.attributes.popper}\n >\n {child}\n </div>\n </Portal>\n ) : (\n <div\n ref={setPopperElement}\n style={{\n zIndex,\n ...popperInstance.styles.popper,\n ...detachedElementStyles,\n }}\n {...popperInstance.attributes.popper}\n >\n {child}\n </div>\n );\n }\n }\n })}\n </>\n );\n};\nPopper.displayName = 'FonduePopper';\nPopper.Trigger = Trigger;\nPopper.Content = Content;\n"],"names":["DEFAULT_POPPER_WIDTH","DEFAULT_POPPER_HEIGHT","DEFAULT_DIALOG_TOP_POSITION","prepareElementStyle","dimension","isVerticalAlignedToTop","Popper","children","open","placement","offset","flip","enablePortal","zIndex","isDetached","verticalAlignment","strategy","referenceElement","setReferenceElement","useState","popperElement","setPopperElement","popperDimensions","setPopperDimensions","popperInstance","usePopper","useLayoutEffect","_b","_a","_d","_c","detachedElementStyles","jsx","Fragment","Children","child","isValidElement","displayName","Trigger","Content","Portal"],"mappings":";;;;;;AASA,MAAMA,IAAuB,KACvBC,IAAwB,KACxBC,IAA8B,SAE9BC,IAAsB,CAAC,EAAE,WAAAC,GAAW,wBAAAC,SAAwD;AAAA,EAC9F,MAAM,IAAI,OAAO,aAAaD,EAAU,SAAS,CAAC;AAAA,EAClD,KAAKC,IAAyBH,IAA8B,IAAI,OAAO,cAAcE,EAAU,UAAU,CAAC;AAAA,EAC1G,WAAW;AACf,IAEaE,IAAS,CAAC;AAAA,EACnB,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,QAAAC,IAAS,CAAC,GAAG,CAAC;AAAA,EACd,MAAAC,IAAO;AAAA,EACP,cAAAC,IAAe;AAAA,EACf,QAAAC,IAAS;AAAA,EACT,YAAAC,IAAa;AAAA,EACb,mBAAAC;AAAA,EACA,UAAAC,IAAW;AACf,MAAmB;AACf,QAAM,CAACC,GAAkBC,CAAmB,IAAIC,EAAgC,IAAI,GAC9E,CAACC,GAAeC,CAAgB,IAAIF,EAAgC,IAAI,GACxE,CAACG,GAAkBC,CAAmB,IAAIJ,EAA0B;AAAA,IACtE,OAAOnB;AAAA,IACP,QAAQC;AAAA,EAAA,CACX,GAEKuB,IAAiBC,EAAUX,IAAa,SAAS,OAAOG,GAAkBG,GAAe;AAAA,IAC3F,WAAAX;AAAA,IACA,WAAW;AAAA,MACP,EAAE,MAAM,UAAU,SAAS,EAAE,QAAAC,IAAS;AAAA,MACtC;AAAA,QACI,MAAM;AAAA,QACN,SAASC;AAAA,MACb;AAAA,IACJ;AAAA,IACA,UAAAK;AAAA,EAAA,CACH;AAED,EAAAU,EAAgB,MAAM;;AACd,IAAAZ,KAAcU,EAAe,SAAShB,KAClBe,EAAA;AAAA,MAChB,QAAOI,KAAAC,IAAAJ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AO,UAAUiC;"}
1
+ {"version":3,"file":"Popper.es.js","sources":["../../../src/components/Popper/Popper.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Children, isValidElement, useLayoutEffect, useState } from 'react';\nimport { Trigger } from '@utilities/dialogs/Trigger';\nimport { Content } from '@utilities/dialogs/Content';\nimport { usePopper } from 'react-popper';\nimport { Portal } from '@components/Portal';\nimport { PopperDimension, PopperProps, PrepareElementStyleProps } from '@components/Popper/types';\n\nconst DEFAULT_POPPER_WIDTH = 200;\nconst DEFAULT_POPPER_HEIGHT = 400;\nconst DEFAULT_DIALOG_TOP_POSITION = '100px';\n\nconst prepareElementStyle = ({ dimension, isVerticalAlignedToTop }: PrepareElementStyleProps) => ({\n left: `${(window.innerWidth - dimension.width) / 2}px`,\n top: isVerticalAlignedToTop ? DEFAULT_DIALOG_TOP_POSITION : `${(window.innerHeight - dimension.height) / 2}px`,\n transform: 'none',\n});\n\nexport const Popper = ({\n children,\n open,\n placement = 'bottom-start',\n offset = [0, 8],\n flip = true,\n enablePortal = true,\n zIndex = 'auto',\n isDetached = false,\n verticalAlignment,\n strategy = 'absolute',\n}: PopperProps) => {\n const [referenceElement, setReferenceElement] = useState<HTMLDivElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n const [popperDimensions, setPopperDimensions] = useState<PopperDimension>({\n width: DEFAULT_POPPER_WIDTH,\n height: DEFAULT_POPPER_HEIGHT,\n });\n\n const popperInstance = usePopper(isDetached ? document.body : referenceElement, popperElement, {\n placement,\n modifiers: [\n { name: 'offset', options: { offset } },\n {\n name: 'flip',\n enabled: flip,\n },\n ],\n strategy,\n });\n\n useLayoutEffect(() => {\n const adjustPopperDimensions = () => {\n if (isDetached && popperInstance.state && open) {\n setPopperDimensions({\n width: popperInstance.state.rects?.popper?.width,\n height: popperInstance.state.rects?.popper?.height,\n });\n }\n };\n\n adjustPopperDimensions();\n window.addEventListener('resize', adjustPopperDimensions);\n\n return () => {\n window.removeEventListener('resize', adjustPopperDimensions);\n };\n }, [isDetached, open, popperInstance.state]);\n\n const detachedElementStyles = isDetached\n ? prepareElementStyle({ dimension: popperDimensions, isVerticalAlignedToTop: verticalAlignment === 'top' })\n : {};\n\n return (\n <>\n {Children.map(children, (child) => {\n if (isValidElement(child) && typeof child.type === 'function') {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Property 'displayName' does not exist on type 'JSXElementConstructor<any>'.ts(2339)\n const { displayName } = child.type;\n\n if (displayName === Trigger.displayName) {\n return <div ref={setReferenceElement}>{child}</div>;\n }\n\n if (displayName === Content.displayName && open) {\n return enablePortal ? (\n <Portal>\n <div\n ref={setPopperElement}\n style={{\n zIndex,\n ...popperInstance.styles.popper,\n ...detachedElementStyles,\n }}\n {...popperInstance.attributes.popper}\n >\n {child}\n </div>\n </Portal>\n ) : (\n <div\n ref={setPopperElement}\n style={{\n zIndex,\n ...popperInstance.styles.popper,\n ...detachedElementStyles,\n }}\n {...popperInstance.attributes.popper}\n >\n {child}\n </div>\n );\n }\n }\n })}\n </>\n );\n};\nPopper.displayName = 'FonduePopper';\nPopper.Trigger = Trigger;\nPopper.Content = Content;\n"],"names":["DEFAULT_POPPER_WIDTH","DEFAULT_POPPER_HEIGHT","DEFAULT_DIALOG_TOP_POSITION","prepareElementStyle","dimension","isVerticalAlignedToTop","Popper","children","open","placement","offset","flip","enablePortal","zIndex","isDetached","verticalAlignment","strategy","referenceElement","setReferenceElement","useState","popperElement","setPopperElement","popperDimensions","setPopperDimensions","popperInstance","usePopper","useLayoutEffect","adjustPopperDimensions","_b","_a","_d","_c","detachedElementStyles","jsx","Fragment","Children","child","isValidElement","displayName","Trigger","Content","Portal"],"mappings":";;;;;;AASA,MAAMA,IAAuB,KACvBC,IAAwB,KACxBC,IAA8B,SAE9BC,IAAsB,CAAC,EAAE,WAAAC,GAAW,wBAAAC,SAAwD;AAAA,EAC9F,MAAM,IAAI,OAAO,aAAaD,EAAU,S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AUA,CAAsB;AAAA,IAAA;AAAA,KAEhE,CAACb,GAAYN,GAAMgB,EAAe,KAAK,CAAC;AAErC,QAAAQ,IAAwBlB,IACxBX,EAAoB,EAAE,WAAWmB,GAAkB,wBAAwBP,MAAsB,MAAO,CAAA,IACxG,CAAA;AAEN,SAES,gBAAAkB,EAAAC,GAAA,EAAA,UAAAC,EAAS,IAAI5B,GAAU,CAAC6B,MAAU;AAC/B,QAAIC,EAAeD,CAAK,KAAK,OAAOA,EAAM,QAAS,YAAY;AAGrD,YAAA,EAAE,aAAAE,EAAY,IAAIF,EAAM;AAE1B,UAAAE,MAAgBC,EAAQ;AACxB,eAAQ,gBAAAN,EAAA,OAAA,EAAI,KAAKf,GAAsB,UAAMkB,EAAA,CAAA;AAG7C,UAAAE,MAAgBE,EAAQ,eAAehC;AAChC,eAAAI,sBACF6B,GACG,EAAA,UAAA,gBAAAR;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,KAAKZ;AAAA,YACL,OAAO;AAAA,cACH,QAAAR;AAAA,cACA,GAAGW,EAAe,OAAO;AAAA,cACzB,GAAGQ;AAAA,YACP;AAAA,YACC,GAAGR,EAAe,WAAW;AAAA,YAE7B,UAAAY;AAAA,UAAA;AAAA,WAET,IAEA,gBAAAH;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,KAAKZ;AAAA,YACL,OAAO;AAAA,cACH,QAAAR;AAAA,cACA,GAAGW,EAAe,OAAO;AAAA,cACzB,GAAGQ;AAAA,YACP;AAAA,YACC,GAAGR,EAAe,WAAW;AAAA,YAE7B,UAAAY;AAAA,UAAA;AAAA,QAAA;AAAA,IAIjB;AAAA,EACH,CAAA,EACL,CAAA;AAER;AACA9B,EAAO,cAAc;AACrBA,EAAO,UAAUiC;AACjBjC,EAAO,UAAUkC;"}
@@ -1,28 +1,28 @@
1
- import { jsx as r, jsxs as I } from "react/jsx-runtime";
2
- import { useMemoizedId as j } from "../../hooks/useMemoizedId.es.js";
3
- import { useFocusRing as F } from "@react-aria/focus";
4
- import { setInteractionModality as M } from "@react-aria/interactions";
5
- import { useRadio as P, useRadioGroup as $ } from "@react-aria/radio";
6
- import { VisuallyHidden as H } from "@react-aria/visually-hidden";
7
- import { useRadioGroupState as O } from "@react-stately/radio";
8
- import { FOCUS_STYLE as A } from "../../utilities/focusStyle.es.js";
9
- import { merge as v } from "../../utilities/merge.es.js";
10
- import { motion as B } from "framer-motion";
11
- import { forwardRef as T, useRef as E, useState as W, useMemo as X, useCallback as N, useEffect as z } from "react";
12
- const h = (m) => m.icon !== void 0, k = T((m, f) => {
13
- const { id: p, item: e, disabled: a, radioGroupState: t, size: d } = m, o = E(null), c = e.id === t.selectedValue, { inputProps: x } = P(
1
+ import { jsx as r, jsxs as R } from "react/jsx-runtime";
2
+ import { useMemoizedId as F } from "../../hooks/useMemoizedId.es.js";
3
+ import { useFocusRing as M } from "@react-aria/focus";
4
+ import { setInteractionModality as P } from "@react-aria/interactions";
5
+ import { useRadio as $, useRadioGroup as z } from "@react-aria/radio";
6
+ import { VisuallyHidden as A } from "@react-aria/visually-hidden";
7
+ import { useRadioGroupState as B } from "@react-stately/radio";
8
+ import { FOCUS_STYLE as T } from "../../utilities/focusStyle.es.js";
9
+ import { merge as S } from "../../utilities/merge.es.js";
10
+ import { motion as X } from "framer-motion";
11
+ import { forwardRef as H, useRef as k, useState as O, useMemo as U, useCallback as I, useEffect as Y } from "react";
12
+ const h = (m) => m.icon !== void 0, D = H((m, u) => {
13
+ const { id: p, item: e, disabled: d, radioGroupState: n, size: o } = m, s = k(null), c = e.id === n.selectedValue, { inputProps: x } = $(
14
14
  {
15
15
  value: e.id,
16
16
  "aria-label": h(e) ? e.ariaLabel : e.value.toString(),
17
- isDisabled: a,
17
+ isDisabled: d,
18
18
  id: c ? p : void 0
19
19
  },
20
- t,
21
- o
22
- ), { isFocusVisible: w, focusProps: S } = F(), s = () => {
23
- var g;
24
- a || (t.setSelectedValue(e.id), (g = o.current) == null || g.focus(), M("pointer"));
25
- }, y = () => {
20
+ n,
21
+ s
22
+ ), { isFocusVisible: w, focusProps: y } = M(), i = () => {
23
+ var b;
24
+ d || (n.setSelectedValue(e.id), (b = s.current) == null || b.focus(), P("pointer"));
25
+ }, C = () => {
26
26
  switch (!0) {
27
27
  case h(e):
28
28
  return "fondue-segmented-controls-item-icon";
@@ -35,35 +35,35 @@ const h = (m) => m.icon !== void 0, k = T((m, f) => {
35
35
  return /* @__PURE__ */ r(
36
36
  "div",
37
37
  {
38
- ref: f,
39
- className: v([
38
+ ref: u,
39
+ className: S([
40
40
  "tw-relative",
41
41
  "after:tw-content-[''] after:tw-border-r after:tw-border-solid after:tw-border-line-strong after:tw-absolute after:tw-right-0 after:tw-h-full last:after:tw-hidden",
42
- w && A
42
+ w && T
43
43
  ]),
44
- children: /* @__PURE__ */ I(
44
+ children: /* @__PURE__ */ R(
45
45
  "div",
46
46
  {
47
47
  role: "none",
48
- onClick: s,
49
- "data-test-id": y(),
50
- className: v([
48
+ onClick: i,
49
+ "data-test-id": C(),
50
+ className: S([
51
51
  "tw-relative tw-w-full tw-py-2 tw-inline-flex tw-justify-center tw-items-center tw-font-sans tw-font-normal tw-h-full tw-text-center",
52
- d === "small" ? "tw-px-2" : "tw-px-4",
53
- c && !a ? "tw-text-text" : "tw-text-text-weak",
54
- a ? "tw-text-box-disabled-inverse tw-bg-box-disabled hover:tw-cursor-not-allowed" : "hover:tw-text-text hover:tw-cursor-pointer"
52
+ o === "small" ? "tw-px-2" : "tw-px-4",
53
+ c && !d ? "tw-text-text" : "tw-text-text-weak",
54
+ d ? "tw-text-box-disabled-inverse tw-bg-box-disabled hover:tw-cursor-not-allowed" : "hover:tw-text-text hover:tw-cursor-pointer"
55
55
  ]),
56
56
  children: [
57
- /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
57
+ /* @__PURE__ */ r(A, { children: /* @__PURE__ */ r(
58
58
  "input",
59
59
  {
60
60
  ...x,
61
- ...S,
61
+ ...y,
62
62
  "data-test-id": "fondue-segmented-controls-input",
63
- ref: o
63
+ ref: s
64
64
  }
65
65
  ) }),
66
- /* @__PURE__ */ I("span", { className: "tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-flex", children: [
66
+ /* @__PURE__ */ R("span", { className: "tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-flex", children: [
67
67
  h(e) && /* @__PURE__ */ r("span", { className: "tw-leading-3", "aria-label": e.ariaLabel, children: e.icon }),
68
68
  e.value && /* @__PURE__ */ r("span", { className: h(e) ? "tw-ml-2" : "", children: e.value.toString() })
69
69
  ] })
@@ -74,76 +74,77 @@ const h = (m) => m.icon !== void 0, k = T((m, f) => {
74
74
  e.id
75
75
  );
76
76
  });
77
- k.displayName = "SegmentedControlsItem";
78
- const U = ({
77
+ D.displayName = "SegmentedControlsItem";
78
+ const _ = ({
79
79
  id: m,
80
- items: f,
80
+ items: u,
81
81
  activeItemId: p,
82
82
  onChange: e,
83
- ariaLabel: a = "SegmentedControls",
84
- disabled: t = !1,
85
- hugWidth: d = !1,
86
- size: o
83
+ ariaLabel: d = "SegmentedControls",
84
+ disabled: n = !1,
85
+ hugWidth: o = !1,
86
+ size: s
87
87
  }) => {
88
- const c = j(m), x = { onChange: e, value: p, label: a, isDisabled: t }, w = O(x), { radioGroupProps: S } = $(x, w), s = E([]), [y, g] = W(null), D = X(() => f.map((n, u) => /* @__PURE__ */ r(
89
- k,
88
+ const c = F(m), x = { onChange: e, value: p, label: d, isDisabled: n }, w = B(x), { radioGroupProps: y } = z(x, w), i = k([]), [C, b] = O(null), G = U(() => u.map((t, a) => /* @__PURE__ */ r(
89
+ D,
90
90
  {
91
91
  id: c,
92
- item: n,
93
- disabled: t,
92
+ item: t,
93
+ disabled: n,
94
94
  radioGroupState: w,
95
- ref: (l) => s.current[u] = l,
96
- size: o
95
+ ref: (f) => i.current[a] = f,
96
+ size: s
97
97
  },
98
- `fondue-segmented-controls-${c}-item-${n.id}`
99
- )), [f, c, t, w, o]), i = f.findIndex((n) => n.id === w.selectedValue), G = d ? "" : "tw-w-full", V = d ? "tw-flex" : "tw-grid tw-grid-flow-col tw-auto-cols-fr tw-justify-evenly", L = N(() => {
100
- var l;
101
- let u = o === "small" || d ? -1 : 0;
102
- for (let C = 0; C < i; C++)
103
- u += ((l = s.current[C]) == null ? void 0 : l.clientWidth) ?? 0;
104
- return `${u}px`;
105
- }, [d, i, o]), R = N(() => {
106
- var l;
107
- const u = i === s.current.length - 1 ? 1 : -1;
108
- return `${(((l = s.current[i]) == null ? void 0 : l.clientWidth) ?? 0) + u}px`;
109
- }, [i]), b = N(() => {
110
- const n = s.current ? { x: L(), width: R() } : { x: "0px", width: "0px" };
111
- g(n);
112
- }, [R, L]);
113
- return z(() => (i >= 0 && b(), window.addEventListener("resize", b), () => {
114
- window.removeEventListener("resize", b);
115
- }), [i, b]), /* @__PURE__ */ r("div", { className: "tw-flex", children: /* @__PURE__ */ I(
98
+ `fondue-segmented-controls-${c}-item-${t.id}`
99
+ )), [u, c, n, w, s]), l = u.findIndex((t) => t.id === w.selectedValue), V = o ? "" : "tw-w-full", j = o ? "tw-flex" : "tw-grid tw-grid-flow-col tw-auto-cols-fr tw-justify-evenly", g = s === "small", N = l === i.current.length - 1, L = I(() => {
100
+ var a;
101
+ let t = o ? -1 : 0;
102
+ t -= g && N ? 1 : 0;
103
+ for (let f = 0; f < l; f++)
104
+ t += ((a = i.current[f]) == null ? void 0 : a.clientWidth) ?? 0;
105
+ return t -= N || o ? 0 : 1, `${t}px`;
106
+ }, [l, g, N, o]), E = I(() => {
107
+ var a;
108
+ const t = g || o ? -1 : 0;
109
+ return `${(((a = i.current[l]) == null ? void 0 : a.clientWidth) ?? 0) + t}px`;
110
+ }, [l, g, o]), v = I(() => {
111
+ const t = i.current ? { x: L(), width: E() } : { x: "0px", width: "0px" };
112
+ b(t);
113
+ }, [E, L]);
114
+ return Y(() => (l >= 0 && v(), window.addEventListener("resize", v), () => {
115
+ window.removeEventListener("resize", v);
116
+ }), [l, v]), /* @__PURE__ */ r("div", { className: "tw-flex", children: /* @__PURE__ */ R(
116
117
  "fieldset",
117
118
  {
118
- ...S,
119
+ ...y,
119
120
  "data-test-id": "fondue-segmented-controls",
120
- className: v([
121
+ className: S([
121
122
  "tw-relative tw-h-9 tw-p-0 tw-border tw-border-solid tw-border-line-strong tw-m-0 tw-bg-base-alt tw-rounded tw-font-sans tw-text-s tw-select-none",
122
- G,
123
- V
123
+ V,
124
+ j
124
125
  ]),
125
126
  children: [
126
127
  /* @__PURE__ */ r(
127
- B.div,
128
+ X.div,
128
129
  {
129
130
  "aria-hidden": "true",
130
- animate: y ?? { x: "0px", width: "0px" },
131
+ animate: C ?? { x: "0px", width: "0px" },
131
132
  initial: !1,
132
133
  transition: { type: "tween", duration: 0.3 },
133
134
  hidden: !p,
134
- className: v([
135
- "tw-absolute tw--inset-px tw-h-full tw-box-content tw-border tw-rounded tw-pointer-events-none",
136
- t ? "tw-border-line-x-strong hover:tw-cursor-not-allowed" : "tw-border-line-xx-strong tw-bg-base"
135
+ className: S([
136
+ "tw-absolute tw--inset-y-px tw-h-full tw-box-content tw-border tw-rounded tw-pointer-events-none",
137
+ n ? "tw-border-line-x-strong hover:tw-cursor-not-allowed" : "tw-border-line-xx-strong tw-bg-base"
137
138
  ])
138
139
  }
139
140
  ),
140
- D
141
+ G
141
142
  ]
142
143
  }
143
144
  ) });
144
145
  };
145
- U.displayName = "FondueSegmentedControls";
146
+ _.displayName = "FondueSegmentedControls";
146
147
  export {
147
- U as SegmentedControls
148
+ _ as SegmentedControls
148
149
  };
149
150
  //# sourceMappingURL=SegmentedControls.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SegmentedControls.es.js","sources":["../../../src/components/SegmentedControls/SegmentedControls.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { IconProps } from '@foundation/Icon/IconProps';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { useFocusRing } from '@react-aria/focus';\nimport { setInteractionModality } from '@react-aria/interactions';\nimport { useRadio, useRadioGroup } from '@react-aria/radio';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\nimport { RadioGroupState, useRadioGroupState } from '@react-stately/radio';\nimport { FOCUS_STYLE } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\nimport { motion } from 'framer-motion';\nimport { ReactElement, forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nexport type IconItem = {\n id: string;\n icon: ReactElement<IconProps>;\n value?: string;\n ariaLabel: string;\n};\n\nexport type TextOrNumberItem = {\n id: string;\n value: string | number;\n};\n\nexport type SegmentSize = 'small' | 'medium';\n\nexport type SegmentedControlsProps = {\n id?: string;\n items: (TextOrNumberItem | IconItem)[];\n activeItemId?: string;\n onChange: (id: string) => void;\n ariaLabel?: string;\n disabled?: boolean;\n hugWidth?: boolean;\n size?: SegmentSize;\n};\n\nconst isIconItem = (item: TextOrNumberItem | IconItem): item is IconItem => (item as IconItem).icon !== undefined;\n\ninterface SegmentedControlsItemProps {\n id: string;\n item: TextOrNumberItem | IconItem;\n disabled: boolean;\n radioGroupState: RadioGroupState;\n size?: SegmentSize;\n}\n\nconst SegmentedControlsItem = forwardRef<HTMLDivElement, SegmentedControlsItemProps>((props, ref) => {\n const { id, item, disabled, radioGroupState, size } = props;\n const inputRef = useRef<HTMLInputElement | null>(null);\n const isActive = item.id === radioGroupState.selectedValue;\n const { inputProps } = useRadio(\n {\n value: item.id,\n 'aria-label': isIconItem(item) ? item.ariaLabel : item.value.toString(),\n isDisabled: disabled,\n id: isActive ? id : undefined,\n },\n radioGroupState,\n inputRef,\n );\n const { isFocusVisible, focusProps } = useFocusRing();\n\n const handleMockLabelClick = () => {\n if (!disabled) {\n radioGroupState.setSelectedValue(item.id);\n inputRef.current?.focus();\n setInteractionModality('pointer');\n }\n };\n\n const getSegmentedControlsItemTestId = () => {\n switch (true) {\n case isIconItem(item):\n return 'fondue-segmented-controls-item-icon';\n case typeof item.value === 'string':\n return 'fondue-segmented-controls-item-text';\n default:\n return 'fondue-segmented-controls-item-number';\n }\n };\n\n return (\n <div\n key={item.id}\n ref={ref}\n className={merge([\n 'tw-relative',\n \"after:tw-content-[''] after:tw-border-r after:tw-border-solid after:tw-border-line-strong after:tw-absolute after:tw-right-0 after:tw-h-full last:after:tw-hidden\",\n isFocusVisible && FOCUS_STYLE,\n ])}\n >\n <div\n // TODO: Change element back to label when bug #2380 from @react-aria is fixed\n // https://github.com/adobe/react-spectrum/issues/2380\n role=\"none\"\n onClick={handleMockLabelClick}\n data-test-id={getSegmentedControlsItemTestId()}\n className={merge([\n 'tw-relative tw-w-full tw-py-2 tw-inline-flex tw-justify-center tw-items-center tw-font-sans tw-font-normal tw-h-full tw-text-center',\n size === 'small' ? 'tw-px-2' : 'tw-px-4',\n isActive && !disabled ? 'tw-text-text' : 'tw-text-text-weak',\n disabled\n ? 'tw-text-box-disabled-inverse tw-bg-box-disabled hover:tw-cursor-not-allowed'\n : 'hover:tw-text-text hover:tw-cursor-pointer',\n ])}\n >\n <VisuallyHidden>\n <input\n {...inputProps}\n {...focusProps}\n data-test-id=\"fondue-segmented-controls-input\"\n ref={inputRef}\n />\n </VisuallyHidden>\n <span className=\"tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-flex\">\n {isIconItem(item) && (\n <span className=\"tw-leading-3\" aria-label={item.ariaLabel}>\n {item.icon}\n </span>\n )}\n {item.value && <span className={isIconItem(item) ? 'tw-ml-2' : ''}>{item.value.toString()}</span>}\n </span>\n </div>\n </div>\n );\n});\n\nSegmentedControlsItem.displayName = 'SegmentedControlsItem';\n\nexport const SegmentedControls = ({\n id: propId,\n items,\n activeItemId,\n onChange,\n ariaLabel = 'SegmentedControls',\n disabled = false,\n hugWidth = false,\n size,\n}: SegmentedControlsProps): ReactElement => {\n const id = useMemoizedId(propId);\n const groupProps = { onChange, value: activeItemId, label: ariaLabel, isDisabled: disabled };\n const radioGroupState = useRadioGroupState(groupProps);\n const { radioGroupProps } = useRadioGroup(groupProps, radioGroupState);\n const itemsRef = useRef<(HTMLDivElement | null)[]>([]);\n const [activeBorderDimensions, setActiveBorderDimensions] = useState<{ x: string; width: string } | null>(null);\n const itemElements = useMemo(() => {\n return items.map((item, index) => (\n <SegmentedControlsItem\n id={id}\n item={item}\n disabled={disabled}\n radioGroupState={radioGroupState}\n ref={(el) => (itemsRef.current[index] = el)}\n key={`fondue-segmented-controls-${id}-item-${item.id}`}\n size={size}\n />\n ));\n }, [items, id, disabled, radioGroupState, size]);\n const selectedIndex = items.findIndex((item) => item.id === radioGroupState.selectedValue);\n const width = hugWidth ? '' : 'tw-w-full';\n const alignment = hugWidth ? 'tw-flex' : 'tw-grid tw-grid-flow-col tw-auto-cols-fr tw-justify-evenly';\n\n const getSliderX = useCallback(() => {\n const isSmallOrHugWidth = size === 'small' || hugWidth;\n let translateX = isSmallOrHugWidth ? -1 : 0;\n for (let i = 0; i < selectedIndex; i++) {\n translateX += itemsRef.current[i]?.clientWidth ?? 0;\n }\n\n return `${translateX}px`;\n }, [hugWidth, selectedIndex, size]);\n\n const getSliderWidth = useCallback(() => {\n const isLastElement = selectedIndex === itemsRef.current.length - 1;\n const width = isLastElement ? 1 : -1;\n\n return `${(itemsRef.current[selectedIndex]?.clientWidth ?? 0) + width}px`;\n }, [selectedIndex]);\n\n const setSliderDimensions = useCallback(() => {\n const dimensions = itemsRef.current ? { x: getSliderX(), width: getSliderWidth() } : { x: '0px', width: '0px' };\n setActiveBorderDimensions(dimensions);\n }, [getSliderWidth, getSliderX]);\n\n useEffect(() => {\n if (selectedIndex >= 0) {\n setSliderDimensions();\n }\n window.addEventListener('resize', setSliderDimensions);\n\n return () => {\n window.removeEventListener('resize', setSliderDimensions);\n };\n }, [selectedIndex, setSliderDimensions]);\n\n return (\n <div className=\"tw-flex\">\n <fieldset\n {...radioGroupProps}\n data-test-id=\"fondue-segmented-controls\"\n className={merge([\n 'tw-relative tw-h-9 tw-p-0 tw-border tw-border-solid tw-border-line-strong tw-m-0 tw-bg-base-alt tw-rounded tw-font-sans tw-text-s tw-select-none',\n width,\n alignment,\n ])}\n >\n <motion.div\n aria-hidden=\"true\"\n // div border is not included in width so it must be subtracted from translation.\n animate={activeBorderDimensions ?? { x: '0px', width: '0px' }}\n initial={false}\n transition={{ type: 'tween', duration: 0.3 }}\n hidden={!activeItemId}\n className={merge([\n 'tw-absolute tw--inset-px tw-h-full tw-box-content tw-border tw-rounded tw-pointer-events-none',\n disabled\n ? 'tw-border-line-x-strong hover:tw-cursor-not-allowed'\n : 'tw-border-line-xx-strong tw-bg-base',\n ])}\n />\n {itemElements}\n </fieldset>\n </div>\n );\n};\nSegmentedControls.displayName = 'FondueSegmentedControls';\n"],"names":["isIconItem","item","SegmentedControlsItem","forwardRef","props","ref","id","disabled","radioGroupState","size","inputRef","useRef","isActive","inputProps","useRadio","isFocusVisible","focusProps","useFocusRing","handleMockLabelClick","_a","setInteractionModality","getSegmentedControlsItemTestId","jsx","merge","FOCUS_STYLE","jsxs","VisuallyHidden","SegmentedControls","propId","items","activeItemId","onChange","ariaLabel","hugWidth","useMemoizedId","groupProps","useRadioGroupState","radioGroupProps","useRadioGroup","itemsRef","activeBorderDimensions","setActiveBorderDimensions","useState","itemElements","useMemo","index","el","selectedIndex","width","alignment","getSliderX","useCallback","translateX","i","getSliderWidth","setSliderDimensions","dimensions","useEffect","motion"],"mappings":";;;;;;;;;;;AAuCA,MAAMA,IAAa,CAACC,MAAyDA,EAAkB,SAAS,QAUlGC,IAAwBC,EAAuD,CAACC,GAAOC,MAAQ;AACjG,QAAM,EAAE,IAAAC,GAAI,MAAAL,GAAM,UAAAM,GAAU,iBAAAC,GAAiB,MAAAC,EAAS,IAAAL,GAChDM,IAAWC,EAAgC,IAAI,GAC/CC,IAAWX,EAAK,OAAOO,EAAgB,eACvC,EAAE,YAAAK,MAAeC;AAAA,IACnB;AAAA,MACI,OAAOb,EAAK;AAAA,MACZ,cAAcD,EAAWC,CAAI,IAAIA,EAAK,YAAYA,EAAK,MAAM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AAY;AAAA,YAEZ,SAASlB,KAA0B,EAAE,GAAG,OAAO,OAAO,MAAM;AAAA,YAC5D,SAAS;AAAA,YACT,YAAY,EAAE,MAAM,SAAS,UAAU,IAAI;AAAA,YAC3C,QAAQ,CAACV;AAAA,YACT,WAAWP,EAAM;AAAA,cACb;AAAA,cACAhB,IACM,wDACA;AAAA,YAAA,CACT;AAAA,UAAA;AAAA,QACL;AAAA,QACCoC;AAAA,MAAA;AAAA,IAAA;AAAA,EAET,EAAA,CAAA;AAER;AACAhB,EAAkB,cAAc;"}
1
+ {"version":3,"file":"SegmentedControls.es.js","sources":["../../../src/components/SegmentedControls/SegmentedControls.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { IconProps } from '@foundation/Icon/IconProps';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { useFocusRing } from '@react-aria/focus';\nimport { setInteractionModality } from '@react-aria/interactions';\nimport { useRadio, useRadioGroup } from '@react-aria/radio';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\nimport { RadioGroupState, useRadioGroupState } from '@react-stately/radio';\nimport { FOCUS_STYLE } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\nimport { motion } from 'framer-motion';\nimport { ReactElement, forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nexport type IconItem = {\n id: string;\n icon: ReactElement<IconProps>;\n value?: string;\n ariaLabel: string;\n};\n\nexport type TextOrNumberItem = {\n id: string;\n value: string | number;\n};\n\nexport type SegmentSize = 'small' | 'medium';\n\nexport type SegmentedControlsProps = {\n id?: string;\n items: (TextOrNumberItem | IconItem)[];\n activeItemId?: string;\n onChange: (id: string) => void;\n ariaLabel?: string;\n disabled?: boolean;\n hugWidth?: boolean;\n size?: SegmentSize;\n};\n\nconst isIconItem = (item: TextOrNumberItem | IconItem): item is IconItem => (item as IconItem).icon !== undefined;\n\ninterface SegmentedControlsItemProps {\n id: string;\n item: TextOrNumberItem | IconItem;\n disabled: boolean;\n radioGroupState: RadioGroupState;\n size?: SegmentSize;\n}\n\nconst SegmentedControlsItem = forwardRef<HTMLDivElement, SegmentedControlsItemProps>((props, ref) => {\n const { id, item, disabled, radioGroupState, size } = props;\n const inputRef = useRef<HTMLInputElement | null>(null);\n const isActive = item.id === radioGroupState.selectedValue;\n const { inputProps } = useRadio(\n {\n value: item.id,\n 'aria-label': isIconItem(item) ? item.ariaLabel : item.value.toString(),\n isDisabled: disabled,\n id: isActive ? id : undefined,\n },\n radioGroupState,\n inputRef,\n );\n const { isFocusVisible, focusProps } = useFocusRing();\n\n const handleMockLabelClick = () => {\n if (!disabled) {\n radioGroupState.setSelectedValue(item.id);\n inputRef.current?.focus();\n setInteractionModality('pointer');\n }\n };\n\n const getSegmentedControlsItemTestId = () => {\n switch (true) {\n case isIconItem(item):\n return 'fondue-segmented-controls-item-icon';\n case typeof item.value === 'string':\n return 'fondue-segmented-controls-item-text';\n default:\n return 'fondue-segmented-controls-item-number';\n }\n };\n\n return (\n <div\n key={item.id}\n ref={ref}\n className={merge([\n 'tw-relative',\n \"after:tw-content-[''] after:tw-border-r after:tw-border-solid after:tw-border-line-strong after:tw-absolute after:tw-right-0 after:tw-h-full last:after:tw-hidden\",\n isFocusVisible && FOCUS_STYLE,\n ])}\n >\n <div\n // TODO: Change element back to label when bug #2380 from @react-aria is fixed\n // https://github.com/adobe/react-spectrum/issues/2380\n role=\"none\"\n onClick={handleMockLabelClick}\n data-test-id={getSegmentedControlsItemTestId()}\n className={merge([\n 'tw-relative tw-w-full tw-py-2 tw-inline-flex tw-justify-center tw-items-center tw-font-sans tw-font-normal tw-h-full tw-text-center',\n size === 'small' ? 'tw-px-2' : 'tw-px-4',\n isActive && !disabled ? 'tw-text-text' : 'tw-text-text-weak',\n disabled\n ? 'tw-text-box-disabled-inverse tw-bg-box-disabled hover:tw-cursor-not-allowed'\n : 'hover:tw-text-text hover:tw-cursor-pointer',\n ])}\n >\n <VisuallyHidden>\n <input\n {...inputProps}\n {...focusProps}\n data-test-id=\"fondue-segmented-controls-input\"\n ref={inputRef}\n />\n </VisuallyHidden>\n <span className=\"tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-flex\">\n {isIconItem(item) && (\n <span className=\"tw-leading-3\" aria-label={item.ariaLabel}>\n {item.icon}\n </span>\n )}\n {item.value && <span className={isIconItem(item) ? 'tw-ml-2' : ''}>{item.value.toString()}</span>}\n </span>\n </div>\n </div>\n );\n});\n\nSegmentedControlsItem.displayName = 'SegmentedControlsItem';\n\nexport const SegmentedControls = ({\n id: propId,\n items,\n activeItemId,\n onChange,\n ariaLabel = 'SegmentedControls',\n disabled = false,\n hugWidth = false,\n size,\n}: SegmentedControlsProps): ReactElement => {\n const id = useMemoizedId(propId);\n const groupProps = { onChange, value: activeItemId, label: ariaLabel, isDisabled: disabled };\n const radioGroupState = useRadioGroupState(groupProps);\n const { radioGroupProps } = useRadioGroup(groupProps, radioGroupState);\n const itemsRef = useRef<(HTMLDivElement | null)[]>([]);\n const [activeBorderDimensions, setActiveBorderDimensions] = useState<{ x: string; width: string } | null>(null);\n const itemElements = useMemo(() => {\n return items.map((item, index) => (\n <SegmentedControlsItem\n id={id}\n item={item}\n disabled={disabled}\n radioGroupState={radioGroupState}\n ref={(el) => (itemsRef.current[index] = el)}\n key={`fondue-segmented-controls-${id}-item-${item.id}`}\n size={size}\n />\n ));\n }, [items, id, disabled, radioGroupState, size]);\n const selectedIndex = items.findIndex((item) => item.id === radioGroupState.selectedValue);\n const width = hugWidth ? '' : 'tw-w-full';\n const alignment = hugWidth ? 'tw-flex' : 'tw-grid tw-grid-flow-col tw-auto-cols-fr tw-justify-evenly';\n const isSmall = size === 'small';\n const isLastElement = selectedIndex === itemsRef.current.length - 1;\n\n const getSliderX = useCallback(() => {\n let translateX = hugWidth ? -1 : 0;\n translateX -= isSmall && isLastElement ? 1 : 0;\n for (let i = 0; i < selectedIndex; i++) {\n translateX += itemsRef.current[i]?.clientWidth ?? 0;\n }\n\n translateX -= isLastElement || hugWidth ? 0 : 1;\n return `${translateX}px`;\n }, [selectedIndex, isSmall, isLastElement, hugWidth]);\n\n const getSliderWidth = useCallback(() => {\n const width = isSmall || hugWidth ? -1 : 0;\n\n return `${(itemsRef.current[selectedIndex]?.clientWidth ?? 0) + width}px`;\n }, [selectedIndex, isSmall, hugWidth]);\n\n const setSliderDimensions = useCallback(() => {\n const dimensions = itemsRef.current ? { x: getSliderX(), width: getSliderWidth() } : { x: '0px', width: '0px' };\n setActiveBorderDimensions(dimensions);\n }, [getSliderWidth, getSliderX]);\n\n useEffect(() => {\n if (selectedIndex >= 0) {\n setSliderDimensions();\n }\n window.addEventListener('resize', setSliderDimensions);\n\n return () => {\n window.removeEventListener('resize', setSliderDimensions);\n };\n }, [selectedIndex, setSliderDimensions]);\n\n return (\n <div className=\"tw-flex\">\n <fieldset\n {...radioGroupProps}\n data-test-id=\"fondue-segmented-controls\"\n className={merge([\n 'tw-relative tw-h-9 tw-p-0 tw-border tw-border-solid tw-border-line-strong tw-m-0 tw-bg-base-alt tw-rounded tw-font-sans tw-text-s tw-select-none',\n width,\n alignment,\n ])}\n >\n <motion.div\n aria-hidden=\"true\"\n // div border is not included in width so it must be subtracted from translation.\n animate={activeBorderDimensions ?? { x: '0px', width: '0px' }}\n initial={false}\n transition={{ type: 'tween', duration: 0.3 }}\n hidden={!activeItemId}\n className={merge([\n 'tw-absolute tw--inset-y-px tw-h-full tw-box-content tw-border tw-rounded tw-pointer-events-none',\n disabled\n ? 'tw-border-line-x-strong hover:tw-cursor-not-allowed'\n : 'tw-border-line-xx-strong tw-bg-base',\n ])}\n />\n {itemElements}\n </fieldset>\n </div>\n );\n};\nSegmentedControls.displayName = 'FondueSegmentedControls';\n"],"names":["isIconItem","item","SegmentedControlsItem","forwardRef","props","ref","id","disabled","radioGroupState","size","inputRef","useRef","isActive","inputProps","useRadio","isFocusVisible","focusProps","useFocusRing","handleMockLabelClick","_a","setInteractionModality","getSegmentedControlsItemTestId","jsx","merge","FOCUS_STYLE","jsxs","VisuallyHidden","SegmentedControls","propId","items","activeItemId","onChange","ariaLabel","hugWidth","useMemoizedId","groupProps","useRadioGroupState","radioGroupProps","useRadioGroup","itemsRef","activeBorderDimensions","setActiveBorderDimensions","useState","itemElements","useMemo","index","el","selectedIndex","width","alignment","isSmall","isLastElement","getSliderX","useCallback","translateX","i","getSliderWidth","setSliderDimensions","dimensions","useEffect","motion"],"mappings":";;;;;;;;;;;AAuCA,MAAMA,IAAa,CAACC,MAAyDA,EAAkB,SAAS,QAUlGC,IAAwBC,EAAuD,CAACC,GAAOC,MAAQ;AACjG,QAAM,EAAE,IAAAC,GAAI,MAAAL,GAAM,UAAAM,GAAU,iBAAAC,GAAiB,MAAAC,EAAS,IAAAL,GAChDM,IAAWC,EAAgC,IAAI,GAC/CC,IAAWX,EAAK,OAAOO,EAAgB,eACvC,EAAE,YAAAK,MAAeC;AAAA,IACnB;AAAA,MACI,OAAOb,EAAK;AAAA,MACZ,cAAcD,EAAWC,CAAI,IAAIA,EAAK,YAAYA,EAAK,MAAM,SAAS;AAAA,MACtE,YAAYM;AAAA,MACZ,IAAIK,IAAWN,IAAK;AAAA,IACxB;AAAA,IACAE;AAAA,IACAE;AAAA,EAAA,GAEE,EAAE,gBAAAK,GAAgB,YAAAC,EAAW,IAAIC,EAAa,GAE9CC,IAAuB,MAAM;;AAC/B,IAAKX,MACeC,EAAA,iBAAiBP,EAAK,EAAE,IACxCkB,IAAAT,EAAS,YAAT,QAAAS,EAAkB,SAClBC,EAAuB,SAAS;AAAA,EACpC,GAGEC,IAAiC,MAAM;AACzC,YAAQ,IAAM;AAAA,MACV,KAAKrB,EAAWC,CAAI;AACT,eAAA;AAAA,MACX,KAAK,OAAOA,EAAK,SAAU;AAChB,eAAA;AAAA,MACX;AACW,eAAA;AAAA,IACf;AAAA,EAAA;AAIA,SAAA,gBAAAqB;AAAA,IAAC;AAAA,IAAA;AAAA,MAEG,KAAAjB;AAAA,MACA,WAAWkB,EAAM;AAA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elledby": m,
89
+ "aria-describedby": m,
90
90
  disabled: f,
91
91
  className: "disabled:tw-text-text-disabled",
92
92
  "data-test-id": `${u}-button`,
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.es.js","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { ReactElement, useCallback, useEffect, useRef, useState } from 'react';\nimport { PopperPlacement } from '@components/Popper';\nimport { usePopper } from 'react-popper';\nimport { merge } from '@utilities/merge';\nimport { useToggleOverlay } from '@hooks/useToggleOverlay';\nimport { Z_INDEX_TOOLTIP } from '@utilities/dialogs/constants';\nimport { EnablePortalWrapper } from '@utilities/dialogs/EnablePortalWrapper';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\n\nconst ARROW_DISTANCE_FROM_CORNER_VALUE = 12;\nconst TOOLTIP_EXTRA_OFFSET_VALUE = 7; // As the arrow is set 12px away from tooltip corner, extra offset should be added to still point to Trigger.\n\nexport type TooltipProps = {\n id?: string;\n children?: ReactElement;\n openOnMount?: boolean;\n placement?: PopperPlacement;\n offset?: [number, number];\n flip?: boolean;\n enablePortal?: boolean;\n content: string;\n withArrow?: boolean;\n size?: 'spacious' | 'compact';\n maxWidth?: string | number;\n maxHeight?: string | number;\n enterDelay?: number;\n leaveDelay?: number;\n 'data-test-id'?: string;\n zIndex?: number;\n disabled?: boolean;\n 'aria-label'?: string;\n};\n\nconst getArrowClasses = (currentPlacement: string) => {\n switch (true) {\n case currentPlacement.includes('top'):\n return 'before:tw-border-t-0 before:tw-border-l-0 tw-bottom-[-6px]';\n case currentPlacement.includes('right'):\n return 'before:tw-border-t-0 before:tw-border-r-0 tw-left-[-6px]';\n case currentPlacement.includes('bottom'):\n return 'before:tw-border-b-0 before:tw-border-r-0 tw-top-[-6px]';\n case currentPlacement.includes('left'):\n return 'before:tw-border-b-0 before:tw-border-l-0 tw-right-[-6px]';\n default:\n return 'before:tw-border-b-0 before:tw-border-r-0 tw-top-[-6px]';\n }\n};\n\nconst formatTooltipText = (text: string) => {\n const lineBreakRegex = /<br\\s*\\/?>/;\n return text.split(lineBreakRegex).join('\\n');\n};\n\nconst getNewOffsetBasedOnArrowPosition = (currentPlacement: string, offset: [number, number]): [number, number] => {\n switch (true) {\n case currentPlacement.includes('end'):\n return [offset[0] + TOOLTIP_EXTRA_OFFSET_VALUE, offset[1]];\n case currentPlacement.includes('start'):\n return [offset[0] - TOOLTIP_EXTRA_OFFSET_VALUE, offset[1]];\n default:\n return offset;\n }\n};\n\nexport const Tooltip = ({\n id: customId,\n children,\n offset = [0, 8],\n flip = true,\n content,\n placement = 'bottom',\n withArrow = true,\n size = 'spacious',\n openOnMount = false,\n maxWidth = 200,\n maxHeight = 'auto',\n enablePortal = true,\n enterDelay = 0,\n leaveDelay = 200,\n disabled = false,\n zIndex = Z_INDEX_TOOLTIP,\n 'data-test-id': dataTestId = 'fondue-tooltip',\n 'aria-label': ariaLabel = 'fondue-tooltip-trigger',\n}: TooltipProps) => {\n const id = useMemoizedId(customId);\n const [open, setOpen] = useToggleOverlay(openOnMount);\n const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null);\n const [tooltipOffset, setTooltipOffset] = useState<[number, number]>(offset);\n\n const { styles, attributes, state } = usePopper(referenceElement, popperElement, {\n placement,\n modifiers: [\n { name: 'arrow', options: { element: arrowElement, padding: ARROW_DISTANCE_FROM_CORNER_VALUE } },\n { name: 'offset', options: { offset: tooltipOffset } },\n { name: 'flip', enabled: flip },\n ],\n });\n\n const currentPlacement = state?.placement ?? placement;\n const arrowStyling = getArrowClasses(currentPlacement);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(() => {\n const newOffset = getNewOffsetBasedOnArrowPosition(currentPlacement, offset);\n setTooltipOffset(newOffset);\n }, [currentPlacement, offset]);\n\n const handleHideTooltip = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n timeoutRef.current = setTimeout(() => setOpen(false), leaveDelay);\n }, [leaveDelay, setOpen]);\n\n const handleShowTooltip = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n if (enterDelay) {\n timeoutRef.current = setTimeout(() => setOpen(true), enterDelay);\n return;\n }\n\n setOpen(true);\n }, [enterDelay, setOpen]);\n\n useEffect(() => {\n if (timeoutRef.current && !open) {\n clearTimeout(timeoutRef.current);\n }\n }, [open]);\n\n return (\n <>\n <button\n ref={setReferenceElement}\n onMouseEnter={handleShowTooltip}\n onFocus={handleShowTooltip}\n onMouseLeave={handleHideTooltip}\n onBlur={handleHideTooltip}\n aria-label={ariaLabel}\n aria-disabled={disabled}\n aria-labelledby={id}\n disabled={disabled}\n className=\"disabled:tw-text-text-disabled\"\n data-test-id={`${dataTestId}-button`}\n >\n {children}\n </button>\n {open && (\n <EnablePortalWrapper enablePortal={enablePortal}>\n <div\n data-test-id={dataTestId}\n role=\"tooltip\"\n id={id}\n aria-hidden={!open}\n ref={setPopperElement}\n className={merge([\n 'tw-popper-container tw-inline-block tw-bg-box-neutral-mighty tw-rounded-md tw-shadow tw-text-heading-medium tw-text-box-neutral-mighty-inverse tw-border tw-border-line-mighty',\n size === 'spacious' ? 'tw-pt-2 tw-px-3 tw-pb-2.5' : 'tw-pt-1 tw-px-2 tw-pb-1.5',\n ])}\n style={{ ...styles.popper, maxWidth, maxHeight, zIndex }}\n {...attributes.popper}\n >\n <p className=\"tw-whitespace-pre-line\">{formatTooltipText(content)}</p>\n {withArrow && (\n <div\n data-test-id={`${dataTestId}-arrow`}\n data-popper-arrow={withArrow}\n aria-hidden=\"true\"\n ref={setArrowElement}\n style={styles.arrow}\n className={merge([\n 'tw-absolute tw-w-3 tw-h-3 tw-pointer-events-none before:tw-absolute before:tw-w-3 before:tw-h-3 before:tw-rotate-45 before:tw-border before:tw-border-line-mighty before:tw-bg-box-neutral-mighty',\n arrowStyling,\n ])}\n />\n )}\n </div>\n </EnablePortalWrapper>\n )}\n </>\n );\n};\nTooltip.displayName = 'FondueTooltip';\n"],"names":["ARROW_DISTANCE_FROM_CORNER_VALUE","TOOLTIP_EXTRA_OFFSET_VALUE","getArrowClasses","currentPlacement","formatTooltipText","text","lineBreakRegex","getNewOffsetBasedOnArrowPosition","offset","Tooltip","customId","children","flip","content","placement","withArrow","size","openOnMount","maxWidth","maxHeight","enablePortal","enterDelay","leaveDelay","disabled","zIndex","Z_INDEX_TOOLTIP","dataTestId","ariaLabel","id","useMemoizedId","open","setOpen","useToggleOverlay","referenceElement","setReferenceElement","useState","popperElement","setPopperElement","arrowElement","setArrowElement","tooltipOffset","setTooltipOffset","styles","attributes","state","usePopper","arrowStyling","timeoutRef","useRef","useEffect","newOffset","handleHideTooltip","useCallback","handleShowTooltip","jsxs","Fragment","jsx","EnablePortalWrapper","merge"],"mappings":";;;;;;;;AAWA,MAAMA,IAAmC,IACnCC,IAA6B,GAuB7BC,IAAkB,CAACC,MAA6B;AAClD,UAAQ,IAAM;AAAA,IACV,KAAKA,EAAiB,SAAS,KAAK;AACzB,aAAA;AAAA,IACX,KAAKA,EAAiB,SAAS,OAAO;AAC3B,aAAA;AAAA,IACX,KAAKA,EAAiB,SAAS,QAAQ;AAC5B,aAAA;AAAA,IACX,KAAKA,EAAiB,SAAS,MAAM;AAC1B,aAAA;AAAA,IACX;AACW,aAAA;AAAA,EACf;AACJ,GAEMC,KAAoB,CAACC,MAAiB;AACxC,QAAMC,IAAiB;AACvB,SAAOD,EAAK,MAAMC,CAAc,EAAE,KAAK;AAAA,CAAI;AAC/C,GAEMC,KAAmC,CAACJ,GAA0BK,MAA+C;AAC/G,UAAQ,IAAM;AAAA,IACV,KAAKL,EAAiB,SAAS,KAAK;AAChC,aAAO,CAACK,EAAO,CAAC,IAAIP,GAA4BO,EAAO,CAAC,CAAC;AAAA,IAC7D,KAAKL,EAAiB,SAAS,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B;AAAA,QACd,MAAK;AAAA,QACL,IAAAE;AAAA,QACA,eAAa,CAACE;AAAA,QACd,KAAKO;AAAA,QACL,WAAWqB,EAAM;AAAA,UACb;AAAA,UACA1C,MAAS,aAAa,8BAA8B;AAAA,QAAA,CACvD;AAAA,QACD,OAAO,EAAE,GAAG0B,EAAO,QAAQ,UAAAxB,GAAU,WAAAC,GAAW,QAAAK,EAAO;AAAA,QACtD,GAAGmB,EAAW;AAAA,QAEf,UAAA;AAAA,UAAA,gBAAAa,EAAC,KAAE,EAAA,WAAU,0BAA0B,UAAApD,GAAkBS,CAAO,GAAE;AAAA,UACjEE,KACG,gBAAAyC;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,gBAAc,GAAG9B,CAAU;AAAA,cAC3B,qBAAmBX;AAAA,cACnB,eAAY;AAAA,cACZ,KAAKwB;AAAA,cACL,OAAOG,EAAO;AAAA,cACd,WAAWgB,EAAM;AAAA,gBACb;AAAA,gBACAZ;AAAA,cAAA,CACH;AAAA,YAAA;AAAA,UACL;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,GAGZ;AAAA,EAER,EAAA,CAAA;AAER;AACArC,GAAQ,cAAc;"}
1
+ {"version":3,"file":"Tooltip.es.js","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { ReactElement, useCallback, useEffect, useRef, useState } from 'react';\nimport { PopperPlacement } from '@components/Popper';\nimport { usePopper } from 'react-popper';\nimport { merge } from '@utilities/merge';\nimport { useToggleOverlay } from '@hooks/useToggleOverlay';\nimport { Z_INDEX_TOOLTIP } from '@utilities/dialogs/constants';\nimport { EnablePortalWrapper } from '@utilities/dialogs/EnablePortalWrapper';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\n\nconst ARROW_DISTANCE_FROM_CORNER_VALUE = 12;\nconst TOOLTIP_EXTRA_OFFSET_VALUE = 7; // As the arrow is set 12px away from tooltip corner, extra offset should be added to still point to Trigger.\n\nexport type TooltipProps = {\n id?: string;\n children?: ReactElement;\n openOnMount?: boolean;\n placement?: PopperPlacement;\n offset?: [number, number];\n flip?: boolean;\n enablePortal?: boolean;\n content: string;\n withArrow?: boolean;\n size?: 'spacious' | 'compact';\n maxWidth?: string | number;\n maxHeight?: string | number;\n enterDelay?: number;\n leaveDelay?: number;\n 'data-test-id'?: string;\n zIndex?: number;\n disabled?: boolean;\n 'aria-label'?: string;\n};\n\nconst getArrowClasses = (currentPlacement: string) => {\n switch (true) {\n case currentPlacement.includes('top'):\n return 'before:tw-border-t-0 before:tw-border-l-0 tw-bottom-[-6px]';\n case currentPlacement.includes('right'):\n return 'before:tw-border-t-0 before:tw-border-r-0 tw-left-[-6px]';\n case currentPlacement.includes('bottom'):\n return 'before:tw-border-b-0 before:tw-border-r-0 tw-top-[-6px]';\n case currentPlacement.includes('left'):\n return 'before:tw-border-b-0 before:tw-border-l-0 tw-right-[-6px]';\n default:\n return 'before:tw-border-b-0 before:tw-border-r-0 tw-top-[-6px]';\n }\n};\n\nconst formatTooltipText = (text: string) => {\n const lineBreakRegex = /<br\\s*\\/?>/;\n return text.split(lineBreakRegex).join('\\n');\n};\n\nconst getNewOffsetBasedOnArrowPosition = (currentPlacement: string, offset: [number, number]): [number, number] => {\n switch (true) {\n case currentPlacement.includes('end'):\n return [offset[0] + TOOLTIP_EXTRA_OFFSET_VALUE, offset[1]];\n case currentPlacement.includes('start'):\n return [offset[0] - TOOLTIP_EXTRA_OFFSET_VALUE, offset[1]];\n default:\n return offset;\n }\n};\n\nexport const Tooltip = ({\n id: customId,\n children,\n offset = [0, 8],\n flip = true,\n content,\n placement = 'bottom',\n withArrow = true,\n size = 'spacious',\n openOnMount = false,\n maxWidth = 200,\n maxHeight = 'auto',\n enablePortal = true,\n enterDelay = 0,\n leaveDelay = 200,\n disabled = false,\n zIndex = Z_INDEX_TOOLTIP,\n 'data-test-id': dataTestId = 'fondue-tooltip',\n 'aria-label': ariaLabel = 'fondue-tooltip-trigger',\n}: TooltipProps) => {\n const id = useMemoizedId(customId);\n const [open, setOpen] = useToggleOverlay(openOnMount);\n const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null);\n const [tooltipOffset, setTooltipOffset] = useState<[number, number]>(offset);\n\n const { styles, attributes, state } = usePopper(referenceElement, popperElement, {\n placement,\n modifiers: [\n { name: 'arrow', options: { element: arrowElement, padding: ARROW_DISTANCE_FROM_CORNER_VALUE } },\n { name: 'offset', options: { offset: tooltipOffset } },\n { name: 'flip', enabled: flip },\n ],\n });\n\n const currentPlacement = state?.placement ?? placement;\n const arrowStyling = getArrowClasses(currentPlacement);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(() => {\n const newOffset = getNewOffsetBasedOnArrowPosition(currentPlacement, offset);\n setTooltipOffset(newOffset);\n }, [currentPlacement, offset]);\n\n const handleHideTooltip = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n timeoutRef.current = setTimeout(() => setOpen(false), leaveDelay);\n }, [leaveDelay, setOpen]);\n\n const handleShowTooltip = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n if (enterDelay) {\n timeoutRef.current = setTimeout(() => setOpen(true), enterDelay);\n return;\n }\n\n setOpen(true);\n }, [enterDelay, setOpen]);\n\n useEffect(() => {\n if (timeoutRef.current && !open) {\n clearTimeout(timeoutRef.current);\n }\n }, [open]);\n\n return (\n <>\n <button\n ref={setReferenceElement}\n onMouseEnter={handleShowTooltip}\n onFocus={handleShowTooltip}\n onMouseLeave={handleHideTooltip}\n onBlur={handleHideTooltip}\n aria-label={ariaLabel}\n aria-disabled={disabled}\n aria-describedby={id}\n disabled={disabled}\n className=\"disabled:tw-text-text-disabled\"\n data-test-id={`${dataTestId}-button`}\n >\n {children}\n </button>\n {open && (\n <EnablePortalWrapper enablePortal={enablePortal}>\n <div\n data-test-id={dataTestId}\n role=\"tooltip\"\n id={id}\n aria-hidden={!open}\n ref={setPopperElement}\n className={merge([\n 'tw-popper-container tw-inline-block tw-bg-box-neutral-mighty tw-rounded-md tw-shadow tw-text-heading-medium tw-text-box-neutral-mighty-inverse tw-border tw-border-line-mighty',\n size === 'spacious' ? 'tw-pt-2 tw-px-3 tw-pb-2.5' : 'tw-pt-1 tw-px-2 tw-pb-1.5',\n ])}\n style={{ ...styles.popper, maxWidth, maxHeight, zIndex }}\n {...attributes.popper}\n >\n <p className=\"tw-whitespace-pre-line\">{formatTooltipText(content)}</p>\n {withArrow && (\n <div\n data-test-id={`${dataTestId}-arrow`}\n data-popper-arrow={withArrow}\n aria-hidden=\"true\"\n ref={setArrowElement}\n style={styles.arrow}\n className={merge([\n 'tw-absolute tw-w-3 tw-h-3 tw-pointer-events-none before:tw-absolute before:tw-w-3 before:tw-h-3 before:tw-rotate-45 before:tw-border before:tw-border-line-mighty before:tw-bg-box-neutral-mighty',\n arrowStyling,\n ])}\n />\n )}\n </div>\n </EnablePortalWrapper>\n )}\n </>\n );\n};\nTooltip.displayName = 'FondueTooltip';\n"],"names":["ARROW_DISTANCE_FROM_CORNER_VALUE","TOOLTIP_EXTRA_OFFSET_VALUE","getArrowClasses","currentPlacement","formatTooltipText","text","lineBreakRegex","getNewOffsetBasedOnArrowPosition","offset","Tooltip","customId","children","flip","content","placement","withArrow","size","openOnMount","maxWidth","maxHeight","enablePortal","enterDelay","leaveDelay","disabled","zIndex","Z_INDEX_TOOLTIP","dataTestId","ariaLabel","id","useMemoizedId","open","setOpen","useToggleOverlay","referenceElement","setReferenceElement","useState","popperElement","setPopperElement","arrowElement","setArrowElement","tooltipOffset","setTooltipOffset","styles","attributes","state","usePopper","arrowStyling","timeoutRef","useRef","useEffect","newOffset","handleHideTooltip","useCallback","handleShowTooltip","jsxs","Fragment","jsx","EnablePortalWrapper","merge"],"mappings":";;;;;;;;AAWA,M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CACH;AAAA,YAAA;AAAA,UACL;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,GAGZ;AAAA,EAER,EAAA,CAAA;AAER;AACArC,GAAQ,cAAc;"}
@@ -3,7 +3,7 @@ const r = () => {
3
3
  const [t, n] = i(!1);
4
4
  return s(() => {
5
5
  const e = () => {
6
- const o = window.matchMedia("only screen and (max-width: 480px)").matches;
6
+ const o = window.matchMedia("only screen and (max-width: 640px)").matches;
7
7
  n(o);
8
8
  };
9
9
  return e(), window.addEventListener("resize", e), window.addEventListener("load", e), () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useMobileDetection.es.js","sources":["../../src/hooks/useMobileDetection.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useEffect, useState } from 'react';\n\nconst useMobileDetection = () => {\n const [isMobile, setIsMobile] = useState(false);\n\n useEffect(() => {\n const handleDeviceDetection = () => {\n const isMobileScreen = window.matchMedia('only screen and (max-width: 480px)').matches;\n\n setIsMobile(isMobileScreen);\n };\n\n handleDeviceDetection();\n window.addEventListener('resize', handleDeviceDetection);\n window.addEventListener('load', handleDeviceDetection);\n\n return () => {\n window.removeEventListener('resize', handleDeviceDetection);\n window.removeEventListener('load', handleDeviceDetection);\n };\n }, []);\n\n return isMobile;\n};\n\nexport default useMobileDetection;\n"],"names":["useMobileDetection","isMobile","setIsMobile","useState","useEffect","handleDeviceDetection","isMobileScreen","useMobileDetection$1"],"mappings":";AAIA,MAAMA,IAAqB,MAAM;AAC7B,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,EAAK;AAE9C,SAAAC,EAAU,MAAM;AACZ,UAAMC,IAAwB,MAAM;AAChC,YAAMC,IAAiB,OAAO,WAAW,oCAAoC,EAAE;AAE/E,MAAAJ,EAAYI,CAAc;AAAA,IAAA;AAGR,WAAAD,KACf,OAAA,iBAAiB,UAAUA,CAAqB,GAChD,OAAA,iBAAiB,QAAQA,CAAqB,GAE9C,MAAM;AACF,aAAA,oBAAoB,UAAUA,CAAqB,GACnD,OAAA,oBAAoB,QAAQA,CAAqB;AAAA,IAAA;AAAA,EAEhE,GAAG,CAAE,CAAA,GAEEJ;AACX,GAEAM,IAAeP;"}
1
+ {"version":3,"file":"useMobileDetection.es.js","sources":["../../src/hooks/useMobileDetection.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useEffect, useState } from 'react';\n\nconst useMobileDetection = () => {\n const [isMobile, setIsMobile] = useState(false);\n\n useEffect(() => {\n const handleDeviceDetection = () => {\n const isSmallScreen = window.matchMedia('only screen and (max-width: 640px)').matches;\n\n setIsMobile(isSmallScreen);\n };\n\n handleDeviceDetection();\n window.addEventListener('resize', handleDeviceDetection);\n window.addEventListener('load', handleDeviceDetection);\n\n return () => {\n window.removeEventListener('resize', handleDeviceDetection);\n window.removeEventListener('load', handleDeviceDetection);\n };\n }, []);\n\n return isMobile;\n};\n\nexport default useMobileDetection;\n"],"names":["useMobileDetection","isMobile","setIsMobile","useState","useEffect","handleDeviceDetection","isSmallScreen","useMobileDetection$1"],"mappings":";AAIA,MAAMA,IAAqB,MAAM;AAC7B,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,EAAK;AAE9C,SAAAC,EAAU,MAAM;AACZ,UAAMC,IAAwB,MAAM;AAChC,YAAMC,IAAgB,OAAO,WAAW,oCAAoC,EAAE;AAE9E,MAAAJ,EAAYI,CAAa;AAAA,IAAA;AAGP,WAAAD,KACf,OAAA,iBAAiB,UAAUA,CAAqB,GAChD,OAAA,iBAAiB,QAAQA,CAAqB,GAE9C,MAAM;AACF,aAAA,oBAAoB,UAAUA,CAAqB,GACnD,OAAA,oBAAoB,QAAQA,CAAqB;AAAA,IAAA;AAAA,EAEhE,GAAG,CAAE,CAAA,GAEEJ;AACX,GAEAM,IAAeP;"}