@fanvue/ui 3.23.0 → 3.25.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 +115 -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/SegmentedControl/SegmentedControl.cjs +14 -4
- package/dist/cjs/components/SegmentedControl/SegmentedControl.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 +115 -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/SegmentedControl/SegmentedControl.mjs +15 -5
- package/dist/components/SegmentedControl/SegmentedControl.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 +406 -17
- 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 +14 -3
- 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
|
@@ -19,98 +19,130 @@ function getLayoutClass(variant, fullWidth, alignLeft) {
|
|
|
19
19
|
if (typeof alignLeft === "string") return `${base} ${alignLeftClasses[alignLeft]}`;
|
|
20
20
|
return base;
|
|
21
21
|
}
|
|
22
|
-
const TabsList = React.forwardRef(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
indicator
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
22
|
+
const TabsList = React.forwardRef(
|
|
23
|
+
({
|
|
24
|
+
className,
|
|
25
|
+
children,
|
|
26
|
+
fullWidth = true,
|
|
27
|
+
alignLeft,
|
|
28
|
+
variant,
|
|
29
|
+
flushLeft = false,
|
|
30
|
+
scrollable = false,
|
|
31
|
+
...props
|
|
32
|
+
}, ref) => {
|
|
33
|
+
const innerRef = React.useRef(null);
|
|
34
|
+
const indicatorRef = React.useRef(null);
|
|
35
|
+
React.useImperativeHandle(ref, () => innerRef.current);
|
|
36
|
+
const updateIndicator = React.useCallback(() => {
|
|
37
|
+
const list = innerRef.current;
|
|
38
|
+
const indicator = indicatorRef.current;
|
|
39
|
+
if (!list || !indicator) return;
|
|
40
|
+
const activeTab = list.querySelector('[data-state="active"]');
|
|
41
|
+
if (!activeTab) {
|
|
42
|
+
indicator.style.opacity = "0";
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const isVertical = list.dataset.orientation === "vertical";
|
|
46
|
+
indicator.style.opacity = "1";
|
|
47
|
+
if (isVertical) {
|
|
48
|
+
indicator.style.background = "linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)";
|
|
49
|
+
indicator.style.inset = `0 -1px auto auto`;
|
|
50
|
+
indicator.style.width = "1px";
|
|
51
|
+
indicator.style.height = `${activeTab.offsetHeight}px`;
|
|
52
|
+
indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;
|
|
53
|
+
} else {
|
|
54
|
+
indicator.style.background = "linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)";
|
|
55
|
+
const textSpan = activeTab.querySelector("span");
|
|
56
|
+
const target = textSpan ?? activeTab;
|
|
57
|
+
const textWidth = target.getBoundingClientRect().width;
|
|
58
|
+
const textOffsetInTab = target === activeTab ? 0 : target.getBoundingClientRect().left - activeTab.getBoundingClientRect().left;
|
|
59
|
+
const indicatorLeft = activeTab.offsetLeft + textOffsetInTab;
|
|
60
|
+
indicator.style.inset = "auto auto 0 0";
|
|
61
|
+
indicator.style.height = "1px";
|
|
62
|
+
indicator.style.width = `${textWidth}px`;
|
|
63
|
+
indicator.style.transform = `translateX(${indicatorLeft}px)`;
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
const revealActiveTab = React.useCallback(() => {
|
|
67
|
+
const list = innerRef.current;
|
|
68
|
+
if (!list || !scrollable || list.dataset.orientation === "vertical") return;
|
|
69
|
+
const activeTab = list.querySelector('[data-state="active"]');
|
|
70
|
+
if (!activeTab) return;
|
|
71
|
+
const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;
|
|
72
|
+
if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;
|
|
73
|
+
}, [scrollable]);
|
|
74
|
+
React.useLayoutEffect(() => {
|
|
75
|
+
const list = innerRef.current;
|
|
76
|
+
const indicator = indicatorRef.current;
|
|
77
|
+
if (!list || !indicator) return;
|
|
78
|
+
indicator.style.transitionDuration = "0s";
|
|
79
|
+
updateIndicator();
|
|
80
|
+
indicator.getBoundingClientRect();
|
|
81
|
+
indicator.style.transitionDuration = "";
|
|
82
|
+
revealActiveTab();
|
|
83
|
+
const mutationObserver = new MutationObserver(updateIndicator);
|
|
84
|
+
mutationObserver.observe(list, {
|
|
85
|
+
attributes: true,
|
|
86
|
+
attributeFilter: ["data-state"],
|
|
87
|
+
childList: true,
|
|
88
|
+
subtree: true
|
|
76
89
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
cancelled =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
90
|
+
const resizeObserver = new ResizeObserver(updateIndicator);
|
|
91
|
+
resizeObserver.observe(list);
|
|
92
|
+
let cancelled = false;
|
|
93
|
+
if (document.fonts?.status !== "loaded") {
|
|
94
|
+
document.fonts?.ready.then(() => {
|
|
95
|
+
if (cancelled) return;
|
|
96
|
+
updateIndicator();
|
|
97
|
+
revealActiveTab();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return () => {
|
|
101
|
+
cancelled = true;
|
|
102
|
+
mutationObserver.disconnect();
|
|
103
|
+
resizeObserver.disconnect();
|
|
104
|
+
};
|
|
105
|
+
}, [updateIndicator, revealActiveTab]);
|
|
106
|
+
return /* @__PURE__ */ jsxs(
|
|
107
|
+
TabsPrimitive.List,
|
|
108
|
+
{
|
|
109
|
+
ref: innerRef,
|
|
110
|
+
className: cn(
|
|
111
|
+
// `isolate` scopes the active indicator's `z-10` to a local stacking
|
|
112
|
+
// context. Without it, `relative` alone creates no stacking context, so
|
|
113
|
+
// the indicator escapes and paints above page chrome (e.g. the header).
|
|
114
|
+
"relative isolate",
|
|
115
|
+
getLayoutClass(variant, fullWidth, alignLeft),
|
|
116
|
+
// Horizontal only: in the vertical orientation the leading padding is
|
|
117
|
+
// the row's left inset, not a label offset, so zeroing it would pull
|
|
118
|
+
// the first label out of line with the others.
|
|
119
|
+
flushLeft && "data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0",
|
|
120
|
+
// `flex-none` is what stops the tabs compressing — without it they
|
|
121
|
+
// share the row and never overflow, so there is nothing to scroll.
|
|
122
|
+
// The scrollbar is hidden in both engines: Firefox reads
|
|
123
|
+
// `scrollbar-width`, WebKit and Blink the pseudo-element.
|
|
124
|
+
scrollable && "data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none",
|
|
125
|
+
"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]",
|
|
126
|
+
"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]",
|
|
127
|
+
className
|
|
128
|
+
),
|
|
129
|
+
...props,
|
|
130
|
+
children: [
|
|
131
|
+
children,
|
|
132
|
+
/* @__PURE__ */ jsx(
|
|
133
|
+
"span",
|
|
134
|
+
{
|
|
135
|
+
ref: indicatorRef,
|
|
136
|
+
"aria-hidden": true,
|
|
137
|
+
className: "pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out",
|
|
138
|
+
style: { opacity: 0 }
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
);
|
|
114
146
|
TabsList.displayName = "TabsList";
|
|
115
147
|
export {
|
|
116
148
|
TabsList
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabsList.mjs","sources":["../../../src/components/Tabs/TabsList.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Breakpoint values for responsive props. */\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nconst alignLeftClasses: Record<Breakpoint | \"always\", string> = {\n always: \"[&>[role=tab]]:flex-initial\",\n sm: \"[&>[role=tab]]:sm:flex-initial\",\n md: \"[&>[role=tab]]:md:flex-initial\",\n lg: \"[&>[role=tab]]:lg:flex-initial\",\n xl: \"[&>[role=tab]]:xl:flex-initial\",\n};\n\nfunction getLayoutClass(\n variant: \"fill\" | \"hug\" | undefined,\n fullWidth: boolean,\n alignLeft?: boolean | Breakpoint,\n): string {\n if (variant === \"hug\") return \"inline-flex\";\n if (variant === \"fill\") return \"flex w-full [&>[role=tab]]:flex-1\";\n\n if (!fullWidth) return \"inline-flex\";\n\n const base = \"flex w-full [&>[role=tab]]:flex-1\";\n if (alignLeft === true) return `${base} ${alignLeftClasses.always}`;\n if (typeof alignLeft === \"string\") return `${base} ${alignLeftClasses[alignLeft]}`;\n return base;\n}\n\n/** Props for the {@link TabsList} component. */\nexport type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n /** When `true` (the default), the tab list spans the full width of its container and each tab grows equally. Set to `false` for inline sizing. */\n fullWidth?: boolean;\n /**\n * Controls tab alignment within a full-width container.\n * - `false` (default): tabs spread evenly\n * - `true`: tabs left-aligned, sized to content\n * - `\"md\"` (breakpoint): spread on mobile, left-aligned at breakpoint and up\n */\n alignLeft?: boolean | Breakpoint;\n /** Explicit layout variant. `\"hug\"` sizes the list to its content; `\"fill\"` stretches it full-width with equal-width tabs. Takes precedence over `fullWidth`/`alignLeft`. */\n variant?: \"fill\" | \"hug\";\n};\n\n/** Container for {@link TabsTrigger} elements. Renders a sliding active-tab indicator that animates between tabs. */\nexport const TabsList = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.List>,\n TabsListProps\n>(({ className, children, fullWidth = true, alignLeft, variant, ...props }, ref) => {\n const innerRef = React.useRef<HTMLDivElement>(null);\n const indicatorRef = React.useRef<HTMLSpanElement>(null);\n\n React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement);\n\n const updateIndicator = React.useCallback(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) {\n indicator.style.opacity = \"0\";\n return;\n }\n\n const isVertical = list.dataset.orientation === \"vertical\";\n\n indicator.style.opacity = \"1\";\n\n if (isVertical) {\n indicator.style.background =\n \"linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = `0 -1px auto auto`;\n indicator.style.width = \"1px\";\n indicator.style.height = `${activeTab.offsetHeight}px`;\n indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;\n } else {\n indicator.style.background =\n \"linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n const textSpan = activeTab.querySelector(\"span\");\n const textWidth = (textSpan ?? activeTab).getBoundingClientRect().width;\n const tabCenter = activeTab.offsetLeft + activeTab.offsetWidth / 2;\n const indicatorLeft = tabCenter - textWidth / 2;\n indicator.style.inset = \"auto auto 0 0\";\n indicator.style.height = \"1px\";\n indicator.style.width = `${textWidth}px`;\n indicator.style.transform = `translateX(${indicatorLeft}px)`;\n }\n }, []);\n\n React.useLayoutEffect(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n indicator.style.transitionDuration = \"0s\";\n updateIndicator();\n indicator.getBoundingClientRect();\n indicator.style.transitionDuration = \"\";\n\n const mutationObserver = new MutationObserver(updateIndicator);\n mutationObserver.observe(list, {\n attributes: true,\n attributeFilter: [\"data-state\"],\n childList: true,\n subtree: true,\n });\n\n const resizeObserver = new ResizeObserver(updateIndicator);\n resizeObserver.observe(list);\n\n let cancelled = false;\n if (document.fonts?.status !== \"loaded\") {\n document.fonts?.ready.then(() => {\n if (!cancelled) updateIndicator();\n });\n }\n\n return () => {\n cancelled = true;\n mutationObserver.disconnect();\n resizeObserver.disconnect();\n };\n }, [updateIndicator]);\n\n return (\n <TabsPrimitive.List\n ref={innerRef}\n className={cn(\n // `isolate` scopes the active indicator's `z-10` to a local stacking\n // context. Without it, `relative` alone creates no stacking context, so\n // the indicator escapes and paints above page chrome (e.g. the header).\n \"relative isolate\",\n getLayoutClass(variant, fullWidth, alignLeft),\n \"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]\",\n \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]\",\n className,\n )}\n {...props}\n >\n {children}\n <span\n ref={indicatorRef}\n aria-hidden\n className=\"pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out\"\n style={{ opacity: 0 }}\n />\n </TabsPrimitive.List>\n );\n});\n\nTabsList.displayName = \"TabsList\";\n"],"names":[],"mappings":";;;;;AAOA,MAAM,mBAA0D;AAAA,EAC9D,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,SAAS,eACP,SACA,WACA,WACQ;AACR,MAAI,YAAY,MAAO,QAAO;AAC9B,MAAI,YAAY,OAAQ,QAAO;AAE/B,MAAI,CAAC,UAAW,QAAO;AAEvB,QAAM,OAAO;AACb,MAAI,cAAc,KAAM,QAAO,GAAG,IAAI,IAAI,iBAAiB,MAAM;AACjE,MAAI,OAAO,cAAc,SAAU,QAAO,GAAG,IAAI,IAAI,iBAAiB,SAAS,CAAC;AAChF,SAAO;AACT;AAkBO,MAAM,WAAW,MAAM,WAG5B,CAAC,EAAE,WAAW,UAAU,YAAY,MAAM,WAAW,SAAS,GAAG,MAAA,GAAS,QAAQ;AAClF,QAAM,WAAW,MAAM,OAAuB,IAAI;AAClD,QAAM,eAAe,MAAM,OAAwB,IAAI;AAEvD,QAAM,oBAAoB,KAAK,MAAM,SAAS,OAAyB;AAEvE,QAAM,k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AAe,eAAe;AACzD,mBAAe,QAAQ,IAAI;AAE3B,QAAI,YAAY;AAChB,QAAI,SAAS,OAAO,WAAW,UAAU;AACvC,eAAS,OAAO,MAAM,KAAK,MAAM;AAC/B,YAAI,CAAC,UAAW,iBAAA;AAAA,MAClB,CAAC;AAAA,IACH;AAEA,WAAO,MAAM;AACX,kBAAY;AACZ,uBAAiB,WAAA;AACjB,qBAAe,WAAA;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,SACE;AAAA,IAAC,cAAc;AAAA,IAAd;AAAA,MACC,KAAK;AAAA,MACL,WAAW;AAAA;AAAA;AAAA;AAAA,QAIT;AAAA,QACA,eAAe,SAAS,WAAW,SAAS;AAAA,QAC5C;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAED,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACD;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,KAAK;AAAA,YACL,eAAW;AAAA,YACX,WAAU;AAAA,YACV,OAAO,EAAE,SAAS,EAAA;AAAA,UAAE;AAAA,QAAA;AAAA,MACtB;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;AAED,SAAS,cAAc;"}
|
|
1
|
+
{"version":3,"file":"TabsList.mjs","sources":["../../../src/components/Tabs/TabsList.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Breakpoint values for responsive props. */\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nconst alignLeftClasses: Record<Breakpoint | \"always\", string> = {\n always: \"[&>[role=tab]]:flex-initial\",\n sm: \"[&>[role=tab]]:sm:flex-initial\",\n md: \"[&>[role=tab]]:md:flex-initial\",\n lg: \"[&>[role=tab]]:lg:flex-initial\",\n xl: \"[&>[role=tab]]:xl:flex-initial\",\n};\n\nfunction getLayoutClass(\n variant: \"fill\" | \"hug\" | undefined,\n fullWidth: boolean,\n alignLeft?: boolean | Breakpoint,\n): string {\n if (variant === \"hug\") return \"inline-flex\";\n if (variant === \"fill\") return \"flex w-full [&>[role=tab]]:flex-1\";\n\n if (!fullWidth) return \"inline-flex\";\n\n const base = \"flex w-full [&>[role=tab]]:flex-1\";\n if (alignLeft === true) return `${base} ${alignLeftClasses.always}`;\n if (typeof alignLeft === \"string\") return `${base} ${alignLeftClasses[alignLeft]}`;\n return base;\n}\n\n/** Props for the {@link TabsList} component. */\nexport type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n /** When `true` (the default), the tab list spans the full width of its container and each tab grows equally. Set to `false` for inline sizing. */\n fullWidth?: boolean;\n /**\n * Controls tab alignment within a full-width container.\n * - `false` (default): tabs spread evenly\n * - `true`: tabs left-aligned, sized to content\n * - `\"md\"` (breakpoint): spread on mobile, left-aligned at breakpoint and up\n */\n alignLeft?: boolean | Breakpoint;\n /** Explicit layout variant. `\"hug\"` sizes the list to its content; `\"fill\"` stretches it full-width with equal-width tabs. Takes precedence over `fullWidth`/`alignLeft`. */\n variant?: \"fill\" | \"hug\";\n /**\n * Drops the leading padding on the first tab so its label sits flush with the\n * list's left edge, lining it up with page content above or below the bar\n * (a heading, for instance) rather than being indented by the tab's own\n * padding. Spacing between tabs is unaffected. Pair with `alignLeft` or\n * `variant=\"hug\"`. @default false\n */\n flushLeft?: boolean;\n /**\n * Scrolls the row horizontally when the tabs don't fit, instead of letting\n * them compress. By default a tab may shrink until its label ellipsises,\n * which on a narrow viewport can truncate every label at once; here each tab\n * keeps its natural width and the overflow scrolls. The scrollbar itself is\n * hidden — the clipped tab at the edge is the affordance.\n *\n * Because the tabs are content-sized, they no longer spread to fill the row:\n * a set that does fit sits left-aligned, as with `alignLeft`.\n *\n * Horizontal orientation only: a vertical list already grows downwards.\n * @default false\n */\n scrollable?: boolean;\n};\n\n/** Container for {@link TabsTrigger} elements. Renders a sliding active-tab indicator that animates between tabs. */\nexport const TabsList = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.List>,\n TabsListProps\n>(\n (\n {\n className,\n children,\n fullWidth = true,\n alignLeft,\n variant,\n flushLeft = false,\n scrollable = false,\n ...props\n },\n ref,\n ) => {\n const innerRef = React.useRef<HTMLDivElement>(null);\n const indicatorRef = React.useRef<HTMLSpanElement>(null);\n\n React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement);\n\n const updateIndicator = React.useCallback(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) {\n indicator.style.opacity = \"0\";\n return;\n }\n\n const isVertical = list.dataset.orientation === \"vertical\";\n\n indicator.style.opacity = \"1\";\n\n if (isVertical) {\n indicator.style.background =\n \"linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = `0 -1px auto auto`;\n indicator.style.width = \"1px\";\n indicator.style.height = `${activeTab.offsetHeight}px`;\n indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;\n } else {\n indicator.style.background =\n \"linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n const textSpan = activeTab.querySelector(\"span\");\n const target = textSpan ?? activeTab;\n const textWidth = target.getBoundingClientRect().width;\n // Anchor to where the label actually sits, not to the tab's centre. The two\n // only coincide when the tab's horizontal padding is symmetric, which\n // `flushLeft` breaks by dropping `pl` on the first tab: the tab's centre then\n // sits `pr / 2` to the right of the label's. Measured as a difference of two\n // rects so it stays correct while a `scrollable` list is scrolled.\n const textOffsetInTab =\n target === activeTab\n ? 0\n : target.getBoundingClientRect().left - activeTab.getBoundingClientRect().left;\n const indicatorLeft = activeTab.offsetLeft + textOffsetInTab;\n indicator.style.inset = \"auto auto 0 0\";\n indicator.style.height = \"1px\";\n indicator.style.width = `${textWidth}px`;\n indicator.style.transform = `translateX(${indicatorLeft}px)`;\n }\n }, []);\n\n // Radix scrolls a tab into view when it takes focus, and mount is not focus, so\n // URL-driven state can land on a tab that is off to the right with nothing on\n // screen to say so: no indicator, and tab one showing as though it were active.\n // Assigns `scrollLeft` rather than calling `scrollIntoView`, which would also\n // scroll every ancestor and the page with it. Only ever scrolls further right, so\n // re-running it after the webfont settles corrects a short initial scroll without\n // yanking the row back from wherever the user has since dragged it.\n const revealActiveTab = React.useCallback(() => {\n const list = innerRef.current;\n if (!list || !scrollable || list.dataset.orientation === \"vertical\") return;\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) return;\n const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;\n if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;\n }, [scrollable]);\n\n React.useLayoutEffect(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n indicator.style.transitionDuration = \"0s\";\n updateIndicator();\n indicator.getBoundingClientRect();\n indicator.style.transitionDuration = \"\";\n revealActiveTab();\n\n const mutationObserver = new MutationObserver(updateIndicator);\n mutationObserver.observe(list, {\n attributes: true,\n attributeFilter: [\"data-state\"],\n childList: true,\n subtree: true,\n });\n\n const resizeObserver = new ResizeObserver(updateIndicator);\n resizeObserver.observe(list);\n\n let cancelled = false;\n if (document.fonts?.status !== \"loaded\") {\n document.fonts?.ready.then(() => {\n if (cancelled) return;\n updateIndicator();\n // The tabs are wider once the real font is in, so the mount-time scroll can\n // fall short of the active tab. Recomputed here against the settled layout.\n revealActiveTab();\n });\n }\n\n return () => {\n cancelled = true;\n mutationObserver.disconnect();\n resizeObserver.disconnect();\n };\n }, [updateIndicator, revealActiveTab]);\n\n return (\n <TabsPrimitive.List\n ref={innerRef}\n className={cn(\n // `isolate` scopes the active indicator's `z-10` to a local stacking\n // context. Without it, `relative` alone creates no stacking context, so\n // the indicator escapes and paints above page chrome (e.g. the header).\n \"relative isolate\",\n getLayoutClass(variant, fullWidth, alignLeft),\n // Horizontal only: in the vertical orientation the leading padding is\n // the row's left inset, not a label offset, so zeroing it would pull\n // the first label out of line with the others.\n flushLeft && \"data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0\",\n // `flex-none` is what stops the tabs compressing — without it they\n // share the row and never overflow, so there is nothing to scroll.\n // The scrollbar is hidden in both engines: Firefox reads\n // `scrollbar-width`, WebKit and Blink the pseudo-element.\n scrollable &&\n \"data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none\",\n \"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]\",\n \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]\",\n className,\n )}\n {...props}\n >\n {children}\n <span\n ref={indicatorRef}\n aria-hidden\n className=\"pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out\"\n style={{ opacity: 0 }}\n />\n </TabsPrimitive.List>\n );\n },\n);\n\nTabsList.displayName = \"TabsList\";\n"],"names":[],"mappings":";;;;;AAOA,MAAM,mBAA0D;AAAA,EAC9D,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,SAAS,eACP,SACA,WACA,WACQ;AACR,MAAI,YAAY,MAAO,QAAO;AAC9B,MAAI,YAAY,OAAQ,QAAO;AAE/B,MAAI,CAAC,UAAW,QAAO;AAEvB,QAAM,OAAO;AACb,MAAI,cAAc,KAAM,QAAO,GAAG,IAAI,IAAI,iBAAiB,MAAM;AACjE,MAAI,OAAO,cAAc,SAAU,QAAO,GAAG,IAAI,IAAI,iBAAiB,SAAS,CAAC;AAChF,SAAO;AACT;AAwCO,MAAM,WAAW,MA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A,UACF;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL,eAAW;AAAA,cACX,WAAU;AAAA,cACV,OAAO,EAAE,SAAS,EAAA;AAAA,YAAE;AAAA,UAAA;AAAA,QACtB;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;"}
|
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { cn } from "../../utils/cn.mjs";
|
|
6
|
-
const
|
|
6
|
+
const DEFAULT_DELAY_DURATION = 200;
|
|
7
|
+
const TooltipProvider = ({
|
|
8
|
+
delayDuration = DEFAULT_DELAY_DURATION,
|
|
9
|
+
...props
|
|
10
|
+
}) => /* @__PURE__ */ jsx(TooltipPrimitive.Provider, { delayDuration, ...props });
|
|
11
|
+
TooltipProvider.displayName = "TooltipProvider";
|
|
7
12
|
const Tooltip = TooltipPrimitive.Root;
|
|
8
13
|
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
9
|
-
const TooltipContent = React.forwardRef(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
18
|
-
TooltipPrimitive.Content,
|
|
19
|
-
{
|
|
20
|
-
ref,
|
|
21
|
-
side: resolvedSide,
|
|
22
|
-
align: resolvedAlign,
|
|
23
|
-
sideOffset,
|
|
24
|
-
collisionPadding: 8,
|
|
25
|
-
style: { zIndex: "var(--fanvue-ui-portal-z-index, 50)", ...style },
|
|
26
|
-
className: cn(
|
|
27
|
-
"typography-description-12px-semibold max-w-[320px] rounded-sm bg-surface-primary-inverted px-4 py-2 text-content-primary-inverted shadow-[0px_1px_4px_0px_rgba(0,0,0,0.06),0px_1px_3px_0px_rgba(0,0,0,0.05)]",
|
|
28
|
-
className
|
|
29
|
-
),
|
|
30
|
-
...props
|
|
14
|
+
const TooltipContent = React.forwardRef(
|
|
15
|
+
({ className, sideOffset = 8, style, placement, side, align, title, children, ...props }, ref) => {
|
|
16
|
+
let resolvedSide = side;
|
|
17
|
+
let resolvedAlign = align ?? "center";
|
|
18
|
+
if (placement) {
|
|
19
|
+
const [parsedSide, parsedAlign] = placement.split("-");
|
|
20
|
+
resolvedSide = parsedSide;
|
|
21
|
+
resolvedAlign = parsedAlign ?? "center";
|
|
31
22
|
}
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
24
|
+
TooltipPrimitive.Content,
|
|
25
|
+
{
|
|
26
|
+
ref,
|
|
27
|
+
side: resolvedSide,
|
|
28
|
+
align: resolvedAlign,
|
|
29
|
+
sideOffset,
|
|
30
|
+
collisionPadding: 8,
|
|
31
|
+
style: { zIndex: "var(--fanvue-ui-portal-z-index, 50)", ...style },
|
|
32
|
+
className: cn(
|
|
33
|
+
"typography-description-12px-semibold max-w-[320px] rounded-sm bg-surface-primary-inverted px-4 py-2 text-content-primary-inverted shadow-[0px_1px_4px_0px_rgba(0,0,0,0.06),0px_1px_3px_0px_rgba(0,0,0,0.05)]",
|
|
34
|
+
className
|
|
35
|
+
),
|
|
36
|
+
...props,
|
|
37
|
+
children: title ? /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-1", children: [
|
|
38
|
+
/* @__PURE__ */ jsx("span", { children: title }),
|
|
39
|
+
/* @__PURE__ */ jsx("span", { className: "typography-description-12px-regular", children })
|
|
40
|
+
] }) : children
|
|
41
|
+
}
|
|
42
|
+
) });
|
|
43
|
+
}
|
|
44
|
+
);
|
|
34
45
|
TooltipContent.displayName = "TooltipContent";
|
|
35
46
|
export {
|
|
36
47
|
Tooltip,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.mjs","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as TooltipPrimitive from \"@radix-ui/react-tooltip\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Props for the {@link TooltipProvider}. Wraps Radix `Tooltip.Provider`. */\nexport type TooltipProviderProps = React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Provider>;\n\n
|
|
1
|
+
{"version":3,"file":"Tooltip.mjs","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as TooltipPrimitive from \"@radix-ui/react-tooltip\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Props for the {@link TooltipProvider}. Wraps Radix `Tooltip.Provider`. */\nexport type TooltipProviderProps = React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Provider>;\n\nconst DEFAULT_DELAY_DURATION = 200;\n\n/**\n * Provides tooltip delay and skip-delay context. Wrap your app or a subtree.\n *\n * Defaults `delayDuration` to 200ms rather than inheriting Radix's 700ms, which\n * reads as unresponsive on the short hint labels this library uses tooltips for.\n * Pass `delayDuration` to override.\n *\n * Note that `TooltipLabel`, `ChartCard` and `SwitchField` each mount their own\n * provider internally, so they take this default but not an app-level override.\n */\nexport const TooltipProvider = ({\n delayDuration = DEFAULT_DELAY_DURATION,\n ...props\n}: TooltipProviderProps) => <TooltipPrimitive.Provider delayDuration={delayDuration} {...props} />;\nTooltipProvider.displayName = \"TooltipProvider\";\n\n/** Props for the {@link Tooltip} root component. */\nexport interface TooltipProps extends React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Root> {\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n defaultOpen?: boolean;\n}\n\n/** Root component that manages open/close state for a single tooltip. */\nexport const Tooltip = TooltipPrimitive.Root;\n\n/** Props for the {@link TooltipTrigger} component. */\nexport type TooltipTriggerProps = React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Trigger>;\n\n/** The element that triggers the tooltip on hover/focus. */\nexport const TooltipTrigger = TooltipPrimitive.Trigger;\n\n/** Position of the tooltip relative to its trigger, combining side and alignment (MUI-style). */\nexport type TooltipPlacement =\n | \"top\"\n | \"top-start\"\n | \"top-end\"\n | \"bottom\"\n | \"bottom-start\"\n | \"bottom-end\"\n | \"left\"\n | \"left-start\"\n | \"left-end\"\n | \"right\"\n | \"right-start\"\n | \"right-end\";\n\nexport interface TooltipContentProps\n extends Omit<React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>, \"title\"> {\n /**\n * Position of the tooltip relative to the trigger. Takes precedence over `side` and `align`.\n * @default \"top\"\n */\n placement?: TooltipPlacement;\n /**\n * Optional heading above the body, for the two-row tooltip: a bold label\n * naming the thing, then a plain-weight description of it. Without it the\n * tooltip is a single bold line.\n */\n title?: React.ReactNode;\n}\n\nexport const TooltipContent = React.forwardRef<\n React.ComponentRef<typeof TooltipPrimitive.Content>,\n TooltipContentProps\n>(\n (\n { className, sideOffset = 8, style, placement, side, align, title, children, ...props },\n ref,\n ) => {\n let resolvedSide = side;\n let resolvedAlign: \"start\" | \"center\" | \"end\" = align ?? \"center\";\n if (placement) {\n const [parsedSide, parsedAlign] = placement.split(\"-\") as [\n \"top\" | \"right\" | \"bottom\" | \"left\",\n \"start\" | \"end\" | undefined,\n ];\n resolvedSide = parsedSide;\n resolvedAlign = parsedAlign ?? \"center\";\n }\n\n return (\n <TooltipPrimitive.Portal>\n <TooltipPrimitive.Content\n ref={ref}\n side={resolvedSide}\n align={resolvedAlign}\n sideOffset={sideOffset}\n collisionPadding={8}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\", ...style }}\n className={cn(\n \"typography-description-12px-semibold max-w-[320px] rounded-sm bg-surface-primary-inverted px-4 py-2 text-content-primary-inverted shadow-[0px_1px_4px_0px_rgba(0,0,0,0.06),0px_1px_3px_0px_rgba(0,0,0,0.05)]\",\n className,\n )}\n {...props}\n >\n {title ? (\n <span className=\"flex flex-col gap-1\">\n <span>{title}</span>\n <span className=\"typography-description-12px-regular\">{children}</span>\n </span>\n ) : (\n children\n )}\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n );\n },\n);\nTooltipContent.displayName = \"TooltipContent\";\n"],"names":[],"mappings":";;;;;AAOA,MAAM,yBAAyB;AAYxB,MAAM,kBAAkB,CAAC;AAAA,EAC9B,gBAAgB;AAAA,EAChB,GAAG;AACL,0BAA6B,iBAAiB,UAAjB,EAA0B,eAA+B,GAAG,MAAA,CAAO;AAChG,gBAAgB,cAAc;AAUvB,MAAM,UAAU,iBAAiB;AAMjC,MAAM,iBAAiB,iBAAiB;AAgCxC,MAAM,iBAAiB,MAAM;AAAA,EAIlC,CACE,EAAE,WAAW,aAAa,GAAG,OAAO,WAAW,MAAM,OAAO,OAAO,UAAU,GAAG,MAAA,GAChF,QACG;AACH,QAAI,eAAe;AACnB,QAAI,gBAA4C,SAAS;AACzD,QAAI,WAAW;AACb,YAAM,CAAC,YAAY,WAAW,IAAI,UAAU,MAAM,GAAG;AAIrD,qBAAe;AACf,sBAAgB,eAAe;AAAA,IACjC;AAEA,WACE,oBAAC,iBAAiB,QAAjB,EACC,UAAA;AAAA,MAAC,iBAAiB;AAAA,MAAjB;AAAA,QACC;AAAA,QACA,MAAM;AAAA,QACN,OAAO;AAAA,QACP;AAAA,QACA,kBAAkB;AAAA,QAClB,OAAO,EAAE,QAAQ,uCAAuC,GAAG,MAAA;AAAA,QAC3D,WAAW;AAAA,UACT;AAAA,UACA;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA,QACC,qBAAC,QAAA,EAAK,WAAU,uBACd,UAAA;AAAA,UAAA,oBAAC,UAAM,UAAA,MAAA,CAAM;AAAA,UACb,oBAAC,QAAA,EAAK,WAAU,uCAAuC,SAAA,CAAS;AAAA,QAAA,EAAA,CAClE,IAEA;AAAA,MAAA;AAAA,IAAA,GAGN;AAAA,EAEJ;AACF;AACA,eAAe,cAAc;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../../utils/cn.mjs";
|
|
5
|
+
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from "./Tooltip.mjs";
|
|
6
|
+
const TooltipLabel = React.forwardRef(
|
|
7
|
+
({ tooltip, children, className, onClick, onPointerDown, onBlur, ...props }, ref) => {
|
|
8
|
+
const [open, setOpen] = React.useState(false);
|
|
9
|
+
const pointerTypeRef = React.useRef("");
|
|
10
|
+
const openAtTapStartRef = React.useRef(false);
|
|
11
|
+
const isTouch = () => pointerTypeRef.current === "touch";
|
|
12
|
+
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip, { open, onOpenChange: setOpen, children: [
|
|
13
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
14
|
+
"button",
|
|
15
|
+
{
|
|
16
|
+
ref,
|
|
17
|
+
type: "button",
|
|
18
|
+
className: cn(
|
|
19
|
+
// `w-fit` keeps the trigger the size of its label. The button is
|
|
20
|
+
// block-level, so a column flex or grid cell would otherwise stretch it
|
|
21
|
+
// and the whole row would answer to hover with a help cursor, opening
|
|
22
|
+
// this label's tooltip from a long way away from the label.
|
|
23
|
+
"typography-body-small-14px-regular w-fit cursor-help rounded-2xs text-left text-content-secondary outline-none",
|
|
24
|
+
"hover:text-content-primary focus-visible:shadow-focus-ring",
|
|
25
|
+
className
|
|
26
|
+
),
|
|
27
|
+
onPointerDown: (event) => {
|
|
28
|
+
pointerTypeRef.current = event.pointerType;
|
|
29
|
+
openAtTapStartRef.current = open;
|
|
30
|
+
onPointerDown?.(event);
|
|
31
|
+
},
|
|
32
|
+
onClick: (event) => {
|
|
33
|
+
onClick?.(event);
|
|
34
|
+
if (!isTouch()) return;
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
setOpen(!openAtTapStartRef.current);
|
|
37
|
+
},
|
|
38
|
+
onBlur: (event) => {
|
|
39
|
+
pointerTypeRef.current = "";
|
|
40
|
+
onBlur?.(event);
|
|
41
|
+
},
|
|
42
|
+
...props,
|
|
43
|
+
children: /* @__PURE__ */ jsx("span", { className: "bg-[length:8px_1px] bg-[linear-gradient(to_right,var(--color-icons-tertiary)_0_4px,transparent_4px_8px)] bg-bottom-left bg-repeat-x", children })
|
|
44
|
+
}
|
|
45
|
+
) }),
|
|
46
|
+
/* @__PURE__ */ jsx(TooltipContent, { title: /* @__PURE__ */ jsx("span", { "aria-hidden": true, children }), children: tooltip })
|
|
47
|
+
] }) });
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
TooltipLabel.displayName = "TooltipLabel";
|
|
51
|
+
export {
|
|
52
|
+
TooltipLabel
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=TooltipLabel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TooltipLabel.mjs","sources":["../../../src/components/Tooltip/TooltipLabel.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from \"./Tooltip\";\n\n/** Props for {@link TooltipLabel}. */\nexport interface TooltipLabelProps\n // `title` is omitted so a native browser tooltip cannot appear alongside the\n // Radix one on the same element. `TooltipContentProps` omits it too.\n extends Omit<React.ComponentPropsWithoutRef<\"button\">, \"title\"> {\n /** Tooltip content. Pass a translated string for i18n. */\n tooltip: React.ReactNode;\n /** The label text, which doubles as the trigger. */\n children: React.ReactNode;\n}\n\n/**\n * A text label that is itself the tooltip trigger, marked by a dashed\n * underline. Use this instead of pairing a label with a separate info glyph:\n * the visible text becomes the trigger's accessible name, and the row stays at\n * text height rather than being stretched by an icon button.\n *\n * The label is repeated as the tooltip's heading, so the tooltip reads as the\n * two-row block the design specifies — the term, then what it means.\n *\n * Tapping the label toggles the tooltip on touch devices, where there is no\n * hover to trigger it. Tapping elsewhere, scrolling, or opening another tooltip\n * dismisses it.\n *\n * @example\n * ```tsx\n * <TooltipLabel tooltip=\"Total earnings for the selected period.\">Total Earnings</TooltipLabel>\n * ```\n */\nexport const TooltipLabel = React.forwardRef<HTMLButtonElement, TooltipLabelProps>(\n ({ tooltip, children, className, onClick, onPointerDown, onBlur, ...props }, ref) => {\n /*\n * Touch has to drive the tooltip from the tap itself, not from focus.\n *\n * Radix's trigger ignores pointer events whose `pointerType` is \"touch\", so\n * hover never opens the tooltip on a phone; focus is the only thing that\n * does. That is not enough on its own for two reasons, and both need the\n * open state controlled here:\n *\n * - The trigger closes on click. Since the tap that focuses the label is\n * also a click, focus opens the tooltip and the click immediately shuts\n * it, so it only flashes.\n * - After the first tap the label keeps focus. Dismissing the tooltip by\n * tapping elsewhere leaves it focused, so a second tap fires no focus\n * event and nothing would reopen it.\n *\n * Radix composes trigger handlers with `checkForDefaultPrevented`, so\n * calling `preventDefault` makes it skip its own open/close and leaves the\n * toggle below in charge. Dismissal still comes from Radix: `TooltipContent`\n * closes on outside pointerdown, Escape, scroll, and when another tooltip\n * opens.\n *\n * All of this is scoped to touch, so mouse and keyboard behave as before.\n */\n const [open, setOpen] = React.useState(false);\n const pointerTypeRef = React.useRef<string>(\"\");\n /**\n * The open state as it was when the tap began. The trigger's own pointerdown\n * close lands between pointerdown and click, so toggling against the live\n * state would read the value Radix just reset and reopen on every tap.\n */\n const openAtTapStartRef = React.useRef(false);\n\n const isTouch = () => pointerTypeRef.current === \"touch\";\n\n return (\n <TooltipProvider>\n <Tooltip open={open} onOpenChange={setOpen}>\n <TooltipTrigger asChild>\n <button\n ref={ref}\n type=\"button\"\n className={cn(\n // `w-fit` keeps the trigger the size of its label. The button is\n // block-level, so a column flex or grid cell would otherwise stretch it\n // and the whole row would answer to hover with a help cursor, opening\n // this label's tooltip from a long way away from the label.\n \"typography-body-small-14px-regular w-fit cursor-help rounded-2xs text-left text-content-secondary outline-none\",\n \"hover:text-content-primary focus-visible:shadow-focus-ring\",\n className,\n )}\n onPointerDown={(event) => {\n pointerTypeRef.current = event.pointerType;\n openAtTapStartRef.current = open;\n onPointerDown?.(event);\n }}\n onClick={(event) => {\n onClick?.(event);\n if (!isTouch()) return;\n event.preventDefault();\n setOpen(!openAtTapStartRef.current);\n }}\n onBlur={(event) => {\n // Forget the pointer type once the label loses focus, so a later\n // keyboard focus still opens the tooltip on a device that has\n // both a touchscreen and a keyboard.\n pointerTypeRef.current = \"\";\n onBlur?.(event);\n }}\n {...props}\n >\n {/*\n * The dash lives on this inline span, not the button. The button is a\n * block-level trigger and stretches to whatever its container gives it —\n * a column flex or grid cell makes it full width — which dragged the\n * underline across the whole row instead of the label.\n *\n * Anchor the 4-on/4-off tile to the left edge. A centred position (the\n * `bg-bottom` default) lays the pattern out from the middle outward and\n * clips mid-dash at the start of the label as well as the end.\n *\n * No bottom padding: the dash sits in the descender space the 18px\n * line-height already leaves under the 14px text. Padding it out made\n * the label 20px, and since this label is the entire header of a\n * title-only insight card, that put the card over its designed height.\n */}\n <span className=\"bg-[length:8px_1px] bg-[linear-gradient(to_right,var(--color-icons-tertiary)_0_4px,transparent_4px_8px)] bg-bottom-left bg-repeat-x\">\n {children}\n </span>\n </button>\n </TooltipTrigger>\n {/*\n * The heading is hidden from assistive tech. Radix wires the whole content\n * as the trigger's `aria-describedby`, and the trigger's name is already\n * this same label, so leaving it exposed described the button as\n * \"Total EarningsTotal earnings for the selected period.\" It stays visible,\n * since the two-row block is the point of the design.\n */}\n <TooltipContent title={<span aria-hidden>{children}</span>}>{tooltip}</TooltipContent>\n </Tooltip>\n </TooltipProvider>\n );\n },\n);\n\nTooltipLabel.displayName = \"TooltipLabel\";\n"],"names":[],"mappings":";;;;;AAiCO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-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { MinusIcon } from "../Icons/MinusIcon.mjs";
|
|
5
|
+
import { PlusIcon } from "../Icons/PlusIcon.mjs";
|
|
6
|
+
import { Pill } from "../Pill/Pill.mjs";
|
|
7
|
+
const TrendPill = React.forwardRef(
|
|
8
|
+
({ label, trend, increaseLabel = "Increase", decreaseLabel = "Decrease", ...props }, ref) => {
|
|
9
|
+
const isPositive = trend === "positive";
|
|
10
|
+
return /* @__PURE__ */ jsxs(
|
|
11
|
+
Pill,
|
|
12
|
+
{
|
|
13
|
+
ref,
|
|
14
|
+
variant: isPositive ? "green" : "red",
|
|
15
|
+
leftIcon: isPositive ? /* @__PURE__ */ jsx(PlusIcon, {}) : /* @__PURE__ */ jsx(MinusIcon, {}),
|
|
16
|
+
...props,
|
|
17
|
+
children: [
|
|
18
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: isPositive ? increaseLabel : decreaseLabel }),
|
|
19
|
+
label
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
TrendPill.displayName = "TrendPill";
|
|
26
|
+
export {
|
|
27
|
+
TrendPill
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=TrendPill.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrendPill.mjs","sources":["../../../src/components/TrendPill/TrendPill.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { MinusIcon } from \"../Icons/MinusIcon\";\nimport { PlusIcon } from \"../Icons/PlusIcon\";\nimport { Pill } from \"../Pill/Pill\";\n\n/** Whether a change is an improvement or a decline. */\nexport type TrendDirection = \"positive\" | \"negative\";\n\n/** Props for {@link TrendPill}. */\nexport interface TrendPillProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n /** The change itself, already formatted (e.g. \"$240 vs Jun\"). */\n label: React.ReactNode;\n /** Drives the colour and the leading glyph. */\n trend: TrendDirection;\n /**\n * Announced before {@link label} when `trend` is `\"positive\"`. Overridable\n * because the component cannot translate it. @default \"Increase\"\n */\n increaseLabel?: string;\n /** As {@link increaseLabel}, for `\"negative\"`. @default \"Decrease\" */\n decreaseLabel?: string;\n}\n\n/**\n * A filled pill stating a change, green for positive and red for negative\n * (Figma `V2 Trend Pill`).\n *\n * Distinct from {@link ChartCard}'s `trendChip`, which is Figma's `V2 Trend`: an\n * unfilled arrow and label sitting beside a headline. Use this one where the\n * change needs to hold its own against surrounding content rather than trail a\n * number, such as inside a list row.\n *\n * @example\n * ```tsx\n * <TrendPill label=\"$240 vs Jun\" trend=\"positive\" />\n * ```\n */\nexport const TrendPill = React.forwardRef<HTMLSpanElement, TrendPillProps>(\n ({ label, trend, increaseLabel = \"Increase\", decreaseLabel = \"Decrease\", ...props }, ref) => {\n const isPositive = trend === \"positive\";\n\n return (\n <Pill\n ref={ref}\n variant={isPositive ? \"green\" : \"red\"}\n leftIcon={isPositive ? <PlusIcon /> : <MinusIcon />}\n {...props}\n >\n {/*\n * `Pill` renders `leftIcon` inside `aria-hidden`, so without this the only\n * channel carrying the direction is the green/red fill and the label itself\n * says nothing about which way it went — WCAG 1.4.1, and the direction is\n * the point of a trend.\n */}\n <span className=\"sr-only\">{isPositive ? increaseLabel : decreaseLabel}</span>\n {label}\n </Pill>\n );\n },\n);\n\nTrendPill.displayName = \"TrendPill\";\n"],"names":[],"mappings":";;;;;;AAqCO,MAAM,YAAY,MAAM;AAAA,EAC7B,CAAC,EAAE,OAAO,OAAO,gBAAgB,YAAY,gBAAgB,YAAY,GAAG,MAAA,GAAS,QAAQ;AAC3F,UAAM,aAAa,UAAU;AAE7B,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,SAAS,aAAa,UAAU;AAAA,QAChC,UAAU,aAAa,oBAAC,UAAA,CAAA,CAAS,wBAAM,WAAA,EAAU;AAAA,QAChD,GAAG;AAAA,QAQJ,UAAA;AAAA,UAAA,oBAAC,QAAA,EAAK,WAAU,WAAW,UAAA,aAAa,gBAAgB,eAAc;AAAA,UACrE;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AAEA,UAAU,cAAc;"}
|
|
@@ -24,6 +24,9 @@ const UserItem = React.forwardRef(
|
|
|
24
24
|
aiDisclosureLabel,
|
|
25
25
|
verified = false,
|
|
26
26
|
verifiedLabel,
|
|
27
|
+
trailing,
|
|
28
|
+
primary,
|
|
29
|
+
secondary,
|
|
27
30
|
className,
|
|
28
31
|
...props
|
|
29
32
|
}, ref) => {
|
|
@@ -46,7 +49,7 @@ const UserItem = React.forwardRef(
|
|
|
46
49
|
}
|
|
47
50
|
),
|
|
48
51
|
/* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-hidden pl-2", children: [
|
|
49
|
-
/* @__PURE__ */ jsx(
|
|
52
|
+
primary ?? /* @__PURE__ */ jsx(
|
|
50
53
|
UserDisplayName,
|
|
51
54
|
{
|
|
52
55
|
aiDisclosure,
|
|
@@ -57,8 +60,10 @@ const UserItem = React.forwardRef(
|
|
|
57
60
|
children: user.nickname || user.displayName
|
|
58
61
|
}
|
|
59
62
|
),
|
|
63
|
+
secondary && /* @__PURE__ */ jsx("p", { className: "typography-description-12px-regular truncate text-content-secondary", children: secondary }),
|
|
60
64
|
showHandle && /* @__PURE__ */ jsx(UserHandle, { children: user.handle })
|
|
61
|
-
] })
|
|
65
|
+
] }),
|
|
66
|
+
trailing && /* @__PURE__ */ jsx("div", { className: "shrink-0 pl-2", children: trailing })
|
|
62
67
|
]
|
|
63
68
|
}
|
|
64
69
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserItem.mjs","sources":["../../../src/components/UserItem/UserItem.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { getInitials } from \"../../utils/getInitials\";\nimport { Avatar } from \"../Avatar/Avatar\";\nimport { BellOffIcon } from \"../Icons/BellOffIcon\";\nimport { UserDisplayName } from \"../UserDisplayName/UserDisplayName\";\nimport { UserHandle } from \"../UserHandle/UserHandle\";\n\nconst AVATAR_SIZES = [16, 24, 32, 40, 48, 64, 88, 148] as const;\ntype AvatarSizeToken = (typeof AVATAR_SIZES)[number];\n\n/** Snap an arbitrary pixel size to the nearest supported {@link Avatar} size token. */\nconst getNearestAvatarSize = (size: number): AvatarSizeToken =>\n AVATAR_SIZES.reduce((prev, curr) =>\n Math.abs(curr - size) < Math.abs(prev - size) ? curr : prev,\n );\n\n/** Minimal user shape consumed by {@link UserItem}. */\nexport type UserItemUser = {\n avatarUri?: { url: string; url2x?: string };\n displayName: string;\n handle: string;\n nickname?: string;\n};\n\nexport interface UserItemProps extends React.HTMLAttributes<HTMLDivElement> {\n /** The user to display. */\n user: UserItemUser;\n /** Desired avatar size in px; snapped to the nearest supported token. @default 48 */\n avatarSize?: number;\n /** Show the muted indicator in the bottom-left corner. @default false */\n isMuted?: boolean;\n /** Whether the user is online (only shown when `showOnlineStatus` is also set). @default false */\n isOnline?: boolean;\n /** Render the avatar. @default true */\n showAvatar?: boolean;\n /** Render the handle line under the display name. @default true */\n showHandle?: boolean;\n /** Enable the avatar online indicator (combined with `isOnline`). */\n showOnlineStatus?: boolean;\n /** Render an AI-disclosure badge after the display name. @default false */\n aiDisclosure?: boolean;\n /** Accessible label for the AI-disclosure badge. @default \"AI creator\" */\n aiDisclosureLabel?: string;\n /** Render a verified badge after the display name. @default false */\n verified?: boolean;\n /** Accessible label for the verified badge. @default \"Verified\" */\n verifiedLabel?: string;\n}\n\n/**\n * A compact user row showing an avatar, display name (or nickname) and handle,\n * with optional verified and AI-disclosure badges and online and muted indicators.\n *\n * @example\n * ```tsx\n * <UserItem user={{ displayName: \"Jane Doe\", handle: \"jane_doe\" }} />\n * ```\n */\nexport const UserItem = React.forwardRef<HTMLDivElement, UserItemProps>(\n (\n {\n user,\n avatarSize,\n isOnline = false,\n isMuted = false,\n showOnlineStatus,\n showHandle = true,\n showAvatar = true,\n aiDisclosure = false,\n aiDisclosureLabel,\n verified = false,\n verifiedLabel,\n className,\n ...props\n },\n ref,\n ) => {\n return (\n <div\n ref={ref}\n className={cn(\"relative flex w-full items-center justify-start px-2 py-1\", className)}\n {...props}\n >\n {isMuted && (\n <div className=\"absolute bottom-0 left-0 z-1 flex rounded-xs bg-surface-primary p-1\">\n <BellOffIcon size={16} />\n </div>\n )}\n {showAvatar && (\n <Avatar\n size={getNearestAvatarSize(avatarSize || 48)}\n src={user.avatarUri?.url}\n alt={user.displayName}\n fallback={getInitials(user.displayName)}\n onlineIndicator={Boolean(showOnlineStatus && isOnline)}\n />\n )}\n <div className=\"flex-1 overflow-hidden pl-2\">\n <UserDisplayName\n
|
|
1
|
+
{"version":3,"file":"UserItem.mjs","sources":["../../../src/components/UserItem/UserItem.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { getInitials } from \"../../utils/getInitials\";\nimport { Avatar } from \"../Avatar/Avatar\";\nimport { BellOffIcon } from \"../Icons/BellOffIcon\";\nimport { UserDisplayName } from \"../UserDisplayName/UserDisplayName\";\nimport { UserHandle } from \"../UserHandle/UserHandle\";\n\nconst AVATAR_SIZES = [16, 24, 32, 40, 48, 64, 88, 148] as const;\ntype AvatarSizeToken = (typeof AVATAR_SIZES)[number];\n\n/** Snap an arbitrary pixel size to the nearest supported {@link Avatar} size token. */\nconst getNearestAvatarSize = (size: number): AvatarSizeToken =>\n AVATAR_SIZES.reduce((prev, curr) =>\n Math.abs(curr - size) < Math.abs(prev - size) ? curr : prev,\n );\n\n/** Minimal user shape consumed by {@link UserItem}. */\nexport type UserItemUser = {\n avatarUri?: { url: string; url2x?: string };\n displayName: string;\n handle: string;\n nickname?: string;\n};\n\nexport interface UserItemProps extends React.HTMLAttributes<HTMLDivElement> {\n /** The user to display. */\n user: UserItemUser;\n /** Desired avatar size in px; snapped to the nearest supported token. @default 48 */\n avatarSize?: number;\n /** Show the muted indicator in the bottom-left corner. @default false */\n isMuted?: boolean;\n /** Whether the user is online (only shown when `showOnlineStatus` is also set). @default false */\n isOnline?: boolean;\n /** Render the avatar. @default true */\n showAvatar?: boolean;\n /** Render the handle line under the display name. @default true */\n showHandle?: boolean;\n /** Enable the avatar online indicator (combined with `isOnline`). */\n showOnlineStatus?: boolean;\n /** Render an AI-disclosure badge after the display name. @default false */\n aiDisclosure?: boolean;\n /** Accessible label for the AI-disclosure badge. @default \"AI creator\" */\n aiDisclosureLabel?: string;\n /** Render a verified badge after the display name. @default false */\n verified?: boolean;\n /** Accessible label for the verified badge. @default \"Verified\" */\n verifiedLabel?: string;\n /**\n * Content pinned to the end of the row — a value, count, timestamp or action.\n * It keeps its intrinsic width while the name block absorbs the remaining\n * space, so trailing content stays aligned down the rows of a list.\n *\n * Prefer {@link UserItemTrailing} over composing the lines yourself.\n */\n trailing?: React.ReactNode;\n /**\n * Replace the display-name line with arbitrary content, for rows that read as\n * a sentence about the user rather than their name — an activity feed entry,\n * for instance. Badges do not apply to custom content.\n */\n primary?: React.ReactNode;\n /**\n * A supporting line under the name, mirroring {@link UserItemTrailing}'s `meta`.\n * Both are block lines on the same 18px advance, so a row using `secondary` on\n * the left and `meta` on the right reads as two aligned tiers. Prefer it over\n * letting a long primary wrap, which mixes line heights and drifts out of step.\n */\n secondary?: React.ReactNode;\n}\n\n/**\n * A compact user row showing an avatar, display name (or nickname) and handle,\n * with optional verified and AI-disclosure badges and online and muted indicators.\n *\n * Pass {@link UserItemProps.trailing} to pin a value to the end of the row, the\n * shape most list rows need — top spenders, most active fans, a recent-activity\n * feed.\n *\n * @example\n * ```tsx\n * <UserItem user={{ displayName: \"Jane Doe\", handle: \"jane_doe\" }} />\n * ```\n *\n * @example A list row with a trailing value\n * ```tsx\n * <UserItem\n * user={user}\n * avatarSize={32}\n * showHandle={false}\n * trailing={<span className=\"typography-body-small-14px-semibold\">$14,523.59</span>}\n * />\n * ```\n */\nexport const UserItem = React.forwardRef<HTMLDivElement, UserItemProps>(\n (\n {\n user,\n avatarSize,\n isOnline = false,\n isMuted = false,\n showOnlineStatus,\n showHandle = true,\n showAvatar = true,\n aiDisclosure = false,\n aiDisclosureLabel,\n verified = false,\n verifiedLabel,\n trailing,\n primary,\n secondary,\n className,\n ...props\n },\n ref,\n ) => {\n return (\n <div\n ref={ref}\n className={cn(\"relative flex w-full items-center justify-start px-2 py-1\", className)}\n {...props}\n >\n {isMuted && (\n <div className=\"absolute bottom-0 left-0 z-1 flex rounded-xs bg-surface-primary p-1\">\n <BellOffIcon size={16} />\n </div>\n )}\n {showAvatar && (\n <Avatar\n size={getNearestAvatarSize(avatarSize || 48)}\n src={user.avatarUri?.url}\n alt={user.displayName}\n fallback={getInitials(user.displayName)}\n onlineIndicator={Boolean(showOnlineStatus && isOnline)}\n />\n )}\n <div className=\"flex-1 overflow-hidden pl-2\">\n {primary ?? (\n <UserDisplayName\n aiDisclosure={aiDisclosure}\n aiDisclosureLabel={aiDisclosureLabel}\n verified={verified}\n verifiedLabel={verifiedLabel}\n className=\"typography-body-small-14px-semibold\"\n >\n {user.nickname || user.displayName}\n </UserDisplayName>\n )}\n {secondary && (\n <p className=\"typography-description-12px-regular truncate text-content-secondary\">\n {secondary}\n </p>\n )}\n {showHandle && <UserHandle>{user.handle}</UserHandle>}\n </div>\n {trailing && <div className=\"shrink-0 pl-2\">{trailing}</div>}\n </div>\n );\n },\n);\n\nUserItem.displayName = \"UserItem\";\n"],"names":[],"mappings":";;;;;;;;;AAQA,MAAM,eAAe,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;AAIrD,MAAM,uBAAuB,CAAC,SAC5B,aAAa;AAAA,EAAO,CAAC,MAAM,SACzB,KAAK,IAAI,OAAO,IAAI,IAAI,KAAK,IAAI,OAAO,IAAI,IAAI,OAAO;AACzD;AA+EK,MAAM,WAAW,MAAM;AAAA,EAC5B,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,UAAU;AAAA,IACV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+
import { cn } from "../../utils/cn.mjs";
|
|
5
|
+
const UserItemTrailing = React.forwardRef(
|
|
6
|
+
({ value, meta, className, ...props }, ref) => {
|
|
7
|
+
return /* @__PURE__ */ jsxs("div", { ref, className: cn("flex flex-col items-end", className), ...props, children: [
|
|
8
|
+
/* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-semibold text-content-primary", children: value }),
|
|
9
|
+
meta && /* @__PURE__ */ jsx("span", { className: "typography-description-12px-regular text-content-secondary", children: meta })
|
|
10
|
+
] });
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
UserItemTrailing.displayName = "UserItemTrailing";
|
|
14
|
+
export {
|
|
15
|
+
UserItemTrailing
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=UserItemTrailing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserItemTrailing.mjs","sources":["../../../src/components/UserItem/UserItemTrailing.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Props for {@link UserItemTrailing}. */\nexport interface UserItemTrailingProps extends React.HTMLAttributes<HTMLDivElement> {\n /** The headline figure — an amount, a count, a percentage. */\n value: React.ReactNode;\n /** Optional supporting line under the value, such as a timestamp. */\n meta?: React.ReactNode;\n}\n\n/**\n * The end-of-row block for a {@link UserItem}: a value with an optional\n * supporting line beneath it, both aligned to the right edge so figures line up\n * down a list.\n *\n * Pass it to {@link UserItem}'s `trailing` slot rather than composing the two\n * lines at each call site, so value and meta typography stay consistent\n * wherever a list row carries a figure.\n *\n * @example\n * ```tsx\n * <UserItem\n * user={user}\n * showHandle={false}\n * trailing={<UserItemTrailing value=\"$421.32\" meta=\"7 hours ago\" />}\n * />\n * ```\n */\nexport const UserItemTrailing = React.forwardRef<HTMLDivElement, UserItemTrailingProps>(\n ({ value, meta, className, ...props }, ref) => {\n return (\n <div ref={ref} className={cn(\"flex flex-col items-end\", className)} {...props}>\n <span className=\"typography-body-small-14px-semibold text-content-primary\">{value}</span>\n {meta && (\n <span className=\"typography-description-12px-regular text-content-secondary\">{meta}</span>\n )}\n </div>\n );\n },\n);\n\nUserItemTrailing.displayName = \"UserItemTrailing\";\n"],"names":[],"mappings":";;;;AA6BO,MAAM,mBAAmB,MAAM;AAAA,EACpC,CAAC,EAAE,OAAO,MAAM,WAAW,GAAG,MAAA,GAAS,QAAQ;AAC7C,WACE,qBAAC,SAAI,KAAU,WAAW,GAAG,2BAA2B,SAAS,GAAI,GAAG,OACtE,UAAA;AAAA,MAAA,oBAAC,QAAA,EAAK,WAAU,4DAA4D,UAAA,OAAM;AAAA,MACjF,QACC,oBAAC,QAAA,EAAK,WAAU,8DAA8D,UAAA,KAAA,CAAK;AAAA,IAAA,GAEvF;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;"}
|