@frontify/fondue 12.0.0-beta.375 → 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.
- package/dist/components/Popper/Popper.es.js +43 -38
- package/dist/components/Popper/Popper.es.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.es.js +1 -1
- package/dist/components/Tooltip/Tooltip.es.js.map +1 -1
- package/dist/hooks/useMobileDetection.es.js +1 -1
- package/dist/hooks/useMobileDetection.es.js.map +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,71 +1,76 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as i, useLayoutEffect as
|
|
3
|
-
import { Trigger as
|
|
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
|
|
5
|
+
import { usePopper as x } from "react-popper";
|
|
6
6
|
import { Portal as H } from "../Portal/Portal.es.js";
|
|
7
|
-
const S = 200,
|
|
8
|
-
left: `${(window.innerWidth -
|
|
9
|
-
top: r ?
|
|
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:
|
|
12
|
+
children: p,
|
|
13
13
|
open: r,
|
|
14
|
-
placement:
|
|
15
|
-
offset:
|
|
16
|
-
flip:
|
|
14
|
+
placement: P = "bottom-start",
|
|
15
|
+
offset: h = [0, 8],
|
|
16
|
+
flip: w = !0,
|
|
17
17
|
enablePortal: g = !0,
|
|
18
|
-
zIndex:
|
|
18
|
+
zIndex: a = "auto",
|
|
19
19
|
isDetached: s = !1,
|
|
20
20
|
verticalAlignment: T,
|
|
21
|
-
strategy:
|
|
21
|
+
strategy: L = "absolute"
|
|
22
22
|
}) => {
|
|
23
|
-
const [_, b] = i(null), [
|
|
23
|
+
const [_, b] = i(null), [v, l] = i(null), [O, A] = i({
|
|
24
24
|
width: S,
|
|
25
|
-
height:
|
|
26
|
-
}), t =
|
|
27
|
-
placement:
|
|
25
|
+
height: C
|
|
26
|
+
}), t = x(s ? document.body : _, v, {
|
|
27
|
+
placement: P,
|
|
28
28
|
modifiers: [
|
|
29
|
-
{ name: "offset", options: { offset:
|
|
29
|
+
{ name: "offset", options: { offset: h } },
|
|
30
30
|
{
|
|
31
31
|
name: "flip",
|
|
32
|
-
enabled:
|
|
32
|
+
enabled: w
|
|
33
33
|
}
|
|
34
34
|
],
|
|
35
|
-
strategy:
|
|
35
|
+
strategy: L
|
|
36
36
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 ?
|
|
45
|
-
return /* @__PURE__ */
|
|
46
|
-
if (
|
|
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 ===
|
|
49
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
56
|
+
return g ? /* @__PURE__ */ n(H, { children: /* @__PURE__ */ n(
|
|
52
57
|
"div",
|
|
53
58
|
{
|
|
54
|
-
ref:
|
|
59
|
+
ref: l,
|
|
55
60
|
style: {
|
|
56
|
-
zIndex:
|
|
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__ */
|
|
68
|
+
) }) : /* @__PURE__ */ n(
|
|
64
69
|
"div",
|
|
65
70
|
{
|
|
66
|
-
ref:
|
|
71
|
+
ref: l,
|
|
67
72
|
style: {
|
|
68
|
-
zIndex:
|
|
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 =
|
|
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
|
|
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,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,YAAA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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 +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","newOff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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,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,SA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,KACI,gBAAA0B,EAAAC,GAAA,EAAoB,cAAArC,GACjB,UAAA,gBAAAkC;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,gBAAc5B;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;"}
|
|
@@ -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:
|
|
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
|
|
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;"}
|