@fanvue/ui 3.48.0 → 3.50.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/README.md +1 -1
- package/dist/animated-icons.d.ts +4 -1
- package/dist/charts.d.ts +37 -0
- package/dist/charts.mjs +2 -0
- package/dist/charts.mjs.map +1 -1
- package/dist/cjs/charts.cjs +2 -0
- package/dist/cjs/charts.cjs.map +1 -1
- package/dist/cjs/components/Alert/Alert.cjs +45 -36
- package/dist/cjs/components/Alert/Alert.cjs.map +1 -1
- package/dist/cjs/components/AnimatedNumber/AnimatedNumber.cjs +7 -3
- package/dist/cjs/components/AnimatedNumber/AnimatedNumber.cjs.map +1 -1
- package/dist/cjs/components/Autocomplete/Autocomplete.cjs +1 -1
- package/dist/cjs/components/Autocomplete/Autocomplete.cjs.map +1 -1
- package/dist/cjs/components/Autocomplete/AutocompleteDropdownContent.cjs +1 -1
- package/dist/cjs/components/Autocomplete/AutocompleteDropdownContent.cjs.map +1 -1
- package/dist/cjs/components/Button/Button.cjs +1 -1
- package/dist/cjs/components/Button/Button.cjs.map +1 -1
- package/dist/cjs/components/Chart/ChartGrid.cjs +40 -0
- package/dist/cjs/components/Chart/ChartGrid.cjs.map +1 -0
- package/dist/cjs/components/ChatInput/ChatInput.cjs +21 -11
- package/dist/cjs/components/ChatInput/ChatInput.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Dialog.cjs +29 -23
- package/dist/cjs/components/Dialog/Dialog.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs +31 -34
- package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuReorderItem.cjs +5 -4
- package/dist/cjs/components/DropdownMenu/DropdownMenuReorderItem.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs +10 -10
- package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs +12 -7
- package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs.map +1 -1
- package/dist/cjs/components/EmptyState/EmptyState.cjs +9 -1
- package/dist/cjs/components/EmptyState/EmptyState.cjs.map +1 -1
- package/dist/cjs/components/IconButton/IconButton.cjs +8 -2
- package/dist/cjs/components/IconButton/IconButton.cjs.map +1 -1
- package/dist/cjs/components/Icons/BaseIcon.cjs +7 -2
- package/dist/cjs/components/Icons/BaseIcon.cjs.map +1 -1
- package/dist/cjs/components/Icons/IconDefaults.cjs +26 -0
- package/dist/cjs/components/Icons/IconDefaults.cjs.map +1 -0
- package/dist/cjs/components/Icons/MenuRowIcon.cjs +26 -0
- package/dist/cjs/components/Icons/MenuRowIcon.cjs.map +1 -0
- package/dist/cjs/components/Icons/SpinnerIcon.cjs +4 -2
- package/dist/cjs/components/Icons/SpinnerIcon.cjs.map +1 -1
- package/dist/cjs/components/Icons/iconSpinClass.cjs +6 -0
- package/dist/cjs/components/Icons/iconSpinClass.cjs.map +1 -0
- package/dist/cjs/components/Link/Link.cjs +7 -3
- package/dist/cjs/components/Link/Link.cjs.map +1 -1
- package/dist/cjs/components/Loader/Loader.cjs +1 -1
- package/dist/cjs/components/Loader/Loader.cjs.map +1 -1
- package/dist/cjs/components/MediaPlayChip/MediaPlayChip.cjs +56 -0
- package/dist/cjs/components/MediaPlayChip/MediaPlayChip.cjs.map +1 -0
- package/dist/cjs/components/Select/Select.cjs +13 -10
- package/dist/cjs/components/Select/Select.cjs.map +1 -1
- package/dist/cjs/components/Skeleton/Skeleton.cjs +17 -1
- package/dist/cjs/components/Skeleton/Skeleton.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsList.cjs +3 -1
- package/dist/cjs/components/Tabs/TabsList.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsListSkeleton.cjs +30 -0
- package/dist/cjs/components/Tabs/TabsListSkeleton.cjs.map +1 -0
- package/dist/cjs/components/UserItem/UserItem.cjs +6 -1
- package/dist/cjs/components/UserItem/UserItem.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/components/Alert/Alert.mjs +45 -36
- package/dist/components/Alert/Alert.mjs.map +1 -1
- package/dist/components/AnimatedNumber/AnimatedNumber.mjs +7 -3
- package/dist/components/AnimatedNumber/AnimatedNumber.mjs.map +1 -1
- package/dist/components/Autocomplete/Autocomplete.mjs +1 -1
- package/dist/components/Autocomplete/Autocomplete.mjs.map +1 -1
- package/dist/components/Autocomplete/AutocompleteDropdownContent.mjs +1 -1
- package/dist/components/Autocomplete/AutocompleteDropdownContent.mjs.map +1 -1
- package/dist/components/Button/Button.mjs +1 -1
- package/dist/components/Button/Button.mjs.map +1 -1
- package/dist/components/Chart/ChartGrid.mjs +40 -0
- package/dist/components/Chart/ChartGrid.mjs.map +1 -0
- package/dist/components/ChatInput/ChatInput.mjs +21 -11
- package/dist/components/ChatInput/ChatInput.mjs.map +1 -1
- package/dist/components/Dialog/Dialog.mjs +29 -23
- package/dist/components/Dialog/Dialog.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuItem.mjs +32 -35
- package/dist/components/DropdownMenu/DropdownMenuItem.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuReorderItem.mjs +5 -4
- package/dist/components/DropdownMenu/DropdownMenuReorderItem.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuRoot.mjs +10 -10
- package/dist/components/DropdownMenu/DropdownMenuRoot.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs +12 -7
- package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs.map +1 -1
- package/dist/components/EmptyState/EmptyState.mjs +9 -1
- package/dist/components/EmptyState/EmptyState.mjs.map +1 -1
- package/dist/components/IconButton/IconButton.mjs +8 -2
- package/dist/components/IconButton/IconButton.mjs.map +1 -1
- package/dist/components/Icons/BaseIcon.mjs +7 -2
- package/dist/components/Icons/BaseIcon.mjs.map +1 -1
- package/dist/components/Icons/IconDefaults.mjs +9 -0
- package/dist/components/Icons/IconDefaults.mjs.map +1 -0
- package/dist/components/Icons/MenuRowIcon.mjs +26 -0
- package/dist/components/Icons/MenuRowIcon.mjs.map +1 -0
- package/dist/components/Icons/SpinnerIcon.mjs +4 -2
- package/dist/components/Icons/SpinnerIcon.mjs.map +1 -1
- package/dist/components/Icons/iconSpinClass.mjs +6 -0
- package/dist/components/Icons/iconSpinClass.mjs.map +1 -0
- package/dist/components/Link/Link.mjs +7 -3
- package/dist/components/Link/Link.mjs.map +1 -1
- package/dist/components/Loader/Loader.mjs +1 -1
- package/dist/components/Loader/Loader.mjs.map +1 -1
- package/dist/components/MediaPlayChip/MediaPlayChip.mjs +39 -0
- package/dist/components/MediaPlayChip/MediaPlayChip.mjs.map +1 -0
- package/dist/components/Select/Select.mjs +13 -10
- package/dist/components/Select/Select.mjs.map +1 -1
- package/dist/components/Skeleton/Skeleton.mjs +17 -1
- package/dist/components/Skeleton/Skeleton.mjs.map +1 -1
- package/dist/components/Tabs/TabsList.mjs +3 -1
- package/dist/components/Tabs/TabsList.mjs.map +1 -1
- package/dist/components/Tabs/TabsListSkeleton.mjs +13 -0
- package/dist/components/Tabs/TabsListSkeleton.mjs.map +1 -0
- package/dist/components/UserItem/UserItem.mjs +6 -1
- package/dist/components/UserItem/UserItem.mjs.map +1 -1
- package/dist/index.d.ts +171 -18
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,7 +105,7 @@ Not every icon has a twin — an icon is only mapped once its animated artwork h
|
|
|
105
105
|
been compared against ours — so a missing export means the pair was rejected or
|
|
106
106
|
upstream has no equivalent. `SpinnerIcon` is deliberately absent: a loading
|
|
107
107
|
indicator must not wait for a hover. Keep using the static one with
|
|
108
|
-
|
|
108
|
+
`<SpinnerIcon spin />`, which respects reduced motion, or `Loader`.
|
|
109
109
|
|
|
110
110
|
Nothing animates when the user has asked for reduced motion
|
|
111
111
|
(`prefers-reduced-motion: reduce`), including animations you start yourself
|
package/dist/animated-icons.d.ts
CHANGED
|
@@ -107,7 +107,8 @@ export declare interface AnimatedIconHandle {
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Props for animated twins of prop-based icons. Mirrors `BaseIconProps` minus
|
|
110
|
-
* `filled` — the animated artwork is stroke-only, so there is no filled
|
|
110
|
+
* `filled` and `spin` — the animated artwork is stroke-only, so there is no filled
|
|
111
|
+
* variant, and it already animates on its own.
|
|
111
112
|
*
|
|
112
113
|
* `size` selects the same box as the static icon of the same name, so swapping
|
|
113
114
|
* `@fanvue/ui` for `@fanvue/ui/animated-icons` never changes layout.
|
|
@@ -121,6 +122,8 @@ export declare interface AnimatedIconProps extends Omit<React_2.SVGAttributes<SV
|
|
|
121
122
|
* through a wrapper's spread fails to compile instead of reaching the DOM.
|
|
122
123
|
*/
|
|
123
124
|
filled?: never;
|
|
125
|
+
/** Not available on animated icons, which animate on their own. Typed as `never` so a spread prop bag cannot leak it onto the `<svg>`. */
|
|
126
|
+
spin?: never;
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
/**
|
package/dist/charts.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CartesianGrid } from 'recharts';
|
|
2
|
+
import { JSX } from 'react/jsx-runtime';
|
|
1
3
|
import { Legend } from 'recharts';
|
|
2
4
|
import { LegendPayload } from 'recharts/types/component/DefaultLegendContent';
|
|
3
5
|
import { NameType } from 'recharts/types/component/DefaultTooltipContent';
|
|
@@ -165,6 +167,41 @@ declare type ChartContextValue = {
|
|
|
165
167
|
config: ChartConfig;
|
|
166
168
|
};
|
|
167
169
|
|
|
170
|
+
/**
|
|
171
|
+
* The design-system grid for cartesian charts: faint solid horizontal lines
|
|
172
|
+
* (`neutral-alphas-200` at 40%) and a stronger `border-strong` baseline at value 0.
|
|
173
|
+
* Render it as a direct child of a Recharts `<LineChart>`, `<AreaChart>` or `<BarChart>`,
|
|
174
|
+
* and leave `<YAxis domain>` at its default.
|
|
175
|
+
*
|
|
176
|
+
* The baseline is a one-row grid placed by the y scale, not a visible `ReferenceLine`,
|
|
177
|
+
* because Recharts draws no `ReferenceLine` while `data` is empty (there is no x scale).
|
|
178
|
+
* The hidden `ReferenceLine` only keeps 0 inside the y domain when every value is negative.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```tsx
|
|
182
|
+
* <ChartContainer config={chartConfig}>
|
|
183
|
+
* <LineChart data={data}>
|
|
184
|
+
* <ChartGrid />
|
|
185
|
+
* <XAxis dataKey="day" />
|
|
186
|
+
* <YAxis />
|
|
187
|
+
* <Line dataKey="net" stroke="var(--color-net)" />
|
|
188
|
+
* </LineChart>
|
|
189
|
+
* </ChartContainer>
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function ChartGrid({ xAxisId, yAxisId, ...props }: ChartGridProps): JSX.Element;
|
|
193
|
+
|
|
194
|
+
export declare namespace ChartGrid {
|
|
195
|
+
var displayName: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Props for {@link ChartGrid}. Forwarded to Recharts' `CartesianGrid`; `xAxisId` and
|
|
200
|
+
* `yAxisId` also place the zero baseline. The line colour, opacity and dash are fixed by
|
|
201
|
+
* the design system, so `stroke`, `strokeOpacity` and `strokeDasharray` are not accepted.
|
|
202
|
+
*/
|
|
203
|
+
export declare type ChartGridProps = Omit<React_2.ComponentProps<typeof CartesianGrid>, "stroke" | "strokeOpacity" | "strokeDasharray">;
|
|
204
|
+
|
|
168
205
|
/** Re-export of Recharts `Legend` — use with `content={<ChartLegendContent />}`. */
|
|
169
206
|
export declare const ChartLegend: typeof Legend;
|
|
170
207
|
|
package/dist/charts.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ChartCard } from "./components/Chart/ChartCard.mjs";
|
|
3
3
|
import { ChartCenterLabel } from "./components/Chart/ChartCenterLabel.mjs";
|
|
4
4
|
import { ChartContainer } from "./components/Chart/ChartContainer.mjs";
|
|
5
|
+
import { ChartGrid } from "./components/Chart/ChartGrid.mjs";
|
|
5
6
|
import { ChartLegend, ChartLegendContent } from "./components/Chart/ChartLegend.mjs";
|
|
6
7
|
import { ChartLoadingOverlay } from "./components/Chart/ChartLoadingOverlay.mjs";
|
|
7
8
|
import { ChartMetricTrend } from "./components/Chart/ChartMetricTrend.mjs";
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
ChartCard,
|
|
17
18
|
ChartCenterLabel,
|
|
18
19
|
ChartContainer,
|
|
20
|
+
ChartGrid,
|
|
19
21
|
ChartLegend,
|
|
20
22
|
ChartLegendContent,
|
|
21
23
|
ChartLoadingOverlay,
|
package/dist/charts.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charts.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"charts.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
package/dist/cjs/charts.cjs
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
const ChartCard = require("./components/Chart/ChartCard.cjs");
|
|
5
5
|
const ChartCenterLabel = require("./components/Chart/ChartCenterLabel.cjs");
|
|
6
6
|
const ChartContainer = require("./components/Chart/ChartContainer.cjs");
|
|
7
|
+
const ChartGrid = require("./components/Chart/ChartGrid.cjs");
|
|
7
8
|
const ChartLegend = require("./components/Chart/ChartLegend.cjs");
|
|
8
9
|
const ChartLoadingOverlay = require("./components/Chart/ChartLoadingOverlay.cjs");
|
|
9
10
|
const ChartMetricTrend = require("./components/Chart/ChartMetricTrend.cjs");
|
|
@@ -17,6 +18,7 @@ const useChart = require("./components/Chart/useChart.cjs");
|
|
|
17
18
|
exports.ChartCard = ChartCard.ChartCard;
|
|
18
19
|
exports.ChartCenterLabel = ChartCenterLabel.ChartCenterLabel;
|
|
19
20
|
exports.ChartContainer = ChartContainer.ChartContainer;
|
|
21
|
+
exports.ChartGrid = ChartGrid.ChartGrid;
|
|
20
22
|
exports.ChartLegend = ChartLegend.ChartLegend;
|
|
21
23
|
exports.ChartLegendContent = ChartLegend.ChartLegendContent;
|
|
22
24
|
exports.ChartLoadingOverlay = ChartLoadingOverlay.ChartLoadingOverlay;
|
package/dist/cjs/charts.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charts.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"charts.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -123,44 +123,53 @@ const Alert = React__namespace.forwardRef(
|
|
|
123
123
|
),
|
|
124
124
|
...props,
|
|
125
125
|
children: [
|
|
126
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
142
|
-
|
|
143
|
-
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
127
|
+
"div",
|
|
128
|
+
{
|
|
129
|
+
className: cn.cn(
|
|
130
|
+
"flex min-w-0 flex-1 py-1 pr-1",
|
|
131
|
+
isTrailing ? "items-center gap-6" : "items-start gap-3"
|
|
132
|
+
),
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3", children: [
|
|
135
|
+
resolvedIcon && // The design's icon slot is 16px, but the default variant icons
|
|
136
|
+
// (InfoCircleIcon and friends) ship at `size-5`, so constrain the
|
|
137
|
+
// glyph here — the same way IconButton sizes its own icon. The 1px
|
|
138
|
+
// top nudge then lands it optically centred on the first 18px line,
|
|
139
|
+
// as in the design's icon-wrapper.
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex shrink-0 items-start pt-px [&>svg]:size-4", "aria-hidden": "true", children: resolvedIcon }),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-3", children: [
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { role: "alert", className: "flex flex-col gap-1", children: [
|
|
143
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
className: cn.cn("typography-body-small-14px-semibold", MESSAGE_CLASSES[variant]),
|
|
147
|
+
children: title
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
children ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
151
|
+
"div",
|
|
152
|
+
{
|
|
153
|
+
className: cn.cn("typography-body-small-14px-regular", MESSAGE_CLASSES[variant]),
|
|
154
|
+
children
|
|
155
|
+
}
|
|
156
|
+
) : null
|
|
157
|
+
] }),
|
|
158
|
+
!isTrailing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
159
|
+
AlertCta,
|
|
144
160
|
{
|
|
145
|
-
|
|
146
|
-
|
|
161
|
+
action,
|
|
162
|
+
ctaLabel,
|
|
163
|
+
ctaProps,
|
|
164
|
+
isTrailing: false
|
|
147
165
|
}
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
ctaLabel,
|
|
156
|
-
ctaProps,
|
|
157
|
-
isTrailing
|
|
158
|
-
}
|
|
159
|
-
)
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
)
|
|
163
|
-
] }),
|
|
166
|
+
)
|
|
167
|
+
] })
|
|
168
|
+
] }),
|
|
169
|
+
isTrailing && /* @__PURE__ */ jsxRuntime.jsx(AlertCta, { action, ctaLabel, ctaProps, isTrailing: true })
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
),
|
|
164
173
|
closable && /* @__PURE__ */ jsxRuntime.jsx(
|
|
165
174
|
IconButton.IconButton,
|
|
166
175
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.cjs","sources":["../../../../src/components/Alert/Alert.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Button, type ButtonProps } from \"../Button/Button\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { AlertIcon } from \"../Icons/AlertIcon\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { InfoIcon } from \"../Icons/InfoIcon\";\nimport { TickCircleIcon } from \"../Icons/TickCircleIcon\";\nimport { WarningIcon } from \"../Icons/WarningIcon\";\n\n/** Visual style variant of the alert. */\nexport type AlertVariant = \"info\" | \"success\" | \"warning\" | \"error\" | \"neutral\";\n\n/**\n * Placement of the call-to-action relative to the message.\n *\n * - `\"under\"` stacks the action beneath the description. Use it when the CTA\n * label is long or the alert is narrow.\n * - `\"trailing\"` keeps the action inline with the message, which keeps the\n * alert compact and works best with short labels.\n */\nexport type AlertLayout = \"under\" | \"trailing\";\n\n/**\n * Per-variant default icon, mapped to the Iconography components the design\n * uses at `Size=16, Fill=Yes`. Note the design's naming: its Error variant\n * takes `Iconography / Warning` and its Warning variant takes\n * `Iconography / Alert`, which reads backwards but is what the node specifies.\n *\n * These carry dedicated 16px geometry, unlike the `*CircleIcon` set they\n * replace, whose 20px art had to be scaled down.\n */\nconst DEFAULT_ICONS: Record<AlertVariant, React.ReactNode> = {\n info: <InfoIcon size={16} filled />,\n success: <TickCircleIcon size={16} filled />,\n warning: <AlertIcon size={16} filled />,\n error: <WarningIcon size={16} filled />,\n neutral: <InfoIcon size={16} filled />,\n};\n\nexport interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Visual style variant of the alert. @default \"info\" */\n variant?: AlertVariant;\n /** Optional title text displayed in bold above the description. */\n title?: string;\n /** Custom icon override. Pass `null` to hide the icon entirely. Each variant shows a default icon when left `undefined`. */\n icon?: React.ReactNode | null;\n /** Whether to show the close button. @default false */\n closable?: boolean;\n /** Callback fired when the close button is clicked. */\n onClose?: () => void;\n /** Accessible label for the close button. @default \"Close alert\" */\n closeLabel?: string;\n /**\n * Composable action slot rendered beneath the description, outside the\n * `role=\"alert\"` live region. Pass your own element (an `<a>`, a `next/link`\n * `<Link>`, or a `<Button>`) and it receives the variant-appropriate link\n * styling via the Radix `Slot` pattern while remaining a real link/button.\n */\n action?: React.ReactNode;\n /** Placement of the call-to-action relative to the message. @default \"under\" */\n layout?: AlertLayout;\n /**\n * Label for a built-in call-to-action button, the button form of the CTA.\n * Use it when the alert asks the user to do something specific — activating a\n * feature, or completing setup — rather than pointing at more detail. Ignored\n * when `action` is set.\n */\n ctaLabel?: React.ReactNode;\n /**\n * Props forwarded to the built-in call-to-action button (e.g. `onClick`).\n * `variant` and `size` default to `secondary`/`32` and can be overridden.\n *\n * The stacked CTA is `w-full sm:w-fit`. To override the width, match the\n * modifier chain — a bare `w-auto` replaces `w-full` but leaves `sm:w-fit`\n * in place, so pass `sm:` variants too.\n */\n ctaProps?: Omit<ButtonProps, \"children\" | \"asChild\">;\n}\n\n/**\n * Title and description colour. The design binds both to\n * `Color/Alerts/Info Prompt/Content/<variant>`, and Neutral to\n * `Color/Content/Secondary` — not to `content-primary`, which reads as plain\n * black on the tinted surface.\n */\nconst MESSAGE_CLASSES: Record<AlertVariant, string> = {\n info: \"text-alerts-info-prompt-content-info\",\n success: \"text-alerts-info-prompt-content-success\",\n warning: \"text-alerts-info-prompt-content-warning\",\n error: \"text-alerts-info-prompt-content-error\",\n neutral: \"text-content-secondary\",\n};\n\n/**\n * Surface fill and icon colour, both read from the component's own design\n * variables: `Color/Alerts/Info Prompt/Background/<variant>` and\n * `Color/Alerts/Info Prompt/Icon/<variant>`.\n *\n * The `text-*` here is inherited by the icon only — the message sets its own\n * colour via {@link MESSAGE_CLASSES}. It matters that this reads the dedicated\n * icon tokens rather than the generic `*-content` ones: those agree only for\n * info, and they carry no dark-mode inversion, where the alert tokens step\n * from `*-600` in light to `*-400` in dark as the design specifies.\n */\nconst SURFACE_CLASSES: Record<AlertVariant, string> = {\n info: \"bg-alerts-info-prompt-background-info text-alerts-info-prompt-icon-info\",\n success: \"bg-alerts-info-prompt-background-success text-alerts-info-prompt-icon-success\",\n warning: \"bg-alerts-info-prompt-background-warning text-alerts-info-prompt-icon-warning\",\n error: \"bg-alerts-info-prompt-background-error text-alerts-info-prompt-icon-error\",\n neutral: \"bg-alerts-info-prompt-background-neutral text-alerts-info-prompt-icon-neutral\",\n};\n\n/**\n * CTA link treatment. The node's CTA is a `V2 Link` instance whose text binds\n * `Color/Buttons/Link/Primary/Default`, with no per-variant override on any of\n * the five — so the link takes the standard link colour rather than the alert's\n * own content tint. These are the same tokens the {@link Link} component\n * applies, including the hover step.\n */\nconst LINK_CLASSES = \"text-buttons-link-primary-default hover:text-buttons-link-primary-hover\";\n\n/**\n * The alert's call-to-action. `action` is the link form: any element passed\n * through receives the variant-appropriate link styling via Radix `Slot` while\n * staying a real link or button. `ctaLabel` is the button form. `action` wins\n * when both are set.\n */\nfunction AlertCta({\n action,\n ctaLabel,\n ctaProps,\n isTrailing,\n}: {\n action: React.ReactNode;\n ctaLabel: React.ReactNode;\n ctaProps?: AlertProps[\"ctaProps\"];\n isTrailing: boolean;\n}) {\n if (action) {\n return (\n <Slot\n className={cn(\n \"typography-body-small-14px-semibold w-fit cursor-pointer underline underline-offset-2\",\n isTrailing && \"shrink-0\",\n LINK_CLASSES,\n )}\n >\n {action}\n </Slot>\n );\n }\n\n if (ctaLabel === undefined || ctaLabel === null || ctaLabel === false) {\n return null;\n }\n\n return (\n <Button\n variant=\"secondary\"\n size=\"32\"\n {...ctaProps}\n className={cn(\n // Stacked, the CTA sits in a flex column, which would otherwise stretch\n // it across the whole alert. Fill on mobile, where a full-width button\n // is the easier target, and hug from `sm` (850px) up. Inline, it always\n // hugs so the message keeps the remaining width.\n isTrailing ? \"shrink-0\" : \"w-full sm:w-fit\",\n ctaProps?.className,\n )}\n >\n {ctaLabel}\n </Button>\n );\n}\n\n/**\n * Displays a contextual feedback message to the user.\n *\n * Supports `info`, `success`, `warning`, `error`, and `neutral` variants with a\n * default icon per variant, optional title, description, dismiss button, and an\n * optional composable `action` slot.\n *\n * Each variant renders a default icon automatically. Pass a custom `icon` to\n * override, or `icon={null}` to hide the icon entirely.\n *\n * Only the title and description live inside the `role=\"alert\"` live region.\n * The icon, `action`, and close button are rendered outside it so interactive\n * controls are announced and navigated consistently by screen readers.\n *\n * @example\n * ```tsx\n * <Alert variant=\"success\" title=\"Saved\" closable onClose={handleClose}>\n * Your changes have been saved.\n * </Alert>\n * ```\n *\n * @example\n * ```tsx\n * <Alert variant=\"neutral\" title=\"Heads up\" action={<a href=\"/docs\">Learn more</a>}>\n * A general notice with no specific sentiment.\n * </Alert>\n * ```\n *\n * @example\n * ```tsx\n * import Link from \"next/link\";\n *\n * <Alert variant=\"info\" title=\"Update available\" action={<Link href=\"/changelog\">See what's new</Link>}>\n * A new version is ready to install.\n * </Alert>\n * ```\n *\n * @example\n * The CTA sits under the description by default. `layout=\"trailing\"` keeps it\n * inline with the message, which suits short labels and keeps the alert compact.\n * ```tsx\n * <Alert variant=\"info\" layout=\"trailing\" action={<a href=\"/docs\">Learn more</a>}>\n * Scheduled posts now publish in your local timezone.\n * </Alert>\n * ```\n *\n * @example\n * `ctaLabel` renders the button form of the CTA instead of a link — use it when\n * the alert asks the user to do something specific.\n * ```tsx\n * <Alert variant=\"warning\" title=\"Finish setup\" layout=\"trailing\" ctaLabel=\"Verify now\" ctaProps={{ onClick: verify }}>\n * Verify your identity to start receiving payouts.\n * </Alert>\n * ```\n */\nexport const Alert = React.forwardRef<HTMLDivElement, AlertProps>(\n (\n {\n className,\n variant = \"info\",\n title,\n icon,\n closable = false,\n onClose,\n closeLabel = \"Close alert\",\n action,\n layout = \"under\",\n ctaLabel,\n ctaProps,\n children,\n ...props\n },\n ref,\n ) => {\n const resolvedIcon = icon === null ? null : (icon ?? DEFAULT_ICONS[variant]);\n const isTrailing = layout === \"trailing\";\n\n return (\n <div\n ref={ref}\n data-testid=\"alert\"\n className={cn(\n // Mirrors the Figma frame: 12px inset with a 16px left inset, 24px\n // from the content row to the close button, `rounded-md` radius.\n \"flex items-start gap-6 rounded-md p-3 pl-4 text-sm leading-[18px]\",\n SURFACE_CLASSES[variant],\n className,\n )}\n {...props}\n >\n {/*\n Content row. Its 4px inset is what takes the container's 12px up to the\n 16px the design specifies around the message, while leaving the close\n button on the container's own 12px. It also puts 28px between the\n message and the close button (this 4px plus the container's 24px gap).\n */}\n <div className=\"flex min-w-0 flex-1 items-start gap-3 py-1 pr-1\">\n {resolvedIcon && (\n // The design's icon slot is 16px, but the default variant icons\n // (InfoCircleIcon and friends) ship at `size-5`, so constrain the\n // glyph here — the same way IconButton sizes its own icon. The 1px\n // top nudge then lands it optically centred on the first 18px line,\n // as in the design's icon-wrapper.\n <span className=\"flex shrink-0 items-start pt-px [&>svg]:size-4\" aria-hidden=\"true\">\n {resolvedIcon}\n </span>\n )}\n\n <div\n className={cn(\n \"flex min-w-0 flex-1\",\n isTrailing ? \"items-center gap-6\" : \"flex-col gap-3\",\n )}\n >\n <div role=\"alert\" className={cn(\"flex flex-col gap-1\", isTrailing && \"min-w-0 flex-1\")}>\n {title && (\n <div\n className={cn(\"typography-body-small-14px-semibold\", MESSAGE_CLASSES[variant])}\n >\n {title}\n </div>\n )}\n {children ? (\n <div className={cn(\"typography-body-small-14px-regular\", MESSAGE_CLASSES[variant])}>\n {children}\n </div>\n ) : null}\n </div>\n <AlertCta\n action={action}\n ctaLabel={ctaLabel}\n ctaProps={ctaProps}\n isTrailing={isTrailing}\n />\n </div>\n </div>\n\n {closable && (\n <IconButton\n variant=\"secondary\"\n size=\"24\"\n onClick={onClose}\n aria-label={closeLabel}\n icon={<CloseIcon size={16} />}\n />\n )}\n </div>\n );\n },\n);\n\nAlert.displayName = \"Alert\";\n"],"names":["jsx","InfoIcon","TickCircleIcon","AlertIcon","WarningIcon","Slot","cn","Button","React","jsxs","IconButton","CloseIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,gBAAuD;AAAA,EAC3D,MAAMA,2BAAAA,IAACC,mBAAA,EAAS,MAAM,IAAI,QAAM,MAAC;AAAA,EACjC,SAASD,2BAAAA,IAACE,+BAAA,EAAe,MAAM,IAAI,QAAM,MAAC;AAAA,EAC1C,SAASF,2BAAAA,IAACG,qBAAA,EAAU,MAAM,IAAI,QAAM,MAAC;AAAA,EACrC,OAAOH,2BAAAA,IAACI,yBAAA,EAAY,MAAM,IAAI,QAAM,MAAC;AAAA,EACrC,SAASJ,2BAAAA,IAACC,mBAAA,EAAS,MAAM,IAAI,QAAM,KAAA,CAAC;AACtC;AAgDA,MAAM,kBAAgD;AAAA,EACpD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACX;AAaA,MAAM,kBAAgD;AAAA,EACpD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACX;AASA,MAAM,eAAe;AAQrB,SAAS,SAAS;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,MAAI,QAAQ;AACV,WACED,2BAAAA;AAAAA,MAACK,UAAAA;AAAAA,MAAA;AAAA,QACC,WAAWC,GAAAA;AAAAA,UACT;AAAA,UACA,cAAc;AAAA,UACd;AAAA,QAAA;AAAA,QAGD,UAAA;AAAA,MAAA;AAAA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AAI,MAAK,SAAQ,WAAWH,GAAAA,GAAG,uBAAuB,cAAc,gBAAgB,GAClF,UAAA;AAAA,oBAAA,SACCN,2BAAAA;AAAAA,sBAAC;AAAA,sBAAA;AAAA,wBACC,WAAWM,GAAAA,GAAG,uCAAuC,gBAAgB,OAAO,CAAC;AAAA,wBAE5E,UAAA;AAAA,sBAAA;AAAA,oBAAA;AAAA,oBAGJ,WACCN,2BAAAA,IAAC,OAAA,EAAI,WAAWM,GAAAA,GAAG,sCAAsC,gBAAgB,OAAO,CAAC,GAC9E,SAAA,CACH,IACE;AAAA,kBAAA,GACN;AAAA,kBACAN,2BAAAA;AAAAA,oBAAC;AAAA,oBAAA;AAAA,sBACC;AAAA,sBACA;AAAA,sBACA;AAAA,sBACA;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBACF;AAAA,cAAA;AAAA,YAAA;AAAA,UACF,GACF;AAAA,UAEC,YACCA,2BAAAA;AAAAA,YAACU,WAAAA;AAAAA,YAAA;AAAA,cACC,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,SAAS;AAAA,cACT,cAAY;AAAA,cACZ,MAAMV,2BAAAA,IAACW,UAAAA,WAAA,EAAU,MAAM,GAAA,CAAI;AAAA,YAAA;AAAA,UAAA;AAAA,QAC7B;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,MAAM,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"Alert.cjs","sources":["../../../../src/components/Alert/Alert.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Button, type ButtonProps } from \"../Button/Button\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { AlertIcon } from \"../Icons/AlertIcon\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { InfoIcon } from \"../Icons/InfoIcon\";\nimport { TickCircleIcon } from \"../Icons/TickCircleIcon\";\nimport { WarningIcon } from \"../Icons/WarningIcon\";\n\n/** Visual style variant of the alert. */\nexport type AlertVariant = \"info\" | \"success\" | \"warning\" | \"error\" | \"neutral\";\n\n/**\n * Placement of the call-to-action relative to the message.\n *\n * - `\"under\"` stacks the action beneath the description. Use it when the CTA\n * label is long or the alert is narrow.\n * - `\"trailing\"` keeps the action inline with the message, which keeps the\n * alert compact and works best with short labels.\n */\nexport type AlertLayout = \"under\" | \"trailing\";\n\n/**\n * Per-variant default icon, mapped to the Iconography components the design\n * uses at `Size=16, Fill=Yes`. Note the design's naming: its Error variant\n * takes `Iconography / Warning` and its Warning variant takes\n * `Iconography / Alert`, which reads backwards but is what the node specifies.\n *\n * These carry dedicated 16px geometry, unlike the `*CircleIcon` set they\n * replace, whose 20px art had to be scaled down.\n */\nconst DEFAULT_ICONS: Record<AlertVariant, React.ReactNode> = {\n info: <InfoIcon size={16} filled />,\n success: <TickCircleIcon size={16} filled />,\n warning: <AlertIcon size={16} filled />,\n error: <WarningIcon size={16} filled />,\n neutral: <InfoIcon size={16} filled />,\n};\n\nexport interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Visual style variant of the alert. @default \"info\" */\n variant?: AlertVariant;\n /** Optional title text displayed in bold above the description. */\n title?: string;\n /** Custom icon override. Pass `null` to hide the icon entirely. Each variant shows a default icon when left `undefined`. */\n icon?: React.ReactNode | null;\n /** Whether to show the close button. @default false */\n closable?: boolean;\n /** Callback fired when the close button is clicked. */\n onClose?: () => void;\n /** Accessible label for the close button. @default \"Close alert\" */\n closeLabel?: string;\n /**\n * Composable action slot rendered beneath the description, outside the\n * `role=\"alert\"` live region. Pass your own element (an `<a>`, a `next/link`\n * `<Link>`, or a `<Button>`) and it receives the variant-appropriate link\n * styling via the Radix `Slot` pattern while remaining a real link/button.\n */\n action?: React.ReactNode;\n /** Placement of the call-to-action relative to the message. @default \"under\" */\n layout?: AlertLayout;\n /**\n * Label for a built-in call-to-action button, the button form of the CTA.\n * Use it when the alert asks the user to do something specific — activating a\n * feature, or completing setup — rather than pointing at more detail. Ignored\n * when `action` is set.\n */\n ctaLabel?: React.ReactNode;\n /**\n * Props forwarded to the built-in call-to-action button (e.g. `onClick`).\n * `variant` and `size` default to `secondary`/`32` and can be overridden.\n *\n * The stacked CTA is `w-full sm:w-fit`. To override the width, match the\n * modifier chain — a bare `w-auto` replaces `w-full` but leaves `sm:w-fit`\n * in place, so pass `sm:` variants too.\n */\n ctaProps?: Omit<ButtonProps, \"children\" | \"asChild\">;\n}\n\n/**\n * Title and description colour. The design binds both to\n * `Color/Alerts/Info Prompt/Content/<variant>`, and Neutral to\n * `Color/Content/Secondary` — not to `content-primary`, which reads as plain\n * black on the tinted surface.\n */\nconst MESSAGE_CLASSES: Record<AlertVariant, string> = {\n info: \"text-alerts-info-prompt-content-info\",\n success: \"text-alerts-info-prompt-content-success\",\n warning: \"text-alerts-info-prompt-content-warning\",\n error: \"text-alerts-info-prompt-content-error\",\n neutral: \"text-content-secondary\",\n};\n\n/**\n * Surface fill and icon colour, both read from the component's own design\n * variables: `Color/Alerts/Info Prompt/Background/<variant>` and\n * `Color/Alerts/Info Prompt/Icon/<variant>`.\n *\n * The `text-*` here is inherited by the icon only — the message sets its own\n * colour via {@link MESSAGE_CLASSES}. It matters that this reads the dedicated\n * icon tokens rather than the generic `*-content` ones: those agree only for\n * info, and they carry no dark-mode inversion, where the alert tokens step\n * from `*-600` in light to `*-400` in dark as the design specifies.\n */\nconst SURFACE_CLASSES: Record<AlertVariant, string> = {\n info: \"bg-alerts-info-prompt-background-info text-alerts-info-prompt-icon-info\",\n success: \"bg-alerts-info-prompt-background-success text-alerts-info-prompt-icon-success\",\n warning: \"bg-alerts-info-prompt-background-warning text-alerts-info-prompt-icon-warning\",\n error: \"bg-alerts-info-prompt-background-error text-alerts-info-prompt-icon-error\",\n neutral: \"bg-alerts-info-prompt-background-neutral text-alerts-info-prompt-icon-neutral\",\n};\n\n/**\n * CTA link treatment. The node's CTA is a `V2 Link` instance whose text binds\n * `Color/Buttons/Link/Primary/Default`, with no per-variant override on any of\n * the five — so the link takes the standard link colour rather than the alert's\n * own content tint. These are the same tokens the {@link Link} component\n * applies, including the hover step.\n */\nconst LINK_CLASSES = \"text-buttons-link-primary-default hover:text-buttons-link-primary-hover\";\n\n/**\n * The alert's call-to-action. `action` is the link form: any element passed\n * through receives the variant-appropriate link styling via Radix `Slot` while\n * staying a real link or button. `ctaLabel` is the button form. `action` wins\n * when both are set.\n */\nfunction AlertCta({\n action,\n ctaLabel,\n ctaProps,\n isTrailing,\n}: {\n action: React.ReactNode;\n ctaLabel: React.ReactNode;\n ctaProps?: AlertProps[\"ctaProps\"];\n isTrailing: boolean;\n}) {\n if (action) {\n return (\n <Slot\n className={cn(\n \"typography-body-small-14px-semibold w-fit cursor-pointer underline underline-offset-2\",\n isTrailing && \"shrink-0\",\n LINK_CLASSES,\n )}\n >\n {action}\n </Slot>\n );\n }\n\n if (ctaLabel === undefined || ctaLabel === null || ctaLabel === false) {\n return null;\n }\n\n return (\n <Button\n variant=\"secondary\"\n size=\"32\"\n {...ctaProps}\n className={cn(\n // Stacked, the CTA sits in a flex column, which would otherwise stretch\n // it across the whole alert. Fill on mobile, where a full-width button\n // is the easier target, and hug from `sm` (850px) up. Inline, it always\n // hugs so the message keeps the remaining width.\n isTrailing ? \"shrink-0\" : \"w-full sm:w-fit\",\n ctaProps?.className,\n )}\n >\n {ctaLabel}\n </Button>\n );\n}\n\n/**\n * Displays a contextual feedback message to the user.\n *\n * Supports `info`, `success`, `warning`, `error`, and `neutral` variants with a\n * default icon per variant, optional title, description, dismiss button, and an\n * optional composable `action` slot.\n *\n * Each variant renders a default icon automatically. Pass a custom `icon` to\n * override, or `icon={null}` to hide the icon entirely.\n *\n * Only the title and description live inside the `role=\"alert\"` live region.\n * The icon, `action`, and close button are rendered outside it so interactive\n * controls are announced and navigated consistently by screen readers.\n *\n * @example\n * ```tsx\n * <Alert variant=\"success\" title=\"Saved\" closable onClose={handleClose}>\n * Your changes have been saved.\n * </Alert>\n * ```\n *\n * @example\n * ```tsx\n * <Alert variant=\"neutral\" title=\"Heads up\" action={<a href=\"/docs\">Learn more</a>}>\n * A general notice with no specific sentiment.\n * </Alert>\n * ```\n *\n * @example\n * ```tsx\n * import Link from \"next/link\";\n *\n * <Alert variant=\"info\" title=\"Update available\" action={<Link href=\"/changelog\">See what's new</Link>}>\n * A new version is ready to install.\n * </Alert>\n * ```\n *\n * @example\n * The CTA sits under the description by default. `layout=\"trailing\"` keeps it\n * inline with the message, which suits short labels and keeps the alert compact.\n * ```tsx\n * <Alert variant=\"info\" layout=\"trailing\" action={<a href=\"/docs\">Learn more</a>}>\n * Scheduled posts now publish in your local timezone.\n * </Alert>\n * ```\n *\n * @example\n * `ctaLabel` renders the button form of the CTA instead of a link — use it when\n * the alert asks the user to do something specific.\n * ```tsx\n * <Alert variant=\"warning\" title=\"Finish setup\" layout=\"trailing\" ctaLabel=\"Verify now\" ctaProps={{ onClick: verify }}>\n * Verify your identity to start receiving payouts.\n * </Alert>\n * ```\n */\nexport const Alert = React.forwardRef<HTMLDivElement, AlertProps>(\n (\n {\n className,\n variant = \"info\",\n title,\n icon,\n closable = false,\n onClose,\n closeLabel = \"Close alert\",\n action,\n layout = \"under\",\n ctaLabel,\n ctaProps,\n children,\n ...props\n },\n ref,\n ) => {\n const resolvedIcon = icon === null ? null : (icon ?? DEFAULT_ICONS[variant]);\n const isTrailing = layout === \"trailing\";\n\n return (\n <div\n ref={ref}\n data-testid=\"alert\"\n className={cn(\n // Mirrors the Figma frame: 12px inset with a 16px left inset, 24px\n // from the content row to the close button, `rounded-md` radius.\n \"flex items-start gap-6 rounded-md p-3 pl-4 text-sm leading-[18px]\",\n SURFACE_CLASSES[variant],\n className,\n )}\n {...props}\n >\n {/*\n Content row. Its 4px inset is what takes the container's 12px up to the\n 16px the design specifies around the message, while leaving the close\n button on the container's own 12px. It also puts 28px between the\n message and the close button (this 4px plus the container's 24px gap).\n */}\n <div\n className={cn(\n \"flex min-w-0 flex-1 py-1 pr-1\",\n isTrailing ? \"items-center gap-6\" : \"items-start gap-3\",\n )}\n >\n {/*\n Trailing, the icon and message move as one group centred against\n the CTA, so a one-line message shorter than the 32px button keeps\n its icon on the text line instead of at the top of the row.\n */}\n <div className=\"flex min-w-0 flex-1 items-start gap-3\">\n {resolvedIcon && (\n // The design's icon slot is 16px, but the default variant icons\n // (InfoCircleIcon and friends) ship at `size-5`, so constrain the\n // glyph here — the same way IconButton sizes its own icon. The 1px\n // top nudge then lands it optically centred on the first 18px line,\n // as in the design's icon-wrapper.\n <span className=\"flex shrink-0 items-start pt-px [&>svg]:size-4\" aria-hidden=\"true\">\n {resolvedIcon}\n </span>\n )}\n\n <div className=\"flex min-w-0 flex-1 flex-col gap-3\">\n <div role=\"alert\" className=\"flex flex-col gap-1\">\n {title && (\n <div\n className={cn(\"typography-body-small-14px-semibold\", MESSAGE_CLASSES[variant])}\n >\n {title}\n </div>\n )}\n {children ? (\n <div\n className={cn(\"typography-body-small-14px-regular\", MESSAGE_CLASSES[variant])}\n >\n {children}\n </div>\n ) : null}\n </div>\n {!isTrailing && (\n <AlertCta\n action={action}\n ctaLabel={ctaLabel}\n ctaProps={ctaProps}\n isTrailing={false}\n />\n )}\n </div>\n </div>\n\n {isTrailing && (\n <AlertCta action={action} ctaLabel={ctaLabel} ctaProps={ctaProps} isTrailing />\n )}\n </div>\n\n {closable && (\n <IconButton\n variant=\"secondary\"\n size=\"24\"\n onClick={onClose}\n aria-label={closeLabel}\n icon={<CloseIcon size={16} />}\n />\n )}\n </div>\n );\n },\n);\n\nAlert.displayName = \"Alert\";\n"],"names":["jsx","InfoIcon","TickCircleIcon","AlertIcon","WarningIcon","Slot","cn","Button","React","jsxs","IconButton","CloseIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,gBAAuD;AAAA,EAC3D,MAAMA,2BAAAA,IAACC,mBAAA,EAAS,MAAM,IAAI,QAAM,MAAC;AAAA,EACjC,SAASD,2BAAAA,IAACE,+BAAA,EAAe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;AAAA,sBAAA;AAAA,wBACC;AAAA,wBACA;AAAA,wBACA;AAAA,wBACA,YAAY;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBACd,EAAA,CAEJ;AAAA,gBAAA,GACF;AAAA,gBAEC,cACCA,2BAAAA,IAAC,UAAA,EAAS,QAAgB,UAAoB,UAAoB,YAAU,KAAA,CAAC;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,UAIhF,YACCA,2BAAAA;AAAAA,YAACU,WAAAA;AAAAA,YAAA;AAAA,cACC,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,SAAS;AAAA,cACT,cAAY;AAAA,cACZ,MAAMV,2BAAAA,IAACW,UAAAA,WAAA,EAAU,MAAM,GAAA,CAAI;AAAA,YAAA;AAAA,UAAA;AAAA,QAC7B;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,MAAM,cAAc;;"}
|
|
@@ -155,9 +155,13 @@ const RollingNumber = React__namespace.forwardRef(
|
|
|
155
155
|
)
|
|
156
156
|
},
|
|
157
157
|
`digit-${index}`
|
|
158
|
-
) : (
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
159
|
+
"span",
|
|
160
|
+
{
|
|
161
|
+
style: { height: "1em", lineHeight: "1em" },
|
|
162
|
+
children: char
|
|
163
|
+
},
|
|
164
|
+
`separator-${index}`
|
|
161
165
|
)
|
|
162
166
|
) })
|
|
163
167
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatedNumber.cjs","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 = \"AnimatedNumber.Rolling\";\n"],"names":["React","usePrefersReducedMotion","jsx","cn","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,sBAAsB;AAE5B,MAAM,gBAAgB,CAAC,UAAkB,OAAO,KAAK,MAAM,KAAK,CAAC;AAGjE,MAAM,eAAe,CAAC,MAAc,KAAK,IAAI,MAAM;AAEnD,MAAM,SAAS,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAEhE,MAAM,UAAU,CAAC,SAAiB,QAAQ,OAAO,QAAQ;AAsBlD,MAAM,iBAAiBA,iBAAM;AAAA,EAClC,CACE;AAAA,IACE;AAAA,IACA,SAAS;AAAA,IACT,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,gBAAgBC,wBAAAA,wBAAA;AAEtB,QAAI,YAAY,QAAQ;AACtB,aACEC,2BAAAA;AAAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA,YAAY,gBAAgB,IAAI;AAAA,UAChC;AAAA,UACC,GAAG;AAAA,QAAA;AAAA,MAAA;AAAA,IAGV;AAEA,WACEA,2BAAAA;AAAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA,YAAY,gBAAgB,IAAI;AAAA,QAChC;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IAAA;AAAA,EAGV;AACF;AAEA,eAAe,cAAc;AAO7B,MAAM,iBAAiBF,iBAAM;AAAA,EAC3B,CAAC,EAAE,OAAO,QAAQ,YAAY,WAAW,GAAG,MAAA,GAAS,QAAQ;AAC3D,UAAM,CAAC,cAAc,e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;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACH;AAAA,cAlBK,SAAS,KAAK;AAAA,YAAA;AAAA;AAAA,cAsBrBA,2BAAAA,IAAC,QAAA,EAAiC,UAAA,KAAA,GAAvB,aAAa,KAAK,EAAU;AAAA;AAAA,UAAA,EAE3C,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,cAAc,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"AnimatedNumber.cjs","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 <span\n // biome-ignore lint/suspicious/noArrayIndexKey: same positional identity as the digit columns\n key={`separator-${index}`}\n style={{ height: \"1em\", lineHeight: \"1em\" }}\n >\n {char}\n </span>\n ),\n )}\n </span>\n </span>\n );\n },\n);\n\nRollingNumber.displayName = \"AnimatedNumber.Rolling\";\n"],"names":["React","usePrefersReducedMotion","jsx","cn","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,sBAAsB;AAE5B,MAAM,gBAAgB,CAAC,UAAkB,OAAO,KAAK,MAAM,KAAK,CAAC;AAGjE,MAAM,eAAe,CAAC,MAAc,KAAK,IAAI,MAAM;AAEnD,MAAM,SAAS,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAEhE,MAAM,UAAU,CAAC,SAAiB,QAAQ,OAAO,QAAQ;AAsBlD,MAAM,iBAAiBA,iBAAM;AAAA,EAClC,CACE;AAAA,IACE;AAAA,IACA,SAAS;AAAA,IACT,UAAU;AAAA,IACV,aAAa;AAAA,IACb;A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SAAQ;AAAA,UACnCA,2BAAAA,IAAC,UAAK,KAAK,YAAY,eAAW,MAAC,WAAU,8BAC1C,UAAA,WAAW;AAAA,YAAI,CAAC,MAAM,UACrB,QAAQ,IAAI,IACVA,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBAGC,WAAU;AAAA,gBACV,OAAO,EAAE,QAAQ,OAAO,YAAY,MAAA;AAAA,gBAEpC,UAAAA,2BAAAA;AAAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,WAAU;AAAA,oBACV,OAAO;AAAA,sBACL,WAAW,eAAe,OAAO,IAAI,IAAI,EAAE;AAAA,sBAC3C,oBAAoB;AAAA,sBACpB,oBAAoB,GAAG,UAAU;AAAA,sBACjC,0BAA0B;AAAA,oBAAA;AAAA,oBAG3B,UAAA,OAAO,IAAI,CAAC,yCACV,QAAA,EAAiB,OAAO,EAAE,QAAQ,OAAO,YAAY,MAAA,GACnD,UAAA,MAAA,GADQ,KAEX,CACD;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACH;AAAA,cAlBK,SAAS,KAAK;AAAA,YAAA,IAqBrBA,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBAGC,OAAO,EAAE,QAAQ,OAAO,YAAY,MAAA;AAAA,gBAEnC,UAAA;AAAA,cAAA;AAAA,cAHI,aAAa,KAAK;AAAA,YAAA;AAAA,UAIzB,EAEJ,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,cAAc,cAAc;;"}
|
|
@@ -154,7 +154,7 @@ const Autocomplete = React__namespace.forwardRef((props, ref) => {
|
|
|
154
154
|
)
|
|
155
155
|
] }),
|
|
156
156
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [
|
|
157
|
-
loading && /* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon.SpinnerIcon, {
|
|
157
|
+
loading && /* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon.SpinnerIcon, { size: 16, spin: true, className: "text-content-secondary" }),
|
|
158
158
|
clearable && ac.hasClearableValue && !disabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
159
159
|
"button",
|
|
160
160
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocomplete.cjs","sources":["../../../../src/components/Autocomplete/Autocomplete.tsx"],"sourcesContent":["import * as Popover from \"@radix-ui/react-popover\";\nimport * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { FLOATING_CONTENT_COLLISION_PADDING } from \"@/utils/floatingContentCollisionPadding\";\nimport { ChevronDownIcon } from \"../Icons/ChevronDownIcon\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { SpinnerIcon } from \"../Icons/SpinnerIcon\";\nimport { AutocompleteDropdownContent } from \"./AutocompleteDropdownContent\";\nimport { AutocompleteTag } from \"./AutocompleteTag\";\nimport { useAutocomplete } from \"./useAutocomplete\";\n\nexport type AutocompleteSize = \"48\" | \"40\" | \"32\";\n\nexport interface AutocompleteOption {\n /** Unique value identifying the option. Returned via `onChange`. */\n value: string;\n /** Visible label. Falls back to `value` when omitted. */\n label?: string;\n /** When `true`, the option renders but cannot be selected. @default false */\n disabled?: boolean;\n /**\n * ID of the group this option belongs to. Must match an entry in the\n * component's `groups` prop. Options without a `groupId` render in an\n * implicit \"ungrouped\" bucket above the first declared group.\n */\n groupId?: string;\n /**\n * Pinned options bypass the search filter and stay visible at the top of\n * the list regardless of the current query. Useful for \"+ Create new\"\n * affordances. Pinned options ignore `groupId` and render before any\n * grouped or ungrouped content. @default false\n */\n pinned?: boolean;\n}\n\n/**\n * Describes a single group rendered above its matching options.\n * Indentation of nested rows (e.g. price under product) is not built in —\n * consumers control it via `renderOption` styling.\n */\nexport interface AutocompleteGroup {\n /** Stable identifier referenced by `option.groupId`. */\n id: string;\n /**\n * Group heading text. Used as the group's accessible name and matched\n * against the search query: when the query matches a group's `label`,\n * every option under that group is kept regardless of whether it\n * individually matches the per-option filter. This supports the common\n * \"heading is the searchable label, items are sub-rows\" shape (e.g.\n * heading = product name, items = prices).\n */\n label: string;\n}\n\ninterface AutocompleteBaseProps {\n label?: string;\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n helperText?: string;\n /** @default \"48\" */\n size?: AutocompleteSize;\n /** @default false */\n error?: boolean;\n errorMessage?: string;\n placeholder?: string;\n leftIcon?: React.ReactNode;\n /** @default false */\n fullWidth?: boolean;\n /** @default false */\n disabled?: boolean;\n /** @default false */\n clearable?: boolean;\n clearAriaLabel?: string;\n id?: string;\n className?: string;\n options: AutocompleteOption[];\n inputValue?: string;\n onInputChange?: (value: string) => void;\n filterFn?: (option: AutocompleteOption, query: string) => boolean;\n /** @default false */\n creatable?: boolean;\n creatableLabel?: (inputValue: string) => string;\n onCreate?: (inputValue: string) => void;\n /** @default false */\n loading?: boolean;\n loadingText?: string;\n emptyText?: string;\n renderOption?: (\n option: AutocompleteOption,\n state: { selected: boolean; active: boolean },\n ) => React.ReactNode;\n renderTag?: (option: AutocompleteOption, onRemove: () => void) => React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * Ordered list of groups. When provided, options whose `groupId` matches\n * an entry render under the corresponding heading. Groups with no visible\n * (post-filter) options collapse silently. Pinned options render above\n * everything; ungrouped options render between pinned and the first group.\n * Only one level of grouping is supported.\n */\n groups?: AutocompleteGroup[];\n /**\n * Custom renderer for group headings. The returned node is wrapped by the\n * component in an element carrying the `id` referenced by the surrounding\n * `role=\"group\"` wrapper's `aria-labelledby`, so consumers only need to\n * return visual content.\n */\n renderGroupHeading?: (group: AutocompleteGroup) => React.ReactNode;\n}\n\ninterface AutocompleteSingleProps extends AutocompleteBaseProps {\n multiple?: false;\n value?: string | null;\n defaultValue?: string | null;\n onChange?: (value: string | null) => void;\n}\n\ninterface AutocompleteMultiProps extends AutocompleteBaseProps {\n multiple: true;\n value?: string[];\n defaultValue?: string[];\n onChange?: (values: string[]) => void;\n}\n\nexport type AutocompleteProps = AutocompleteSingleProps | AutocompleteMultiProps;\n\nconst CONTAINER_HEIGHT: Record<AutocompleteSize, string> = {\n \"48\": \"min-h-12\",\n \"40\": \"min-h-10\",\n \"32\": \"min-h-8\",\n};\n\nconst INPUT_SIZE_CLASSES: Record<AutocompleteSize, string> = {\n \"48\": \"typography-body-default-16px-regular\",\n \"40\": \"typography-body-default-16px-regular\",\n \"32\": \"typography-body-small-14px-regular\",\n};\n\nconst PADDING_CLASSES: Record<AutocompleteSize, string> = {\n \"48\": \"px-4 py-1.5 gap-3\",\n \"40\": \"px-4 py-1 gap-3\",\n \"32\": \"px-3 py-1 gap-2\",\n};\n\nfunction warnMissingAccessibleName(label?: string, ariaLabel?: string, ariaLabelledBy?: string) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn(\n \"Autocomplete: no accessible name provided. Pass a `label`, `aria-label`, or `aria-labelledby` prop.\",\n );\n }\n }\n}\n\n/**\n * A combobox input with single- or multi-select, optional async loading, and\n * native support for grouped + pinned options.\n *\n * - Pass `groups` plus an `options` array whose entries reference each group\n * via `groupId` to render hierarchical lists with proper `role=\"group\"` +\n * `aria-labelledby` semantics. Options without a `groupId` render above\n * the first group; options marked `pinned` render above everything and\n * bypass the search filter.\n * - Indentation of nested rows (e.g. price under product) is controlled by\n * the consumer via `renderOption` styling — there is no built-in indent.\n *\n * @example\n * ```tsx\n * <Autocomplete\n * aria-label=\"Choose a product\"\n * options={[\n * { value: \"__new__\", label: \"+ Create new product\", pinned: true },\n * { value: \"product:abc\", label: \"Demo Product\", groupId: \"recent\" },\n * ]}\n * groups={[{ id: \"recent\", label: \"Recent products\" }]}\n * onChange={handleSelect}\n * />\n * ```\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Conditional JSX branches in the render template\nexport const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>((props, ref) => {\n const {\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledby,\n helperText,\n size = \"48\",\n error = false,\n errorMessage,\n placeholder,\n leftIcon,\n fullWidth = false,\n disabled = false,\n clearable = false,\n clearAriaLabel = \"Clear\",\n className,\n loading = false,\n loadingText,\n emptyText = \"No results\",\n renderOption,\n renderTag,\n renderGroupHeading,\n } = props;\n\n const ac = useAutocomplete(props);\n\n React.useImperativeHandle(ref, () => ac.inputRef.current as HTMLInputElement);\n\n warnMissingAccessibleName(label, ariaLabel, ariaLabelledby);\n\n const bottomText = error && errorMessage ? errorMessage : helperText;\n\n return (\n <Popover.Root open={ac.isOpen && !disabled} onOpenChange={ac.handleOpenChange}>\n <div\n className={cn(\"flex flex-col\", fullWidth && \"w-full\", className)}\n data-autocomplete-root=\"\"\n data-disabled={disabled ? \"\" : undefined}\n data-error={error ? \"\" : undefined}\n >\n {label && (\n <label\n htmlFor={ac.inputId}\n className=\"typography-description-12px-semibold px-1 pt-1 pb-2 text-content-primary\"\n >\n {label}\n </label>\n )}\n\n <Popover.Anchor asChild>\n {/* biome-ignore lint/a11y/noStaticElementInteractions: Container delegates click to the inner input */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: Keyboard interaction is handled by the inner combobox input */}\n <div\n className={cn(\n \"relative flex flex-wrap items-center overflow-hidden rounded-sm border bg-neutral-alphas-100 after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] has-focus-visible:outline-none has-focus-visible:after:shadow-focus-ring motion-safe:transition-colors\",\n error ? \"border-error-content\" : \"border-transparent\",\n !disabled && !error && \"hover:border-neutral-alphas-400\",\n ac.isOpen && !error && !disabled && \"border-neutral-alphas-400\",\n CONTAINER_HEIGHT[size],\n PADDING_CLASSES[size],\n disabled && \"opacity-50\",\n )}\n onClick={ac.handleContainerClick}\n >\n {leftIcon && (\n <div className=\"flex size-5 shrink-0 items-center justify-center text-content-secondary\">\n {leftIcon}\n </div>\n )}\n\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-1.5\">\n {ac.isMulti &&\n ac.selectedMultiOptions.map((opt) => (\n <AutocompleteTag\n key={opt.value}\n option={opt}\n disabled={disabled}\n onRemove={() => ac.toggleMulti(opt.value)}\n renderTag={renderTag}\n />\n ))}\n\n <input\n ref={ac.inputRef}\n id={ac.inputId}\n role=\"combobox\"\n type=\"text\"\n disabled={disabled}\n aria-expanded={ac.isOpen}\n aria-controls={ac.isOpen ? ac.listboxId : undefined}\n aria-activedescendant={ac.activeDescendantId}\n aria-autocomplete=\"list\"\n aria-describedby={bottomText ? ac.helperTextId : undefined}\n aria-invalid={error || undefined}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n autoComplete=\"off\"\n placeholder={\n ac.isMulti && ac.selectedMultiValues.length > 0 ? undefined : placeholder\n }\n value={ac.displayInputValue}\n onChange={ac.handleInputChange}\n onKeyDown={ac.handleKeyDown}\n onFocus={ac.handleFocus}\n onBlur={ac.handleBlur}\n className={cn(\n \"min-w-[40px] flex-1 truncate bg-transparent text-content-primary no-underline placeholder:text-content-secondary placeholder:opacity-40 focus:outline-none disabled:cursor-not-allowed\",\n INPUT_SIZE_CLASSES[size],\n )}\n />\n </div>\n\n <div className=\"flex shrink-0 items-center gap-1\">\n {loading && <SpinnerIcon className=\"size-4 animate-spin text-content-secondary\" />}\n {clearable && ac.hasClearableValue && !disabled && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={clearAriaLabel}\n className=\"flex size-5 shrink-0 cursor-pointer items-center justify-center text-content-secondary hover:text-content-primary active:scale-95\"\n onClick={ac.handleClear}\n >\n <CloseIcon className=\"size-4\" />\n </button>\n )}\n <div className=\"flex size-5 shrink-0 items-center justify-center text-content-secondary\">\n <ChevronDownIcon\n className={cn(\"size-5 transition-transform\", ac.isOpen && \"rotate-180\")}\n />\n </div>\n </div>\n </div>\n </Popover.Anchor>\n\n <Popover.Portal>\n <Popover.Content\n sideOffset={4}\n collisionPadding={FLOATING_CONTENT_COLLISION_PADDING}\n onOpenAutoFocus={(e) => e.preventDefault()}\n onCloseAutoFocus={(e) => e.preventDefault()}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\" }}\n className={cn(\n \"w-max min-w-(--radix-popper-anchor-width) max-w-(--radix-popover-content-available-width) overflow-hidden rounded-sm border border-neutral-alphas-200 bg-background-primary text-content-primary shadow-[0_4px_16px_rgba(0,0,0,0.10)]\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0\",\n \"data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95\",\n \"data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2\",\n )}\n >\n <div\n ref={ac.listRef}\n id={ac.listboxId}\n role=\"listbox\"\n aria-label={label ?? ariaLabel ?? \"Options\"}\n aria-multiselectable={ac.isMulti || undefined}\n className=\"max-h-60 overflow-y-auto p-1\"\n >\n <AutocompleteDropdownContent\n loading={loading}\n loadingText={loadingText}\n emptyText={emptyText}\n visibleOptions={ac.visibleOptions}\n visibleSections={ac.visibleSections}\n createOption={ac.createOption}\n listboxId={ac.listboxId}\n activeIndex={ac.activeIndex}\n isMulti={ac.isMulti}\n selectedMultiValues={ac.selectedMultiValues}\n selectedValue={ac.selectedValue}\n onSelect={ac.handleSelect}\n onMouseEnter={ac.setActiveIndex}\n renderOption={renderOption}\n renderGroupHeading={renderGroupHeading}\n />\n </div>\n </Popover.Content>\n </Popover.Portal>\n\n {bottomText && (\n <p\n id={ac.helperTextId}\n className={cn(\n \"typography-description-12px-regular px-2 pt-1 pb-0.5\",\n error ? \"text-error-content\" : \"text-content-secondary\",\n )}\n >\n {bottomText}\n </p>\n )}\n </div>\n </Popover.Root>\n );\n});\n\nAutocomplete.displayName = \"Autocomplete\";\n"],"names":["React","useAutocomplete","jsx","Popover","jsxs","cn","AutocompleteTag","SpinnerIcon","CloseIcon","ChevronDownIcon","FLOATING_CONTENT_COLLISION_PADDING","AutocompleteDropdownContent"],"mappings":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s","sources":["../../../../src/components/Autocomplete/Autocomplete.tsx"],"sourcesContent":["import * as Popover from \"@radix-ui/react-popover\";\nimport * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { FLOATING_CONTENT_COLLISION_PADDING } from \"@/utils/floatingContentCollisionPadding\";\nimport { ChevronDownIcon } from \"../Icons/ChevronDownIcon\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { SpinnerIcon } from \"../Icons/SpinnerIcon\";\nimport { AutocompleteDropdownContent } from \"./AutocompleteDropdownContent\";\nimport { AutocompleteTag } from \"./AutocompleteTag\";\nimport { useAutocomplete } from \"./useAutocomplete\";\n\nexport type AutocompleteSize = \"48\" | \"40\" | \"32\";\n\nexport interface AutocompleteOption {\n /** Unique value identifying the option. Returned via `onChange`. */\n value: string;\n /** Visible label. Falls back to `value` when omitted. */\n label?: string;\n /** When `true`, the option renders but cannot be selected. @default false */\n disabled?: boolean;\n /**\n * ID of the group this option belongs to. Must match an entry in the\n * component's `groups` prop. Options without a `groupId` render in an\n * implicit \"ungrouped\" bucket above the first declared group.\n */\n groupId?: string;\n /**\n * Pinned options bypass the search filter and stay visible at the top of\n * the list regardless of the current query. Useful for \"+ Create new\"\n * affordances. Pinned options ignore `groupId` and render before any\n * grouped or ungrouped content. @default false\n */\n pinned?: boolean;\n}\n\n/**\n * Describes a single group rendered above its matching options.\n * Indentation of nested rows (e.g. price under product) is not built in —\n * consumers control it via `renderOption` styling.\n */\nexport interface AutocompleteGroup {\n /** Stable identifier referenced by `option.groupId`. */\n id: string;\n /**\n * Group heading text. Used as the group's accessible name and matched\n * against the search query: when the query matches a group's `label`,\n * every option under that group is kept regardless of whether it\n * individually matches the per-option filter. This supports the common\n * \"heading is the searchable label, items are sub-rows\" shape (e.g.\n * heading = product name, items = prices).\n */\n label: string;\n}\n\ninterface AutocompleteBaseProps {\n label?: string;\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n helperText?: string;\n /** @default \"48\" */\n size?: AutocompleteSize;\n /** @default false */\n error?: boolean;\n errorMessage?: string;\n placeholder?: string;\n leftIcon?: React.ReactNode;\n /** @default false */\n fullWidth?: boolean;\n /** @default false */\n disabled?: boolean;\n /** @default false */\n clearable?: boolean;\n clearAriaLabel?: string;\n id?: string;\n className?: string;\n options: AutocompleteOption[];\n inputValue?: string;\n onInputChange?: (value: string) => void;\n filterFn?: (option: AutocompleteOption, query: string) => boolean;\n /** @default false */\n creatable?: boolean;\n creatableLabel?: (inputValue: string) => string;\n onCreate?: (inputValue: string) => void;\n /** @default false */\n loading?: boolean;\n loadingText?: string;\n emptyText?: string;\n renderOption?: (\n option: AutocompleteOption,\n state: { selected: boolean; active: boolean },\n ) => React.ReactNode;\n renderTag?: (option: AutocompleteOption, onRemove: () => void) => React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * Ordered list of groups. When provided, options whose `groupId` matches\n * an entry render under the corresponding heading. Groups with no visible\n * (post-filter) options collapse silently. Pinned options render above\n * everything; ungrouped options render between pinned and the first group.\n * Only one level of grouping is supported.\n */\n groups?: AutocompleteGroup[];\n /**\n * Custom renderer for group headings. The returned node is wrapped by the\n * component in an element carrying the `id` referenced by the surrounding\n * `role=\"group\"` wrapper's `aria-labelledby`, so consumers only need to\n * return visual content.\n */\n renderGroupHeading?: (group: AutocompleteGroup) => React.ReactNode;\n}\n\ninterface AutocompleteSingleProps extends AutocompleteBaseProps {\n multiple?: false;\n value?: string | null;\n defaultValue?: string | null;\n onChange?: (value: string | null) => void;\n}\n\ninterface AutocompleteMultiProps extends AutocompleteBaseProps {\n multiple: true;\n value?: string[];\n defaultValue?: string[];\n onChange?: (values: string[]) => void;\n}\n\nexport type AutocompleteProps = AutocompleteSingleProps | AutocompleteMultiProps;\n\nconst CONTAINER_HEIGHT: Record<AutocompleteSize, string> = {\n \"48\": \"min-h-12\",\n \"40\": \"min-h-10\",\n \"32\": \"min-h-8\",\n};\n\nconst INPUT_SIZE_CLASSES: Record<AutocompleteSize, string> = {\n \"48\": \"typography-body-default-16px-regular\",\n \"40\": \"typography-body-default-16px-regular\",\n \"32\": \"typography-body-small-14px-regular\",\n};\n\nconst PADDING_CLASSES: Record<AutocompleteSize, string> = {\n \"48\": \"px-4 py-1.5 gap-3\",\n \"40\": \"px-4 py-1 gap-3\",\n \"32\": \"px-3 py-1 gap-2\",\n};\n\nfunction warnMissingAccessibleName(label?: string, ariaLabel?: string, ariaLabelledBy?: string) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn(\n \"Autocomplete: no accessible name provided. Pass a `label`, `aria-label`, or `aria-labelledby` prop.\",\n );\n }\n }\n}\n\n/**\n * A combobox input with single- or multi-select, optional async loading, and\n * native support for grouped + pinned options.\n *\n * - Pass `groups` plus an `options` array whose entries reference each group\n * via `groupId` to render hierarchical lists with proper `role=\"group\"` +\n * `aria-labelledby` semantics. Options without a `groupId` render above\n * the first group; options marked `pinned` render above everything and\n * bypass the search filter.\n * - Indentation of nested rows (e.g. price under product) is controlled by\n * the consumer via `renderOption` styling — there is no built-in indent.\n *\n * @example\n * ```tsx\n * <Autocomplete\n * aria-label=\"Choose a product\"\n * options={[\n * { value: \"__new__\", label: \"+ Create new product\", pinned: true },\n * { value: \"product:abc\", label: \"Demo Product\", groupId: \"recent\" },\n * ]}\n * groups={[{ id: \"recent\", label: \"Recent products\" }]}\n * onChange={handleSelect}\n * />\n * ```\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Conditional JSX branches in the render template\nexport const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>((props, ref) => {\n const {\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledby,\n helperText,\n size = \"48\",\n error = false,\n errorMessage,\n placeholder,\n leftIcon,\n fullWidth = false,\n disabled = false,\n clearable = false,\n clearAriaLabel = \"Clear\",\n className,\n loading = false,\n loadingText,\n emptyText = \"No results\",\n renderOption,\n renderTag,\n renderGroupHeading,\n } = props;\n\n const ac = useAutocomplete(props);\n\n React.useImperativeHandle(ref, () => ac.inputRef.current as HTMLInputElement);\n\n warnMissingAccessibleName(label, ariaLabel, ariaLabelledby);\n\n const bottomText = error && errorMessage ? errorMessage : helperText;\n\n return (\n <Popover.Root open={ac.isOpen && !disabled} onOpenChange={ac.handleOpenChange}>\n <div\n className={cn(\"flex flex-col\", fullWidth && \"w-full\", className)}\n data-autocomplete-root=\"\"\n data-disabled={disabled ? \"\" : undefined}\n data-error={error ? \"\" : undefined}\n >\n {label && (\n <label\n htmlFor={ac.inputId}\n className=\"typography-description-12px-semibold px-1 pt-1 pb-2 text-content-primary\"\n >\n {label}\n </label>\n )}\n\n <Popover.Anchor asChild>\n {/* biome-ignore lint/a11y/noStaticElementInteractions: Container delegates click to the inner input */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: Keyboard interaction is handled by the inner combobox input */}\n <div\n className={cn(\n \"relative flex flex-wrap items-center overflow-hidden rounded-sm border bg-neutral-alphas-100 after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] has-focus-visible:outline-none has-focus-visible:after:shadow-focus-ring motion-safe:transition-colors\",\n error ? \"border-error-content\" : \"border-transparent\",\n !disabled && !error && \"hover:border-neutral-alphas-400\",\n ac.isOpen && !error && !disabled && \"border-neutral-alphas-400\",\n CONTAINER_HEIGHT[size],\n PADDING_CLASSES[size],\n disabled && \"opacity-50\",\n )}\n onClick={ac.handleContainerClick}\n >\n {leftIcon && (\n <div className=\"flex size-5 shrink-0 items-center justify-center text-content-secondary\">\n {leftIcon}\n </div>\n )}\n\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-1.5\">\n {ac.isMulti &&\n ac.selectedMultiOptions.map((opt) => (\n <AutocompleteTag\n key={opt.value}\n option={opt}\n disabled={disabled}\n onRemove={() => ac.toggleMulti(opt.value)}\n renderTag={renderTag}\n />\n ))}\n\n <input\n ref={ac.inputRef}\n id={ac.inputId}\n role=\"combobox\"\n type=\"text\"\n disabled={disabled}\n aria-expanded={ac.isOpen}\n aria-controls={ac.isOpen ? ac.listboxId : undefined}\n aria-activedescendant={ac.activeDescendantId}\n aria-autocomplete=\"list\"\n aria-describedby={bottomText ? ac.helperTextId : undefined}\n aria-invalid={error || undefined}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n autoComplete=\"off\"\n placeholder={\n ac.isMulti && ac.selectedMultiValues.length > 0 ? undefined : placeholder\n }\n value={ac.displayInputValue}\n onChange={ac.handleInputChange}\n onKeyDown={ac.handleKeyDown}\n onFocus={ac.handleFocus}\n onBlur={ac.handleBlur}\n className={cn(\n \"min-w-[40px] flex-1 truncate bg-transparent text-content-primary no-underline placeholder:text-content-secondary placeholder:opacity-40 focus:outline-none disabled:cursor-not-allowed\",\n INPUT_SIZE_CLASSES[size],\n )}\n />\n </div>\n\n <div className=\"flex shrink-0 items-center gap-1\">\n {loading && <SpinnerIcon size={16} spin className=\"text-content-secondary\" />}\n {clearable && ac.hasClearableValue && !disabled && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={clearAriaLabel}\n className=\"flex size-5 shrink-0 cursor-pointer items-center justify-center text-content-secondary hover:text-content-primary active:scale-95\"\n onClick={ac.handleClear}\n >\n <CloseIcon className=\"size-4\" />\n </button>\n )}\n <div className=\"flex size-5 shrink-0 items-center justify-center text-content-secondary\">\n <ChevronDownIcon\n className={cn(\"size-5 transition-transform\", ac.isOpen && \"rotate-180\")}\n />\n </div>\n </div>\n </div>\n </Popover.Anchor>\n\n <Popover.Portal>\n <Popover.Content\n sideOffset={4}\n collisionPadding={FLOATING_CONTENT_COLLISION_PADDING}\n onOpenAutoFocus={(e) => e.preventDefault()}\n onCloseAutoFocus={(e) => e.preventDefault()}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\" }}\n className={cn(\n \"w-max min-w-(--radix-popper-anchor-width) max-w-(--radix-popover-content-available-width) overflow-hidden rounded-sm border border-neutral-alphas-200 bg-background-primary text-content-primary shadow-[0_4px_16px_rgba(0,0,0,0.10)]\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0\",\n \"data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95\",\n \"data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2\",\n )}\n >\n <div\n ref={ac.listRef}\n id={ac.listboxId}\n role=\"listbox\"\n aria-label={label ?? ariaLabel ?? \"Options\"}\n aria-multiselectable={ac.isMulti || undefined}\n className=\"max-h-60 overflow-y-auto p-1\"\n >\n <AutocompleteDropdownContent\n loading={loading}\n loadingText={loadingText}\n emptyText={emptyText}\n visibleOptions={ac.visibleOptions}\n visibleSections={ac.visibleSections}\n createOption={ac.createOption}\n listboxId={ac.listboxId}\n activeIndex={ac.activeIndex}\n isMulti={ac.isMulti}\n selectedMultiValues={ac.selectedMultiValues}\n selectedValue={ac.selectedValue}\n onSelect={ac.handleSelect}\n onMouseEnter={ac.setActiveIndex}\n renderOption={renderOption}\n renderGroupHeading={renderGroupHeading}\n />\n </div>\n </Popover.Content>\n </Popover.Portal>\n\n {bottomText && (\n <p\n id={ac.helperTextId}\n className={cn(\n \"typography-description-12px-regular px-2 pt-1 pb-0.5\",\n error ? \"text-error-content\" : \"text-content-secondary\",\n )}\n >\n {bottomText}\n </p>\n )}\n </div>\n </Popover.Root>\n );\n});\n\nAutocomplete.displayName = \"Autocomplete\";\n"],"names":["React","useAutocomplete","jsx","Popover","jsxs","cn","AutocompleteTag","SpinnerIcon","CloseIcon","ChevronDownIcon","FLOATING_CONTENT_COLLISION_PADDING","AutocompleteDropdownContent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIA,MAAM,mBAAqD;AAAA,EACzD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,qBAAuD;AAAA,EAC3D,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;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AAA;AAAAA,cACT;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,YAGF,UAAAH,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,KAAK,GAAG;AAAA,gBACR,IAAI,GAAG;AAAA,gBACP,MAAK;AAAA,gBACL,cAAY,SAAS,aAAa;AAAA,gBAClC,wBAAsB,GAAG,WAAW;AAAA,gBACpC,WAAU;AAAA,gBAEV,UAAAA,2BAAAA;AAAAA,kBAACS,4BAAAA;AAAAA,kBAAA;AAAA,oBACC;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA,gBAAgB,GAAG;AAAA,oBACnB,iBAAiB,GAAG;AAAA,oBACpB,cAAc,GAAG;AAAA,oBACjB,WAAW,GAAG;AAAA,oBACd,aAAa,GAAG;AAAA,oBAChB,SAAS,GAAG;AAAA,oBACZ,qBAAqB,GAAG;AAAA,oBACxB,eAAe,GAAG;AAAA,oBAClB,UAAU,GAAG;AAAA,oBACb,cAAc,GAAG;AAAA,oBACjB;AAAA,oBACA;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACF;AAAA,YAAA;AAAA,UACF;AAAA,QAAA,GAEJ;AAAA,QAEC,cACCT,2BAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,GAAG;AAAA,YACP,WAAWG,GAAAA;AAAAA,cACT;AAAA,cACA,QAAQ,uBAAuB;AAAA,YAAA;AAAA,YAGhC,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ,CAAC;AAED,aAAa,cAAc;;"}
|
|
@@ -29,7 +29,7 @@ function AutocompleteDropdownContent({
|
|
|
29
29
|
return (
|
|
30
30
|
// biome-ignore lint/a11y/useSemanticElements: <output> is not appropriate here; using role="status" for live region announcements
|
|
31
31
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { role: "status", className: "flex items-center justify-center py-4", children: [
|
|
32
|
-
/* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon.SpinnerIcon, { className: "
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon.SpinnerIcon, { spin: true, className: "text-content-secondary" }),
|
|
33
33
|
loadingText && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "typography-body-small-14px-regular ml-2 text-content-secondary", children: loadingText })
|
|
34
34
|
] })
|
|
35
35
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteDropdownContent.cjs","sources":["../../../../src/components/Autocomplete/AutocompleteDropdownContent.tsx"],"sourcesContent":["import type * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { SpinnerIcon } from \"../Icons/SpinnerIcon\";\nimport type { AutocompleteGroup, AutocompleteOption } from \"./Autocomplete\";\nimport { AutocompleteOptionItem } from \"./AutocompleteOptionItem\";\nimport type { AutocompleteVisibleSections } from \"./constants\";\n\ninterface AutocompleteDropdownContentProps {\n loading: boolean;\n loadingText?: string;\n emptyText?: string;\n visibleOptions: AutocompleteOption[];\n visibleSections: AutocompleteVisibleSections;\n /**\n * Synthetic \"Create new …\" row, when `creatable` is on and the search\n * doesn't already match an existing option. Rendered as a trailing row,\n * always shown regardless of filter, and indexed last in\n * `visibleOptions` so keyboard navigation works.\n */\n createOption?: AutocompleteOption | null;\n listboxId: string;\n activeIndex: number;\n isMulti: boolean;\n selectedMultiValues: string[];\n selectedValue: string | null;\n onSelect: (option: AutocompleteOption) => void;\n onMouseEnter: (index: number) => void;\n renderOption?: (\n option: AutocompleteOption,\n state: { selected: boolean; active: boolean },\n ) => React.ReactNode;\n renderGroupHeading?: (group: AutocompleteGroup) => React.ReactNode;\n}\n\nfunction DefaultGroupHeading({ children }: { children: React.ReactNode }) {\n return (\n <span className=\"typography-description-12px-semibold block px-3 pt-2 pb-1 text-content-secondary uppercase tracking-wide\">\n {children}\n </span>\n );\n}\n\nexport function AutocompleteDropdownContent({\n loading,\n loadingText,\n emptyText,\n visibleOptions,\n visibleSections,\n createOption,\n listboxId,\n activeIndex,\n isMulti,\n selectedMultiValues,\n selectedValue,\n onSelect,\n onMouseEnter,\n renderOption,\n renderGroupHeading,\n}: AutocompleteDropdownContentProps) {\n if (loading) {\n return (\n // biome-ignore lint/a11y/useSemanticElements: <output> is not appropriate here; using role=\"status\" for live region announcements\n <div role=\"status\" className=\"flex items-center justify-center py-4\">\n <SpinnerIcon className=\"
|
|
1
|
+
{"version":3,"file":"AutocompleteDropdownContent.cjs","sources":["../../../../src/components/Autocomplete/AutocompleteDropdownContent.tsx"],"sourcesContent":["import type * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { SpinnerIcon } from \"../Icons/SpinnerIcon\";\nimport type { AutocompleteGroup, AutocompleteOption } from \"./Autocomplete\";\nimport { AutocompleteOptionItem } from \"./AutocompleteOptionItem\";\nimport type { AutocompleteVisibleSections } from \"./constants\";\n\ninterface AutocompleteDropdownContentProps {\n loading: boolean;\n loadingText?: string;\n emptyText?: string;\n visibleOptions: AutocompleteOption[];\n visibleSections: AutocompleteVisibleSections;\n /**\n * Synthetic \"Create new …\" row, when `creatable` is on and the search\n * doesn't already match an existing option. Rendered as a trailing row,\n * always shown regardless of filter, and indexed last in\n * `visibleOptions` so keyboard navigation works.\n */\n createOption?: AutocompleteOption | null;\n listboxId: string;\n activeIndex: number;\n isMulti: boolean;\n selectedMultiValues: string[];\n selectedValue: string | null;\n onSelect: (option: AutocompleteOption) => void;\n onMouseEnter: (index: number) => void;\n renderOption?: (\n option: AutocompleteOption,\n state: { selected: boolean; active: boolean },\n ) => React.ReactNode;\n renderGroupHeading?: (group: AutocompleteGroup) => React.ReactNode;\n}\n\nfunction DefaultGroupHeading({ children }: { children: React.ReactNode }) {\n return (\n <span className=\"typography-description-12px-semibold block px-3 pt-2 pb-1 text-content-secondary uppercase tracking-wide\">\n {children}\n </span>\n );\n}\n\nexport function AutocompleteDropdownContent({\n loading,\n loadingText,\n emptyText,\n visibleOptions,\n visibleSections,\n createOption,\n listboxId,\n activeIndex,\n isMulti,\n selectedMultiValues,\n selectedValue,\n onSelect,\n onMouseEnter,\n renderOption,\n renderGroupHeading,\n}: AutocompleteDropdownContentProps) {\n if (loading) {\n return (\n // biome-ignore lint/a11y/useSemanticElements: <output> is not appropriate here; using role=\"status\" for live region announcements\n <div role=\"status\" className=\"flex items-center justify-center py-4\">\n <SpinnerIcon spin className=\"text-content-secondary\" />\n {loadingText && (\n <span className=\"typography-body-small-14px-regular ml-2 text-content-secondary\">\n {loadingText}\n </span>\n )}\n </div>\n );\n }\n\n const { pinned, ungrouped, groups } = visibleSections;\n const hasTopBlock = pinned.length > 0 || ungrouped.length > 0;\n const hasGroups = groups.length > 0;\n const nonPinnedVisibleCount =\n ungrouped.length + groups.reduce((n, g) => n + g.options.length, 0) + (createOption ? 1 : 0);\n\n if (visibleOptions.length === 0) {\n return (\n <div className=\"typography-body-small-14px-regular block px-3 py-4 text-center text-content-secondary\">\n {emptyText}\n </div>\n );\n }\n\n let cursor = 0;\n const renderOptionRow = (option: AutocompleteOption) => {\n const index = cursor++;\n const isSelected = isMulti\n ? selectedMultiValues.includes(option.value)\n : option.value === selectedValue;\n return (\n <AutocompleteOptionItem\n key={option.value}\n option={option}\n optionId={`${listboxId}-option-${index}`}\n index={index}\n isSelected={isSelected}\n isActive={index === activeIndex}\n onSelect={() => onSelect(option)}\n onMouseEnter={() => onMouseEnter(index)}\n renderOption={renderOption}\n />\n );\n };\n\n const showDivider = hasTopBlock && hasGroups;\n const emptyAfterPinned = nonPinnedVisibleCount === 0 && pinned.length > 0;\n\n return (\n <>\n {pinned.map(renderOptionRow)}\n {ungrouped.map(renderOptionRow)}\n {groups.map((section, sectionIndex) => {\n const headingId = `${listboxId}-group-${section.group.id}`;\n const headingNode = renderGroupHeading\n ? renderGroupHeading(section.group)\n : section.group.label;\n return (\n // biome-ignore lint/a11y/useSemanticElements: <fieldset> carries form semantics and default styling we don't want inside a listbox; role=\"group\" is the correct ARIA pattern here\n <div\n key={section.group.id}\n role=\"group\"\n aria-labelledby={headingId}\n className={cn(\n showDivider && sectionIndex === 0 && \"mt-1 border-neutral-alphas-200 border-t pt-1\",\n )}\n >\n <div role=\"presentation\" id={headingId}>\n {renderGroupHeading ? (\n headingNode\n ) : (\n <DefaultGroupHeading>{headingNode}</DefaultGroupHeading>\n )}\n </div>\n {section.options.map(renderOptionRow)}\n </div>\n );\n })}\n {createOption && renderOptionRow(createOption)}\n {emptyAfterPinned && (\n <div className=\"typography-body-small-14px-regular block px-3 py-4 text-center text-content-secondary\">\n {emptyText}\n </div>\n )}\n </>\n );\n}\n"],"names":["jsx","jsxs","SpinnerIcon","AutocompleteOptionItem","Fragment","cn"],"mappings":";;;;;;;AAkCA,SAAS,oBAAoB,EAAE,YAA2C;AACxE,SACEA,2BAAAA,IAAC,QAAA,EAAK,WAAU,4GACb,SAAA,CACH;AAEJ;AAEO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqC;AACnC,MAAI,SAAS;AACX;AAAA;AAAA,MAEEC,2BAAAA,KAAC,OAAA,EAAI,MAAK,UAAS,WAAU,yCAC3B,UAAA;AAAA,QAAAD,2BAAAA,IAACE,YAAAA,aAAA,EAAY,MAAI,MAAC,WAAU,0BAAyB;AAAA,QACpD,eACCF,2BAAAA,IAAC,QAAA,EAAK,WAAU,kEACb,UAAA,YAAA,CACH;AAAA,MAAA,EAAA,CAEJ;AAAA;AAAA,EAEJ;AAEA,QAAM,EAAE,QAAQ,WAAW,OAAA,IAAW;AACtC,QAAM,cAAc,OAAO,SAAS,KAAK,UAAU,SAAS;AAC5D,QAAM,YAAY,OAAO,SAAS;AAClC,QAAM,wBACJ,UAAU,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,IAAI,EAAE,Q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,GAEtC;AAAA,cACC,QAAQ,QAAQ,IAAI,eAAe;AAAA,YAAA;AAAA,UAAA;AAAA,UAd/B,QAAQ,MAAM;AAAA,QAAA;AAAA;AAAA,IAiBzB,CAAC;AAAA,IACA,gBAAgB,gBAAgB,YAAY;AAAA,IAC5C,oBACCA,2BAAAA,IAAC,OAAA,EAAI,WAAU,yFACZ,UAAA,UAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;;"}
|
|
@@ -139,7 +139,7 @@ function getTextContent(node) {
|
|
|
139
139
|
return void 0;
|
|
140
140
|
}
|
|
141
141
|
const LoadingSpinner = ({ size }) => {
|
|
142
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
142
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon.SpinnerIcon, { spin: true, className: ICON_SIZE_CLASS[size], children: /* @__PURE__ */ jsxRuntime.jsx("title", { children: "Loading" }) }) });
|
|
143
143
|
};
|
|
144
144
|
function renderContent({
|
|
145
145
|
loading,
|