@fanvue/ui 3.23.0 → 3.24.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/charts.d.ts +94 -4
- package/dist/charts.mjs +4 -0
- package/dist/charts.mjs.map +1 -1
- package/dist/cjs/charts.cjs +4 -0
- package/dist/cjs/charts.cjs.map +1 -1
- package/dist/cjs/components/AiButton/AiButton.cjs +170 -0
- package/dist/cjs/components/AiButton/AiButton.cjs.map +1 -0
- package/dist/cjs/components/AnimatedNumber/AnimatedNumber.cjs +170 -0
- package/dist/cjs/components/AnimatedNumber/AnimatedNumber.cjs.map +1 -0
- package/dist/cjs/components/Chart/ChartLoadingOverlay.cjs +24 -2
- package/dist/cjs/components/Chart/ChartLoadingOverlay.cjs.map +1 -1
- package/dist/cjs/components/Chart/ChartMetricTrend.cjs +71 -0
- package/dist/cjs/components/Chart/ChartMetricTrend.cjs.map +1 -0
- package/dist/cjs/components/Chart/ChartSkeleton.cjs +95 -0
- package/dist/cjs/components/Chart/ChartSkeleton.cjs.map +1 -0
- package/dist/cjs/components/Chip/Chip.cjs +40 -11
- package/dist/cjs/components/Chip/Chip.cjs.map +1 -1
- package/dist/cjs/components/CountryFlag/CountryFlag.cjs +91 -0
- package/dist/cjs/components/CountryFlag/CountryFlag.cjs.map +1 -0
- package/dist/cjs/components/CountryFlag/flagShapes.cjs +3358 -0
- package/dist/cjs/components/CountryFlag/flagShapes.cjs.map +1 -0
- package/dist/cjs/components/CyclingText/CyclingText.cjs +9 -26
- package/dist/cjs/components/CyclingText/CyclingText.cjs.map +1 -1
- package/dist/cjs/components/CyclingText/useCyclingMotion.cjs +53 -0
- package/dist/cjs/components/CyclingText/useCyclingMotion.cjs.map +1 -0
- package/dist/cjs/components/Demographics/Demographics.cjs +39 -0
- package/dist/cjs/components/Demographics/Demographics.cjs.map +1 -0
- package/dist/cjs/components/Drawer/Drawer.cjs +9 -1
- package/dist/cjs/components/Drawer/Drawer.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs +122 -16
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
- package/dist/cjs/components/IconButton/IconButton.cjs +11 -1
- package/dist/cjs/components/IconButton/IconButton.cjs.map +1 -1
- package/dist/cjs/components/ProgressBar/ProgressBar.cjs +9 -1
- package/dist/cjs/components/ProgressBar/ProgressBar.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsList.cjs +123 -91
- package/dist/cjs/components/Tabs/TabsList.cjs.map +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.cjs +36 -25
- package/dist/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
- package/dist/cjs/components/Tooltip/TooltipLabel.cjs +71 -0
- package/dist/cjs/components/Tooltip/TooltipLabel.cjs.map +1 -0
- package/dist/cjs/components/TrendPill/TrendPill.cjs +46 -0
- package/dist/cjs/components/TrendPill/TrendPill.cjs.map +1 -0
- package/dist/cjs/components/UserItem/UserItem.cjs +7 -2
- package/dist/cjs/components/UserItem/UserItem.cjs.map +1 -1
- package/dist/cjs/components/UserItem/UserItemTrailing.cjs +34 -0
- package/dist/cjs/components/UserItem/UserItemTrailing.cjs.map +1 -0
- package/dist/cjs/flags.cjs +6 -0
- package/dist/cjs/flags.cjs.map +1 -0
- package/dist/cjs/index.cjs +13 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{components/CyclingText → utils}/usePrefersReducedMotion.cjs +14 -14
- package/dist/cjs/utils/usePrefersReducedMotion.cjs.map +1 -0
- package/dist/components/AiButton/AiButton.mjs +153 -0
- package/dist/components/AiButton/AiButton.mjs.map +1 -0
- package/dist/components/AnimatedNumber/AnimatedNumber.mjs +153 -0
- package/dist/components/AnimatedNumber/AnimatedNumber.mjs.map +1 -0
- package/dist/components/Chart/ChartLoadingOverlay.mjs +24 -2
- package/dist/components/Chart/ChartLoadingOverlay.mjs.map +1 -1
- package/dist/components/Chart/ChartMetricTrend.mjs +54 -0
- package/dist/components/Chart/ChartMetricTrend.mjs.map +1 -0
- package/dist/components/Chart/ChartSkeleton.mjs +78 -0
- package/dist/components/Chart/ChartSkeleton.mjs.map +1 -0
- package/dist/components/Chip/Chip.mjs +40 -11
- package/dist/components/Chip/Chip.mjs.map +1 -1
- package/dist/components/CountryFlag/CountryFlag.mjs +74 -0
- package/dist/components/CountryFlag/CountryFlag.mjs.map +1 -0
- package/dist/components/CountryFlag/flagShapes.mjs +3358 -0
- package/dist/components/CountryFlag/flagShapes.mjs.map +1 -0
- package/dist/components/CyclingText/CyclingText.mjs +9 -26
- package/dist/components/CyclingText/CyclingText.mjs.map +1 -1
- package/dist/components/CyclingText/useCyclingMotion.mjs +36 -0
- package/dist/components/CyclingText/useCyclingMotion.mjs.map +1 -0
- package/dist/components/Demographics/Demographics.mjs +22 -0
- package/dist/components/Demographics/Demographics.mjs.map +1 -0
- package/dist/components/Drawer/Drawer.mjs +9 -1
- package/dist/components/Drawer/Drawer.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.mjs +122 -16
- package/dist/components/DropdownMenu/DropdownMenu.mjs.map +1 -1
- package/dist/components/IconButton/IconButton.mjs +11 -1
- package/dist/components/IconButton/IconButton.mjs.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.mjs +9 -1
- package/dist/components/ProgressBar/ProgressBar.mjs.map +1 -1
- package/dist/components/Tabs/TabsList.mjs +123 -91
- package/dist/components/Tabs/TabsList.mjs.map +1 -1
- package/dist/components/Tooltip/Tooltip.mjs +37 -26
- package/dist/components/Tooltip/Tooltip.mjs.map +1 -1
- package/dist/components/Tooltip/TooltipLabel.mjs +54 -0
- package/dist/components/Tooltip/TooltipLabel.mjs.map +1 -0
- package/dist/components/TrendPill/TrendPill.mjs +29 -0
- package/dist/components/TrendPill/TrendPill.mjs.map +1 -0
- package/dist/components/UserItem/UserItem.mjs +7 -2
- package/dist/components/UserItem/UserItem.mjs.map +1 -1
- package/dist/components/UserItem/UserItemTrailing.mjs +17 -0
- package/dist/components/UserItem/UserItemTrailing.mjs.map +1 -0
- package/dist/flags.d.ts +59 -0
- package/dist/flags.mjs +6 -0
- package/dist/flags.mjs.map +1 -0
- package/dist/index.d.ts +381 -11
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/dist/styles/base.css +166 -0
- package/dist/styles/theme.css +12 -0
- package/dist/utils/usePrefersReducedMotion.mjs +22 -0
- package/dist/utils/usePrefersReducedMotion.mjs.map +1 -0
- package/package.json +13 -2
- package/dist/cjs/components/CyclingText/usePrefersReducedMotion.cjs.map +0 -1
- package/dist/components/CyclingText/usePrefersReducedMotion.mjs +0 -22
- package/dist/components/CyclingText/usePrefersReducedMotion.mjs.map +0 -1
|
@@ -3,12 +3,11 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cn } from "../../utils/cn.mjs";
|
|
5
5
|
import { useCyclingCycle } from "./useCyclingCycle.mjs";
|
|
6
|
+
import { useCyclingMotion } from "./useCyclingMotion.mjs";
|
|
6
7
|
import { useCyclingTextTrackWidth } from "./useCyclingTextTrackWidth.mjs";
|
|
7
8
|
import { usePageVisibility } from "./usePageVisibility.mjs";
|
|
8
|
-
import { usePrefersReducedMotion } from "./usePrefersReducedMotion.mjs";
|
|
9
9
|
const DEFAULT_INTERVAL_MS = 2100;
|
|
10
10
|
const DEFAULT_TRANSITION_MS = 200;
|
|
11
|
-
const SLIDE_OFFSET_PX = 18;
|
|
12
11
|
const CyclingText = React.forwardRef(
|
|
13
12
|
({
|
|
14
13
|
items,
|
|
@@ -24,7 +23,6 @@ const CyclingText = React.forwardRef(
|
|
|
24
23
|
...rest
|
|
25
24
|
}, ref) => {
|
|
26
25
|
const docVisible = usePageVisibility();
|
|
27
|
-
const reducedMotion = usePrefersReducedMotion();
|
|
28
26
|
const { sizingLabelRef, trackWidth } = useCyclingTextTrackWidth();
|
|
29
27
|
const {
|
|
30
28
|
cycle,
|
|
@@ -42,32 +40,17 @@ const CyclingText = React.forwardRef(
|
|
|
42
40
|
React.useEffect(() => {
|
|
43
41
|
onActiveIndexChangeRef.current?.(currentIndex);
|
|
44
42
|
}, [currentIndex]);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
transform: exiting ? `translate3d(0, ${yExit}px, 0)` : "translate3d(0, 0, 0)",
|
|
52
|
-
transition: exiting && durMs > 0 ? `opacity ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1), transform ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1)` : "none"
|
|
53
|
-
};
|
|
54
|
-
}, [cycle.transitioning, direction, transitionMs, reducedMotion]);
|
|
55
|
-
const incomingMotionStyle = React.useMemo(() => {
|
|
56
|
-
const durMs = reducedMotion ? 0 : transitionMs;
|
|
57
|
-
const entered = cycle.incomingEntered;
|
|
58
|
-
const yEnter = direction === "up" ? SLIDE_OFFSET_PX : -SLIDE_OFFSET_PX;
|
|
59
|
-
return {
|
|
60
|
-
opacity: entered ? 1 : 0,
|
|
61
|
-
transform: entered ? "translate3d(0, 0, 0)" : `translate3d(0, ${yEnter}px, 0)`,
|
|
62
|
-
transition: durMs > 0 ? `opacity ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1), transform ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1)` : "none"
|
|
63
|
-
};
|
|
64
|
-
}, [cycle.incomingEntered, direction, transitionMs, reducedMotion]);
|
|
43
|
+
const { outgoingStyle, incomingStyle } = useCyclingMotion({
|
|
44
|
+
transitioning: cycle.transitioning,
|
|
45
|
+
incomingEntered: cycle.incomingEntered,
|
|
46
|
+
direction,
|
|
47
|
+
transitionMs
|
|
48
|
+
});
|
|
65
49
|
if (itemCount === 0) {
|
|
66
50
|
return null;
|
|
67
51
|
}
|
|
68
52
|
const wrapperStyle = {
|
|
69
53
|
...trackWidth !== null ? { width: `${trackWidth}px` } : {}
|
|
70
|
-
// paddingTop: SLIDE_OFFSET_PX,
|
|
71
54
|
};
|
|
72
55
|
const showIncoming = incomingLabel !== null && cycle.transitioning;
|
|
73
56
|
return /* @__PURE__ */ jsxs(
|
|
@@ -108,7 +91,7 @@ const CyclingText = React.forwardRef(
|
|
|
108
91
|
"absolute inset-0 flex items-center whitespace-nowrap leading-[inherit]",
|
|
109
92
|
labelClassName
|
|
110
93
|
),
|
|
111
|
-
style:
|
|
94
|
+
style: outgoingStyle,
|
|
112
95
|
children: currentLabel
|
|
113
96
|
}
|
|
114
97
|
),
|
|
@@ -122,7 +105,7 @@ const CyclingText = React.forwardRef(
|
|
|
122
105
|
"absolute inset-0 flex items-center whitespace-nowrap leading-[inherit]",
|
|
123
106
|
labelClassName
|
|
124
107
|
),
|
|
125
|
-
style:
|
|
108
|
+
style: incomingStyle,
|
|
126
109
|
children: incomingLabel
|
|
127
110
|
}
|
|
128
111
|
) : null
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CyclingText.mjs","sources":["../../../src/components/CyclingText/CyclingText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useCyclingCycle } from \"./useCyclingCycle\";\nimport { useCyclingTextTrackWidth } from \"./useCyclingTextTrackWidth\";\nimport { usePageVisibility } from \"./usePageVisibility\";\nimport { usePrefersReducedMotion } from \"./usePrefersReducedMotion\";\n\nconst DEFAULT_INTERVAL_MS = 2100;\nconst DEFAULT_TRANSITION_MS = 200;\n\nconst SLIDE_OFFSET_PX = 18;\n\n/** How the wrapper should be sized to accommodate variable-length items. */\nexport type CyclingTextSizing = \"longest\" | \"current\";\n\nexport interface CyclingTextProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n /** Strings to cycle through, in order. Cycles back to the first after the last. */\n items: readonly string[];\n /**\n * Milliseconds to wait after the previous transition finishes before starting the next one.\n * @default 2100\n */\n intervalMs?: number;\n /** Slide and cross-fade duration in milliseconds. @default 200 */\n transitionMs?: number;\n /** Direction the outgoing item slides. @default \"up\" */\n direction?: \"up\" | \"down\";\n /** When true, freezes on the current item — no further cycling until cleared. @default false */\n paused?: boolean;\n /**\n * How the wrapper sizes itself horizontally.\n * - `longest` reserves space for the longest item — no width jitter as items cycle.\n * - `current` shrinks/grows with each item, animating width between cycles.\n * @default \"longest\"\n */\n sizing?: CyclingTextSizing;\n /**\n * When `true`, updates are exposed to assistive technologies via `aria-live=\"polite\"`.\n * Leave `false` for decorative or frequently changing copy so screen readers are not interrupted on every cycle.\n * @default false\n */\n announceChanges?: boolean;\n /**\n * Class applied to each visible label span (current + incoming). Use this for\n * effects that have to sit on the text element itself, e.g. `background-clip: text`.\n */\n labelClassName?: string;\n /**\n * Called with the index of the settled, fully-visible item — once on mount and\n * again whenever it changes (after each transition completes). Lets a parent\n * stay in lockstep with what is on screen (e.g. to act on the item the user is\n * currently looking at) without running a second, drifting timer of its own.\n */\n onActiveIndexChange?: (index: number) => void;\n}\n\n/**\n * Cycles through a list of strings with a slide-in/slide-out animation. Lives\n * inline so it can sit inside divs, spans, buttons, or as a fake placeholder\n * overlay.\n *\n * @example\n * ```tsx\n * <CyclingText items={[\"Thinking\", \"Reading messages\", \"Drafting reply\"]} />\n * ```\n */\nexport const CyclingText = React.forwardRef<HTMLSpanElement, CyclingTextProps>(\n (\n {\n items,\n intervalMs = DEFAULT_INTERVAL_MS,\n transitionMs = DEFAULT_TRANSITION_MS,\n direction = \"up\",\n paused = false,\n sizing = \"longest\",\n className,\n labelClassName,\n announceChanges = false,\n onActiveIndexChange,\n ...rest\n },\n ref,\n ) => {\n const docVisible = usePageVisibility();\n const reducedMotion = usePrefersReducedMotion();\n const { sizingLabelRef, trackWidth } = useCyclingTextTrackWidth();\n const {\n cycle,\n currentIndex,\n currentLabel,\n incomingLabel,\n sizingLabel,\n onOutgoingTransitionEnd,\n } = useCyclingCycle(items, sizing, intervalMs, paused, docVisible, transitionMs);\n\n const itemCount = items.length;\n\n // Notify the parent of the settled active index without re-subscribing when\n // an inline callback identity changes each render — the latest is always\n // read from the ref.\n const onActiveIndexChangeRef = React.useRef(onActiveIndexChange);\n React.useEffect(() => {\n onActiveIndexChangeRef.current = onActiveIndexChange;\n }, [onActiveIndexChange]);\n React.useEffect(() => {\n onActiveIndexChangeRef.current?.(currentIndex);\n }, [currentIndex]);\n\n const outgoingMotionStyle = React.useMemo((): React.CSSProperties => {\n const durMs = reducedMotion ? 0 : transitionMs;\n const exiting = cycle.transitioning;\n const yExit = direction === \"up\" ? -SLIDE_OFFSET_PX : SLIDE_OFFSET_PX;\n return {\n opacity: exiting ? 0 : 1,\n transform: exiting ? `translate3d(0, ${yExit}px, 0)` : \"translate3d(0, 0, 0)\",\n transition:\n exiting && durMs > 0\n ? `opacity ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1), transform ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1)`\n : \"none\",\n };\n }, [cycle.transitioning, direction, transitionMs, reducedMotion]);\n\n const incomingMotionStyle = React.useMemo((): React.CSSProperties => {\n const durMs = reducedMotion ? 0 : transitionMs;\n const entered = cycle.incomingEntered;\n const yEnter = direction === \"up\" ? SLIDE_OFFSET_PX : -SLIDE_OFFSET_PX;\n return {\n opacity: entered ? 1 : 0,\n transform: entered ? \"translate3d(0, 0, 0)\" : `translate3d(0, ${yEnter}px, 0)`,\n transition:\n durMs > 0\n ? `opacity ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1), transform ${durMs}ms cubic-bezier(0.4, 0, 0.2, 1)`\n : \"none\",\n };\n }, [cycle.incomingEntered, direction, transitionMs, reducedMotion]);\n\n if (itemCount === 0) {\n return null;\n }\n\n const wrapperStyle = {\n ...(trackWidth !== null ? { width: `${trackWidth}px` } : {}),\n // paddingTop: SLIDE_OFFSET_PX,\n } as React.CSSProperties;\n\n const showIncoming = incomingLabel !== null && cycle.transitioning;\n\n return (\n <span\n ref={ref}\n data-testid=\"cycling-text\"\n data-paused={paused ? \"true\" : undefined}\n className={cn(\n \"relative inline-flex items-center overflow-hidden align-middle leading-[inherit]\",\n \"motion-safe:transition-[width] motion-safe:duration-300 motion-safe:ease-out\",\n className,\n )}\n style={wrapperStyle}\n {...rest}\n >\n <span\n ref={sizingLabelRef}\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none invisible inline-block select-none whitespace-nowrap leading-[inherit]\",\n labelClassName,\n )}\n >\n {sizingLabel}\n </span>\n\n <span\n data-layer=\"current\"\n aria-live={announceChanges ? \"polite\" : undefined}\n aria-atomic={announceChanges ? true : undefined}\n data-state={cycle.transitioning ? \"exit\" : \"idle\"}\n onTransitionEnd={onOutgoingTransitionEnd}\n className={cn(\n \"absolute inset-0 flex items-center whitespace-nowrap leading-[inherit]\",\n labelClassName,\n )}\n style={outgoingMotionStyle}\n >\n {currentLabel}\n </span>\n\n {showIncoming ? (\n <span\n aria-hidden=\"true\"\n data-layer=\"incoming\"\n data-state={cycle.incomingEntered ? \"idle\" : \"enter\"}\n className={cn(\n \"absolute inset-0 flex items-center whitespace-nowrap leading-[inherit]\",\n labelClassName,\n )}\n style={incomingMotionStyle}\n >\n {incomingLabel}\n </span>\n ) : null}\n </span>\n );\n },\n);\n\nCyclingText.displayName = \"CyclingText\";\n"],"names":[],"mappings":";;;;;;;;AAOA,MAAM,sBAAsB;AAC5B,MAAM,wBAAwB;AAE9B,MAAM,kBAAkB;AAwDjB,MAAM,cAAc,MAAM;AAAA,EAC/B,CACE;AAAA,IACE;AAAA,IACA,aAAa;AAAA,IACb,eAAe;AAAA,IACf,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,aAAa,kBAAA;AACnB,UAAM,gBAAgB,wBAAA;AACtB,UAAM,EAAE,gBAAgB,WAAA,IAAe,yBAAA;AACvC,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA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AAM;AAErD,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,eAAY;AAAA,QACZ,eAAa,SAAS,SAAS;AAAA,QAC/B,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAEF,OAAO;AAAA,QACN,GAAG;AAAA,QAEJ,UAAA;AAAA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL,eAAY;AAAA,cACZ,WAAW;AAAA,gBACT;AAAA,gBACA;AAAA,cAAA;AAAA,cAGD,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,UAGH;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,cAAW;AAAA,cACX,aAAW,kBAAkB,WAAW;AAAA,cACxC,eAAa,kBAAkB,OAAO;AAAA,cACtC,cAAY,MAAM,gBAAgB,SAAS;AAAA,cAC3C,iBAAiB;AAAA,cACjB,WAAW;AAAA,gBACT;AAAA,gBACA;AAAA,cAAA;AAAA,cAEF,OAAO;AAAA,cAEN,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,UAGF,eACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,eAAY;AAAA,cACZ,cAAW;AAAA,cACX,cAAY,MAAM,kBAAkB,SAAS;AAAA,cAC7C,WAAW;AAAA,gBACT;AAAA,gBACA;AAAA,cAAA;AAAA,cAEF,OAAO;AAAA,cAEN,UAAA;AAAA,YAAA;AAAA,UAAA,IAED;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGV;AACF;AAEA,YAAY,cAAc;"}
|
|
1
|
+
{"version":3,"file":"CyclingText.mjs","sources":["../../../src/components/CyclingText/CyclingText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useCyclingCycle } from \"./useCyclingCycle\";\nimport { useCyclingMotion } from \"./useCyclingMotion\";\nimport { useCyclingTextTrackWidth } from \"./useCyclingTextTrackWidth\";\nimport { usePageVisibility } from \"./usePageVisibility\";\n\nconst DEFAULT_INTERVAL_MS = 2100;\nconst DEFAULT_TRANSITION_MS = 200;\n\n/** How the wrapper should be sized to accommodate variable-length items. */\nexport type CyclingTextSizing = \"longest\" | \"current\";\n\nexport interface CyclingTextProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n /** Strings to cycle through, in order. Cycles back to the first after the last. */\n items: readonly string[];\n /**\n * Milliseconds to wait after the previous transition finishes before starting the next one.\n * @default 2100\n */\n intervalMs?: number;\n /** Slide and cross-fade duration in milliseconds. @default 200 */\n transitionMs?: number;\n /** Direction the outgoing item slides. @default \"up\" */\n direction?: \"up\" | \"down\";\n /** When true, freezes on the current item — no further cycling until cleared. @default false */\n paused?: boolean;\n /**\n * How the wrapper sizes itself horizontally.\n * - `longest` reserves space for the longest item — no width jitter as items cycle.\n * - `current` shrinks/grows with each item, animating width between cycles.\n * @default \"longest\"\n */\n sizing?: CyclingTextSizing;\n /**\n * When `true`, updates are exposed to assistive technologies via `aria-live=\"polite\"`.\n * Leave `false` for decorative or frequently changing copy so screen readers are not interrupted on every cycle.\n * @default false\n */\n announceChanges?: boolean;\n /**\n * Class applied to each visible label span (current + incoming). Use this for\n * effects that have to sit on the text element itself, e.g. `background-clip: text`.\n */\n labelClassName?: string;\n /**\n * Called with the index of the settled, fully-visible item — once on mount and\n * again whenever it changes (after each transition completes). Lets a parent\n * stay in lockstep with what is on screen (e.g. to act on the item the user is\n * currently looking at) without running a second, drifting timer of its own.\n */\n onActiveIndexChange?: (index: number) => void;\n}\n\n/**\n * Cycles through a list of strings with a slide-in/slide-out animation. Lives\n * inline so it can sit inside divs, spans, buttons, or as a fake placeholder\n * overlay.\n *\n * @example\n * ```tsx\n * <CyclingText items={[\"Thinking\", \"Reading messages\", \"Drafting reply\"]} />\n * ```\n */\nexport const CyclingText = React.forwardRef<HTMLSpanElement, CyclingTextProps>(\n (\n {\n items,\n intervalMs = DEFAULT_INTERVAL_MS,\n transitionMs = DEFAULT_TRANSITION_MS,\n direction = \"up\",\n paused = false,\n sizing = \"longest\",\n className,\n labelClassName,\n announceChanges = false,\n onActiveIndexChange,\n ...rest\n },\n ref,\n ) => {\n const docVisible = usePageVisibility();\n const { sizingLabelRef, trackWidth } = useCyclingTextTrackWidth();\n const {\n cycle,\n currentIndex,\n currentLabel,\n incomingLabel,\n sizingLabel,\n onOutgoingTransitionEnd,\n } = useCyclingCycle(items, sizing, intervalMs, paused, docVisible, transitionMs);\n\n const itemCount = items.length;\n\n // Notify the parent of the settled active index without re-subscribing when\n // an inline callback identity changes each render — the latest is always\n // read from the ref.\n const onActiveIndexChangeRef = React.useRef(onActiveIndexChange);\n React.useEffect(() => {\n onActiveIndexChangeRef.current = onActiveIndexChange;\n }, [onActiveIndexChange]);\n React.useEffect(() => {\n onActiveIndexChangeRef.current?.(currentIndex);\n }, [currentIndex]);\n\n const { outgoingStyle, incomingStyle } = useCyclingMotion({\n transitioning: cycle.transitioning,\n incomingEntered: cycle.incomingEntered,\n direction,\n transitionMs,\n });\n\n if (itemCount === 0) {\n return null;\n }\n\n const wrapperStyle = {\n ...(trackWidth !== null ? { width: `${trackWidth}px` } : {}),\n } as React.CSSProperties;\n\n const showIncoming = incomingLabel !== null && cycle.transitioning;\n\n return (\n <span\n ref={ref}\n data-testid=\"cycling-text\"\n data-paused={paused ? \"true\" : undefined}\n className={cn(\n \"relative inline-flex items-center overflow-hidden align-middle leading-[inherit]\",\n \"motion-safe:transition-[width] motion-safe:duration-300 motion-safe:ease-out\",\n className,\n )}\n style={wrapperStyle}\n {...rest}\n >\n <span\n ref={sizingLabelRef}\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none invisible inline-block select-none whitespace-nowrap leading-[inherit]\",\n labelClassName,\n )}\n >\n {sizingLabel}\n </span>\n\n <span\n data-layer=\"current\"\n aria-live={announceChanges ? \"polite\" : undefined}\n aria-atomic={announceChanges ? true : undefined}\n data-state={cycle.transitioning ? \"exit\" : \"idle\"}\n onTransitionEnd={onOutgoingTransitionEnd}\n className={cn(\n \"absolute inset-0 flex items-center whitespace-nowrap leading-[inherit]\",\n labelClassName,\n )}\n style={outgoingStyle}\n >\n {currentLabel}\n </span>\n\n {showIncoming ? (\n <span\n aria-hidden=\"true\"\n data-layer=\"incoming\"\n data-state={cycle.incomingEntered ? \"idle\" : \"enter\"}\n className={cn(\n \"absolute inset-0 flex items-center whitespace-nowrap leading-[inherit]\",\n labelClassName,\n )}\n style={incomingStyle}\n >\n {incomingLabel}\n </span>\n ) : null}\n </span>\n );\n },\n);\n\nCyclingText.displayName = \"CyclingText\";\n"],"names":[],"mappings":";;;;;;;;AAOA,MAAM,sBAAsB;AAC5B,MAAM,wBAAwB;AAwDvB,MAAM,cAAc,MAAM;AAAA,EAC/B,CACE;AAAA,IACE;AAAA,IACA,aAAa;AAAA,IACb,eAAe;AAAA,IACf,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,aAAa,kBAAA;AACnB,UAAM,EAAE,gBAAgB,WAAA,IAAe,yBAAA;AACvC,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,IACE,gBAAgB,OAAO,QAAQ,YAAY,QAAQ,YAAY,YAAY;AAE/E,UAAM,YAAY,MAAM;AAKxB,UAAM,yBAAyB,MAAM,OAAO,mBAAmB;AAC/D,UAAM,UAAU,MAAM;AACpB,6BAAuB,UAAU;AAAA,IACnC,GAAG,CAAC,mBAAmB,CAAC;AACxB,UAAM,UAAU,MAAM;AACpB,6BAAuB,UAAU,YAAY;AAAA,IAC/C,GAAG,CAAC,YAAY,CAAC;AAEjB,UAAM,EAAE,eAAe,cAAA,IAAkB,iBAAiB;AAAA,MACxD,eAAe,MAAM;AAAA,MACrB,iBAAiB,MAAM;AAAA,MACvB;AAAA,MACA;A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* as React from "react";
|
|
3
|
+
import { usePrefersReducedMotion } from "../../utils/usePrefersReducedMotion.mjs";
|
|
4
|
+
const SLIDE_OFFSET_PX = 18;
|
|
5
|
+
const EASING = "cubic-bezier(0.4, 0, 0.2, 1)";
|
|
6
|
+
function useCyclingMotion({
|
|
7
|
+
transitioning,
|
|
8
|
+
incomingEntered,
|
|
9
|
+
direction,
|
|
10
|
+
transitionMs
|
|
11
|
+
}) {
|
|
12
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
13
|
+
const durMs = reducedMotion ? 0 : transitionMs;
|
|
14
|
+
const outgoingStyle = React.useMemo(() => {
|
|
15
|
+
const yExit = direction === "up" ? -SLIDE_OFFSET_PX : SLIDE_OFFSET_PX;
|
|
16
|
+
return {
|
|
17
|
+
opacity: transitioning ? 0 : 1,
|
|
18
|
+
transform: transitioning ? `translate3d(0, ${yExit}px, 0)` : "translate3d(0, 0, 0)",
|
|
19
|
+
// Only while exiting: returning to idle should snap, not animate back.
|
|
20
|
+
transition: transitioning && durMs > 0 ? `opacity ${durMs}ms ${EASING}, transform ${durMs}ms ${EASING}` : "none"
|
|
21
|
+
};
|
|
22
|
+
}, [transitioning, direction, durMs]);
|
|
23
|
+
const incomingStyle = React.useMemo(() => {
|
|
24
|
+
const yEnter = direction === "up" ? SLIDE_OFFSET_PX : -SLIDE_OFFSET_PX;
|
|
25
|
+
return {
|
|
26
|
+
opacity: incomingEntered ? 1 : 0,
|
|
27
|
+
transform: incomingEntered ? "translate3d(0, 0, 0)" : `translate3d(0, ${yEnter}px, 0)`,
|
|
28
|
+
transition: durMs > 0 ? `opacity ${durMs}ms ${EASING}, transform ${durMs}ms ${EASING}` : "none"
|
|
29
|
+
};
|
|
30
|
+
}, [incomingEntered, direction, durMs]);
|
|
31
|
+
return { outgoingStyle, incomingStyle };
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useCyclingMotion
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=useCyclingMotion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCyclingMotion.mjs","sources":["../../../src/components/CyclingText/useCyclingMotion.ts"],"sourcesContent":["import * as React from \"react\";\nimport { usePrefersReducedMotion } from \"../../utils/usePrefersReducedMotion\";\n\nconst SLIDE_OFFSET_PX = 18;\nconst EASING = \"cubic-bezier(0.4, 0, 0.2, 1)\";\n\nexport interface CyclingMotionOptions {\n /** True while the outgoing item is sliding out and the incoming one is sliding in. */\n transitioning: boolean;\n /** True once the incoming item has been moved to its resting position. */\n incomingEntered: boolean;\n /** Direction the outgoing item slides. */\n direction: \"up\" | \"down\";\n /** Slide and cross-fade duration in milliseconds. */\n transitionMs: number;\n}\n\nexport interface CyclingMotion {\n outgoingStyle: React.CSSProperties;\n incomingStyle: React.CSSProperties;\n}\n\n/**\n * Inline styles driving the slide and cross-fade between two cycling items.\n *\n * Inline rather than utility classes because `transitionMs` is a runtime prop.\n * Reduced motion collapses the duration to zero, leaving the end states intact;\n * the cycle is advanced by the fallback timer in `useCyclingCycle`, not by\n * `transitionend`, so it keeps running when no transition fires.\n */\nexport function useCyclingMotion({\n transitioning,\n incomingEntered,\n direction,\n transitionMs,\n}: CyclingMotionOptions): CyclingMotion {\n const reducedMotion = usePrefersReducedMotion();\n const durMs = reducedMotion ? 0 : transitionMs;\n\n const outgoingStyle = React.useMemo((): React.CSSProperties => {\n const yExit = direction === \"up\" ? -SLIDE_OFFSET_PX : SLIDE_OFFSET_PX;\n return {\n opacity: transitioning ? 0 : 1,\n transform: transitioning ? `translate3d(0, ${yExit}px, 0)` : \"translate3d(0, 0, 0)\",\n // Only while exiting: returning to idle should snap, not animate back.\n transition:\n transitioning && durMs > 0\n ? `opacity ${durMs}ms ${EASING}, transform ${durMs}ms ${EASING}`\n : \"none\",\n };\n }, [transitioning, direction, durMs]);\n\n const incomingStyle = React.useMemo((): React.CSSProperties => {\n const yEnter = direction === \"up\" ? SLIDE_OFFSET_PX : -SLIDE_OFFSET_PX;\n return {\n opacity: incomingEntered ? 1 : 0,\n transform: incomingEntered ? \"translate3d(0, 0, 0)\" : `translate3d(0, ${yEnter}px, 0)`,\n transition:\n durMs > 0 ? `opacity ${durMs}ms ${EASING}, transform ${durMs}ms ${EASING}` : \"none\",\n };\n }, [incomingEntered, direction, durMs]);\n\n return { outgoingStyle, incomingStyle };\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,kBAAkB;AACxB,MAAM,SAAS;AA0BR,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAwC;AACtC,QAAM,gBAAgB,wBAAA;AACtB,QAAM,QAAQ,gBAAgB,IAAI;AAElC,QAAM,gBAAgB,MAAM,QAAQ,MAA2B;AAC7D,UAAM,QAAQ,cAAc,OAAO,CAAC,kBAAkB;AACtD,WAAO;AAAA,MACL,SAAS,gBAAgB,IAAI;AAAA,MAC7B,WAAW,gBAAgB,kBAAkB,KAAK,WAAW;AAAA;AAAA,MAE7D,YACE,iBAAiB,QAAQ,IACrB,WAAW,KAAK,MAAM,MAAM,eAAe,KAAK,MAAM,MAAM,KAC5D;AAAA,IAAA;AAAA,EAEV,GAAG,CAAC,eAAe,WAAW,KAAK,CAAC;AAEpC,QAAM,gBAAgB,MAAM,QAAQ,MAA2B;AAC7D,UAAM,SAAS,cAAc,OAAO,kBAAkB,CAAC;AACvD,WAAO;AAAA,MACL,SAAS,kBAAkB,IAAI;AAAA,MAC/B,WAAW,kBAAkB,yBAAyB,kBAAkB,MAAM;AAAA,MAC9E,YACE,QAAQ,IAAI,WAAW,KAAK,MAAM,MAAM,eAAe,KAAK,MAAM,MAAM,KAAK;AAAA,IAAA;AAAA,EAEnF,GAAG,CAAC,iBAAiB,WAAW,KAAK,CAAC;AAEtC,SAAO,EAAE,eAAe,cAAA;AAC1B;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../../utils/cn.mjs";
|
|
5
|
+
import { ProgressBar } from "../ProgressBar/ProgressBar.mjs";
|
|
6
|
+
const Demographics = React.forwardRef(
|
|
7
|
+
({ label, value, formattedValue, icon, className, ...props }, ref) => /* @__PURE__ */ jsxs("div", { ref, className: cn("flex w-full flex-col gap-2", className), ...props, children: [
|
|
8
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between gap-2", children: [
|
|
9
|
+
/* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
|
|
10
|
+
icon && /* @__PURE__ */ jsx("span", { className: "flex size-5 shrink-0 items-center justify-center", children: icon }),
|
|
11
|
+
/* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-semibold truncate text-content-primary", children: label })
|
|
12
|
+
] }),
|
|
13
|
+
/* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-regular shrink-0 text-content-primary", children: formattedValue })
|
|
14
|
+
] }),
|
|
15
|
+
/* @__PURE__ */ jsx(ProgressBar, { variant: "sky", size: "medium", value, ariaLabel: label })
|
|
16
|
+
] })
|
|
17
|
+
);
|
|
18
|
+
Demographics.displayName = "Demographics";
|
|
19
|
+
export {
|
|
20
|
+
Demographics
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=Demographics.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Demographics.mjs","sources":["../../../src/components/Demographics/Demographics.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { ProgressBar } from \"../ProgressBar/ProgressBar\";\n\n/** Props for {@link Demographics}. */\nexport interface DemographicsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n /**\n * Row label, e.g. a country name. Pass a translated string for i18n.\n *\n * A string rather than a node because it is also the bar's accessible name:\n * a node would leave the bar announcing \"Progress\" and a bare number, with\n * nothing saying which row it belongs to.\n */\n label: string;\n /** Share of the total, 0–100. Drives the bar and is announced to assistive tech. */\n value: number;\n /** Formatted share shown at the end of the row, e.g. `\"52.6%\"`. */\n formattedValue: React.ReactNode;\n /** Leading 20px glyph — a flag for a country row. */\n icon?: React.ReactNode;\n}\n\n/**\n * One row of a breakdown: a leading glyph and label, its share at the far end,\n * and a bar underneath. Stack these to show how a total splits across\n * categories — the top-countries breakdown on the insights dashboard, and the\n * same list expanded inside a dialog.\n *\n * @example\n * ```tsx\n * <Demographics\n * icon={<span aria-hidden>🇺🇸</span>}\n * label=\"United States\"\n * value={52.6}\n * formattedValue=\"52.6%\"\n * />\n * ```\n */\nexport const Demographics = React.forwardRef<HTMLDivElement, DemographicsProps>(\n ({ label, value, formattedValue, icon, className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex w-full flex-col gap-2\", className)} {...props}>\n <div className=\"flex w-full items-center justify-between gap-2\">\n <span className=\"flex min-w-0 items-center gap-2\">\n {icon && <span className=\"flex size-5 shrink-0 items-center justify-center\">{icon}</span>}\n <span className=\"typography-body-small-14px-semibold truncate text-content-primary\">\n {label}\n </span>\n </span>\n <span className=\"typography-body-small-14px-regular shrink-0 text-content-primary\">\n {formattedValue}\n </span>\n </div>\n <ProgressBar variant=\"sky\" size=\"medium\" value={value} ariaLabel={label} />\n </div>\n ),\n);\n\nDemographics.displayName = \"Demographics\";\n"],"names":[],"mappings":";;;;;AAsCO,MAAM,eAAe,MAAM;AAAA,EAChC,CAAC,EAAE,OAAO,OAAO,gBAAgB,MAAM,WAAW,GAAG,MAAA,GAAS,QAC5D,qBAAC,OAAA,EAAI,KAAU,WAAW,GAAG,8BAA8B,SAAS,GAAI,GAAG,OACzE,UAAA;AAAA,IAAA,qBAAC,OAAA,EAAI,WAAU,kDACb,UAAA;AAAA,MAAA,qBAAC,QAAA,EAAK,WAAU,mCACb,UAAA;AAAA,QAAA,QAAQ,oBAAC,QAAA,EAAK,WAAU,oDAAoD,UAAA,MAAK;AAAA,QAClF,oBAAC,QAAA,EAAK,WAAU,qEACb,UAAA,MAAA,CACH;AAAA,MAAA,GACF;AAAA,MACA,oBAAC,QAAA,EAAK,WAAU,oEACb,UAAA,eAAA,CACH;AAAA,IAAA,GACF;AAAA,IACA,oBAAC,eAAY,SAAQ,OAAM,MAAK,UAAS,OAAc,WAAW,MAAA,CAAO;AAAA,EAAA,EAAA,CAC3E;AAEJ;AAEA,aAAa,cAAc;"}
|
|
@@ -7,6 +7,7 @@ import { useSuppressClickAfterDrag } from "../../utils/useSuppressClickAfterDrag
|
|
|
7
7
|
import { IconButton } from "../IconButton/IconButton.mjs";
|
|
8
8
|
import { CloseIcon } from "../Icons/CloseIcon.mjs";
|
|
9
9
|
const SHEET_CLASSES = "rounded-t-xl border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]";
|
|
10
|
+
const MENU_CLASSES = "inset-x-4 bottom-4 w-auto rounded-lg border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]";
|
|
10
11
|
const DrawerContext = React.createContext({
|
|
11
12
|
overlay: true
|
|
12
13
|
});
|
|
@@ -78,13 +79,20 @@ const DrawerContent = React.forwardRef(
|
|
|
78
79
|
...style
|
|
79
80
|
},
|
|
80
81
|
className: cn(
|
|
81
|
-
"fixed flex flex-col bg-surface-secondary
|
|
82
|
+
"fixed flex flex-col bg-surface-secondary outline-none backdrop-blur-lg",
|
|
83
|
+
// `shadow-lg` is scoped to `panel` rather than sitting in the base classes.
|
|
84
|
+
// tailwind-merge does not recognise `shadow-blur-menu` as a box-shadow
|
|
85
|
+
// utility, so it never deduped the two and `shadow-lg` won on stylesheet
|
|
86
|
+
// order — meaning the sheet and menu surfaces silently rendered `shadow-lg`
|
|
87
|
+
// instead of the menu shadow their tokens name.
|
|
88
|
+
variant === "panel" && "shadow-lg",
|
|
82
89
|
"data-[state=closed]:animate-out data-[state=open]:animate-in",
|
|
83
90
|
"data-[state=closed]:duration-150 data-[state=closed]:ease-in",
|
|
84
91
|
"data-[state=open]:duration-200 data-[state=open]:ease-out",
|
|
85
92
|
SLIDE_CLASSES[position],
|
|
86
93
|
sizeClass,
|
|
87
94
|
variant === "sheet" && SHEET_CLASSES,
|
|
95
|
+
variant === "menu" && MENU_CLASSES,
|
|
88
96
|
className
|
|
89
97
|
),
|
|
90
98
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.mjs","sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useSuppressClickAfterDrag } from \"../../utils/useSuppressClickAfterDrag\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\n\n/** The side from which the drawer slides in. */\nexport type DrawerPosition = \"left\" | \"right\" | \"top\" | \"bottom\";\n\n/** Size presets for the drawer panel. Maps to max-width (left/right) or max-height (top/bottom). */\nexport type DrawerSize = \"sm\" | \"md\" | \"lg\" | \"full\";\n\n/**\n * Visual treatment of the drawer panel.\n *\n * - `\"panel\"` (default) — the standard edge-anchored surface.\n * - `\"sheet\"` — a bottom-sheet treatment matching the modal surface: large\n * top-only radius (32px), modal background/stroke, and menu blur+shadow.\n * Intended for `position=\"bottom\"`.\n */\nexport type DrawerVariant = \"panel\" | \"sheet\";\n\n/**\n * Shared surface classes for the `\"sheet\"` variant. Mirrors the mobile sheet\n * treatment used by {@link Dialog} so bottom sheets are visually consistent.\n */\nconst SHEET_CLASSES =\n \"rounded-t-xl border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Props for the {@link Drawer} root component.\n *\n * Inherits `open`, `onOpenChange`, and `defaultOpen` from Radix Dialog.Root.\n *\n * The Radix `modal` prop (default `true`) can also be passed to create a\n * non-modal drawer — useful for persistent side navigation that does not\n * block interaction with the rest of the page.\n *\n * **`overlay` behaviour:** When `overlay` is `false`, the component\n * automatically sets `modal={false}` on the underlying Radix Dialog.Root.\n * A modal dialog without a visible overlay is confusing because focus is\n * still trapped and scroll is blocked even though the page appears\n * interactive. Passing `modal={true}` explicitly will override this.\n */\nexport interface DrawerProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root> {\n /**\n * Whether the default {@link DrawerOverlay} is rendered.\n * When `false`, `modal` is automatically set to `false` as well\n * (unless explicitly overridden) so focus-trap and scroll-lock are disabled.\n * @default true\n */\n overlay?: boolean;\n}\n\nconst DrawerContext = React.createContext<{ overlay: boolean }>({\n overlay: true,\n});\n\n/**\n * Root component that manages open/close state for a drawer.\n * Wraps Radix Dialog.Root.\n *\n * @example\n * ```tsx\n * <Drawer>\n * <DrawerTrigger>Open</DrawerTrigger>\n * <DrawerContent position=\"right\">\n * <DrawerHeader>\n * <DrawerTitle>Settings</DrawerTitle>\n * <DrawerDescription>Adjust your preferences.</DrawerDescription>\n * </DrawerHeader>\n * <p>Content goes here.</p>\n * <DrawerFooter>\n * <DrawerClose>Done</DrawerClose>\n * </DrawerFooter>\n * </DrawerContent>\n * </Drawer>\n * ```\n */\nexport function Drawer({ overlay = true, modal, children, ...props }: DrawerProps) {\n const resolvedModal = modal ?? (overlay ? undefined : false);\n return (\n <DrawerContext.Provider value={{ overlay }}>\n <DialogPrimitive.Root modal={resolvedModal} {...props}>\n {children}\n </DialogPrimitive.Root>\n </DrawerContext.Provider>\n );\n}\nDrawer.displayName = \"Drawer\";\n\n/** Props for the {@link DrawerTrigger} component. */\nexport type DrawerTriggerProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Trigger>;\n\n/**\n * The element that opens the drawer when clicked.\n *\n * On touch / pen, a press-and-release that crosses a small movement threshold\n * is treated as a drag and the resulting synthetic click is suppressed —\n * defends against Android Chrome opening the drawer on a scroll-drag-end.\n */\nexport const DrawerTrigger = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Trigger>,\n DrawerTriggerProps\n>((props, ref) => <DialogPrimitive.Trigger ref={ref} {...useSuppressClickAfterDrag(props)} />);\nDrawerTrigger.displayName = \"DrawerTrigger\";\n\n/** Props for the {@link DrawerClose} component. */\nexport type DrawerCloseProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>;\n\n/** Closes the drawer when clicked. Can be placed anywhere inside the drawer. */\nexport const DrawerClose = DialogPrimitive.Close;\nDrawerClose.displayName = \"DrawerClose\";\n\n/** Props for the {@link DrawerOverlay} component. */\nexport interface DrawerOverlayProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> {}\n\n/**\n * A translucent backdrop rendered behind the drawer content.\n * Clicking the overlay closes the drawer by default.\n */\nexport const DrawerOverlay = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Overlay>,\n DrawerOverlayProps\n>(({ className, style, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\", ...style }}\n className={cn(\n \"fixed inset-0 bg-background-overlay-default\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:fade-in-0 data-[state=open]:duration-200 data-[state=open]:ease-out\",\n className,\n )}\n {...props}\n />\n));\nDrawerOverlay.displayName = \"DrawerOverlay\";\n\n/**\n * Slide-in animation classes keyed by position.\n * Uses Tailwind animate utilities (animate-in / animate-out).\n */\nconst SLIDE_CLASSES: Record<DrawerPosition, string> = {\n right:\n \"inset-y-0 right-0 h-full w-2/3 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right\",\n left: \"inset-y-0 left-0 h-full w-2/3 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left\",\n top: \"inset-x-0 top-0 w-full data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top\",\n bottom:\n \"inset-x-0 bottom-0 w-full rounded-t-xs data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom\",\n};\n\n/** Props for the {@link DrawerContent} component. */\nexport interface DrawerContentProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {\n /**\n * The edge from which the drawer slides in.\n *\n * Named `position` (rather than `side`) to avoid confusion with the CSS\n * `side` concept used by Radix Popover/Tooltip and to better convey the\n * spatial relationship of the drawer to the viewport.\n *\n * @default \"right\"\n */\n position?: DrawerPosition;\n /**\n * Controls the maximum extent of the drawer panel.\n * For left/right drawers this sets `max-width`; for top/bottom it sets `max-height`.\n * @default \"sm\"\n */\n size?: DrawerSize;\n /**\n * Visual treatment of the panel. Use `\"sheet\"` (with `position=\"bottom\"`) for\n * a bottom sheet with the modal surface treatment. @default \"panel\"\n */\n variant?: DrawerVariant;\n /**\n * Whether to render the default {@link DrawerOverlay} behind the content.\n * Set to `false` to provide your own overlay or omit it entirely.\n *\n * Prefer setting `overlay` on the {@link Drawer} root instead so that\n * `modal` is also adjusted automatically.\n *\n * @default true\n */\n overlay?: boolean;\n /** Props forwarded to the default {@link DrawerOverlay} when `overlay` is `true`. */\n overlayProps?: DrawerOverlayProps;\n}\n\n/**\n * The panel that slides in from the chosen edge. Renders inside a portal with\n * an overlay backdrop by default.\n *\n * Includes focus-trap, `aria-describedby`, and Escape-to-close from Radix Dialog.\n */\nexport const DrawerContent = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Content>,\n DrawerContentProps\n>(\n (\n {\n className,\n position = \"right\",\n size = \"sm\",\n variant = \"panel\",\n overlay: overlayProp,\n overlayProps,\n style,\n children,\n ...props\n },\n ref,\n ) => {\n const ctx = React.useContext(DrawerContext);\n const overlay = overlayProp ?? ctx.overlay;\n const isHorizontal = position === \"left\" || position === \"right\";\n const sizeClass = isHorizontal\n ? (\n {\n sm: \"max-w-sm\",\n md: \"max-w-md\",\n lg: \"max-w-lg\",\n full: \"max-w-full\",\n } as const\n )[size]\n : (\n {\n sm: \"max-h-[24rem]\",\n md: \"max-h-[28rem]\",\n lg: \"max-h-[32rem]\",\n full: \"max-h-full\",\n } as const\n )[size];\n\n return (\n <DialogPrimitive.Portal>\n {overlay && <DrawerOverlay {...overlayProps} />}\n <DialogPrimitive.Content\n ref={ref}\n style={{\n zIndex: \"calc(var(--fanvue-ui-portal-z-index, 50) + 1)\",\n ...style,\n }}\n className={cn(\n \"fixed flex flex-col bg-surface-secondary shadow-lg outline-none backdrop-blur-lg\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:duration-200 data-[state=open]:ease-out\",\n SLIDE_CLASSES[position],\n sizeClass,\n variant === \"sheet\" && SHEET_CLASSES,\n className,\n )}\n {...props}\n >\n {children}\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n );\n },\n);\nDrawerContent.displayName = \"DrawerContent\";\n\n/** Props for the {@link DrawerHeader} component. */\nexport interface DrawerHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Whether to show a built-in close (X) button. @default true */\n showClose?: boolean;\n /** Accessible label for the close button. @default \"Close drawer\" */\n closeLabel?: string;\n}\n\n/**\n * A semantic header area for the drawer, typically containing a title and description.\n * Renders a built-in close button by default.\n */\nexport const DrawerHeader = React.forwardRef<HTMLDivElement, DrawerHeaderProps>(\n ({ className, showClose = true, closeLabel = \"Close drawer\", children, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex items-center gap-2 p-4\", className)} {...props}>\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">{children}</div>\n {showClose && (\n <DialogPrimitive.Close asChild>\n <IconButton\n icon={<CloseIcon />}\n aria-label={closeLabel}\n variant=\"secondary\"\n size=\"32\"\n className=\"shrink-0\"\n />\n </DialogPrimitive.Close>\n )}\n </div>\n ),\n);\nDrawerHeader.displayName = \"DrawerHeader\";\n\n/** Props for the {@link DrawerFooter} component. */\nexport interface DrawerFooterProps extends React.HTMLAttributes<HTMLDivElement> {}\n\n/** A semantic footer area for the drawer, typically containing action buttons. */\nexport const DrawerFooter = React.forwardRef<HTMLDivElement, DrawerFooterProps>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex flex-col gap-2 p-4\", className)} {...props} />\n ),\n);\nDrawerFooter.displayName = \"DrawerFooter\";\n\n/** Props for the {@link DrawerTitle} component. */\nexport interface DrawerTitleProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> {}\n\n/** An accessible title for the drawer. Required for screen readers. */\nexport const DrawerTitle = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Title>,\n DrawerTitleProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn(\"typography-body-default-16px-semibold truncate text-content-primary\", className)}\n {...props}\n />\n));\nDrawerTitle.displayName = \"DrawerTitle\";\n\n/** Props for the {@link DrawerDescription} component. */\nexport interface DrawerDescriptionProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> {}\n\n/** An accessible description for the drawer, providing supplementary context. */\nexport const DrawerDescription = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Description>,\n DrawerDescriptionProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description\n ref={ref}\n className={cn(\"typography-body-small-14px-regular text-content-secondary\", className)}\n {...props}\n />\n));\nDrawerDescription.displayName = \"DrawerDescription\";\n"],"names":[],"mappings":";;;;;;;;AA2BA,MAAM,gBACJ;AA2BF,MAAM,gBAAgB,MAAM,cAAoC;AAAA,EAC9D,SAAS;AACX,CAAC;AAuBM,SAAS,OAAO,EAAE,UAAU,MAAM,OAAO,UAAU,GAAG,SAAsB;AACjF,QAAM,gBAAgB,UAAU,UAAU,SAAY;AACtD,6BACG,cAAc,UAAd,EAAuB,OAAO,EAAE,QAAA,GAC/B,UAAA,oBAAC,gBAAgB,MAAhB,EAAqB,OAAO,eAAgB,GAAG,OAC7C,UACH,GACF;AAEJ;AACA,OAAO,cAAc;AAYd,MAAM,gBAAgB,MAAM,WAGjC,CAAC,OAAO,QAAQ,oBAAC,gBAAgB,SAAhB,EAAwB,KAAW,GAA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A,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,6DAA6D,SAAS;AAAA,IACnF,GAAG;AAAA,EAAA;AACN,CACD;AACD,kBAAkB,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Drawer.mjs","sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useSuppressClickAfterDrag } from \"../../utils/useSuppressClickAfterDrag\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\n\n/** The side from which the drawer slides in. */\nexport type DrawerPosition = \"left\" | \"right\" | \"top\" | \"bottom\";\n\n/** Size presets for the drawer panel. Maps to max-width (left/right) or max-height (top/bottom). */\nexport type DrawerSize = \"sm\" | \"md\" | \"lg\" | \"full\";\n\n/**\n * Visual treatment of the drawer panel.\n *\n * - `\"panel\"` (default) — the standard edge-anchored surface.\n * - `\"sheet\"` — a bottom-sheet treatment matching the modal surface: large\n * top-only radius (32px), modal background/stroke, and menu blur+shadow.\n * Intended for `position=\"bottom\"`.\n * - `\"menu\"` — a floating menu near the bottom edge rather than a sheet fixed to\n * it: inset from all three sides and rounded on every corner. Shares the modal\n * surface with `\"sheet\"`; only the shape differs. Intended for\n * `position=\"bottom\"`.\n */\nexport type DrawerVariant = \"panel\" | \"sheet\" | \"menu\";\n\n/**\n * Shared surface classes for the `\"sheet\"` variant. Mirrors the mobile sheet\n * treatment used by {@link Dialog} so bottom sheets are visually consistent.\n */\nconst SHEET_CLASSES =\n \"rounded-t-xl border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Surface and inset for the `\"menu\"` variant. Same modal background and stroke as\n * a sheet — the design puts this panel on `background/secondary` with\n * `border/strong`, not on the lighter surface the trigger-anchored dropdown uses.\n * The 24px radius is the design's `rounded-lg`.\n *\n * The insets restate position on purpose — they override `SLIDE_CLASSES.bottom`,\n * which pins a sheet flush to the bottom edge at full width.\n */\nconst MENU_CLASSES =\n \"inset-x-4 bottom-4 w-auto rounded-lg border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Props for the {@link Drawer} root component.\n *\n * Inherits `open`, `onOpenChange`, and `defaultOpen` from Radix Dialog.Root.\n *\n * The Radix `modal` prop (default `true`) can also be passed to create a\n * non-modal drawer — useful for persistent side navigation that does not\n * block interaction with the rest of the page.\n *\n * **`overlay` behaviour:** When `overlay` is `false`, the component\n * automatically sets `modal={false}` on the underlying Radix Dialog.Root.\n * A modal dialog without a visible overlay is confusing because focus is\n * still trapped and scroll is blocked even though the page appears\n * interactive. Passing `modal={true}` explicitly will override this.\n */\nexport interface DrawerProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root> {\n /**\n * Whether the default {@link DrawerOverlay} is rendered.\n * When `false`, `modal` is automatically set to `false` as well\n * (unless explicitly overridden) so focus-trap and scroll-lock are disabled.\n * @default true\n */\n overlay?: boolean;\n}\n\nconst DrawerContext = React.createContext<{ overlay: boolean }>({\n overlay: true,\n});\n\n/**\n * Root component that manages open/close state for a drawer.\n * Wraps Radix Dialog.Root.\n *\n * @example\n * ```tsx\n * <Drawer>\n * <DrawerTrigger>Open</DrawerTrigger>\n * <DrawerContent position=\"right\">\n * <DrawerHeader>\n * <DrawerTitle>Settings</DrawerTitle>\n * <DrawerDescription>Adjust your preferences.</DrawerDescription>\n * </DrawerHeader>\n * <p>Content goes here.</p>\n * <DrawerFooter>\n * <DrawerClose>Done</DrawerClose>\n * </DrawerFooter>\n * </DrawerContent>\n * </Drawer>\n * ```\n */\nexport function Drawer({ overlay = true, modal, children, ...props }: DrawerProps) {\n const resolvedModal = modal ?? (overlay ? undefined : false);\n return (\n <DrawerContext.Provider value={{ overlay }}>\n <DialogPrimitive.Root modal={resolvedModal} {...props}>\n {children}\n </DialogPrimitive.Root>\n </DrawerContext.Provider>\n );\n}\nDrawer.displayName = \"Drawer\";\n\n/** Props for the {@link DrawerTrigger} component. */\nexport type DrawerTriggerProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Trigger>;\n\n/**\n * The element that opens the drawer when clicked.\n *\n * On touch / pen, a press-and-release that crosses a small movement threshold\n * is treated as a drag and the resulting synthetic click is suppressed —\n * defends against Android Chrome opening the drawer on a scroll-drag-end.\n */\nexport const DrawerTrigger = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Trigger>,\n DrawerTriggerProps\n>((props, ref) => <DialogPrimitive.Trigger ref={ref} {...useSuppressClickAfterDrag(props)} />);\nDrawerTrigger.displayName = \"DrawerTrigger\";\n\n/** Props for the {@link DrawerClose} component. */\nexport type DrawerCloseProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>;\n\n/** Closes the drawer when clicked. Can be placed anywhere inside the drawer. */\nexport const DrawerClose = DialogPrimitive.Close;\nDrawerClose.displayName = \"DrawerClose\";\n\n/** Props for the {@link DrawerOverlay} component. */\nexport interface DrawerOverlayProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> {}\n\n/**\n * A translucent backdrop rendered behind the drawer content.\n * Clicking the overlay closes the drawer by default.\n */\nexport const DrawerOverlay = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Overlay>,\n DrawerOverlayProps\n>(({ className, style, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\", ...style }}\n className={cn(\n \"fixed inset-0 bg-background-overlay-default\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:fade-in-0 data-[state=open]:duration-200 data-[state=open]:ease-out\",\n className,\n )}\n {...props}\n />\n));\nDrawerOverlay.displayName = \"DrawerOverlay\";\n\n/**\n * Slide-in animation classes keyed by position.\n * Uses Tailwind animate utilities (animate-in / animate-out).\n */\nconst SLIDE_CLASSES: Record<DrawerPosition, string> = {\n right:\n \"inset-y-0 right-0 h-full w-2/3 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right\",\n left: \"inset-y-0 left-0 h-full w-2/3 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left\",\n top: \"inset-x-0 top-0 w-full data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top\",\n bottom:\n \"inset-x-0 bottom-0 w-full rounded-t-xs data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom\",\n};\n\n/** Props for the {@link DrawerContent} component. */\nexport interface DrawerContentProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {\n /**\n * The edge from which the drawer slides in.\n *\n * Named `position` (rather than `side`) to avoid confusion with the CSS\n * `side` concept used by Radix Popover/Tooltip and to better convey the\n * spatial relationship of the drawer to the viewport.\n *\n * @default \"right\"\n */\n position?: DrawerPosition;\n /**\n * Controls the maximum extent of the drawer panel.\n * For left/right drawers this sets `max-width`; for top/bottom it sets `max-height`.\n * @default \"sm\"\n */\n size?: DrawerSize;\n /**\n * Visual treatment of the panel. Use `\"sheet\"` (with `position=\"bottom\"`) for\n * a bottom sheet with the modal surface treatment, or `\"menu\"` for a floating\n * inset menu carrying the dropdown surface. @default \"panel\"\n */\n variant?: DrawerVariant;\n /**\n * Whether to render the default {@link DrawerOverlay} behind the content.\n * Set to `false` to provide your own overlay or omit it entirely.\n *\n * Prefer setting `overlay` on the {@link Drawer} root instead so that\n * `modal` is also adjusted automatically.\n *\n * @default true\n */\n overlay?: boolean;\n /** Props forwarded to the default {@link DrawerOverlay} when `overlay` is `true`. */\n overlayProps?: DrawerOverlayProps;\n}\n\n/**\n * The panel that slides in from the chosen edge. Renders inside a portal with\n * an overlay backdrop by default.\n *\n * Includes focus-trap, `aria-describedby`, and Escape-to-close from Radix Dialog.\n */\nexport const DrawerContent = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Content>,\n DrawerContentProps\n>(\n (\n {\n className,\n position = \"right\",\n size = \"sm\",\n variant = \"panel\",\n overlay: overlayProp,\n overlayProps,\n style,\n children,\n ...props\n },\n ref,\n ) => {\n const ctx = React.useContext(DrawerContext);\n const overlay = overlayProp ?? ctx.overlay;\n const isHorizontal = position === \"left\" || position === \"right\";\n const sizeClass = isHorizontal\n ? (\n {\n sm: \"max-w-sm\",\n md: \"max-w-md\",\n lg: \"max-w-lg\",\n full: \"max-w-full\",\n } as const\n )[size]\n : (\n {\n sm: \"max-h-[24rem]\",\n md: \"max-h-[28rem]\",\n lg: \"max-h-[32rem]\",\n full: \"max-h-full\",\n } as const\n )[size];\n\n return (\n <DialogPrimitive.Portal>\n {overlay && <DrawerOverlay {...overlayProps} />}\n <DialogPrimitive.Content\n ref={ref}\n style={{\n zIndex: \"calc(var(--fanvue-ui-portal-z-index, 50) + 1)\",\n ...style,\n }}\n className={cn(\n \"fixed flex flex-col bg-surface-secondary outline-none backdrop-blur-lg\",\n // `shadow-lg` is scoped to `panel` rather than sitting in the base classes.\n // tailwind-merge does not recognise `shadow-blur-menu` as a box-shadow\n // utility, so it never deduped the two and `shadow-lg` won on stylesheet\n // order — meaning the sheet and menu surfaces silently rendered `shadow-lg`\n // instead of the menu shadow their tokens name.\n variant === \"panel\" && \"shadow-lg\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:duration-200 data-[state=open]:ease-out\",\n SLIDE_CLASSES[position],\n sizeClass,\n variant === \"sheet\" && SHEET_CLASSES,\n variant === \"menu\" && MENU_CLASSES,\n className,\n )}\n {...props}\n >\n {children}\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n );\n },\n);\nDrawerContent.displayName = \"DrawerContent\";\n\n/** Props for the {@link DrawerHeader} component. */\nexport interface DrawerHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Whether to show a built-in close (X) button. @default true */\n showClose?: boolean;\n /** Accessible label for the close button. @default \"Close drawer\" */\n closeLabel?: string;\n}\n\n/**\n * A semantic header area for the drawer, typically containing a title and description.\n * Renders a built-in close button by default.\n */\nexport const DrawerHeader = React.forwardRef<HTMLDivElement, DrawerHeaderProps>(\n ({ className, showClose = true, closeLabel = \"Close drawer\", children, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex items-center gap-2 p-4\", className)} {...props}>\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">{children}</div>\n {showClose && (\n <DialogPrimitive.Close asChild>\n <IconButton\n icon={<CloseIcon />}\n aria-label={closeLabel}\n variant=\"secondary\"\n size=\"32\"\n className=\"shrink-0\"\n />\n </DialogPrimitive.Close>\n )}\n </div>\n ),\n);\nDrawerHeader.displayName = \"DrawerHeader\";\n\n/** Props for the {@link DrawerFooter} component. */\nexport interface DrawerFooterProps extends React.HTMLAttributes<HTMLDivElement> {}\n\n/** A semantic footer area for the drawer, typically containing action buttons. */\nexport const DrawerFooter = React.forwardRef<HTMLDivElement, DrawerFooterProps>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex flex-col gap-2 p-4\", className)} {...props} />\n ),\n);\nDrawerFooter.displayName = \"DrawerFooter\";\n\n/** Props for the {@link DrawerTitle} component. */\nexport interface DrawerTitleProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> {}\n\n/** An accessible title for the drawer. Required for screen readers. */\nexport const DrawerTitle = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Title>,\n DrawerTitleProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn(\"typography-body-default-16px-semibold truncate text-content-primary\", className)}\n {...props}\n />\n));\nDrawerTitle.displayName = \"DrawerTitle\";\n\n/** Props for the {@link DrawerDescription} component. */\nexport interface DrawerDescriptionProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> {}\n\n/** An accessible description for the drawer, providing supplementary context. */\nexport const DrawerDescription = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Description>,\n DrawerDescriptionProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description\n ref={ref}\n className={cn(\"typography-body-small-14px-regular text-content-secondary\", className)}\n {...props}\n />\n));\nDrawerDescription.displayName = \"DrawerDescription\";\n"],"names":[],"mappings":";;;;;;;;AA+BA,MAAM,gBACJ;AAWF,MAAM,eACJ;AA2BF,MAAM,gBAAgB,MAAM,cAAoC;AAAA,EAC9D,SAAS;AACX,CAAC;AAuBM,SAAS,OAAO,EAAE,UAAU,MAAM,OAAO,UAAU,GAAG,SAAsB;AACjF,QAAM,gBAAgB,UAAU,UAAU,SAAY;AACtD,6BACG,cAAc,UAAd,EAAuB,OAAO,EAAE,QAAA,GAC/B,UAAA,oBAAC,gBAAgB,MAAhB,EAAqB,OAAO,eAAgB,GAAG,OAC7C,UACH,GACF;AAEJ;AACA,OAAO,cAAc;AAYd,MAAM,gBAAgB,MAAM,WAGjC,CAAC,OAAO,QAAQ,oBAAC,gBAAgB,SAAhB,EAAwB,KAAW,GAAG,0BAA0B,KAAK,GAAG,CAAE;AAC7F,cAAc,cAAc;AAMrB,MAAM,cAAc,gBAAgB;AAC3C,YAAY,cAAc;AAUnB,MAAM,gBAAgB,MAAM,WAGjC,CAAC,EAAE,WAAW,OAAO,GAAG,SAAS,QACjC;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,OAAO,EAAE,QAAQ,uCAAuC,GAAG,MAAA;AAAA,IAC3D,WAAW;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAED,GAAG;AAAA,EAAA;AACN,CACD;AACD,cAAc,cAAc;AAM5B,MAAM,gBAAgD;AAAA,EACpD,OACE;AAAA,EACF,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QACE;AACJ;AA+CO,MAAM,gBAAgB,MAAM;AAAA,EAIjC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AA,EAAI,WAAU,wCAAwC,SAAA,CAAS;AAAA,IAC/D,aACC,oBAAC,gBAAgB,OAAhB,EAAsB,SAAO,MAC5B,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,0BAAO,WAAA,EAAU;AAAA,QACjB,cAAY;AAAA,QACZ,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,WAAU;AAAA,MAAA;AAAA,IAAA,EACZ,CACF;AAAA,EAAA,EAAA,CAEJ;AAEJ;AACA,aAAa,cAAc;AAMpB,MAAM,eAAe,MAAM;AAAA,EAChC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QACxB,oBAAC,OAAA,EAAI,KAAU,WAAW,GAAG,2BAA2B,SAAS,GAAI,GAAG,MAAA,CAAO;AAEnF;AACA,aAAa,cAAc;AAOpB,MAAM,cAAc,MAAM,WAG/B,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,uEAAuE,SAAS;AAAA,IAC7F,GAAG;AAAA,EAAA;AACN,CACD;AACD,YAAY,cAAc;AAOnB,MAAM,oBAAoB,MAAM,WAGrC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,6DAA6D,SAAS;AAAA,IACnF,GAAG;AAAA,EAAA;AACN,CACD;AACD,kBAAkB,cAAc;"}
|
|
@@ -11,6 +11,7 @@ import { IconButton } from "../IconButton/IconButton.mjs";
|
|
|
11
11
|
import { CheckIcon } from "../Icons/CheckIcon.mjs";
|
|
12
12
|
import { CloseIcon } from "../Icons/CloseIcon.mjs";
|
|
13
13
|
import { SearchIcon } from "../Icons/SearchIcon.mjs";
|
|
14
|
+
import { TickIcon } from "../Icons/TickIcon.mjs";
|
|
14
15
|
const TAP_MOVEMENT_THRESHOLD_PX = 10;
|
|
15
16
|
const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
|
|
16
17
|
"ArrowDown",
|
|
@@ -110,18 +111,22 @@ const DropdownMenuContent = React.forwardRef(
|
|
|
110
111
|
// is enough to keep the menu flipping/shifting to stay on screen — no
|
|
111
112
|
// hand-rolled reposition logic needed.
|
|
112
113
|
collisionPadding = FLOATING_CONTENT_COLLISION_PADDING,
|
|
114
|
+
onPointerDownOutside,
|
|
115
|
+
onCloseAutoFocus,
|
|
113
116
|
children,
|
|
114
117
|
...props
|
|
115
118
|
}, ref) => {
|
|
116
119
|
const variant = React.useContext(DropdownMenuVariantContext);
|
|
120
|
+
const dismissedByPointer = React.useRef(false);
|
|
117
121
|
if (variant === "sheet") {
|
|
118
122
|
return /* @__PURE__ */ jsx(
|
|
119
123
|
DrawerContent,
|
|
120
124
|
{
|
|
121
125
|
ref,
|
|
122
126
|
position: "bottom",
|
|
123
|
-
variant: "
|
|
124
|
-
className:
|
|
127
|
+
variant: "menu",
|
|
128
|
+
overlayProps: { className: "backdrop-blur-[8px]" },
|
|
129
|
+
className: cn("flex flex-col gap-1 p-1 pb-4", className),
|
|
125
130
|
style,
|
|
126
131
|
...props,
|
|
127
132
|
children
|
|
@@ -132,10 +137,27 @@ const DropdownMenuContent = React.forwardRef(
|
|
|
132
137
|
DropdownMenuPrimitive.Content,
|
|
133
138
|
{
|
|
134
139
|
ref,
|
|
140
|
+
onPointerDownOutside: (event) => {
|
|
141
|
+
dismissedByPointer.current = true;
|
|
142
|
+
onPointerDownOutside?.(event);
|
|
143
|
+
},
|
|
144
|
+
onCloseAutoFocus: (event) => {
|
|
145
|
+
if (dismissedByPointer.current) event.preventDefault();
|
|
146
|
+
dismissedByPointer.current = false;
|
|
147
|
+
onCloseAutoFocus?.(event);
|
|
148
|
+
},
|
|
135
149
|
sideOffset,
|
|
136
150
|
collisionPadding,
|
|
137
151
|
className: cn(
|
|
138
|
-
|
|
152
|
+
// `rounded-sm` (12px) is the panel radius `V2 Menu Dropdown` carries
|
|
153
|
+
// (product file node `7393:62008`). The 8px `rounded-xs` belongs to the
|
|
154
|
+
// rows inside it, not the panel.
|
|
155
|
+
//
|
|
156
|
+
// The `sheet` variant is deliberately not 12px: it renders through
|
|
157
|
+
// `DrawerContent variant="menu"`, whose `MENU_CLASSES` is `rounded-lg`
|
|
158
|
+
// (24px). A bottom sheet is a full-width surface with its own radius,
|
|
159
|
+
// not a scaled-up popper, so the two are meant to differ.
|
|
160
|
+
"w-max min-w-(--radix-dropdown-menu-trigger-width) max-w-(--radix-dropdown-menu-content-available-width) overflow-y-auto rounded-sm border border-border-primary bg-surface-primary p-1 text-content-primary shadow-blur-menu backdrop-blur-[4px]",
|
|
139
161
|
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
140
162
|
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
|
141
163
|
"data-[side=top]:slide-in-from-bottom-2 data-[side=bottom]:slide-in-from-top-2",
|
|
@@ -180,14 +202,21 @@ const ITEM_SIZE_CLASSES = {
|
|
|
180
202
|
"32": "min-h-8 py-[7px] typography-body-small-14px-regular"
|
|
181
203
|
};
|
|
182
204
|
const ITEM_COUNT_TYPOGRAPHY = {
|
|
183
|
-
"40": "typography-body-
|
|
205
|
+
"40": "typography-body-small-14px-regular",
|
|
184
206
|
"32": "typography-body-small-14px-regular"
|
|
185
207
|
};
|
|
186
208
|
function SelectedCheckIndicator({ hasDescription }) {
|
|
187
209
|
return /* @__PURE__ */ jsx(
|
|
188
210
|
CheckIcon,
|
|
189
211
|
{
|
|
190
|
-
className: cn(
|
|
212
|
+
className: cn(
|
|
213
|
+
"size-4 shrink-0 text-content-primary",
|
|
214
|
+
// The two-line layout switches the row to `items-start`, which would hang
|
|
215
|
+
// the tick off the title's line. A leading icon or avatar belongs there —
|
|
216
|
+
// it labels the title — but the tick is a property of the whole row, so it
|
|
217
|
+
// centres against both lines. {@link SelectItem} already does this.
|
|
218
|
+
hasDescription && "self-center"
|
|
219
|
+
)
|
|
191
220
|
}
|
|
192
221
|
);
|
|
193
222
|
}
|
|
@@ -214,8 +243,22 @@ const DropdownMenuItem = React.forwardRef(
|
|
|
214
243
|
const hasDescription = description != null;
|
|
215
244
|
const hasAvatar = avatar != null;
|
|
216
245
|
const itemClassName = cn(
|
|
217
|
-
|
|
246
|
+
// `rounded-sm` (12px), not the 8px the rows carried before: `V2 Menu Item` is
|
|
247
|
+
// `rounded-[var(--radius/rounded-sm,12px)]` (node `21542:8629`). Deliberately
|
|
248
|
+
// different from `DropdownMenuRadioItem` and `DropdownMenuCheckboxItem`, which
|
|
249
|
+
// `V2 Menu Radio Item` draws at `rounded-xs` (node `7393:62008`).
|
|
250
|
+
//
|
|
251
|
+
// `text-start` because the sheet variant renders the row as a <button>, and
|
|
252
|
+
// the UA centres a button's text — which centred the two-line title and
|
|
253
|
+
// description while the popper variant (a div) inherited the panel's start
|
|
254
|
+
// alignment. Both read from the same edge now.
|
|
255
|
+
"group flex w-full cursor-pointer gap-2 rounded-sm px-3 text-start outline-none",
|
|
218
256
|
hasDescription ? "items-start" : "items-center",
|
|
257
|
+
// The sheet's header runs the full width of the panel, so its rows have to
|
|
258
|
+
// come in off the edge themselves — 12px here on the panel's own 4px is the
|
|
259
|
+
// design's 16px. `w-auto` lets the column stretch them to the space left
|
|
260
|
+
// over; `w-full` plus a margin would overflow.
|
|
261
|
+
variant === "sheet" && "mx-3 w-auto",
|
|
219
262
|
ITEM_SIZE_CLASSES[normalizedSize],
|
|
220
263
|
// A 24px avatar would push the compact 32px row past its height with the
|
|
221
264
|
// default padding; tighten it so the avatar variant keeps the 32px contract.
|
|
@@ -235,12 +278,13 @@ const DropdownMenuItem = React.forwardRef(
|
|
|
235
278
|
selected && ["bg-neutral-alphas-100", "data-[highlighted]:bg-neutral-alphas-200"],
|
|
236
279
|
className
|
|
237
280
|
);
|
|
238
|
-
const iconAlignClassName = hasDescription ? "flex shrink-0 items-center
|
|
281
|
+
const iconAlignClassName = hasDescription ? "flex h-[18px] shrink-0 items-center" : null;
|
|
239
282
|
const countNode = count != null && /* @__PURE__ */ jsx(
|
|
240
283
|
"span",
|
|
241
284
|
{
|
|
242
285
|
className: cn(
|
|
243
286
|
"shrink-0 tabular-nums",
|
|
287
|
+
iconAlignClassName,
|
|
244
288
|
ITEM_COUNT_TYPOGRAPHY[normalizedSize],
|
|
245
289
|
destructive ? "text-error-content" : "text-content-tertiary",
|
|
246
290
|
"group-data-[disabled]:text-content-disabled"
|
|
@@ -250,9 +294,9 @@ const DropdownMenuItem = React.forwardRef(
|
|
|
250
294
|
);
|
|
251
295
|
const trailingNode = trailingIcon != null ? hasDescription ? /* @__PURE__ */ jsx("span", { className: iconAlignClassName, children: trailingIcon }) : trailingIcon : selected && /* @__PURE__ */ jsx(SelectedCheckIndicator, { hasDescription });
|
|
252
296
|
const itemChildren = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
253
|
-
avatar != null ? /* @__PURE__ */ jsx("span", { className: "shrink-0", children: avatar }) : leadingIcon != null && (hasDescription ? /* @__PURE__ */ jsx("span", { className: iconAlignClassName, children: leadingIcon }) : leadingIcon),
|
|
297
|
+
avatar != null ? /* @__PURE__ */ jsx("span", { className: cn("shrink-0", iconAlignClassName), children: avatar }) : leadingIcon != null && (hasDescription ? /* @__PURE__ */ jsx("span", { className: iconAlignClassName, children: leadingIcon }) : leadingIcon),
|
|
254
298
|
hasDescription ? /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [
|
|
255
|
-
/* @__PURE__ */ jsx("span", { className: "truncate", children }),
|
|
299
|
+
/* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-semibold truncate", children }),
|
|
256
300
|
/* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-regular truncate text-content-secondary", children: description })
|
|
257
301
|
] }) : /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children }),
|
|
258
302
|
countNode,
|
|
@@ -335,8 +379,9 @@ const DropdownMenuHeader = React.forwardRef(
|
|
|
335
379
|
children,
|
|
336
380
|
...props
|
|
337
381
|
}, ref) => {
|
|
338
|
-
const titleTypography = size === "32" ? "typography-body-small-14px-
|
|
382
|
+
const titleTypography = size === "32" ? "typography-body-small-14px-regular" : "typography-body-default-16px-regular";
|
|
339
383
|
const toggleOpen = React.useContext(ToggleOpenContext);
|
|
384
|
+
const variant = React.useContext(DropdownMenuVariantContext);
|
|
340
385
|
const handleClose = () => {
|
|
341
386
|
onClose?.();
|
|
342
387
|
toggleOpen?.(() => false);
|
|
@@ -351,11 +396,15 @@ const DropdownMenuHeader = React.forwardRef(
|
|
|
351
396
|
// default (title) variant uses 4px because the title baseline sits
|
|
352
397
|
// closer to the divider naturally.
|
|
353
398
|
type === "search" ? "gap-2" : "gap-1",
|
|
399
|
+
// The sheet is a taller, roomier surface than a trigger-anchored panel:
|
|
400
|
+
// the design sets 16px between the rule and the first row, which this
|
|
401
|
+
// margin plus the panel's own 4px gap adds up to.
|
|
402
|
+
variant === "sheet" && "mb-3",
|
|
354
403
|
className
|
|
355
404
|
),
|
|
356
405
|
...props,
|
|
357
406
|
children: [
|
|
358
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 pl-2", children: [
|
|
407
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-4", type === "default" && "pl-2"), children: [
|
|
359
408
|
type === "default" ? /* @__PURE__ */ jsx("div", { className: cn("min-w-0 flex-1 truncate text-content-primary", titleTypography), children: children ?? title }) : /* @__PURE__ */ jsx(SearchInput, { ...searchProps }),
|
|
360
409
|
showClose && /* @__PURE__ */ jsx(
|
|
361
410
|
IconButton,
|
|
@@ -368,7 +417,7 @@ const DropdownMenuHeader = React.forwardRef(
|
|
|
368
417
|
}
|
|
369
418
|
)
|
|
370
419
|
] }),
|
|
371
|
-
/* @__PURE__ */ jsx(DropdownMenuSeparator, { className: "my-0" })
|
|
420
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, { className: "-mx-2 my-0 bg-border-strong" })
|
|
372
421
|
]
|
|
373
422
|
}
|
|
374
423
|
);
|
|
@@ -380,18 +429,23 @@ function SearchInput({
|
|
|
380
429
|
defaultValue,
|
|
381
430
|
onChange,
|
|
382
431
|
placeholder = "Search…",
|
|
383
|
-
"aria-label": ariaLabel = "Search"
|
|
432
|
+
"aria-label": ariaLabel = "Search",
|
|
433
|
+
autoFocus
|
|
384
434
|
} = {}) {
|
|
435
|
+
const inputRef = React.useRef(null);
|
|
436
|
+
React.useEffect(() => {
|
|
437
|
+
if (autoFocus) inputRef.current?.focus();
|
|
438
|
+
}, [autoFocus]);
|
|
385
439
|
return /* @__PURE__ */ jsxs(
|
|
386
440
|
"label",
|
|
387
441
|
{
|
|
388
442
|
className: cn(
|
|
389
443
|
"flex min-w-0 flex-1 items-center gap-2 rounded-xs border border-border-primary",
|
|
390
|
-
"bg-
|
|
444
|
+
"bg-inputs-inputs-primary px-3 py-1 text-content-primary",
|
|
391
445
|
"focus-within:shadow-focus-ring focus-within:outline-none"
|
|
392
446
|
),
|
|
393
447
|
children: [
|
|
394
|
-
/* @__PURE__ */ jsx(SearchIcon, { className: "size-4 shrink-0 text-content-
|
|
448
|
+
/* @__PURE__ */ jsx(SearchIcon, { className: "size-4 shrink-0 text-content-primary", "aria-hidden": "true" }),
|
|
395
449
|
/* @__PURE__ */ jsx(
|
|
396
450
|
"input",
|
|
397
451
|
{
|
|
@@ -400,6 +454,7 @@ function SearchInput({
|
|
|
400
454
|
"typography-body-default-16px-regular min-w-0 flex-1 bg-transparent outline-none",
|
|
401
455
|
"placeholder:text-content-tertiary"
|
|
402
456
|
),
|
|
457
|
+
ref: inputRef,
|
|
403
458
|
value,
|
|
404
459
|
defaultValue,
|
|
405
460
|
placeholder,
|
|
@@ -423,7 +478,10 @@ const DropdownMenuRadioItem = React.forwardRef(({ className, children, helper, s
|
|
|
423
478
|
{
|
|
424
479
|
ref,
|
|
425
480
|
className: cn(
|
|
426
|
-
|
|
481
|
+
// `px-3` (12px), not 16px: `V2 Menu Radio Item` is `px-[12px] py-[8px]`
|
|
482
|
+
// (node `7393:62008`), and at 16px a radio row indented 4px further than a
|
|
483
|
+
// `DropdownMenuCheckboxItem` in the same menu.
|
|
484
|
+
"group flex w-full cursor-pointer items-start gap-3 rounded-xs px-3 py-2 outline-none",
|
|
427
485
|
"data-[highlighted]:bg-neutral-alphas-50",
|
|
428
486
|
"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled",
|
|
429
487
|
// See DropdownMenuItem above: bg-interaction-hover aliases to the same
|
|
@@ -464,8 +522,56 @@ const DropdownMenuRadioItem = React.forwardRef(({ className, children, helper, s
|
|
|
464
522
|
);
|
|
465
523
|
});
|
|
466
524
|
DropdownMenuRadioItem.displayName = "DropdownMenuRadioItem";
|
|
525
|
+
const DropdownMenuCheckboxItem = React.forwardRef(({ className, children, helper, avatar, ...props }, ref) => {
|
|
526
|
+
return /* @__PURE__ */ jsxs(
|
|
527
|
+
DropdownMenuPrimitive.CheckboxItem,
|
|
528
|
+
{
|
|
529
|
+
ref,
|
|
530
|
+
className: cn(
|
|
531
|
+
"group flex w-full cursor-pointer items-center gap-3 rounded-xs px-3 py-2 outline-none",
|
|
532
|
+
// Checked state is carried by the tick alone. A background here would
|
|
533
|
+
// leave every selected row shaded, which reads as "all highlighted" on
|
|
534
|
+
// a menu that starts fully selected.
|
|
535
|
+
"data-[highlighted]:bg-neutral-alphas-50",
|
|
536
|
+
"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled",
|
|
537
|
+
className
|
|
538
|
+
),
|
|
539
|
+
...props,
|
|
540
|
+
children: [
|
|
541
|
+
/* @__PURE__ */ jsx(
|
|
542
|
+
"span",
|
|
543
|
+
{
|
|
544
|
+
className: cn(
|
|
545
|
+
"flex size-4 shrink-0 items-center justify-center rounded-2xs border border-icons-primary",
|
|
546
|
+
"group-data-[state=checked]:bg-icons-primary",
|
|
547
|
+
"group-data-[disabled]:border-content-disabled"
|
|
548
|
+
),
|
|
549
|
+
"aria-hidden": "true",
|
|
550
|
+
children: /* @__PURE__ */ jsx(DropdownMenuPrimitive.ItemIndicator, { asChild: true, children: /* @__PURE__ */ jsx(TickIcon, { className: "size-4 text-content-primary-inverted" }) })
|
|
551
|
+
}
|
|
552
|
+
),
|
|
553
|
+
avatar && /* @__PURE__ */ jsx("span", { className: "shrink-0", children: avatar }),
|
|
554
|
+
/* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
555
|
+
/* @__PURE__ */ jsx("span", { className: "typography-body-default-16px-semibold truncate", children }),
|
|
556
|
+
helper && /* @__PURE__ */ jsx(
|
|
557
|
+
"span",
|
|
558
|
+
{
|
|
559
|
+
className: cn(
|
|
560
|
+
"typography-description-12px-regular text-content-secondary",
|
|
561
|
+
"group-data-[disabled]:text-content-disabled"
|
|
562
|
+
),
|
|
563
|
+
children: helper
|
|
564
|
+
}
|
|
565
|
+
)
|
|
566
|
+
] })
|
|
567
|
+
]
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
});
|
|
571
|
+
DropdownMenuCheckboxItem.displayName = "DropdownMenuCheckboxItem";
|
|
467
572
|
export {
|
|
468
573
|
DropdownMenu,
|
|
574
|
+
DropdownMenuCheckboxItem,
|
|
469
575
|
DropdownMenuContent,
|
|
470
576
|
DropdownMenuGroup,
|
|
471
577
|
DropdownMenuHeader,
|