@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
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const cn = require("../../utils/cn.cjs");
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
24
|
+
const UserItemTrailing = React__namespace.forwardRef(
|
|
25
|
+
({ value, meta, className, ...props }, ref) => {
|
|
26
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, className: cn.cn("flex flex-col items-end", className), ...props, children: [
|
|
27
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "typography-body-small-14px-semibold text-content-primary", children: value }),
|
|
28
|
+
meta && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "typography-description-12px-regular text-content-secondary", children: meta })
|
|
29
|
+
] });
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
UserItemTrailing.displayName = "UserItemTrailing";
|
|
33
|
+
exports.UserItemTrailing = UserItemTrailing;
|
|
34
|
+
//# sourceMappingURL=UserItemTrailing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserItemTrailing.cjs","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":["React","jsxs","cn","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6BO,MAAM,mBAAmBA,iBAAM;AAAA,EACpC,CAAC,EAAE,OAAO,MAAM,WAAW,GAAG,MAAA,GAAS,QAAQ;AAC7C,WACEC,gCAAC,SAAI,KAAU,WAAWC,MAAG,2BAA2B,SAAS,GAAI,GAAG,OACtE,UAAA;AAAA,MAAAC,2BAAAA,IAAC,QAAA,EAAK,WAAU,4DAA4D,UAAA,OAAM;AAAA,MACjF,QACCA,2BAAAA,IAAC,QAAA,EAAK,WAAU,8DAA8D,UAAA,KAAA,CAAK;AAAA,IAAA,GAEvF;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -6,7 +6,9 @@ const Accordion = require("./components/Accordion/Accordion.cjs");
|
|
|
6
6
|
const AccordionContent = require("./components/Accordion/AccordionContent.cjs");
|
|
7
7
|
const AccordionItem = require("./components/Accordion/AccordionItem.cjs");
|
|
8
8
|
const AccordionTrigger = require("./components/Accordion/AccordionTrigger.cjs");
|
|
9
|
+
const AiButton = require("./components/AiButton/AiButton.cjs");
|
|
9
10
|
const Alert = require("./components/Alert/Alert.cjs");
|
|
11
|
+
const AnimatedNumber = require("./components/AnimatedNumber/AnimatedNumber.cjs");
|
|
10
12
|
const AudioPlayer = require("./components/AudioPlayer/AudioPlayer.cjs");
|
|
11
13
|
const AudioRecordButton = require("./components/AudioRecordButton/AudioRecordButton.cjs");
|
|
12
14
|
const AudioUpload = require("./components/AudioUpload/AudioUpload.cjs");
|
|
@@ -32,6 +34,7 @@ const CreatorCover = require("./components/CreatorCover/CreatorCover.cjs");
|
|
|
32
34
|
const CreatorTile = require("./components/CreatorTile/CreatorTile.cjs");
|
|
33
35
|
const CriticalBanner = require("./components/CriticalBanner/CriticalBanner.cjs");
|
|
34
36
|
const CyclingText = require("./components/CyclingText/CyclingText.cjs");
|
|
37
|
+
const Demographics = require("./components/Demographics/Demographics.cjs");
|
|
35
38
|
const Dialog = require("./components/Dialog/Dialog.cjs");
|
|
36
39
|
const Divider = require("./components/Divider/Divider.cjs");
|
|
37
40
|
const Drawer = require("./components/Drawer/Drawer.cjs");
|
|
@@ -252,9 +255,12 @@ const TextArea = require("./components/TextArea/TextArea.cjs");
|
|
|
252
255
|
const TextField = require("./components/TextField/TextField.cjs");
|
|
253
256
|
const Toast = require("./components/Toast/Toast.cjs");
|
|
254
257
|
const Tooltip = require("./components/Tooltip/Tooltip.cjs");
|
|
258
|
+
const TooltipLabel = require("./components/Tooltip/TooltipLabel.cjs");
|
|
259
|
+
const TrendPill = require("./components/TrendPill/TrendPill.cjs");
|
|
255
260
|
const UserDisplayName = require("./components/UserDisplayName/UserDisplayName.cjs");
|
|
256
261
|
const UserHandle = require("./components/UserHandle/UserHandle.cjs");
|
|
257
262
|
const UserItem = require("./components/UserItem/UserItem.cjs");
|
|
263
|
+
const UserItemTrailing = require("./components/UserItem/UserItemTrailing.cjs");
|
|
258
264
|
const VoiceNote = require("./components/VoiceNote/VoiceNote.cjs");
|
|
259
265
|
const cn = require("./utils/cn.cjs");
|
|
260
266
|
const getInitials = require("./utils/getInitials.cjs");
|
|
@@ -271,7 +277,9 @@ exports.Accordion = Accordion.Accordion;
|
|
|
271
277
|
exports.AccordionContent = AccordionContent.AccordionContent;
|
|
272
278
|
exports.AccordionItem = AccordionItem.AccordionItem;
|
|
273
279
|
exports.AccordionTrigger = AccordionTrigger.AccordionTrigger;
|
|
280
|
+
exports.AiButton = AiButton.AiButton;
|
|
274
281
|
exports.Alert = Alert.Alert;
|
|
282
|
+
exports.AnimatedNumber = AnimatedNumber.AnimatedNumber;
|
|
275
283
|
exports.AudioPlayer = AudioPlayer.AudioPlayer;
|
|
276
284
|
exports.AudioRecordButton = AudioRecordButton.AudioRecordButton;
|
|
277
285
|
exports.AudioUpload = AudioUpload.AudioUpload;
|
|
@@ -310,6 +318,7 @@ exports.CreatorCover = CreatorCover.CreatorCover;
|
|
|
310
318
|
exports.CreatorTile = CreatorTile.CreatorTile;
|
|
311
319
|
exports.CriticalBanner = CriticalBanner.CriticalBanner;
|
|
312
320
|
exports.CyclingText = CyclingText.CyclingText;
|
|
321
|
+
exports.Demographics = Demographics.Demographics;
|
|
313
322
|
exports.Dialog = Dialog.Dialog;
|
|
314
323
|
exports.DialogBody = Dialog.DialogBody;
|
|
315
324
|
exports.DialogClose = Dialog.DialogClose;
|
|
@@ -331,6 +340,7 @@ exports.DrawerOverlay = Drawer.DrawerOverlay;
|
|
|
331
340
|
exports.DrawerTitle = Drawer.DrawerTitle;
|
|
332
341
|
exports.DrawerTrigger = Drawer.DrawerTrigger;
|
|
333
342
|
exports.DropdownMenu = DropdownMenu.DropdownMenu;
|
|
343
|
+
exports.DropdownMenuCheckboxItem = DropdownMenu.DropdownMenuCheckboxItem;
|
|
334
344
|
exports.DropdownMenuContent = DropdownMenu.DropdownMenuContent;
|
|
335
345
|
exports.DropdownMenuGroup = DropdownMenu.DropdownMenuGroup;
|
|
336
346
|
exports.DropdownMenuHeader = DropdownMenu.DropdownMenuHeader;
|
|
@@ -587,9 +597,12 @@ exports.Tooltip = Tooltip.Tooltip;
|
|
|
587
597
|
exports.TooltipContent = Tooltip.TooltipContent;
|
|
588
598
|
exports.TooltipProvider = Tooltip.TooltipProvider;
|
|
589
599
|
exports.TooltipTrigger = Tooltip.TooltipTrigger;
|
|
600
|
+
exports.TooltipLabel = TooltipLabel.TooltipLabel;
|
|
601
|
+
exports.TrendPill = TrendPill.TrendPill;
|
|
590
602
|
exports.UserDisplayName = UserDisplayName.UserDisplayName;
|
|
591
603
|
exports.UserHandle = UserHandle.UserHandle;
|
|
592
604
|
exports.UserItem = UserItem.UserItem;
|
|
605
|
+
exports.UserItemTrailing = UserItemTrailing.UserItemTrailing;
|
|
593
606
|
exports.VoiceNote = VoiceNote.VoiceNote;
|
|
594
607
|
exports.cn = cn.cn;
|
|
595
608
|
exports.getInitials = getInitials.getInitials;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -19,21 +19,21 @@ function _interopNamespaceDefault(e) {
|
|
|
19
19
|
return Object.freeze(n);
|
|
20
20
|
}
|
|
21
21
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
29
|
-
const sync = () => {
|
|
30
|
-
setReduced(mq.matches);
|
|
22
|
+
const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
23
|
+
const isSupported = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
24
|
+
const subscribe = (onStoreChange) => {
|
|
25
|
+
if (!isSupported()) {
|
|
26
|
+
return () => {
|
|
31
27
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
}
|
|
29
|
+
const mq = window.matchMedia(REDUCED_MOTION_QUERY);
|
|
30
|
+
mq.addEventListener("change", onStoreChange);
|
|
31
|
+
return () => mq.removeEventListener("change", onStoreChange);
|
|
32
|
+
};
|
|
33
|
+
const getSnapshot = () => isSupported() ? window.matchMedia(REDUCED_MOTION_QUERY).matches : false;
|
|
34
|
+
const getServerSnapshot = () => false;
|
|
35
|
+
function usePrefersReducedMotion() {
|
|
36
|
+
return React__namespace.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
37
37
|
}
|
|
38
38
|
exports.usePrefersReducedMotion = usePrefersReducedMotion;
|
|
39
39
|
//# sourceMappingURL=usePrefersReducedMotion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrefersReducedMotion.cjs","sources":["../../../src/utils/usePrefersReducedMotion.ts"],"sourcesContent":["import * as React from \"react\";\n\nconst REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\n\n// jsdom has no `matchMedia`, and `getSnapshot` runs during render, so an\n// unguarded call throws rather than degrades.\nconst isSupported = () => typeof window !== \"undefined\" && typeof window.matchMedia === \"function\";\n\nconst subscribe = (onStoreChange: () => void) => {\n if (!isSupported()) {\n return () => {};\n }\n const mq = window.matchMedia(REDUCED_MOTION_QUERY);\n mq.addEventListener(\"change\", onStoreChange);\n return () => mq.removeEventListener(\"change\", onStoreChange);\n};\n\nconst getSnapshot = () => (isSupported() ? window.matchMedia(REDUCED_MOTION_QUERY).matches : false);\n\nconst getServerSnapshot = () => false;\n\n/**\n * Whether the user has asked for reduced motion.\n *\n * Read during render rather than synced into state from an effect: an effect\n * returns `false` on the first render, which lets a reduced-motion user catch one\n * animated frame, and can read a stale value under concurrent rendering.\n */\nexport function usePrefersReducedMotion(): boolean {\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,uBAAuB;AAI7B,MAAM,cAAc,MAAM,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe;AAExF,MAAM,YAAY,CAAC,kBAA8B;AAC/C,MAAI,CAAC,eAAe;AAClB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,QAAM,KAAK,OAAO,WAAW,oBAAoB;AACjD,KAAG,iBAAiB,UAAU,aAAa;AAC3C,SAAO,MAAM,GAAG,oBAAoB,UAAU,aAAa;AAC7D;AAEA,MAAM,cAAc,MAAO,gBAAgB,OAAO,WAAW,oBAAoB,EAAE,UAAU;AAE7F,MAAM,oBAAoB,MAAM;AASzB,SAAS,0BAAmC;AACjD,SAAOA,iBAAM,qBAAqB,WAAW,aAAa,iBAAiB;AAC7E;;"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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 { AIIcon } from "../Icons/AIIcon.mjs";
|
|
6
|
+
const sizeVariants = {
|
|
7
|
+
// At 24 the label steps down to the 12px description scale: the 14px label
|
|
8
|
+
// Button uses at this height leaves the glyph and text crowding a 24px box,
|
|
9
|
+
// since 16px is the smallest authored icon geometry and cannot step down with it.
|
|
10
|
+
"24": "h-6 gap-1 px-2 py-1 typography-description-12px-semibold",
|
|
11
|
+
"32": "h-8 gap-2 px-3 py-[7px] typography-body-small-14px-semibold",
|
|
12
|
+
"40": "h-10 gap-2 px-4 py-2 typography-body-default-16px-semibold"
|
|
13
|
+
};
|
|
14
|
+
const iconSizeVariants = {
|
|
15
|
+
"24": 16,
|
|
16
|
+
"32": 16,
|
|
17
|
+
"40": 24
|
|
18
|
+
};
|
|
19
|
+
const iconScaleVariants = {
|
|
20
|
+
"24": "[&_svg]:size-3.5",
|
|
21
|
+
"32": "",
|
|
22
|
+
"40": ""
|
|
23
|
+
};
|
|
24
|
+
const LETTER_STAGGER = 0.08;
|
|
25
|
+
const trackPointer = (event) => {
|
|
26
|
+
const { left, width } = event.currentTarget.getBoundingClientRect();
|
|
27
|
+
event.currentTarget.style.setProperty("--fv-ai-x", `${(event.clientX - left) / width * 100}%`);
|
|
28
|
+
};
|
|
29
|
+
const ShimmerLabel = ({ text, disabled }) => /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: Array.from(text).map((character, index) => /* @__PURE__ */ jsx(
|
|
30
|
+
"span",
|
|
31
|
+
{
|
|
32
|
+
className: cn(
|
|
33
|
+
"inline-block whitespace-pre text-content-secondary",
|
|
34
|
+
// Gated in JS rather than with a `group-disabled/ai:` override, because
|
|
35
|
+
// that would rely on the generated rule ordering to beat `group-hover`.
|
|
36
|
+
// A faded control that still shimmers and still lights up green under the
|
|
37
|
+
// cursor reads as busy rather than unavailable.
|
|
38
|
+
!disabled && [
|
|
39
|
+
"[animation:fv-ai-letter_2s_ease-in-out_infinite]",
|
|
40
|
+
"group-hover/ai:text-content-primary group-hover/ai:[animation:none]",
|
|
41
|
+
// On focus each letter blows up and settles, then the idle shimmer
|
|
42
|
+
// resumes underneath it — the two animations are sequenced by delay.
|
|
43
|
+
"group-focus-visible/ai:[animation:fv-ai-letter-focus_1s_ease-in-out,fv-ai-letter_1.2s_ease-in-out_infinite_1s]",
|
|
44
|
+
"group-active/ai:text-content-primary group-active/ai:[animation:none]",
|
|
45
|
+
"group-active/ai:[text-shadow:0_0_4px_var(--color-content-primary)]"
|
|
46
|
+
],
|
|
47
|
+
"motion-reduce:[animation:none]"
|
|
48
|
+
),
|
|
49
|
+
style: { animationDelay: `${index * LETTER_STAGGER}s` },
|
|
50
|
+
children: character
|
|
51
|
+
},
|
|
52
|
+
`${character}-${index}`
|
|
53
|
+
)) });
|
|
54
|
+
const AiButton = React.forwardRef(
|
|
55
|
+
({
|
|
56
|
+
label,
|
|
57
|
+
activeLabel,
|
|
58
|
+
active = false,
|
|
59
|
+
size = "32",
|
|
60
|
+
icon,
|
|
61
|
+
type = "button",
|
|
62
|
+
className,
|
|
63
|
+
disabled,
|
|
64
|
+
onPointerMove,
|
|
65
|
+
onPointerLeave,
|
|
66
|
+
...props
|
|
67
|
+
}, ref) => {
|
|
68
|
+
const resolvedActiveLabel = activeLabel ?? label;
|
|
69
|
+
return /* @__PURE__ */ jsxs(
|
|
70
|
+
"button",
|
|
71
|
+
{
|
|
72
|
+
ref,
|
|
73
|
+
type,
|
|
74
|
+
disabled,
|
|
75
|
+
"aria-label": props["aria-label"] ?? (active ? resolvedActiveLabel : label),
|
|
76
|
+
"aria-busy": active || void 0,
|
|
77
|
+
onPointerMove: (event) => {
|
|
78
|
+
trackPointer(event);
|
|
79
|
+
onPointerMove?.(event);
|
|
80
|
+
},
|
|
81
|
+
onPointerLeave: (event) => {
|
|
82
|
+
event.currentTarget.style.removeProperty("--fv-ai-x");
|
|
83
|
+
onPointerLeave?.(event);
|
|
84
|
+
},
|
|
85
|
+
className: cn(
|
|
86
|
+
"fv-ai-button",
|
|
87
|
+
"group/ai inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full",
|
|
88
|
+
"border border-border-primary bg-background-primary",
|
|
89
|
+
// Matched to the rim and sheen so the whole treatment arrives as one
|
|
90
|
+
// movement — at the old 300ms the outline landed ahead of the glow.
|
|
91
|
+
"transition-[background-color,border-color] duration-[400ms] ease-out",
|
|
92
|
+
"hover:border-brand-primary-default",
|
|
93
|
+
"focus-visible:outline-none",
|
|
94
|
+
"active:border-brand-primary-hover active:bg-brand-primary-muted",
|
|
95
|
+
"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-border-primary",
|
|
96
|
+
sizeVariants[size],
|
|
97
|
+
className
|
|
98
|
+
),
|
|
99
|
+
...props,
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsx(
|
|
102
|
+
"span",
|
|
103
|
+
{
|
|
104
|
+
className: cn(
|
|
105
|
+
"flex shrink-0 items-center text-content-primary",
|
|
106
|
+
iconScaleVariants[size],
|
|
107
|
+
"[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]",
|
|
108
|
+
// Same reasoning as the letters: no flicker and no green lift once the
|
|
109
|
+
// button is unavailable.
|
|
110
|
+
!disabled && [
|
|
111
|
+
"[animation:fv-ai-flicker_2s_linear_infinite] [animation-delay:0.5s]",
|
|
112
|
+
// Settles solid on hover, lit green from below like the sheen.
|
|
113
|
+
"group-hover/ai:[animation:none]",
|
|
114
|
+
"group-hover/ai:[filter:drop-shadow(0_0_3px_var(--color-brand-primary-default))_drop-shadow(0_-4px_6px_color-mix(in_srgb,var(--color-content-always-black)_60%,transparent))]",
|
|
115
|
+
"group-focus-visible/ai:[animation-duration:1.2s] group-focus-visible/ai:[animation-delay:0.2s]"
|
|
116
|
+
],
|
|
117
|
+
"motion-reduce:[animation:none]"
|
|
118
|
+
),
|
|
119
|
+
children: icon ?? /* @__PURE__ */ jsx(AIIcon, { size: iconSizeVariants[size], filled: true })
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ jsxs("span", { className: "grid", children: [
|
|
123
|
+
/* @__PURE__ */ jsx(
|
|
124
|
+
"span",
|
|
125
|
+
{
|
|
126
|
+
className: cn(
|
|
127
|
+
"col-start-1 row-start-1 transition-opacity duration-300",
|
|
128
|
+
active ? "opacity-0" : "opacity-100"
|
|
129
|
+
),
|
|
130
|
+
children: /* @__PURE__ */ jsx(ShimmerLabel, { text: label, disabled })
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ jsx(
|
|
134
|
+
"span",
|
|
135
|
+
{
|
|
136
|
+
className: cn(
|
|
137
|
+
"col-start-1 row-start-1 transition-opacity duration-300",
|
|
138
|
+
active ? "opacity-100" : "opacity-0"
|
|
139
|
+
),
|
|
140
|
+
children: /* @__PURE__ */ jsx(ShimmerLabel, { text: resolvedActiveLabel, disabled })
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
] })
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
AiButton.displayName = "AiButton";
|
|
150
|
+
export {
|
|
151
|
+
AiButton
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=AiButton.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiButton.mjs","sources":["../../../src/components/AiButton/AiButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport type { IconSize } from \"../Icons/types\";\n\n/** Height, padding and label typography, matching {@link Button}'s scale. */\nexport type AiButtonSize = \"24\" | \"32\" | \"40\";\n\nconst sizeVariants: Record<AiButtonSize, string> = {\n // At 24 the label steps down to the 12px description scale: the 14px label\n // Button uses at this height leaves the glyph and text crowding a 24px box,\n // since 16px is the smallest authored icon geometry and cannot step down with it.\n \"24\": \"h-6 gap-1 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 gap-2 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 gap-2 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nconst iconSizeVariants: Record<AiButtonSize, IconSize> = {\n \"24\": 16,\n \"32\": 16,\n \"40\": 24,\n};\n\n/**\n * Optical size, applied on top of the authored geometry. Only 16, 24 and 32 have\n * dedicated paths, so the 24 button renders the 16px glyph down at 14 to sit with\n * its 12px label rather than towering over it.\n */\nconst iconScaleVariants: Record<AiButtonSize, string> = {\n \"24\": \"[&_svg]:size-3.5\",\n \"32\": \"\",\n \"40\": \"\",\n};\n\n/** Delay between adjacent letters, in seconds. */\nconst LETTER_STAGGER = 0.08;\n\n/**\n * Points the bottom sheen at the cursor by writing its x offset, as a percentage\n * of the button's width, straight to the DOM node. Deliberately not React state:\n * this fires every pointer-move frame, and a re-render per frame would both cost\n * more than the paint and leave the glow trailing the cursor.\n */\nconst trackPointer = (event: React.PointerEvent<HTMLButtonElement>) => {\n const { left, width } = event.currentTarget.getBoundingClientRect();\n event.currentTarget.style.setProperty(\"--fv-ai-x\", `${((event.clientX - left) / width) * 100}%`);\n};\n\n/** Props for {@link AiButton}. */\nexport interface AiButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\"> {\n /** Resting label. Also the accessible name unless `aria-label` is given. */\n label: string;\n /** Label shown while `active`. Falls back to {@link label}. */\n activeLabel?: string;\n /** Swap to {@link activeLabel} and keep the shimmer running. @default false */\n active?: boolean;\n /** @default \"32\" */\n size?: AiButtonSize;\n /** Replace the leading AI glyph. */\n icon?: React.ReactNode;\n /** @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Renders one `<span>` per character so each can carry its own animation delay.\n * The run is hidden from assistive tech — the button's accessible name comes from\n * its `aria-label`, so a screen reader says \"Analyse\" rather than spelling it out.\n */\nconst ShimmerLabel: React.FC<{ text: string; disabled?: boolean }> = ({ text, disabled }) => (\n <span aria-hidden=\"true\">\n {Array.from(text).map((character, index) => (\n <span\n key={`${character}-${index}`}\n className={cn(\n \"inline-block whitespace-pre text-content-secondary\",\n // Gated in JS rather than with a `group-disabled/ai:` override, because\n // that would rely on the generated rule ordering to beat `group-hover`.\n // A faded control that still shimmers and still lights up green under the\n // cursor reads as busy rather than unavailable.\n !disabled && [\n \"[animation:fv-ai-letter_2s_ease-in-out_infinite]\",\n \"group-hover/ai:text-content-primary group-hover/ai:[animation:none]\",\n // On focus each letter blows up and settles, then the idle shimmer\n // resumes underneath it — the two animations are sequenced by delay.\n \"group-focus-visible/ai:[animation:fv-ai-letter-focus_1s_ease-in-out,fv-ai-letter_1.2s_ease-in-out_infinite_1s]\",\n \"group-active/ai:text-content-primary group-active/ai:[animation:none]\",\n \"group-active/ai:[text-shadow:0_0_4px_var(--color-content-primary)]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n style={{ animationDelay: `${index * LETTER_STAGGER}s` }}\n >\n {character}\n </span>\n ))}\n </span>\n);\n\n/**\n * A pill button for AI actions. The label shimmers letter by letter and the glyph\n * flickers at rest; on hover both settle and the green treatment eases in together\n * — outline, rim and a sheen pooling along the bottom edge under the cursor, which\n * follows it across the button. On focus each letter blooms once before the shimmer\n * resumes. The lit rim and sheen come from the `fv-ai-button` utility in `base.css`.\n *\n * It shares {@link Button}'s geometry — `rounded-full`, the same heights and label\n * typography — so it sits alongside one without looking foreign. Both labels are\n * rendered stacked in a single grid cell, so swapping to `active` crossfades\n * without the button changing width.\n *\n * Honours `prefers-reduced-motion`: the shimmer and flicker are dropped and the\n * label renders in its settled state.\n *\n * @example\n * ```tsx\n * <AiButton label=\"Analyse\" activeLabel=\"Analysing\" active={isPending} onClick={run} />\n * ```\n */\nexport const AiButton = React.forwardRef<HTMLButtonElement, AiButtonProps>(\n (\n {\n label,\n activeLabel,\n active = false,\n size = \"32\",\n icon,\n type = \"button\",\n className,\n disabled,\n onPointerMove,\n onPointerLeave,\n ...props\n },\n ref,\n ) => {\n const resolvedActiveLabel = activeLabel ?? label;\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-label={props[\"aria-label\"] ?? (active ? resolvedActiveLabel : label)}\n aria-busy={active || undefined}\n onPointerMove={(event) => {\n trackPointer(event);\n onPointerMove?.(event);\n }}\n // Drop back to the utility's centred default, so a keyboard focus after\n // the pointer has left does not light up wherever the cursor last was.\n onPointerLeave={(event) => {\n event.currentTarget.style.removeProperty(\"--fv-ai-x\");\n onPointerLeave?.(event);\n }}\n className={cn(\n \"fv-ai-button\",\n \"group/ai inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full\",\n \"border border-border-primary bg-background-primary\",\n // Matched to the rim and sheen so the whole treatment arrives as one\n // movement — at the old 300ms the outline landed ahead of the glow.\n \"transition-[background-color,border-color] duration-[400ms] ease-out\",\n \"hover:border-brand-primary-default\",\n \"focus-visible:outline-none\",\n \"active:border-brand-primary-hover active:bg-brand-primary-muted\",\n \"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-border-primary\",\n sizeVariants[size],\n className,\n )}\n {...props}\n >\n <span\n className={cn(\n \"flex shrink-0 items-center text-content-primary\",\n iconScaleVariants[size],\n \"[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]\",\n // Same reasoning as the letters: no flicker and no green lift once the\n // button is unavailable.\n !disabled && [\n \"[animation:fv-ai-flicker_2s_linear_infinite] [animation-delay:0.5s]\",\n // Settles solid on hover, lit green from below like the sheen.\n \"group-hover/ai:[animation:none]\",\n \"group-hover/ai:[filter:drop-shadow(0_0_3px_var(--color-brand-primary-default))_drop-shadow(0_-4px_6px_color-mix(in_srgb,var(--color-content-always-black)_60%,transparent))]\",\n \"group-focus-visible/ai:[animation-duration:1.2s] group-focus-visible/ai:[animation-delay:0.2s]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n >\n {icon ?? <AIIcon size={iconSizeVariants[size]} filled />}\n </span>\n {/* Both labels occupy one grid cell so the button keeps the width of the\n longer of the two and the swap never reflows the row around it. */}\n <span className=\"grid\">\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-0\" : \"opacity-100\",\n )}\n >\n <ShimmerLabel text={label} disabled={disabled} />\n </span>\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <ShimmerLabel text={resolvedActiveLabel} disabled={disabled} />\n </span>\n </span>\n </button>\n );\n },\n);\n\nAiButton.displayName = \"AiButton\";\n"],"names":[],"mappings":";;;;;AAQA,MAAM,eAA6C;AAAA;AAAA;AAAA;AAAA,EAIjD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,oBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,iBAAiB;AAQvB,MAAM,eAAe,CAAC,UAAiD;AACrE,QAAM,EAAE,MAAM,MAAA,IAAU,MAAM,cAAc,sBAAA;AAC5C,QAAM,cAAc,MAAM,YAAY,aAAa,IAAK,MAAM,UAAU,QAAQ,QAAS,GAAG,GAAG;AACjG;AAuBA,MAAM,eAA+D,CAAC,EAAE,MAAM,SAAA,MAC5E,oBAAC,QAAA,EAAK,eAAY,QACf,gBAAM,KAAK,IAAI,EAAE,IAAI,CAAC,WAAW,UAChC;AAAA,EAAC;AAAA,EAAA;AAAA,IAEC,WAAW;AAAA,MACT;AAAA;AAAA;AAAA;AAAA;AAAA,MAKA,CAAC,YAAY;AAAA,QACX;AAAA,QACA;AAAA;AAAA;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAEF;AAAA,IAAA;AAAA,IAEF,OAAO,EAAE,gBAAgB,GAAG,QAAQ,cAAc,IAAA;AAAA,IAEjD,UAAA;AAAA,EAAA;AAAA,EApBI,GAAG,SAAS,IAAI,KAAK;AAqB5B,CACD,GACH;AAuBK,MAAM,WAAW,MAAM;AAAA,EAC5B,CACE;AAAA,IACE;AAAA,IACA;AAA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OAAO,SAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,YAEjD;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,SAAS,gBAAgB;AAAA,gBAAA;AAAA,gBAG3B,UAAA,oBAAC,cAAA,EAAa,MAAM,qBAAqB,SAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,UAC/D,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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 { usePrefersReducedMotion } from "../../utils/usePrefersReducedMotion.mjs";
|
|
6
|
+
const DEFAULT_DURATION_MS = 500;
|
|
7
|
+
const defaultFormat = (value) => String(Math.round(value));
|
|
8
|
+
const easeOutCubic = (t) => 1 - (1 - t) ** 3;
|
|
9
|
+
const DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
10
|
+
const isDigit = (char) => char >= "0" && char <= "9";
|
|
11
|
+
const AnimatedNumber = React.forwardRef(
|
|
12
|
+
({
|
|
13
|
+
value,
|
|
14
|
+
format = defaultFormat,
|
|
15
|
+
variant = "count",
|
|
16
|
+
durationMs = DEFAULT_DURATION_MS,
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}, ref) => {
|
|
20
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
21
|
+
if (variant === "roll") {
|
|
22
|
+
return /* @__PURE__ */ jsx(
|
|
23
|
+
RollingNumber,
|
|
24
|
+
{
|
|
25
|
+
ref,
|
|
26
|
+
value,
|
|
27
|
+
format,
|
|
28
|
+
durationMs: reducedMotion ? 0 : durationMs,
|
|
29
|
+
className,
|
|
30
|
+
...props
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
CountingNumber,
|
|
36
|
+
{
|
|
37
|
+
ref,
|
|
38
|
+
value,
|
|
39
|
+
format,
|
|
40
|
+
durationMs: reducedMotion ? 0 : durationMs,
|
|
41
|
+
className,
|
|
42
|
+
...props
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
AnimatedNumber.displayName = "AnimatedNumber";
|
|
48
|
+
const CountingNumber = React.forwardRef(
|
|
49
|
+
({ value, format, durationMs, className, ...props }, ref) => {
|
|
50
|
+
const [displayValue, setDisplayValue] = React.useState(value);
|
|
51
|
+
const displayRef = React.useRef(value);
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
const from = displayRef.current;
|
|
54
|
+
if (from === value || durationMs === 0) {
|
|
55
|
+
displayRef.current = value;
|
|
56
|
+
setDisplayValue(value);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let frame = 0;
|
|
60
|
+
let start;
|
|
61
|
+
const step = (now) => {
|
|
62
|
+
start ??= now;
|
|
63
|
+
const progress = Math.min((now - start) / durationMs, 1);
|
|
64
|
+
const next = from + (value - from) * easeOutCubic(progress);
|
|
65
|
+
displayRef.current = next;
|
|
66
|
+
setDisplayValue(next);
|
|
67
|
+
if (progress < 1) {
|
|
68
|
+
frame = requestAnimationFrame(step);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
frame = requestAnimationFrame(step);
|
|
72
|
+
return () => cancelAnimationFrame(frame);
|
|
73
|
+
}, [value, durationMs]);
|
|
74
|
+
return /* @__PURE__ */ jsx("span", { ref, className: cn("tabular-nums", className), ...props, children: format(displayValue) });
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
CountingNumber.displayName = "AnimatedNumber.Counting";
|
|
78
|
+
const RollingNumber = React.forwardRef(
|
|
79
|
+
({ value, format, durationMs, className, ...props }, ref) => {
|
|
80
|
+
const display = format(value);
|
|
81
|
+
const characters = React.useMemo(() => Array.from(display), [display]);
|
|
82
|
+
const contentRef = React.useRef(null);
|
|
83
|
+
const [boxWidth, setBoxWidth] = React.useState();
|
|
84
|
+
const hasMeasured = boxWidth !== void 0;
|
|
85
|
+
React.useLayoutEffect(() => {
|
|
86
|
+
const node = contentRef.current;
|
|
87
|
+
if (!node || !display) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const measure = () => {
|
|
91
|
+
const measured = node.scrollWidth;
|
|
92
|
+
if (measured) {
|
|
93
|
+
setBoxWidth(measured);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
measure();
|
|
97
|
+
if (typeof ResizeObserver === "undefined") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const observer = new ResizeObserver(measure);
|
|
101
|
+
observer.observe(node);
|
|
102
|
+
return () => observer.disconnect();
|
|
103
|
+
}, [display]);
|
|
104
|
+
return /* @__PURE__ */ jsxs(
|
|
105
|
+
"span",
|
|
106
|
+
{
|
|
107
|
+
ref,
|
|
108
|
+
className: cn("inline-flex overflow-hidden tabular-nums", className),
|
|
109
|
+
style: {
|
|
110
|
+
width: boxWidth,
|
|
111
|
+
transitionProperty: "width",
|
|
112
|
+
transitionDuration: hasMeasured ? `${durationMs}ms` : "0ms",
|
|
113
|
+
transitionTimingFunction: "cubic-bezier(0.22, 1, 0.36, 1)"
|
|
114
|
+
},
|
|
115
|
+
...props,
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: display }),
|
|
118
|
+
/* @__PURE__ */ jsx("span", { ref: contentRef, "aria-hidden": true, className: "inline-flex whitespace-pre", children: characters.map(
|
|
119
|
+
(char, index) => isDigit(char) ? /* @__PURE__ */ jsx(
|
|
120
|
+
"span",
|
|
121
|
+
{
|
|
122
|
+
className: "relative inline-block overflow-hidden",
|
|
123
|
+
style: { height: "1em", lineHeight: "1em" },
|
|
124
|
+
children: /* @__PURE__ */ jsx(
|
|
125
|
+
"span",
|
|
126
|
+
{
|
|
127
|
+
className: "flex flex-col",
|
|
128
|
+
style: {
|
|
129
|
+
transform: `translateY(-${Number(char) * 10}%)`,
|
|
130
|
+
transitionProperty: "transform",
|
|
131
|
+
transitionDuration: `${durationMs}ms`,
|
|
132
|
+
transitionTimingFunction: "cubic-bezier(0.22, 1, 0.36, 1)"
|
|
133
|
+
},
|
|
134
|
+
children: DIGITS.map((digit) => /* @__PURE__ */ jsx("span", { style: { height: "1em", lineHeight: "1em" }, children: digit }, digit))
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
},
|
|
138
|
+
`digit-${index}`
|
|
139
|
+
) : (
|
|
140
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: same positional identity as the digit columns
|
|
141
|
+
/* @__PURE__ */ jsx("span", { children: char }, `separator-${index}`)
|
|
142
|
+
)
|
|
143
|
+
) })
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
RollingNumber.displayName = "AnimatedNumber.Rolling";
|
|
150
|
+
export {
|
|
151
|
+
AnimatedNumber
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=AnimatedNumber.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedNumber.mjs","sources":["../../../src/components/AnimatedNumber/AnimatedNumber.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { usePrefersReducedMotion } from \"@/utils/usePrefersReducedMotion\";\n\n/** How a value change is animated. */\nexport type AnimatedNumberVariant =\n /**\n * Per-digit odometer: each digit column slides to its new value and the box\n * width eases when the digit count changes. Reads as mechanical, so it suits\n * a single headline figure rather than a grid of them.\n */\n | \"roll\"\n /**\n * Interpolates the value and re-formats it each frame, so the whole number\n * counts from old to new. Calmer than `roll` when several figures on a page\n * change at once.\n */\n | \"count\";\n\n/** Props for {@link AnimatedNumber}. */\nexport interface AnimatedNumberProps\n extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n /** The value to display. Animates whenever this changes. */\n value: number;\n /**\n * Turns the value into the displayed string. Receives interpolated values in\n * the `count` variant, so it must handle non-integers.\n * @default String(Math.round(value))\n */\n format?: (value: number) => string;\n /** Which animation to run. @default \"count\" */\n variant?: AnimatedNumberVariant;\n /** Animation duration in milliseconds. @default 500 */\n durationMs?: number;\n}\n\nconst DEFAULT_DURATION_MS = 500;\n\nconst defaultFormat = (value: number) => String(Math.round(value));\n\n/** Decelerating ease, so the value settles rather than stopping abruptly. */\nconst easeOutCubic = (t: number) => 1 - (1 - t) ** 3;\n\nconst DIGITS = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\n\nconst isDigit = (char: string) => char >= \"0\" && char <= \"9\";\n\n/**\n * Animates a number when its value changes, either by rolling each digit like\n * an odometer or by counting through the intermediate values.\n *\n * Both variants collapse to an instant swap under\n * `prefers-reduced-motion: reduce`.\n *\n * The rolling variant stacks all ten digits in each column, so the visual is\n * hidden from assistive technology and the formatted value is exposed once as\n * text instead.\n *\n * @example\n * ```tsx\n * // Headline figure\n * <AnimatedNumber value={totalGross} format={formatPrice} variant=\"roll\" />\n *\n * // Supporting figure\n * <AnimatedNumber value={activeFans} variant=\"count\" />\n * ```\n */\nexport const AnimatedNumber = React.forwardRef<HTMLSpanElement, AnimatedNumberProps>(\n (\n {\n value,\n format = defaultFormat,\n variant = \"count\",\n durationMs = DEFAULT_DURATION_MS,\n className,\n ...props\n },\n ref,\n ) => {\n const reducedMotion = usePrefersReducedMotion();\n\n if (variant === \"roll\") {\n return (\n <RollingNumber\n ref={ref}\n value={value}\n format={format}\n durationMs={reducedMotion ? 0 : durationMs}\n className={className}\n {...props}\n />\n );\n }\n\n return (\n <CountingNumber\n ref={ref}\n value={value}\n format={format}\n durationMs={reducedMotion ? 0 : durationMs}\n className={className}\n {...props}\n />\n );\n },\n);\n\nAnimatedNumber.displayName = \"AnimatedNumber\";\n\ntype VariantProps = Omit<AnimatedNumberProps, \"variant\" | \"format\" | \"durationMs\"> & {\n format: (value: number) => string;\n durationMs: number;\n};\n\nconst CountingNumber = React.forwardRef<HTMLSpanElement, VariantProps>(\n ({ value, format, durationMs, className, ...props }, ref) => {\n const [displayValue, setDisplayValue] = React.useState(value);\n // Tracks what is on screen, so an interrupted tween resumes from there. Storing\n // the abandoned *target* instead would start the next tween from a number that\n // was never displayed, which shows as a jump to the old target before counting\n // on — a refetch or filter change landing mid-animation is enough to hit it.\n const displayRef = React.useRef(value);\n\n React.useEffect(() => {\n const from = displayRef.current;\n if (from === value || durationMs === 0) {\n displayRef.current = value;\n setDisplayValue(value);\n return;\n }\n\n let frame = 0;\n let start: number | undefined;\n\n const step = (now: number) => {\n start ??= now;\n const progress = Math.min((now - start) / durationMs, 1);\n const next = from + (value - from) * easeOutCubic(progress);\n displayRef.current = next;\n setDisplayValue(next);\n if (progress < 1) {\n frame = requestAnimationFrame(step);\n }\n };\n\n frame = requestAnimationFrame(step);\n return () => cancelAnimationFrame(frame);\n }, [value, durationMs]);\n\n return (\n <span ref={ref} className={cn(\"tabular-nums\", className)} {...props}>\n {format(displayValue)}\n </span>\n );\n },\n);\n\nCountingNumber.displayName = \"AnimatedNumber.Counting\";\n\nconst RollingNumber = React.forwardRef<HTMLSpanElement, VariantProps>(\n ({ value, format, durationMs, className, ...props }, ref) => {\n const display = format(value);\n const characters = React.useMemo(() => Array.from(display), [display]);\n\n // Lock the box to its measured width so a change in digit count eases\n // instead of snapping: `width: auto` cannot be transitioned.\n const contentRef = React.useRef<HTMLSpanElement>(null);\n const [boxWidth, setBoxWidth] = React.useState<number>();\n\n // On the render where the width is still `auto` there is nothing to\n // transition from, so the duration is zeroed. This is belt-and-braces rather\n // than load-bearing: `auto` to a length is not interpolatable, so no\n // transition would run either way.\n const hasMeasured = boxWidth !== undefined;\n\n // Re-measure rather than measuring once per `display`: the box is\n // `overflow-hidden`, so a web font landing after the first measurement leaves\n // the locked width too narrow for the wider glyphs and clips the number until\n // the value next changes, which for a headline figure may be never. Observing\n // covers a container change too. Same approach as `useCyclingTextTrackWidth`.\n React.useLayoutEffect(() => {\n const node = contentRef.current;\n if (!node || !display) {\n return;\n }\n\n const measure = () => {\n const measured = node.scrollWidth;\n if (measured) {\n setBoxWidth(measured);\n }\n };\n\n measure();\n\n if (typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, [display]);\n\n return (\n <span\n ref={ref}\n className={cn(\"inline-flex overflow-hidden tabular-nums\", className)}\n style={{\n width: boxWidth,\n transitionProperty: \"width\",\n transitionDuration: hasMeasured ? `${durationMs}ms` : \"0ms\",\n transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n }}\n {...props}\n >\n {/* The digit columns list 0-9 apiece, which assistive tech would read\n out in full, so expose the formatted value as text instead. */}\n <span className=\"sr-only\">{display}</span>\n <span ref={contentRef} aria-hidden className=\"inline-flex whitespace-pre\">\n {characters.map((char, index) =>\n isDigit(char) ? (\n <span\n // biome-ignore lint/suspicious/noArrayIndexKey: a column is a position in the number, so it must keep its identity (and animate) when its digit changes\n key={`digit-${index}`}\n className=\"relative inline-block overflow-hidden\"\n style={{ height: \"1em\", lineHeight: \"1em\" }}\n >\n <span\n className=\"flex flex-col\"\n style={{\n transform: `translateY(-${Number(char) * 10}%)`,\n transitionProperty: \"transform\",\n transitionDuration: `${durationMs}ms`,\n transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n }}\n >\n {DIGITS.map((digit) => (\n <span key={digit} style={{ height: \"1em\", lineHeight: \"1em\" }}>\n {digit}\n </span>\n ))}\n </span>\n </span>\n ) : (\n // biome-ignore lint/suspicious/noArrayIndexKey: same positional identity as the digit columns\n <span key={`separator-${index}`}>{char}</span>\n ),\n )}\n </span>\n </span>\n );\n },\n);\n\nRollingNumber.displayName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|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cn } from "../../utils/cn.mjs";
|
|
5
5
|
import { Loader } from "../Loader/Loader.mjs";
|
|
6
|
+
import { ChartSkeleton } from "./ChartSkeleton.mjs";
|
|
6
7
|
const ChartLoadingOverlay = React.forwardRef(
|
|
7
|
-
({
|
|
8
|
+
({
|
|
9
|
+
loading = false,
|
|
10
|
+
variant = "area",
|
|
11
|
+
loadingLabel = "Loading chart",
|
|
12
|
+
children,
|
|
13
|
+
className,
|
|
14
|
+
...props
|
|
15
|
+
}, ref) => {
|
|
8
16
|
return /* @__PURE__ */ jsxs("div", { ref, className: cn("relative", className), ...props, children: [
|
|
9
17
|
children,
|
|
10
|
-
loading && /* @__PURE__ */ jsx(
|
|
18
|
+
loading && /* @__PURE__ */ jsx(
|
|
19
|
+
"div",
|
|
20
|
+
{
|
|
21
|
+
className: cn(
|
|
22
|
+
"absolute inset-0 z-10 flex items-center justify-center",
|
|
23
|
+
variant ? "bg-background-primary" : "bg-surface-primary/60"
|
|
24
|
+
),
|
|
25
|
+
...variant && {
|
|
26
|
+
role: "status",
|
|
27
|
+
"aria-busy": true,
|
|
28
|
+
"aria-label": loadingLabel
|
|
29
|
+
},
|
|
30
|
+
children: variant ? /* @__PURE__ */ jsx(ChartSkeleton, { variant }) : /* @__PURE__ */ jsx(Loader, { show: true, center: true })
|
|
31
|
+
}
|
|
32
|
+
)
|
|
11
33
|
] });
|
|
12
34
|
}
|
|
13
35
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartLoadingOverlay.mjs","sources":["../../../src/components/Chart/ChartLoadingOverlay.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Loader } from \"../Loader/Loader\";\n\n/** Props for {@link ChartLoadingOverlay}. */\nexport interface ChartLoadingOverlayProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Whether to show the loading overlay. @default false */\n loading?: boolean;\n /** Chart content to render underneath the overlay. */\n children: React.ReactNode;\n}\n\n/**\n * A positioned overlay
|
|
1
|
+
{"version":3,"file":"ChartLoadingOverlay.mjs","sources":["../../../src/components/Chart/ChartLoadingOverlay.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Loader } from \"../Loader/Loader\";\nimport { ChartSkeleton, type ChartSkeletonVariant } from \"./ChartSkeleton\";\n\n/** Props for {@link ChartLoadingOverlay}. */\nexport interface ChartLoadingOverlayProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Whether to show the loading overlay. @default false */\n loading?: boolean;\n /**\n * Shape of the wave-animated {@link ChartSkeleton} shown while loading. Set it\n * to match the chart underneath — `circular` for pie/radial, `bar` for bar\n * charts. Pass `false` to fall back to the legacy centred spinner.\n * @default \"area\"\n */\n variant?: ChartSkeletonVariant | false;\n /**\n * Accessible name for the loading region, announced while `loading` is true.\n * Pass a translated string for i18n. Only applies to the skeleton path; the\n * `variant={false}` spinner carries its own label. @default \"Loading chart\"\n */\n loadingLabel?: string;\n /** Chart content to render underneath the overlay. */\n children: React.ReactNode;\n}\n\n/**\n * A positioned overlay shown on top of chart content while it loads. The children\n * are always rendered to maintain layout dimensions.\n *\n * By default the overlay is opaque and shows a wave-animated\n * {@link ChartSkeleton} shaped like the chart. At `variant={false}` it falls back\n * to a semi-transparent wash with a centred spinner.\n *\n * @example\n * ```tsx\n * <ChartLoadingOverlay loading={isFetching} variant=\"area\">\n * <ChartContainer config={config} className=\"min-h-48\">\n * <LineChart data={data}>...</LineChart>\n * </ChartContainer>\n * </ChartLoadingOverlay>\n * ```\n */\nexport const ChartLoadingOverlay = React.forwardRef<HTMLDivElement, ChartLoadingOverlayProps>(\n (\n {\n loading = false,\n variant = \"area\",\n loadingLabel = \"Loading chart\",\n children,\n className,\n ...props\n },\n ref,\n ) => {\n return (\n <div ref={ref} className={cn(\"relative\", className)} {...props}>\n {children}\n {loading && (\n <div\n className={cn(\n \"absolute inset-0 z-10 flex items-center justify-center\",\n variant ? \"bg-background-primary\" : \"bg-surface-primary/60\",\n )}\n // Every `Skeleton` is `aria-hidden`, so without this the skeleton path\n // announces nothing where the spinner announced through its `<output>`.\n // This is the contract `Skeleton`'s own doc comment asks callers to honour.\n // Scoped to the skeleton path deliberately: adding it to the spinner path\n // would nest a live region inside a live region and risk a double\n // announcement.\n {...(variant && {\n role: \"status\",\n \"aria-busy\": true,\n \"aria-label\": loadingLabel,\n })}\n >\n {variant ? <ChartSkeleton variant={variant} /> : <Loader show center />}\n </div>\n )}\n </div>\n );\n },\n);\n\nChartLoadingOverlay.displayName = \"ChartLoadingOverlay\";\n"],"names":[],"mappings":";;;;;;AA2CO,MAAM,sBAAsB,MAAM;AAAA,EACvC,CACE;AAAA,IACE,UAAU;AAAA,IACV,UAAU;AAAA,IACV,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,WACE,qBAAC,SAAI,KAAU,WAAW,GAAG,YAAY,SAAS,GAAI,GAAG,OACtD,UAAA;AAAA,MAAA;AAAA,MACA,WACC;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAW;AAAA,YACT;AAAA,YACA,UAAU,0BAA0B;AAAA,UAAA;AAAA,UAQrC,GAAI,WAAW;AAAA,YACd,MAAM;AAAA,YACN,aAAa;AAAA,YACb,cAAc;AAAA,UAAA;AAAA,UAGf,UAAA,UAAU,oBAAC,eAAA,EAAc,QAAA,CAAkB,wBAAM,QAAA,EAAO,MAAI,MAAC,QAAM,KAAA,CAAC;AAAA,QAAA;AAAA,MAAA;AAAA,IACvE,GAEJ;AAAA,EAEJ;AACF;AAEA,oBAAoB,cAAc;"}
|