@fanvue/ui 3.23.0 → 3.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts.d.ts +94 -4
- package/dist/charts.mjs +4 -0
- package/dist/charts.mjs.map +1 -1
- package/dist/cjs/charts.cjs +4 -0
- package/dist/cjs/charts.cjs.map +1 -1
- package/dist/cjs/components/AiButton/AiButton.cjs +170 -0
- package/dist/cjs/components/AiButton/AiButton.cjs.map +1 -0
- package/dist/cjs/components/AnimatedNumber/AnimatedNumber.cjs +170 -0
- package/dist/cjs/components/AnimatedNumber/AnimatedNumber.cjs.map +1 -0
- package/dist/cjs/components/Chart/ChartLoadingOverlay.cjs +24 -2
- package/dist/cjs/components/Chart/ChartLoadingOverlay.cjs.map +1 -1
- package/dist/cjs/components/Chart/ChartMetricTrend.cjs +71 -0
- package/dist/cjs/components/Chart/ChartMetricTrend.cjs.map +1 -0
- package/dist/cjs/components/Chart/ChartSkeleton.cjs +95 -0
- package/dist/cjs/components/Chart/ChartSkeleton.cjs.map +1 -0
- package/dist/cjs/components/Chip/Chip.cjs +40 -11
- package/dist/cjs/components/Chip/Chip.cjs.map +1 -1
- package/dist/cjs/components/CountryFlag/CountryFlag.cjs +91 -0
- package/dist/cjs/components/CountryFlag/CountryFlag.cjs.map +1 -0
- package/dist/cjs/components/CountryFlag/flagShapes.cjs +3358 -0
- package/dist/cjs/components/CountryFlag/flagShapes.cjs.map +1 -0
- package/dist/cjs/components/CyclingText/CyclingText.cjs +9 -26
- package/dist/cjs/components/CyclingText/CyclingText.cjs.map +1 -1
- package/dist/cjs/components/CyclingText/useCyclingMotion.cjs +53 -0
- package/dist/cjs/components/CyclingText/useCyclingMotion.cjs.map +1 -0
- package/dist/cjs/components/Demographics/Demographics.cjs +39 -0
- package/dist/cjs/components/Demographics/Demographics.cjs.map +1 -0
- package/dist/cjs/components/Drawer/Drawer.cjs +9 -1
- package/dist/cjs/components/Drawer/Drawer.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs +122 -16
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
- package/dist/cjs/components/IconButton/IconButton.cjs +11 -1
- package/dist/cjs/components/IconButton/IconButton.cjs.map +1 -1
- package/dist/cjs/components/ProgressBar/ProgressBar.cjs +9 -1
- package/dist/cjs/components/ProgressBar/ProgressBar.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsList.cjs +123 -91
- package/dist/cjs/components/Tabs/TabsList.cjs.map +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.cjs +36 -25
- package/dist/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
- package/dist/cjs/components/Tooltip/TooltipLabel.cjs +71 -0
- package/dist/cjs/components/Tooltip/TooltipLabel.cjs.map +1 -0
- package/dist/cjs/components/TrendPill/TrendPill.cjs +46 -0
- package/dist/cjs/components/TrendPill/TrendPill.cjs.map +1 -0
- package/dist/cjs/components/UserItem/UserItem.cjs +7 -2
- package/dist/cjs/components/UserItem/UserItem.cjs.map +1 -1
- package/dist/cjs/components/UserItem/UserItemTrailing.cjs +34 -0
- package/dist/cjs/components/UserItem/UserItemTrailing.cjs.map +1 -0
- package/dist/cjs/flags.cjs +6 -0
- package/dist/cjs/flags.cjs.map +1 -0
- package/dist/cjs/index.cjs +13 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{components/CyclingText → utils}/usePrefersReducedMotion.cjs +14 -14
- package/dist/cjs/utils/usePrefersReducedMotion.cjs.map +1 -0
- package/dist/components/AiButton/AiButton.mjs +153 -0
- package/dist/components/AiButton/AiButton.mjs.map +1 -0
- package/dist/components/AnimatedNumber/AnimatedNumber.mjs +153 -0
- package/dist/components/AnimatedNumber/AnimatedNumber.mjs.map +1 -0
- package/dist/components/Chart/ChartLoadingOverlay.mjs +24 -2
- package/dist/components/Chart/ChartLoadingOverlay.mjs.map +1 -1
- package/dist/components/Chart/ChartMetricTrend.mjs +54 -0
- package/dist/components/Chart/ChartMetricTrend.mjs.map +1 -0
- package/dist/components/Chart/ChartSkeleton.mjs +78 -0
- package/dist/components/Chart/ChartSkeleton.mjs.map +1 -0
- package/dist/components/Chip/Chip.mjs +40 -11
- package/dist/components/Chip/Chip.mjs.map +1 -1
- package/dist/components/CountryFlag/CountryFlag.mjs +74 -0
- package/dist/components/CountryFlag/CountryFlag.mjs.map +1 -0
- package/dist/components/CountryFlag/flagShapes.mjs +3358 -0
- package/dist/components/CountryFlag/flagShapes.mjs.map +1 -0
- package/dist/components/CyclingText/CyclingText.mjs +9 -26
- package/dist/components/CyclingText/CyclingText.mjs.map +1 -1
- package/dist/components/CyclingText/useCyclingMotion.mjs +36 -0
- package/dist/components/CyclingText/useCyclingMotion.mjs.map +1 -0
- package/dist/components/Demographics/Demographics.mjs +22 -0
- package/dist/components/Demographics/Demographics.mjs.map +1 -0
- package/dist/components/Drawer/Drawer.mjs +9 -1
- package/dist/components/Drawer/Drawer.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.mjs +122 -16
- package/dist/components/DropdownMenu/DropdownMenu.mjs.map +1 -1
- package/dist/components/IconButton/IconButton.mjs +11 -1
- package/dist/components/IconButton/IconButton.mjs.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.mjs +9 -1
- package/dist/components/ProgressBar/ProgressBar.mjs.map +1 -1
- package/dist/components/Tabs/TabsList.mjs +123 -91
- package/dist/components/Tabs/TabsList.mjs.map +1 -1
- package/dist/components/Tooltip/Tooltip.mjs +37 -26
- package/dist/components/Tooltip/Tooltip.mjs.map +1 -1
- package/dist/components/Tooltip/TooltipLabel.mjs +54 -0
- package/dist/components/Tooltip/TooltipLabel.mjs.map +1 -0
- package/dist/components/TrendPill/TrendPill.mjs +29 -0
- package/dist/components/TrendPill/TrendPill.mjs.map +1 -0
- package/dist/components/UserItem/UserItem.mjs +7 -2
- package/dist/components/UserItem/UserItem.mjs.map +1 -1
- package/dist/components/UserItem/UserItemTrailing.mjs +17 -0
- package/dist/components/UserItem/UserItemTrailing.mjs.map +1 -0
- package/dist/flags.d.ts +59 -0
- package/dist/flags.mjs +6 -0
- package/dist/flags.mjs.map +1 -0
- package/dist/index.d.ts +381 -11
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/dist/styles/base.css +166 -0
- package/dist/styles/theme.css +12 -0
- package/dist/utils/usePrefersReducedMotion.mjs +22 -0
- package/dist/utils/usePrefersReducedMotion.mjs.map +1 -0
- package/package.json +13 -2
- package/dist/cjs/components/CyclingText/usePrefersReducedMotion.cjs.map +0 -1
- package/dist/components/CyclingText/usePrefersReducedMotion.mjs +0 -22
- package/dist/components/CyclingText/usePrefersReducedMotion.mjs.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
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 recharts = require("recharts");
|
|
7
|
+
const cn = require("../../utils/cn.cjs");
|
|
8
|
+
const ChartContainer = require("./ChartContainer.cjs");
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== "default") {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
26
|
+
const CHART_COLORS = {
|
|
27
|
+
red: "var(--color-special-chart-red)",
|
|
28
|
+
teal: "var(--color-special-chart-teal)"
|
|
29
|
+
};
|
|
30
|
+
const ChartMetricTrend = React__namespace.forwardRef(
|
|
31
|
+
({ value, color, series, className, ...props }, ref) => {
|
|
32
|
+
const points = series && series.length > 1 ? series : [value, value];
|
|
33
|
+
const chartData = points.map((point, index) => ({ index, value: point }));
|
|
34
|
+
const chartConfig = { value: { color: CHART_COLORS[color] } };
|
|
35
|
+
const gradientId = `metric-trend-gradient-${React__namespace.useId().replace(/:/g, "")}`;
|
|
36
|
+
return (
|
|
37
|
+
// 106px is the design's `V2 Area Chart Item` slot height.
|
|
38
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
39
|
+
ChartContainer.ChartContainer,
|
|
40
|
+
{
|
|
41
|
+
ref,
|
|
42
|
+
config: chartConfig,
|
|
43
|
+
className: cn.cn("block aspect-auto h-[106px] w-full", className),
|
|
44
|
+
...props,
|
|
45
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(recharts.AreaChart, { data: chartData, margin: { top: 4, bottom: 0, left: 0, right: 0 }, children: [
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
47
|
+
/* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0%", stopColor: "var(--color-value)", stopOpacity: 0.3 }),
|
|
48
|
+
/* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "100%", stopColor: "var(--color-value)", stopOpacity: 0 })
|
|
49
|
+
] }) }),
|
|
50
|
+
/* @__PURE__ */ jsxRuntime.jsx(recharts.YAxis, { hide: true, domain: ["dataMin - 1", "dataMax + 1"] }),
|
|
51
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
52
|
+
recharts.Area,
|
|
53
|
+
{
|
|
54
|
+
type: "monotone",
|
|
55
|
+
dataKey: "value",
|
|
56
|
+
stroke: "var(--color-value)",
|
|
57
|
+
strokeWidth: 2,
|
|
58
|
+
fill: `url(#${gradientId})`,
|
|
59
|
+
dot: false,
|
|
60
|
+
isAnimationActive: false
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
] })
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
ChartMetricTrend.displayName = "ChartMetricTrend";
|
|
70
|
+
exports.ChartMetricTrend = ChartMetricTrend;
|
|
71
|
+
//# sourceMappingURL=ChartMetricTrend.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartMetricTrend.cjs","sources":["../../../../src/components/Chart/ChartMetricTrend.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Area, AreaChart, YAxis } from \"recharts\";\nimport { cn } from \"../../utils/cn\";\nimport { ChartContainer } from \"./ChartContainer\";\nimport type { ChartConfig } from \"./types\";\n\n/**\n * Each card carries its own gradient in the design: red on Retention Rate,\n * green on Average Fan Lifetime. The DS has no `special-chart-green`, so the\n * green maps to `teal` (#28ba8e) — the emerald in the Figma render, as opposed\n * to `lime` (#8fcb3a), which is yellow-green.\n */\nexport type ChartMetricTrendColor = \"red\" | \"teal\";\n\nconst CHART_COLORS: Record<ChartMetricTrendColor, string> = {\n red: \"var(--color-special-chart-red)\",\n teal: \"var(--color-special-chart-teal)\",\n};\n\n/** Props for {@link ChartMetricTrend}. */\nexport interface ChartMetricTrendProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Current value. Also the flat-line height when `series` is absent. */\n value: number;\n /** Gradient and stroke colour. */\n color: ChartMetricTrendColor;\n /** History to plot. Needs more than one point to draw a shape. */\n series?: number[];\n}\n\n/**\n * The small area chart inside a metric tile, per the `V2 Area Chart Item` slot of\n * the Figma insight card.\n *\n * `series` is optional because the endpoints behind these cards often return a\n * single scalar with no history. With nothing to plot the chart draws a flat line\n * at the current value rather than collapsing the slot, so the card keeps the\n * height and shape the design gives it. The line is deliberately level rather\n * than shaped, so it asserts no history that the data cannot support.\n *\n * @example\n * ```tsx\n * <ChartMetricTrend value={42} color=\"teal\" />\n * ```\n */\nexport const ChartMetricTrend = React.forwardRef<HTMLDivElement, ChartMetricTrendProps>(\n ({ value, color, series, className, ...props }, ref) => {\n const points = series && series.length > 1 ? series : [value, value];\n const chartData = points.map((point, index) => ({ index, value: point }));\n const chartConfig: ChartConfig = { value: { color: CHART_COLORS[color] } };\n // Per instance, not per colour: two same-colour cards would otherwise emit the\n // same id and every `url(#...)` in the document would resolve to whichever\n // rendered first. `useId` emits colons, which are legal in an `id` but break\n // `querySelector`, so strip them.\n const gradientId = `metric-trend-gradient-${React.useId().replace(/:/g, \"\")}`;\n\n return (\n // 106px is the design's `V2 Area Chart Item` slot height.\n <ChartContainer\n ref={ref}\n config={chartConfig}\n className={cn(\"block aspect-auto h-[106px] w-full\", className)}\n {...props}\n >\n <AreaChart data={chartData} margin={{ top: 4, bottom: 0, left: 0, right: 0 }}>\n <defs>\n <linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"0%\" stopColor=\"var(--color-value)\" stopOpacity={0.3} />\n <stop offset=\"100%\" stopColor=\"var(--color-value)\" stopOpacity={0} />\n </linearGradient>\n </defs>\n {/*\n * Padded domain so a flat line sits inside the plot area instead of\n * along its floor, where it would read as a zero value.\n */}\n <YAxis hide domain={[\"dataMin - 1\", \"dataMax + 1\"]} />\n <Area\n type=\"monotone\"\n dataKey=\"value\"\n stroke=\"var(--color-value)\"\n strokeWidth={2}\n fill={`url(#${gradientId})`}\n dot={false}\n isAnimationActive={false}\n />\n </AreaChart>\n </ChartContainer>\n );\n },\n);\n\nChartMetricTrend.displayName = \"ChartMetricTrend\";\n"],"names":["React","jsx","ChartContainer","cn","jsxs","AreaChart","YAxis","Area"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,eAAsD;AAAA,EAC1D,KAAK;AAAA,EACL,MAAM;AACR;AA2BO,MAAM,mBAAmB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ACL,mBAAmB;AAAA,cAAA;AAAA,YAAA;AAAA,UACrB,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA;AAAA,EAGN;AACF;AAEA,iBAAiB,cAAc;;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
const Skeleton = require("../Skeleton/Skeleton.cjs");
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
25
|
+
const BAR_HEIGHTS = ["45%", "70%", "55%", "85%", "60%", "95%", "75%"];
|
|
26
|
+
const barHeight = (index) => BAR_HEIGHTS[index % BAR_HEIGHTS.length];
|
|
27
|
+
const LABEL_WIDTHS = ["w-24", "w-32", "w-20", "w-28", "w-24"];
|
|
28
|
+
const labelWidth = (index) => LABEL_WIDTHS[index % LABEL_WIDTHS.length];
|
|
29
|
+
const Bar = ({ className }) => /* @__PURE__ */ jsxRuntime.jsx(Skeleton.Skeleton, { animation: "wave", variant: "rounded", className });
|
|
30
|
+
const TableSkeleton = ({ rows }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col", children: [
|
|
31
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-8 items-center gap-3", children: [
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: "h-3 w-4" }),
|
|
33
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: "h-3 w-16" }),
|
|
34
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: "ml-auto h-3 w-12" })
|
|
35
|
+
] }),
|
|
36
|
+
Array.from({ length: rows }, (_, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-12 items-center gap-3", children: [
|
|
37
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: "h-4 w-4" }),
|
|
38
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton.Skeleton, { animation: "wave", variant: "circular", className: "size-6 shrink-0" }),
|
|
39
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: cn.cn("h-4", labelWidth(index)) }),
|
|
40
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: "ml-auto h-4 w-16" })
|
|
41
|
+
] }, `table-row-${index}`))
|
|
42
|
+
] });
|
|
43
|
+
const RowsSkeleton = ({ rows }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col gap-4", children: Array.from({ length: rows }, (_, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-2", children: [
|
|
44
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-between gap-2", children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton.Skeleton, { animation: "wave", variant: "circular", className: "size-5 shrink-0" }),
|
|
47
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: cn.cn("h-4", labelWidth(index)) })
|
|
48
|
+
] }),
|
|
49
|
+
/* @__PURE__ */ jsxRuntime.jsx(Bar, { className: "h-4 w-10 shrink-0" })
|
|
50
|
+
] }),
|
|
51
|
+
/* @__PURE__ */ jsxRuntime.jsx(Skeleton.Skeleton, { animation: "wave", variant: "rounded", className: "h-2 w-full rounded-full" })
|
|
52
|
+
] }, `row-${index}`)) });
|
|
53
|
+
const ChartSkeleton = React__namespace.forwardRef(
|
|
54
|
+
({ variant = "area", rows, className, ...props }, ref) => {
|
|
55
|
+
const rowCount = rows ?? 5;
|
|
56
|
+
const bars = rows ?? BAR_HEIGHTS.length;
|
|
57
|
+
if (variant === "table" || variant === "rows") {
|
|
58
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn.cn("w-full", className), ...props, children: variant === "table" ? /* @__PURE__ */ jsxRuntime.jsx(TableSkeleton, { rows: rowCount }) : /* @__PURE__ */ jsxRuntime.jsx(RowsSkeleton, { rows: rowCount }) });
|
|
59
|
+
}
|
|
60
|
+
if (variant === "circular") {
|
|
61
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
62
|
+
"div",
|
|
63
|
+
{
|
|
64
|
+
ref,
|
|
65
|
+
className: cn.cn("flex size-full items-center justify-center", className),
|
|
66
|
+
...props,
|
|
67
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-square h-full", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
68
|
+
Skeleton.Skeleton,
|
|
69
|
+
{
|
|
70
|
+
animation: "wave",
|
|
71
|
+
variant: "circular",
|
|
72
|
+
className: "size-full [mask-image:radial-gradient(circle,transparent_27%,black_28%)]"
|
|
73
|
+
}
|
|
74
|
+
) })
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (variant === "bar") {
|
|
79
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn.cn("flex size-full items-end gap-2", className), ...props, children: Array.from({ length: bars }, (_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
80
|
+
Skeleton.Skeleton,
|
|
81
|
+
{
|
|
82
|
+
animation: "wave",
|
|
83
|
+
variant: "rounded",
|
|
84
|
+
className: "flex-1",
|
|
85
|
+
height: barHeight(index)
|
|
86
|
+
},
|
|
87
|
+
`bar-${index}`
|
|
88
|
+
)) });
|
|
89
|
+
}
|
|
90
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn.cn("size-full", className), ...props, children: /* @__PURE__ */ jsxRuntime.jsx(Skeleton.Skeleton, { animation: "wave", variant: "rounded", className: "size-full" }) });
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
ChartSkeleton.displayName = "ChartSkeleton";
|
|
94
|
+
exports.ChartSkeleton = ChartSkeleton;
|
|
95
|
+
//# sourceMappingURL=ChartSkeleton.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartSkeleton.cjs","sources":["../../../../src/components/Chart/ChartSkeleton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Skeleton } from \"../Skeleton/Skeleton\";\n\n/**\n * Shape the skeleton should imitate while data loads. `area` and `line` render\n * the same filled band — a continuous series reads better as a band than as\n * discrete bars. `table` and `rows` stand in for the two list bodies an insight\n * card can hold rather than a chart: a ranked table, and a breakdown of labelled\n * bars.\n */\nexport type ChartSkeletonVariant = \"area\" | \"line\" | \"bar\" | \"circular\" | \"table\" | \"rows\";\n\n/** Props for {@link ChartSkeleton}. */\nexport interface ChartSkeletonProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Which shape to imitate. @default \"area\" */\n variant?: ChartSkeletonVariant;\n /**\n * How many items to draw: rows for `table` and `rows`, bars for `bar`. Match\n * the count the loaded card will show, so the card does not resize once the\n * real content arrives. Defaults to 5 rows, or 7 bars.\n */\n rows?: number;\n}\n\n/** Varying bar heights, so the series does not read as a solid block. */\nconst BAR_HEIGHTS = [\"45%\", \"70%\", \"55%\", \"85%\", \"60%\", \"95%\", \"75%\"];\n\nconst barHeight = (index: number) => BAR_HEIGHTS[index % BAR_HEIGHTS.length];\n\n/** Varying label widths, so the rows do not read as a single solid block. */\nconst LABEL_WIDTHS = [\"w-24\", \"w-32\", \"w-20\", \"w-28\", \"w-24\"];\n\nconst labelWidth = (index: number) => LABEL_WIDTHS[index % LABEL_WIDTHS.length];\n\nconst Bar = ({ className }: { className?: string }) => (\n <Skeleton animation=\"wave\" variant=\"rounded\" className={className} />\n);\n\n/**\n * A ranked table: the header, then one 48px row per entry holding a rank, an\n * avatar and handle, and a value at the end — the columns {@link ChartCard}'s\n * table bodies use.\n */\nconst TableSkeleton = ({ rows }: { rows: number }) => (\n <div className=\"flex w-full flex-col\">\n <div className=\"flex h-8 items-center gap-3\">\n <Bar className=\"h-3 w-4\" />\n <Bar className=\"h-3 w-16\" />\n <Bar className=\"ml-auto h-3 w-12\" />\n </div>\n {Array.from({ length: rows }, (_, index) => (\n <div key={`table-row-${index}`} className=\"flex h-12 items-center gap-3\">\n <Bar className=\"h-4 w-4\" />\n <Skeleton animation=\"wave\" variant=\"circular\" className=\"size-6 shrink-0\" />\n <Bar className={cn(\"h-4\", labelWidth(index))} />\n <Bar className=\"ml-auto h-4 w-16\" />\n </div>\n ))}\n </div>\n);\n\n/**\n * A breakdown list: per row a leading glyph and label with its share at the far\n * end, then the bar underneath. Mirrors `Demographics`, down to its 8px inner gap\n * and 8px `medium` bar, so the swap to real rows is invisible.\n */\nconst RowsSkeleton = ({ rows }: { rows: number }) => (\n <div className=\"flex w-full flex-col gap-4\">\n {Array.from({ length: rows }, (_, index) => (\n <div key={`row-${index}`} className=\"flex w-full flex-col gap-2\">\n <div className=\"flex w-full items-center justify-between gap-2\">\n <span className=\"flex items-center gap-2\">\n <Skeleton animation=\"wave\" variant=\"circular\" className=\"size-5 shrink-0\" />\n <Bar className={cn(\"h-4\", labelWidth(index))} />\n </span>\n <Bar className=\"h-4 w-10 shrink-0\" />\n </div>\n <Skeleton animation=\"wave\" variant=\"rounded\" className=\"h-2 w-full rounded-full\" />\n </div>\n ))}\n </div>\n);\n\n/**\n * A wave-animated placeholder shaped like the content it stands in for — a chart\n * series, a ranked table, or a breakdown of labelled bars. Use it while data\n * loads instead of a generic spinner, so the layout does not visibly shift once\n * the real content renders.\n *\n * For a chart body, pass it to {@link ChartLoadingOverlay} via its `variant` prop\n * rather than rendering it directly. For a card body, pass it to `ChartCard`'s\n * `skeleton` prop.\n *\n * @example\n * ```tsx\n * <ChartSkeleton variant=\"bar\" className=\"h-48\" />\n * <ChartSkeleton variant=\"table\" rows={5} />\n * ```\n */\nexport const ChartSkeleton = React.forwardRef<HTMLDivElement, ChartSkeletonProps>(\n ({ variant = \"area\", rows, className, ...props }, ref) => {\n // Resolved per variant so `rows` can drive the bar count without moving the bar\n // default from 7 to the list default of 5.\n const rowCount = rows ?? 5;\n const bars = rows ?? BAR_HEIGHTS.length;\n\n if (variant === \"table\" || variant === \"rows\") {\n return (\n <div ref={ref} className={cn(\"w-full\", className)} {...props}>\n {variant === \"table\" ? (\n <TableSkeleton rows={rowCount} />\n ) : (\n <RowsSkeleton rows={rowCount} />\n )}\n </div>\n );\n }\n\n if (variant === \"circular\") {\n return (\n <div\n ref={ref}\n className={cn(\"flex size-full items-center justify-center\", className)}\n {...props}\n >\n <div className=\"aspect-square h-full\">\n {/*\n * The hole is masked out rather than painted over. A disc filled with a\n * surface colour only disappears on a surface of exactly that colour, and\n * this renders standalone via `ChartCard`'s `skeleton` prop as well as\n * inside `ChartLoadingOverlay`, so it cannot assume what is underneath.\n */}\n <Skeleton\n animation=\"wave\"\n variant=\"circular\"\n className=\"size-full [mask-image:radial-gradient(circle,transparent_27%,black_28%)]\"\n />\n </div>\n </div>\n );\n }\n\n if (variant === \"bar\") {\n return (\n <div ref={ref} className={cn(\"flex size-full items-end gap-2\", className)} {...props}>\n {Array.from({ length: bars }, (_, index) => (\n <Skeleton\n key={`bar-${index}`}\n animation=\"wave\"\n variant=\"rounded\"\n className=\"flex-1\"\n height={barHeight(index)}\n />\n ))}\n </div>\n );\n }\n\n return (\n <div ref={ref} className={cn(\"size-full\", className)} {...props}>\n <Skeleton animation=\"wave\" variant=\"rounded\" className=\"size-full\" />\n </div>\n );\n },\n);\n\nChartSkeleton.displayName = \"ChartSkeleton\";\n"],"names":["jsx","Skeleton","jsxs","cn","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,cAAc,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AAEpE,MAAM,YAAY,CAAC,UAAkB,YAAY,QAAQ,YAAY,MAAM;AAG3E,MAAM,eAAe,CAAC,QAAQ,QAAQ,QAAQ,QAAQ,MAAM;AAE5D,MAAM,aAAa,CAAC,UAAkB,aAAa,QAAQ,aAAa,MAAM;AAE9E,MAAM,MAAM,CAAC,EAAE,UAAA,MACbA,2BAAAA,IAACC,SAAAA,UAAA,EAAS,WAAU,QAAO,SAAQ,WAAU,UAAA,CAAsB;AAQrE,MAAM,gBAAgB,CAAC,EAAE,WACvBC,2BAAAA,KAAC,OAAA,EAAI,WAAU,wBACb,UAAA;AAAA,EAAAA,2BAAAA,KAAC,OAAA,EAAI,WAAU,+BACb,UAAA;AAAA,IAAAF,2BAAAA,IAAC,KAAA,EAAI,WAAU,UAAA,CAAU;AAAA,IACzBA,2BAAAA,IAAC,KAAA,EAAI,WAAU,WAAA,CAAW;AAAA,IAC1BA,2BAAAA,IAAC,KAAA,EAAI,WAAU,mBAAA,CAAmB;AAAA,EAAA,GACpC;AAAA,EACC,MAAM,KAAK,EAAE,QAAQ,KAAA,GAAQ,CAAC,GAAG,UAChCE,2BAAAA,KAAC,OAAA,EAA+B,WAAU,gCACxC,UAAA;AAAA,IAAAF,2BAAAA,IAAC,KAAA,EAAI,WAAU,UAAA,CAAU;AAAA,mCACxBC,SAAAA,UAAA,EAAS,WAAU,QAAO,SAAQ,YAAW,WAAU,mBAAkB;AAAA,IAC1ED,+BAAC,OAAI,WAAWG,GAAAA,GAAG,OAAO,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;AAEA,QAAI,YAAY,YAAY;AAC1B,aACEA,2BAAAA;AAAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA,WAAWG,GAAAA,GAAG,8CAA8C,SAAS;AAAA,UACpE,GAAG;AAAA,UAEJ,UAAAH,2BAAAA,IAAC,OAAA,EAAI,WAAU,wBAOb,UAAAA,2BAAAA;AAAAA,YAACC,SAAAA;AAAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,SAAQ;AAAA,cACR,WAAU;AAAA,YAAA;AAAA,UAAA,EACZ,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAGN;AAEA,QAAI,YAAY,OAAO;AACrB,4CACG,OAAA,EAAI,KAAU,WAAWE,MAAG,kCAAkC,SAAS,GAAI,GAAG,OAC5E,UAAA,MAAM,KAAK,EAAE,QAAQ,QAAQ,CAAC,GAAG,UAChCH,2BAAAA;AAAAA,QAACC,SAAAA;AAAAA,QAAA;AAAA,UAEC,WAAU;AAAA,UACV,SAAQ;AAAA,UACR,WAAU;AAAA,UACV,QAAQ,UAAU,KAAK;AAAA,QAAA;AAAA,QAJlB,OAAO,KAAK;AAAA,MAAA,CAMpB,GACH;AAAA,IAEJ;AAEA,0CACG,OAAA,EAAI,KAAU,WAAWE,GAAAA,GAAG,aAAa,SAAS,GAAI,GAAG,OACxD,UAAAH,+BAACC,SAAAA,YAAS,WAAU,QAAO,SAAQ,WAAU,WAAU,aAAY,GACrE;AAAA,EAEJ;AACF;AAEA,cAAc,cAAc;;"}
|
|
@@ -32,6 +32,7 @@ const Chip = React__namespace.forwardRef(
|
|
|
32
32
|
disabled = false,
|
|
33
33
|
leftDot = false,
|
|
34
34
|
dotted = false,
|
|
35
|
+
outlined = false,
|
|
35
36
|
leftIcon,
|
|
36
37
|
rightIcon,
|
|
37
38
|
notificationLabel,
|
|
@@ -46,13 +47,19 @@ const Chip = React__namespace.forwardRef(
|
|
|
46
47
|
const isInteractive = !!onClick && !asChild;
|
|
47
48
|
const Comp = asChild ? reactSlot.Slot : isInteractive ? "button" : "span";
|
|
48
49
|
const isDark = variant === "dark";
|
|
49
|
-
const
|
|
50
|
+
const isDotted = !isDark && dotted;
|
|
51
|
+
const isSolid = !isDark && !dotted && !outlined;
|
|
52
|
+
const isOutlined = !isDark && !dotted && outlined;
|
|
53
|
+
const showDottedBorder = isDotted && !selected && !asChild;
|
|
50
54
|
const dottedBorder = showDottedBorder ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
51
55
|
"svg",
|
|
52
56
|
{
|
|
53
57
|
"aria-hidden": "true",
|
|
54
58
|
className: cn.cn(
|
|
55
|
-
|
|
59
|
+
// `-1px` spans the reserved transparent border rather than the padding box
|
|
60
|
+
// inside it, so the dash lands on the same ring as the solid border it
|
|
61
|
+
// becomes when selected.
|
|
62
|
+
"pointer-events-none absolute -top-px -left-px h-[calc(100%+2px)] w-[calc(100%+2px)] overflow-visible",
|
|
56
63
|
disabled ? "text-buttons-chip-disabled" : "text-buttons-chip-dotted-default",
|
|
57
64
|
isInteractive && !disabled && "group-hover:text-buttons-chip-dotted-hover-stroke group-active:text-buttons-chip-dotted-hover-stroke"
|
|
58
65
|
),
|
|
@@ -85,20 +92,39 @@ const Chip = React__namespace.forwardRef(
|
|
|
85
92
|
size === "40" && "typography-body-small-14px-semibold h-10 py-2.5",
|
|
86
93
|
// Variant colors
|
|
87
94
|
isDark && "bg-neutral-alphas-600 text-content-always-white",
|
|
88
|
-
|
|
95
|
+
(isSolid || isOutlined) && selected && "bg-buttons-chip-active text-content-primary-inverted",
|
|
89
96
|
// Active + dotted is a subtle filled state with a solid (non-dashed) border.
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
isDotted && selected && "border border-border-primary border-solid bg-inputs-inputs-primary text-content-primary",
|
|
98
|
+
isSolid && !selected && "bg-buttons-chip-default text-content-primary",
|
|
99
|
+
// Outlined: the same token as a 1px stroke rather than a fill. The border
|
|
100
|
+
// is declared in BOTH states and only changes colour, going transparent
|
|
101
|
+
// once selected. It cannot be dropped on selection: `border-box` constrains
|
|
102
|
+
// only explicitly sized axes, and a chip's width is intrinsic, so losing the
|
|
103
|
+
// border would narrow the chip by 2px and reflow the whole row on every
|
|
104
|
+
// click. Height is safe either way because `h-8` is explicit.
|
|
105
|
+
isOutlined && "border border-solid",
|
|
106
|
+
isOutlined && !selected && "border-buttons-chip-default bg-transparent text-content-primary",
|
|
107
|
+
isOutlined && selected && "border-transparent",
|
|
92
108
|
// Dotted (non-selected): the dashed border is drawn via SVG (`dottedBorder`).
|
|
93
109
|
// `group` lets that SVG react to hover/active. `asChild` keeps a CSS dashed
|
|
94
110
|
// border fallback since the SVG is only rendered in the default path.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
isDotted && !selected && "bg-transparent text-content-primary",
|
|
112
|
+
isDotted && !selected && !asChild && "group",
|
|
113
|
+
// The SVG path draws no CSS border, so selecting one used to add 1px and
|
|
114
|
+
// widen the chip by 2px, shifting the row on every toggle. Reserving a
|
|
115
|
+
// transparent border also puts the dash on the same ring as the solid
|
|
116
|
+
// border it becomes. The `asChild` path already has a real border below.
|
|
117
|
+
isDotted && !selected && !asChild && "border border-transparent border-solid",
|
|
118
|
+
isDotted && !selected && asChild && (disabled ? "border border-buttons-chip-disabled border-dashed" : "border border-buttons-chip-dotted-default border-dashed"),
|
|
98
119
|
// Interactive
|
|
99
120
|
isInteractive && !disabled && "cursor-pointer",
|
|
100
|
-
isInteractive && !disabled &&
|
|
101
|
-
|
|
121
|
+
isInteractive && !disabled && isSolid && !selected && "hover:bg-buttons-chip-hover",
|
|
122
|
+
// Outlined darkens its stroke rather than filling. `buttons-chip-hover` is
|
|
123
|
+
// the one-step darkening for chips, but as a fill it is 20% over a 10%
|
|
124
|
+
// stroke, so it swallows the outline the variant exists to show. Moved onto
|
|
125
|
+
// the border, over `interaction-hover`, the atomic hover surface.
|
|
126
|
+
isInteractive && !disabled && isOutlined && !selected && "hover:border-buttons-chip-hover hover:bg-interaction-hover",
|
|
127
|
+
isInteractive && !disabled && isDotted && !selected && "hover:bg-neutral-alphas-50 active:bg-neutral-alphas-50",
|
|
102
128
|
// Focus
|
|
103
129
|
"focus-visible:shadow-focus-ring focus-visible:outline-none",
|
|
104
130
|
// Disabled
|
|
@@ -106,7 +132,10 @@ const Chip = React__namespace.forwardRef(
|
|
|
106
132
|
disabled && !isDark && "pointer-events-none text-content-disabled",
|
|
107
133
|
// Solid (non-dotted) disabled chips get a muted fill; dotted ones stay
|
|
108
134
|
// transparent with their dashed border (drawn via SVG).
|
|
109
|
-
disabled &&
|
|
135
|
+
disabled && (isSolid || isOutlined && selected) && "bg-buttons-chip-disabled",
|
|
136
|
+
// Unselected outlined greys only its stroke. Selected is already filled, so
|
|
137
|
+
// it takes the muted fill above and keeps `border-transparent` for its width.
|
|
138
|
+
disabled && isOutlined && !selected && "border-buttons-chip-disabled",
|
|
110
139
|
className
|
|
111
140
|
),
|
|
112
141
|
...isInteractive && {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chip.cjs","sources":["../../../../src/components/Chip/Chip.tsx"],"sourcesContent":["import { Slot, Slottable } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Count, type CountVariant } from \"../Count/Count\";\n\n/** Visual variant of the chip. */\nexport type ChipVariant = \"rounded\" | \"square\" | \"dark\";\n/** Height of the chip in pixels. */\nexport type ChipSize = \"32\" | \"40\";\n\nexport interface ChipProps extends React.HTMLAttributes<HTMLElement> {\n /** Visual variant of the chip. @default \"rounded\" */\n variant?: ChipVariant;\n /** Height of the chip in pixels. @default \"32\" */\n size?: ChipSize;\n /** Whether the chip is in a selected (pressed) state. @default false */\n selected?: boolean;\n /** Whether the chip is disabled. @default false */\n disabled?: boolean;\n /** Whether to show a coloured status dot at the leading edge. @default false */\n leftDot?: boolean;\n /**\n * Whether the chip uses a dashed border for add/create affordances.\n * When `selected`, it becomes a subtle filled state with a solid border.\n * Has no effect when `variant=\"dark\"`.\n * @default false\n */\n dotted?: boolean;\n /** Icon element displayed before the label. */\n leftIcon?: React.ReactNode;\n /** Icon element displayed after the label. */\n rightIcon?: React.ReactNode;\n /** Notification badge content (e.g. `\"99+\"`). Passed as a string for i18n support. */\n notificationLabel?: string;\n /** Numeric value for the notification badge. Uses the `Count` component for overflow formatting. Takes precedence over `notificationLabel` when both are provided. */\n notificationCount?: number;\n /** Maximum value before the badge shows overflow (e.g. `\"9+\"`). Only applies when `notificationCount` is set. @default 99 */\n notificationMax?: number;\n /** Colour variant of the notification badge. @default \"brand\" */\n notificationVariant?: CountVariant;\n /** Click handler — when provided, the chip renders as a `<button>` for accessibility. */\n onClick?: React.MouseEventHandler<HTMLElement>;\n /** Merge props onto a child element instead of rendering a wrapper. @default false */\n asChild?: boolean;\n}\n\n/**\n * A compact element for filters, tags, or toggleable actions. When an `onClick`\n * handler is provided, the chip renders as an interactive `<button>` with\n * `aria-pressed` support.\n *\n * @example\n * ```tsx\n * <Chip selected onClick={toggle}>Music</Chip>\n * ```\n */\nexport const Chip = React.forwardRef<HTMLButtonElement, ChipProps>(\n (\n {\n className,\n variant = \"rounded\",\n size = \"32\",\n selected = false,\n disabled = false,\n leftDot = false,\n dotted = false,\n leftIcon,\n rightIcon,\n notificationLabel,\n notificationCount,\n notificationMax,\n notificationVariant = \"brand\",\n onClick,\n asChild = false,\n children,\n ...props\n },\n ref,\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Variant-heavy UI component\n ) => {\n const isInteractive = !!onClick && !asChild;\n const Comp = asChild ? Slot : isInteractive ? \"button\" : \"span\";\n const isDark = variant === \"dark\";\n\n // The dashed border is drawn as an SVG so the dash length matches the design\n // spec (8/8 for the 40px square, 6/6 otherwise). CSS `border-dashed` only\n // renders browser-default dash lengths, which are too short. The stroke colour\n // is driven by `currentColor`, and `group-hover`/`group-active` react to the\n // chip's interactive states. Rendered only in the default (non-`asChild`) path.\n const showDottedBorder = !isDark && dotted && !selected && !asChild;\n const dottedBorder = showDottedBorder ? (\n <svg\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute inset-0 size-full overflow-visible\",\n disabled ? \"text-buttons-chip-disabled\" : \"text-buttons-chip-dotted-default\",\n isInteractive &&\n !disabled &&\n \"group-hover:text-buttons-chip-dotted-hover-stroke group-active:text-buttons-chip-dotted-hover-stroke\",\n )}\n >\n <rect\n x=\"0.5\"\n y=\"0.5\"\n rx={variant === \"square\" ? 7.5 : size === \"40\" ? 19.5 : 15.5}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1\"\n strokeDasharray={variant === \"square\" && size === \"40\" ? \"8 8\" : \"6 6\"}\n style={{ width: \"calc(100% - 1px)\", height: \"calc(100% - 1px)\" }}\n />\n </svg>\n ) : null;\n\n return (\n <Comp\n ref={ref}\n data-testid=\"chip\"\n className={cn(\n \"relative inline-flex min-w-0 items-center justify-center whitespace-nowrap motion-safe:transition-colors motion-safe:duration-150\",\n // Shape\n variant === \"square\" ? \"rounded-xs\" : \"rounded-full\",\n // Size (32px uses 12px text, 40px uses 14px text per the design spec)\n size === \"32\" && \"typography-description-12px-semibold h-8 py-1\",\n size === \"40\" && \"typography-body-small-14px-semibold h-10 py-2.5\",\n // Variant colors\n isDark && \"bg-neutral-alphas-600 text-content-always-white\",\n !isDark && selected && !dotted && \"bg-buttons-chip-active text-content-primary-inverted\",\n // Active + dotted is a subtle filled state with a solid (non-dashed) border.\n !isDark &&\n selected &&\n dotted &&\n \"border border-border-primary border-solid bg-inputs-inputs-primary text-content-primary\",\n !isDark && !selected && !dotted && \"bg-buttons-chip-default text-content-primary\",\n // Dotted (non-selected): the dashed border is drawn via SVG (`dottedBorder`).\n // `group` lets that SVG react to hover/active. `asChild` keeps a CSS dashed\n // border fallback since the SVG is only rendered in the default path.\n !isDark && !selected && dotted && \"bg-transparent text-content-primary\",\n !isDark && !selected && dotted && !asChild && \"group\",\n asChild &&\n !isDark &&\n !selected &&\n dotted &&\n (disabled\n ? \"border border-buttons-chip-disabled border-dashed\"\n : \"border border-buttons-chip-dotted-default border-dashed\"),\n // Interactive\n isInteractive && !disabled && \"cursor-pointer\",\n isInteractive &&\n !disabled &&\n !isDark &&\n !selected &&\n !dotted &&\n \"hover:bg-buttons-chip-hover\",\n isInteractive &&\n !disabled &&\n !isDark &&\n !selected &&\n dotted &&\n \"hover:bg-neutral-alphas-50 active:bg-neutral-alphas-50\",\n // Focus\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n // Disabled\n disabled && isDark && \"pointer-events-none opacity-50\",\n disabled && !isDark && \"pointer-events-none text-content-disabled\",\n // Solid (non-dotted) disabled chips get a muted fill; dotted ones stay\n // transparent with their dashed border (drawn via SVG).\n disabled && !isDark && !dotted && \"bg-buttons-chip-disabled\",\n className,\n )}\n {...(isInteractive && {\n type: \"button\" as const,\n disabled,\n \"aria-pressed\": selected,\n onClick,\n })}\n {...(!isInteractive && disabled && { \"aria-disabled\": true })}\n {...(selected && { \"data-selected\": \"\" })}\n {...props}\n >\n {asChild ? (\n <Slottable>{children}</Slottable>\n ) : (\n <>\n {dottedBorder}\n <span className=\"flex min-w-0 items-center gap-0.5 overflow-hidden px-3\">\n {leftDot && (\n <span className=\"size-2 shrink-0 rounded-full bg-current\" aria-hidden=\"true\" />\n )}\n {leftIcon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {leftIcon}\n </span>\n )}\n <span className=\"min-w-0 truncate\">{children}</span>\n {rightIcon && (\n <span\n className=\"flex size-5 shrink-0 items-center justify-center\"\n aria-hidden=\"true\"\n >\n {rightIcon}\n </span>\n )}\n </span>\n {(notificationCount != null || notificationLabel) && (\n <Count\n variant={notificationVariant}\n size=\"32\"\n className={cn(\n // V2 Notification Count: 20px high/min-width, caption 12,\n // 4px horizontal and 2px vertical padding, rounded-md.\n \"absolute top-[-4px] rounded-md px-1 py-0.5\",\n // Anchor the leading edge so wider values grow away from the label.\n size === \"40\" ? \"left-[calc(100%_-_16px)]\" : \"left-[calc(100%_-_11px)]\",\n )}\n value={notificationCount ?? 0}\n max={notificationMax}\n >\n {notificationCount == null ? notificationLabel : undefined}\n </Count>\n )}\n </>\n )}\n </Comp>\n );\n },\n);\n\nChip.displayName = \"Chip\";\n"],"names":["React","Slot","jsx","cn","Slottable","jsxs","Fragment","Count"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwDO,MAAM,OAAOA,iBAAM;AAAA,EACxB,CACE;AAAA,IACE;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,IACP,WAAW;AAAA,IACX,WAAW;AAAA,IACX,UAAU;AAAA,IACV,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,sBAAsB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QAEG;AACH,UAAM,gBAAgB,CAAC,CAAC,WAAW,CAAC;AACpC,UAAM,OAAO,UAAUC,UAAAA,OAAO,gBAAgB,WAAW;AACzD,UAAM,SAAS,YAAY;AAO3B,UAAM,mBAAmB,CAAC,UAAU,UAAU,CAAC,YAAY,CAAC;AAC5D,UAAM,eAAe,mBACnBC,2BAAAA;AAAAA,MAAC;AAAA,MAAA;AAAA,QACC,eAAY;AAAA,QACZ,WAAWC,GAAAA;AAAAA,UACT;AAAA,UACA,WAAW,+BAA+B;AAAA,UAC1C,iBACE,CAAC,YACD;AAAA,QAAA;AAAA,QAGJ,UAAAD,2BAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,GAAE;AAAA,YACF,GAAE;AAAA,YACF,IAAI,YAAY,WAAW,MAAM,SAAS,OAAO,OAAO;AAAA,YACxD,MAAK;AAAA,YACL,QAAO;AAAA,YACP,aAAY;AAAA,YACZ,iBAAiB,YAAY,YAAY,SAAS,OAAO,QAAQ;AAAA,YACjE,OAAO,EAAE,OAAO,oBAAoB,QAAQ,mBAAA;AAAA,UAAmB;AAAA,QAAA;AAAA,MACjE;A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AAU,0DACb,UAAA;AAAA,YAAA,WACCH,2BAAAA,IAAC,QAAA,EAAK,WAAU,2CAA0C,eAAY,QAAO;AAAA,YAE9E,YACCA,2BAAAA,IAAC,QAAA,EAAK,WAAU,6CAA4C,eAAY,QACrE,UAAA,UACH;AAAA,YAEFA,2BAAAA,IAAC,QAAA,EAAK,WAAU,oBAAoB,SAAA,CAAS;AAAA,YAC5C,aACCA,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAU;AAAA,gBACV,eAAY;AAAA,gBAEX,UAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACH,GAEJ;AAAA,WACE,qBAAqB,QAAQ,sBAC7BA,2BAAAA;AAAAA,YAACK,MAAAA;AAAAA,YAAA;AAAA,cACC,SAAS;AAAA,cACT,MAAK;AAAA,cACL,WAAWJ,GAAAA;AAAAA;AAAAA;AAAAA,gBAGT;AAAA;AAAA,gBAEA,SAAS,OAAO,6BAA6B;AAAA,cAAA;AAAA,cAE/C,OAAO,qBAAqB;AAAA,cAC5B,KAAK;AAAA,cAEJ,UAAA,qBAAqB,OAAO,oBAAoB;AAAA,YAAA;AAAA,UAAA;AAAA,QACnD,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,KAAK,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"Chip.cjs","sources":["../../../../src/components/Chip/Chip.tsx"],"sourcesContent":["import { Slot, Slottable } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Count, type CountVariant } from \"../Count/Count\";\n\n/** Visual variant of the chip. */\nexport type ChipVariant = \"rounded\" | \"square\" | \"dark\";\n/** Height of the chip in pixels. */\nexport type ChipSize = \"32\" | \"40\";\n\nexport interface ChipProps extends React.HTMLAttributes<HTMLElement> {\n /** Visual variant of the chip. @default \"rounded\" */\n variant?: ChipVariant;\n /** Height of the chip in pixels. @default \"32\" */\n size?: ChipSize;\n /** Whether the chip is in a selected (pressed) state. @default false */\n selected?: boolean;\n /** Whether the chip is disabled. @default false */\n disabled?: boolean;\n /** Whether to show a coloured status dot at the leading edge. @default false */\n leftDot?: boolean;\n /**\n * Whether the chip uses a dashed border for add/create affordances.\n * When `selected`, it becomes a subtle filled state with a solid border.\n * Has no effect when `variant=\"dark\"`.\n * @default false\n */\n dotted?: boolean;\n /**\n * Draws the unselected state as a 1px `buttons-chip-default` outline over a\n * transparent background instead of filling with that same token. This is the\n * Figma `V2 Insights Chips` treatment, used where chips sit over a chart and a\n * row of solid fills would compete with the plotted series. The selected state\n * is unaffected — it stays filled — as are the `dark` and `dotted` variants.\n * @default false\n */\n outlined?: boolean;\n /** Icon element displayed before the label. */\n leftIcon?: React.ReactNode;\n /** Icon element displayed after the label. */\n rightIcon?: React.ReactNode;\n /** Notification badge content (e.g. `\"99+\"`). Passed as a string for i18n support. */\n notificationLabel?: string;\n /** Numeric value for the notification badge. Uses the `Count` component for overflow formatting. Takes precedence over `notificationLabel` when both are provided. */\n notificationCount?: number;\n /** Maximum value before the badge shows overflow (e.g. `\"9+\"`). Only applies when `notificationCount` is set. @default 99 */\n notificationMax?: number;\n /** Colour variant of the notification badge. @default \"brand\" */\n notificationVariant?: CountVariant;\n /** Click handler — when provided, the chip renders as a `<button>` for accessibility. */\n onClick?: React.MouseEventHandler<HTMLElement>;\n /** Merge props onto a child element instead of rendering a wrapper. @default false */\n asChild?: boolean;\n}\n\n/**\n * A compact element for filters, tags, or toggleable actions. When an `onClick`\n * handler is provided, the chip renders as an interactive `<button>` with\n * `aria-pressed` support.\n *\n * @example\n * ```tsx\n * <Chip selected onClick={toggle}>Music</Chip>\n * ```\n */\nexport const Chip = React.forwardRef<HTMLButtonElement, ChipProps>(\n (\n {\n className,\n variant = \"rounded\",\n size = \"32\",\n selected = false,\n disabled = false,\n leftDot = false,\n dotted = false,\n outlined = false,\n leftIcon,\n rightIcon,\n notificationLabel,\n notificationCount,\n notificationMax,\n notificationVariant = \"brand\",\n onClick,\n asChild = false,\n children,\n ...props\n },\n ref,\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Variant-heavy UI component\n ) => {\n const isInteractive = !!onClick && !asChild;\n const Comp = asChild ? Slot : isInteractive ? \"button\" : \"span\";\n const isDark = variant === \"dark\";\n // Precedence between the three treatments, named once rather than re-derived per\n // rule: `dark` owns its own palette, `dotted` wins over `outlined`, and what is\n // left is the normal chip, either filled or outlined.\n const isDotted = !isDark && dotted;\n const isSolid = !isDark && !dotted && !outlined;\n const isOutlined = !isDark && !dotted && outlined;\n\n // The dashed border is drawn as an SVG so the dash length matches the design\n // spec (8/8 for the 40px square, 6/6 otherwise). CSS `border-dashed` only\n // renders browser-default dash lengths, which are too short. The stroke colour\n // is driven by `currentColor`, and `group-hover`/`group-active` react to the\n // chip's interactive states. Rendered only in the default (non-`asChild`) path.\n const showDottedBorder = isDotted && !selected && !asChild;\n const dottedBorder = showDottedBorder ? (\n <svg\n aria-hidden=\"true\"\n className={cn(\n // `-1px` spans the reserved transparent border rather than the padding box\n // inside it, so the dash lands on the same ring as the solid border it\n // becomes when selected.\n \"pointer-events-none absolute -top-px -left-px h-[calc(100%+2px)] w-[calc(100%+2px)] overflow-visible\",\n disabled ? \"text-buttons-chip-disabled\" : \"text-buttons-chip-dotted-default\",\n isInteractive &&\n !disabled &&\n \"group-hover:text-buttons-chip-dotted-hover-stroke group-active:text-buttons-chip-dotted-hover-stroke\",\n )}\n >\n <rect\n x=\"0.5\"\n y=\"0.5\"\n rx={variant === \"square\" ? 7.5 : size === \"40\" ? 19.5 : 15.5}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1\"\n strokeDasharray={variant === \"square\" && size === \"40\" ? \"8 8\" : \"6 6\"}\n style={{ width: \"calc(100% - 1px)\", height: \"calc(100% - 1px)\" }}\n />\n </svg>\n ) : null;\n\n return (\n <Comp\n ref={ref}\n data-testid=\"chip\"\n className={cn(\n \"relative inline-flex min-w-0 items-center justify-center whitespace-nowrap motion-safe:transition-colors motion-safe:duration-150\",\n // Shape\n variant === \"square\" ? \"rounded-xs\" : \"rounded-full\",\n // Size (32px uses 12px text, 40px uses 14px text per the design spec)\n size === \"32\" && \"typography-description-12px-semibold h-8 py-1\",\n size === \"40\" && \"typography-body-small-14px-semibold h-10 py-2.5\",\n // Variant colors\n isDark && \"bg-neutral-alphas-600 text-content-always-white\",\n (isSolid || isOutlined) &&\n selected &&\n \"bg-buttons-chip-active text-content-primary-inverted\",\n // Active + dotted is a subtle filled state with a solid (non-dashed) border.\n isDotted &&\n selected &&\n \"border border-border-primary border-solid bg-inputs-inputs-primary text-content-primary\",\n isSolid && !selected && \"bg-buttons-chip-default text-content-primary\",\n // Outlined: the same token as a 1px stroke rather than a fill. The border\n // is declared in BOTH states and only changes colour, going transparent\n // once selected. It cannot be dropped on selection: `border-box` constrains\n // only explicitly sized axes, and a chip's width is intrinsic, so losing the\n // border would narrow the chip by 2px and reflow the whole row on every\n // click. Height is safe either way because `h-8` is explicit.\n isOutlined && \"border border-solid\",\n isOutlined &&\n !selected &&\n \"border-buttons-chip-default bg-transparent text-content-primary\",\n isOutlined && selected && \"border-transparent\",\n // Dotted (non-selected): the dashed border is drawn via SVG (`dottedBorder`).\n // `group` lets that SVG react to hover/active. `asChild` keeps a CSS dashed\n // border fallback since the SVG is only rendered in the default path.\n isDotted && !selected && \"bg-transparent text-content-primary\",\n isDotted && !selected && !asChild && \"group\",\n // The SVG path draws no CSS border, so selecting one used to add 1px and\n // widen the chip by 2px, shifting the row on every toggle. Reserving a\n // transparent border also puts the dash on the same ring as the solid\n // border it becomes. The `asChild` path already has a real border below.\n isDotted && !selected && !asChild && \"border border-transparent border-solid\",\n isDotted &&\n !selected &&\n asChild &&\n (disabled\n ? \"border border-buttons-chip-disabled border-dashed\"\n : \"border border-buttons-chip-dotted-default border-dashed\"),\n // Interactive\n isInteractive && !disabled && \"cursor-pointer\",\n isInteractive && !disabled && isSolid && !selected && \"hover:bg-buttons-chip-hover\",\n // Outlined darkens its stroke rather than filling. `buttons-chip-hover` is\n // the one-step darkening for chips, but as a fill it is 20% over a 10%\n // stroke, so it swallows the outline the variant exists to show. Moved onto\n // the border, over `interaction-hover`, the atomic hover surface.\n isInteractive &&\n !disabled &&\n isOutlined &&\n !selected &&\n \"hover:border-buttons-chip-hover hover:bg-interaction-hover\",\n isInteractive &&\n !disabled &&\n isDotted &&\n !selected &&\n \"hover:bg-neutral-alphas-50 active:bg-neutral-alphas-50\",\n // Focus\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n // Disabled\n disabled && isDark && \"pointer-events-none opacity-50\",\n disabled && !isDark && \"pointer-events-none text-content-disabled\",\n // Solid (non-dotted) disabled chips get a muted fill; dotted ones stay\n // transparent with their dashed border (drawn via SVG).\n disabled && (isSolid || (isOutlined && selected)) && \"bg-buttons-chip-disabled\",\n // Unselected outlined greys only its stroke. Selected is already filled, so\n // it takes the muted fill above and keeps `border-transparent` for its width.\n disabled && isOutlined && !selected && \"border-buttons-chip-disabled\",\n className,\n )}\n {...(isInteractive && {\n type: \"button\" as const,\n disabled,\n \"aria-pressed\": selected,\n onClick,\n })}\n {...(!isInteractive && disabled && { \"aria-disabled\": true })}\n {...(selected && { \"data-selected\": \"\" })}\n {...props}\n >\n {asChild ? (\n <Slottable>{children}</Slottable>\n ) : (\n <>\n {dottedBorder}\n <span className=\"flex min-w-0 items-center gap-0.5 overflow-hidden px-3\">\n {leftDot && (\n <span className=\"size-2 shrink-0 rounded-full bg-current\" aria-hidden=\"true\" />\n )}\n {leftIcon && (\n <span className=\"flex shrink-0 items-center justify-center\" aria-hidden=\"true\">\n {leftIcon}\n </span>\n )}\n <span className=\"min-w-0 truncate\">{children}</span>\n {rightIcon && (\n <span\n className=\"flex size-5 shrink-0 items-center justify-center\"\n aria-hidden=\"true\"\n >\n {rightIcon}\n </span>\n )}\n </span>\n {(notificationCount != null || notificationLabel) && (\n <Count\n variant={notificationVariant}\n size=\"32\"\n className={cn(\n // V2 Notification Count: 20px high/min-width, caption 12,\n // 4px horizontal and 2px vertical padding, rounded-md.\n \"absolute top-[-4px] rounded-md px-1 py-0.5\",\n // Anchor the leading edge so wider values grow away from the label.\n size === \"40\" ? \"left-[calc(100%_-_16px)]\" : \"left-[calc(100%_-_11px)]\",\n )}\n value={notificationCount ?? 0}\n max={notificationMax}\n >\n {notificationCount == null ? notificationLabel : undefined}\n </Count>\n )}\n </>\n )}\n </Comp>\n );\n },\n);\n\nChip.displayName = \"Chip\";\n"],"names":["React","Slot","jsx","cn","Slottable","jsxs","Fragment","Count"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiEO,MAAM,OAAOA,iBAAM;AAAA,EACxB,CACE;AAAA,IACE;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,IACP,WAAW;AAAA,IACX,WAAW;AAAA,IACX,UAAU;AAAA,IACV,SAAS;AAAA,IACT,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,sBAAsB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QAEG;AACH,UAAM,gBAAgB,CAAC,CAAC,WAAW,CAAC;AACpC,UAAM,OAAO,UAAUC,UAAAA,OAAO,gBAAgB,WAAW;AACzD,UAAM,SAAS,YAAY;AAI3B,UAAM,WAAW,CAAC,UAAU;AAC5B,UAAM,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC;AACvC,UAAM,aAAa,CAAC,UAAU,CAAC,UAAU;AAOzC,UAAM,mBAAmB,YAAY,CAAC,YAAY,CAAC;AACnD,UAAM,eAAe,mBACnBC,2BAAAA;AAAAA,MAAC;AAAA,MAAA;AAAA,QACC,eAAY;AAAA,QACZ,WAAWC,GAAAA;AAAAA;AAAAA;AAAAA;AAAAA,UAIT;AAAA,UACA,WAAW,+BAA+B;AAAA,UAC1C,iBACE,CAAC,YACD;AAAA,QAAA;AAAA,QAGJ,UAAAD,2BAAAA;A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J;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,KAAK,cAAc;;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const flagShapes = require("./flagShapes.cjs");
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
25
|
+
const SIZE_CLASS = {
|
|
26
|
+
16: "size-4",
|
|
27
|
+
20: "size-5",
|
|
28
|
+
24: "size-6",
|
|
29
|
+
32: "size-8"
|
|
30
|
+
};
|
|
31
|
+
const UNKNOWN_CODE = "xx";
|
|
32
|
+
const renderShape = (shape, index) => {
|
|
33
|
+
switch (shape.tag) {
|
|
34
|
+
case "path":
|
|
35
|
+
return /* @__PURE__ */ jsxRuntime.jsx("path", { fill: shape.fill, d: shape.d }, index);
|
|
36
|
+
case "circle":
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsx("circle", { fill: shape.fill, cx: shape.cx, cy: shape.cy, r: shape.r }, index);
|
|
38
|
+
case "rect":
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
40
|
+
"rect",
|
|
41
|
+
{
|
|
42
|
+
fill: shape.fill,
|
|
43
|
+
x: shape.x,
|
|
44
|
+
y: shape.y,
|
|
45
|
+
width: shape.width,
|
|
46
|
+
height: shape.height,
|
|
47
|
+
rx: shape.rx,
|
|
48
|
+
ry: shape.ry
|
|
49
|
+
},
|
|
50
|
+
index
|
|
51
|
+
);
|
|
52
|
+
case "ellipse":
|
|
53
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
54
|
+
"ellipse",
|
|
55
|
+
{
|
|
56
|
+
fill: shape.fill,
|
|
57
|
+
cx: shape.cx,
|
|
58
|
+
cy: shape.cy,
|
|
59
|
+
rx: shape.rx,
|
|
60
|
+
ry: shape.ry
|
|
61
|
+
},
|
|
62
|
+
index
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const CountryFlag = React__namespace.forwardRef(
|
|
67
|
+
({ country, size = 20, label, className, ...props }, ref) => {
|
|
68
|
+
const generatedId = React__namespace.useId();
|
|
69
|
+
const maskId = `country-flag-${generatedId.replace(/:/g, "")}`;
|
|
70
|
+
const shapes = flagShapes.FLAG_SHAPES[country.toLowerCase()] ?? flagShapes.FLAG_SHAPES[UNKNOWN_CODE];
|
|
71
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
72
|
+
"svg",
|
|
73
|
+
{
|
|
74
|
+
ref,
|
|
75
|
+
viewBox: "0 0 512 512",
|
|
76
|
+
className: cn.cn("shrink-0", SIZE_CLASS[size], className),
|
|
77
|
+
role: label ? "img" : void 0,
|
|
78
|
+
"aria-hidden": label ? void 0 : true,
|
|
79
|
+
...props,
|
|
80
|
+
children: [
|
|
81
|
+
label && /* @__PURE__ */ jsxRuntime.jsx("title", { children: label }),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: maskId, children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "256", cy: "256", r: "256", fill: "#fff" }) }),
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { mask: `url(#${maskId})`, children: shapes.map(renderShape) })
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
CountryFlag.displayName = "CountryFlag";
|
|
90
|
+
exports.CountryFlag = CountryFlag;
|
|
91
|
+
//# sourceMappingURL=CountryFlag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountryFlag.cjs","sources":["../../../../src/components/CountryFlag/CountryFlag.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { type CountryFlagCode, FLAG_SHAPES, type FlagShape } from \"./flagShapes\";\n\nconst SIZE_CLASS = {\n 16: \"size-4\",\n 20: \"size-5\",\n 24: \"size-6\",\n 32: \"size-8\",\n} as const;\n\n/** Rendered edge length in px. */\nexport type CountryFlagSize = keyof typeof SIZE_CLASS;\n\n/** The source's placeholder disc, used for any code we hold no artwork for. */\nconst UNKNOWN_CODE = \"xx\" as const;\n\n/** Props for {@link CountryFlag}. */\nexport interface CountryFlagProps extends Omit<React.SVGProps<SVGSVGElement>, \"children\"> {\n /**\n * Two-letter country code, case-insensitive (e.g. `\"US\"`, `\"nl\"`). Codes we\n * hold no artwork for render a grey placeholder disc, so a live feed of\n * country codes can be passed straight through.\n */\n country: string;\n /** Rendered edge length in px. Defaults to 20, the size the designs use. */\n size?: CountryFlagSize;\n /**\n * Accessible name, e.g. the country's translated name. Leave unset when the\n * flag sits next to that name anyway — it is then hidden from assistive tech\n * rather than read out twice.\n */\n label?: string;\n}\n\nconst renderShape = (shape: FlagShape, index: number) => {\n switch (shape.tag) {\n case \"path\":\n return <path key={index} fill={shape.fill} d={shape.d} />;\n case \"circle\":\n return <circle key={index} fill={shape.fill} cx={shape.cx} cy={shape.cy} r={shape.r} />;\n case \"rect\":\n return (\n <rect\n key={index}\n fill={shape.fill}\n x={shape.x}\n y={shape.y}\n width={shape.width}\n height={shape.height}\n rx={shape.rx}\n ry={shape.ry}\n />\n );\n case \"ellipse\":\n return (\n <ellipse\n key={index}\n fill={shape.fill}\n cx={shape.cx}\n cy={shape.cy}\n rx={shape.rx}\n ry={shape.ry}\n />\n );\n }\n};\n\n/**\n * A country's flag, drawn as a circle. Use it wherever a row is keyed by\n * country — a demographics breakdown, a country picker, the country selector on\n * `PhoneField`.\n *\n * Prefer this to a flag emoji: emoji flags fall back to bare letter pairs on\n * Windows, where the fonts carry no flag glyphs.\n *\n * @example\n * ```tsx\n * <CountryFlag country=\"US\" label=\"United States\" />\n * ```\n */\nexport const CountryFlag = React.forwardRef<SVGSVGElement, CountryFlagProps>(\n ({ country, size = 20, label, className, ...props }, ref) => {\n const generatedId = React.useId();\n // Several flags share a page, so the clipping mask needs an id of its own.\n // Strip the colons React 18's `useId` produces — a url(#...) reference\n // can't carry them.\n const maskId = `country-flag-${generatedId.replace(/:/g, \"\")}`;\n\n // Unmapped codes fall back to the source's own `xx` placeholder — a plain\n // grey disc — rather than rendering nothing. A live feed can hand us a code\n // we hold no artwork for, and a blank where every other row has a glyph\n // reads as a broken image rather than an unknown country. Using `xx` keeps\n // the placeholder on the same viewBox and circular mask as a real flag,\n // which a hand-drawn disc would not.\n const shapes =\n FLAG_SHAPES[country.toLowerCase() as CountryFlagCode] ?? FLAG_SHAPES[UNKNOWN_CODE];\n\n return (\n <svg\n ref={ref}\n viewBox=\"0 0 512 512\"\n className={cn(\"shrink-0\", SIZE_CLASS[size], className)}\n role={label ? \"img\" : undefined}\n aria-hidden={label ? undefined : true}\n {...props}\n >\n {label && <title>{label}</title>}\n <mask id={maskId}>\n <circle cx=\"256\" cy=\"256\" r=\"256\" fill=\"#fff\" />\n </mask>\n <g mask={`url(#${maskId})`}>{shapes.map(renderShape)}</g>\n </svg>\n );\n },\n);\n\nCountryFlag.displayName = \"CountryFlag\";\n"],"names":["jsx","React","FLAG_SHAPES","jsxs","cn"],"mappings":";;;;;;;;;;;;;;;;;;;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