@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
|
@@ -104,44 +104,53 @@ const Alert = React.forwardRef(
|
|
|
104
104
|
),
|
|
105
105
|
...props,
|
|
106
106
|
children: [
|
|
107
|
-
/* @__PURE__ */ jsxs(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/* @__PURE__ */ jsxs("div", {
|
|
123
|
-
|
|
124
|
-
|
|
107
|
+
/* @__PURE__ */ jsxs(
|
|
108
|
+
"div",
|
|
109
|
+
{
|
|
110
|
+
className: cn(
|
|
111
|
+
"flex min-w-0 flex-1 py-1 pr-1",
|
|
112
|
+
isTrailing ? "items-center gap-6" : "items-start gap-3"
|
|
113
|
+
),
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3", children: [
|
|
116
|
+
resolvedIcon && // The design's icon slot is 16px, but the default variant icons
|
|
117
|
+
// (InfoCircleIcon and friends) ship at `size-5`, so constrain the
|
|
118
|
+
// glyph here — the same way IconButton sizes its own icon. The 1px
|
|
119
|
+
// top nudge then lands it optically centred on the first 18px line,
|
|
120
|
+
// as in the design's icon-wrapper.
|
|
121
|
+
/* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-start pt-px [&>svg]:size-4", "aria-hidden": "true", children: resolvedIcon }),
|
|
122
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-3", children: [
|
|
123
|
+
/* @__PURE__ */ jsxs("div", { role: "alert", className: "flex flex-col gap-1", children: [
|
|
124
|
+
title && /* @__PURE__ */ jsx(
|
|
125
|
+
"div",
|
|
126
|
+
{
|
|
127
|
+
className: cn("typography-body-small-14px-semibold", MESSAGE_CLASSES[variant]),
|
|
128
|
+
children: title
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
children ? /* @__PURE__ */ jsx(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: cn("typography-body-small-14px-regular", MESSAGE_CLASSES[variant]),
|
|
135
|
+
children
|
|
136
|
+
}
|
|
137
|
+
) : null
|
|
138
|
+
] }),
|
|
139
|
+
!isTrailing && /* @__PURE__ */ jsx(
|
|
140
|
+
AlertCta,
|
|
125
141
|
{
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
action,
|
|
143
|
+
ctaLabel,
|
|
144
|
+
ctaProps,
|
|
145
|
+
isTrailing: false
|
|
128
146
|
}
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
ctaLabel,
|
|
137
|
-
ctaProps,
|
|
138
|
-
isTrailing
|
|
139
|
-
}
|
|
140
|
-
)
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
)
|
|
144
|
-
] }),
|
|
147
|
+
)
|
|
148
|
+
] })
|
|
149
|
+
] }),
|
|
150
|
+
isTrailing && /* @__PURE__ */ jsx(AlertCta, { action, ctaLabel, ctaProps, isTrailing: true })
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
),
|
|
145
154
|
closable && /* @__PURE__ */ jsx(
|
|
146
155
|
IconButton,
|
|
147
156
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.mjs","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":[],"mappings":";;;;;;;;;;;;AAiCA,MAAM,gBAAuD;AAAA,EAC3D,MAAM,oBAAC,UAAA,EAAS,MAAM,IAAI,QAAM,MAAC;AAAA,EACjC,SAAS,oBAAC,gBAAA,EAAe,MAAM,IAAI,QAAM,MAAC;AAAA,EAC1C,SAAS,oBAAC,WAAA,EAAU,MAAM,IAAI,QAAM,MAAC;AAAA,EACrC,OAAO,oBAAC,aAAA,EAAY,MAAM,IAAI,QAAM,MAAC;AAAA,EACrC,SAAS,oBAAC,UAAA,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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gBAGtC,UAAA;AAAA,kBAAA,qBAAC,OAAA,EAAI,MAAK,SAAQ,WAAW,GAAG,uBAAuB,cAAc,gBAAgB,GAClF,UAAA;AAAA,oBAAA,SACC;AAAA,sBAAC;AAAA,sBAAA;AAAA,wBACC,WAAW,GAAG,uCAAuC,gBAAgB,OAAO,CAAC;AAAA,wBAE5E,UAAA;AAAA,sBAAA;AAAA,oBAAA;AAAA,oBAGJ,WACC,oBAAC,OAAA,EAAI,WAAW,GAAG,sCAAsC,gBAAgB,OAAO,CAAC,GAC9E,SAAA,CACH,IACE;AAAA,kBAAA,GACN;AAAA,kBACA;AAAA,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,YACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,SAAS;AAAA,cACT,cAAY;AAAA,cACZ,MAAM,oBAAC,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.mjs","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":[],"mappings":";;;;;;;;;;;;AAiCA,MAAM,gBAAuD;AAAA,EAC3D,MAAM,oBAAC,UAAA,EAAS,MAAM,IAAI,QAAM,MAAC;AAAA,EACjC,SAAS,oBAAC,gBAAA,EAAe,MAAM,IAAI,QAAM,MAAC;AAAA,EAC1C,SAAS,oBAAC,WAAA,EAAU,MAAM,IAAI,QAAM,MAAC;AAAA,EACrC,OAAO,oBAAC,aAAA,EAAY,MAAM,IAAI,QAAM,MAAC;AAAA,EACrC,SAAS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MAAM,oBAAC,WAAA,EAAU,MAAM,GAAA,CAAI;AAAA,YAAA;AAAA,UAAA;AAAA,QAC7B;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,MAAM,cAAc;"}
|
|
@@ -136,9 +136,13 @@ const RollingNumber = React.forwardRef(
|
|
|
136
136
|
)
|
|
137
137
|
},
|
|
138
138
|
`digit-${index}`
|
|
139
|
-
) : (
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
) : /* @__PURE__ */ jsx(
|
|
140
|
+
"span",
|
|
141
|
+
{
|
|
142
|
+
style: { height: "1em", lineHeight: "1em" },
|
|
143
|
+
children: char
|
|
144
|
+
},
|
|
145
|
+
`separator-${index}`
|
|
142
146
|
)
|
|
143
147
|
) })
|
|
144
148
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatedNumber.mjs","sources":["../../../src/components/AnimatedNumber/AnimatedNumber.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { usePrefersReducedMotion } from \"@/utils/usePrefersReducedMotion\";\n\n/** How a value change is animated. */\nexport type AnimatedNumberVariant =\n /**\n * Per-digit odometer: each digit column slides to its new value and the box\n * width eases when the digit count changes. Reads as mechanical, so it suits\n * a single headline figure rather than a grid of them.\n */\n | \"roll\"\n /**\n * Interpolates the value and re-formats it each frame, so the whole number\n * counts from old to new. Calmer than `roll` when several figures on a page\n * change at once.\n */\n | \"count\";\n\n/** Props for {@link AnimatedNumber}. */\nexport interface AnimatedNumberProps\n extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n /** The value to display. Animates whenever this changes. */\n value: number;\n /**\n * Turns the value into the displayed string. Receives interpolated values in\n * the `count` variant, so it must handle non-integers.\n * @default String(Math.round(value))\n */\n format?: (value: number) => string;\n /** Which animation to run. @default \"count\" */\n variant?: AnimatedNumberVariant;\n /** Animation duration in milliseconds. @default 500 */\n durationMs?: number;\n}\n\nconst DEFAULT_DURATION_MS = 500;\n\nconst defaultFormat = (value: number) => String(Math.round(value));\n\n/** Decelerating ease, so the value settles rather than stopping abruptly. */\nconst easeOutCubic = (t: number) => 1 - (1 - t) ** 3;\n\nconst DIGITS = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\n\nconst isDigit = (char: string) => char >= \"0\" && char <= \"9\";\n\n/**\n * Animates a number when its value changes, either by rolling each digit like\n * an odometer or by counting through the intermediate values.\n *\n * Both variants collapse to an instant swap under\n * `prefers-reduced-motion: reduce`.\n *\n * The rolling variant stacks all ten digits in each column, so the visual is\n * hidden from assistive technology and the formatted value is exposed once as\n * text instead.\n *\n * @example\n * ```tsx\n * // Headline figure\n * <AnimatedNumber value={totalGross} format={formatPrice} variant=\"roll\" />\n *\n * // Supporting figure\n * <AnimatedNumber value={activeFans} variant=\"count\" />\n * ```\n */\nexport const AnimatedNumber = React.forwardRef<HTMLSpanElement, AnimatedNumberProps>(\n (\n {\n value,\n format = defaultFormat,\n variant = \"count\",\n durationMs = DEFAULT_DURATION_MS,\n className,\n ...props\n },\n ref,\n ) => {\n const reducedMotion = usePrefersReducedMotion();\n\n if (variant === \"roll\") {\n return (\n <RollingNumber\n ref={ref}\n value={value}\n format={format}\n durationMs={reducedMotion ? 0 : durationMs}\n className={className}\n {...props}\n />\n );\n }\n\n return (\n <CountingNumber\n ref={ref}\n value={value}\n format={format}\n durationMs={reducedMotion ? 0 : durationMs}\n className={className}\n {...props}\n />\n );\n },\n);\n\nAnimatedNumber.displayName = \"AnimatedNumber\";\n\ntype VariantProps = Omit<AnimatedNumberProps, \"variant\" | \"format\" | \"durationMs\"> & {\n format: (value: number) => string;\n durationMs: number;\n};\n\nconst CountingNumber = React.forwardRef<HTMLSpanElement, VariantProps>(\n ({ value, format, durationMs, className, ...props }, ref) => {\n const [displayValue, setDisplayValue] = React.useState(value);\n // Tracks what is on screen, so an interrupted tween resumes from there. Storing\n // the abandoned *target* instead would start the next tween from a number that\n // was never displayed, which shows as a jump to the old target before counting\n // on — a refetch or filter change landing mid-animation is enough to hit it.\n const displayRef = React.useRef(value);\n\n React.useEffect(() => {\n const from = displayRef.current;\n if (from === value || durationMs === 0) {\n displayRef.current = value;\n setDisplayValue(value);\n return;\n }\n\n let frame = 0;\n let start: number | undefined;\n\n const step = (now: number) => {\n start ??= now;\n const progress = Math.min((now - start) / durationMs, 1);\n const next = from + (value - from) * easeOutCubic(progress);\n displayRef.current = next;\n setDisplayValue(next);\n if (progress < 1) {\n frame = requestAnimationFrame(step);\n }\n };\n\n frame = requestAnimationFrame(step);\n return () => cancelAnimationFrame(frame);\n }, [value, durationMs]);\n\n return (\n <span ref={ref} className={cn(\"tabular-nums\", className)} {...props}>\n {format(displayValue)}\n </span>\n );\n },\n);\n\nCountingNumber.displayName = \"AnimatedNumber.Counting\";\n\nconst RollingNumber = React.forwardRef<HTMLSpanElement, VariantProps>(\n ({ value, format, durationMs, className, ...props }, ref) => {\n const display = format(value);\n const characters = React.useMemo(() => Array.from(display), [display]);\n\n // Lock the box to its measured width so a change in digit count eases\n // instead of snapping: `width: auto` cannot be transitioned.\n const contentRef = React.useRef<HTMLSpanElement>(null);\n const [boxWidth, setBoxWidth] = React.useState<number>();\n\n // On the render where the width is still `auto` there is nothing to\n // transition from, so the duration is zeroed. This is belt-and-braces rather\n // than load-bearing: `auto` to a length is not interpolatable, so no\n // transition would run either way.\n const hasMeasured = boxWidth !== undefined;\n\n // Re-measure rather than measuring once per `display`: the box is\n // `overflow-hidden`, so a web font landing after the first measurement leaves\n // the locked width too narrow for the wider glyphs and clips the number until\n // the value next changes, which for a headline figure may be never. Observing\n // covers a container change too. Same approach as `useCyclingTextTrackWidth`.\n React.useLayoutEffect(() => {\n const node = contentRef.current;\n if (!node || !display) {\n return;\n }\n\n const measure = () => {\n const measured = node.scrollWidth;\n if (measured) {\n setBoxWidth(measured);\n }\n };\n\n measure();\n\n if (typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, [display]);\n\n return (\n <span\n ref={ref}\n className={cn(\"inline-flex overflow-hidden tabular-nums\", className)}\n style={{\n width: boxWidth,\n transitionProperty: \"width\",\n transitionDuration: hasMeasured ? `${durationMs}ms` : \"0ms\",\n transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n }}\n {...props}\n >\n {/* The digit columns list 0-9 apiece, which assistive tech would read\n out in full, so expose the formatted value as text instead. */}\n <span className=\"sr-only\">{display}</span>\n <span ref={contentRef} aria-hidden className=\"inline-flex whitespace-pre\">\n {characters.map((char, index) =>\n isDigit(char) ? (\n <span\n // biome-ignore lint/suspicious/noArrayIndexKey: a column is a position in the number, so it must keep its identity (and animate) when its digit changes\n key={`digit-${index}`}\n className=\"relative inline-block overflow-hidden\"\n style={{ height: \"1em\", lineHeight: \"1em\" }}\n >\n <span\n className=\"flex flex-col\"\n style={{\n transform: `translateY(-${Number(char) * 10}%)`,\n transitionProperty: \"transform\",\n transitionDuration: `${durationMs}ms`,\n transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n }}\n >\n {DIGITS.map((digit) => (\n <span key={digit} style={{ height: \"1em\", lineHeight: \"1em\" }}>\n {digit}\n </span>\n ))}\n </span>\n </span>\n ) : (\n // biome-ignore lint/suspicious/noArrayIndexKey: same positional identity as the digit columns\n <span key={`separator-${index}`}>{char}</span>\n ),\n )}\n </span>\n </span>\n );\n },\n);\n\nRollingNumber.displayName = \"AnimatedNumber.Rolling\";\n"],"names":[],"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,QAA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,oBAAC,QAAA,EAAK,WAAU,WAAW,UAAA,SAAQ;AAAA,UACnC,oBAAC,UAAK,KAAK,YAAY,eAAW,MAAC,WAAU,8BAC1C,UAAA,WAAW;AAAA,YAAI,CAAC,MAAM,UACrB,QAAQ,IAAI,IACV;AAAA,cAAC;AAAA,cAAA;AAAA,gBAGC,WAAU;AAAA,gBACV,OAAO,EAAE,QAAQ,OAAO,YAAY,MAAA;AAAA,gBAEpC,UAAA;AAAA,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,8BACV,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;AAAA;AAAA,cAsBrB,oBAAC,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.mjs","sources":["../../../src/components/AnimatedNumber/AnimatedNumber.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { usePrefersReducedMotion } from \"@/utils/usePrefersReducedMotion\";\n\n/** How a value change is animated. */\nexport type AnimatedNumberVariant =\n /**\n * Per-digit odometer: each digit column slides to its new value and the box\n * width eases when the digit count changes. Reads as mechanical, so it suits\n * a single headline figure rather than a grid of them.\n */\n | \"roll\"\n /**\n * Interpolates the value and re-formats it each frame, so the whole number\n * counts from old to new. Calmer than `roll` when several figures on a page\n * change at once.\n */\n | \"count\";\n\n/** Props for {@link AnimatedNumber}. */\nexport interface AnimatedNumberProps\n extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n /** The value to display. Animates whenever this changes. */\n value: number;\n /**\n * Turns the value into the displayed string. Receives interpolated values in\n * the `count` variant, so it must handle non-integers.\n * @default String(Math.round(value))\n */\n format?: (value: number) => string;\n /** Which animation to run. @default \"count\" */\n variant?: AnimatedNumberVariant;\n /** Animation duration in milliseconds. @default 500 */\n durationMs?: number;\n}\n\nconst DEFAULT_DURATION_MS = 500;\n\nconst defaultFormat = (value: number) => String(Math.round(value));\n\n/** Decelerating ease, so the value settles rather than stopping abruptly. */\nconst easeOutCubic = (t: number) => 1 - (1 - t) ** 3;\n\nconst DIGITS = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\n\nconst isDigit = (char: string) => char >= \"0\" && char <= \"9\";\n\n/**\n * Animates a number when its value changes, either by rolling each digit like\n * an odometer or by counting through the intermediate values.\n *\n * Both variants collapse to an instant swap under\n * `prefers-reduced-motion: reduce`.\n *\n * The rolling variant stacks all ten digits in each column, so the visual is\n * hidden from assistive technology and the formatted value is exposed once as\n * text instead.\n *\n * @example\n * ```tsx\n * // Headline figure\n * <AnimatedNumber value={totalGross} format={formatPrice} variant=\"roll\" />\n *\n * // Supporting figure\n * <AnimatedNumber value={activeFans} variant=\"count\" />\n * ```\n */\nexport const AnimatedNumber = React.forwardRef<HTMLSpanElement, AnimatedNumberProps>(\n (\n {\n value,\n format = defaultFormat,\n variant = \"count\",\n durationMs = DEFAULT_DURATION_MS,\n className,\n ...props\n },\n ref,\n ) => {\n const reducedMotion = usePrefersReducedMotion();\n\n if (variant === \"roll\") {\n return (\n <RollingNumber\n ref={ref}\n value={value}\n format={format}\n durationMs={reducedMotion ? 0 : durationMs}\n className={className}\n {...props}\n />\n );\n }\n\n return (\n <CountingNumber\n ref={ref}\n value={value}\n format={format}\n durationMs={reducedMotion ? 0 : durationMs}\n className={className}\n {...props}\n />\n );\n },\n);\n\nAnimatedNumber.displayName = \"AnimatedNumber\";\n\ntype VariantProps = Omit<AnimatedNumberProps, \"variant\" | \"format\" | \"durationMs\"> & {\n format: (value: number) => string;\n durationMs: number;\n};\n\nconst CountingNumber = React.forwardRef<HTMLSpanElement, VariantProps>(\n ({ value, format, durationMs, className, ...props }, ref) => {\n const [displayValue, setDisplayValue] = React.useState(value);\n // Tracks what is on screen, so an interrupted tween resumes from there. Storing\n // the abandoned *target* instead would start the next tween from a number that\n // was never displayed, which shows as a jump to the old target before counting\n // on — a refetch or filter change landing mid-animation is enough to hit it.\n const displayRef = React.useRef(value);\n\n React.useEffect(() => {\n const from = displayRef.current;\n if (from === value || durationMs === 0) {\n displayRef.current = value;\n setDisplayValue(value);\n return;\n }\n\n let frame = 0;\n let start: number | undefined;\n\n const step = (now: number) => {\n start ??= now;\n const progress = Math.min((now - start) / durationMs, 1);\n const next = from + (value - from) * easeOutCubic(progress);\n displayRef.current = next;\n setDisplayValue(next);\n if (progress < 1) {\n frame = requestAnimationFrame(step);\n }\n };\n\n frame = requestAnimationFrame(step);\n return () => cancelAnimationFrame(frame);\n }, [value, durationMs]);\n\n return (\n <span ref={ref} className={cn(\"tabular-nums\", className)} {...props}>\n {format(displayValue)}\n </span>\n );\n },\n);\n\nCountingNumber.displayName = \"AnimatedNumber.Counting\";\n\nconst RollingNumber = React.forwardRef<HTMLSpanElement, VariantProps>(\n ({ value, format, durationMs, className, ...props }, ref) => {\n const display = format(value);\n const characters = React.useMemo(() => Array.from(display), [display]);\n\n // Lock the box to its measured width so a change in digit count eases\n // instead of snapping: `width: auto` cannot be transitioned.\n const contentRef = React.useRef<HTMLSpanElement>(null);\n const [boxWidth, setBoxWidth] = React.useState<number>();\n\n // On the render where the width is still `auto` there is nothing to\n // transition from, so the duration is zeroed. This is belt-and-braces rather\n // than load-bearing: `auto` to a length is not interpolatable, so no\n // transition would run either way.\n const hasMeasured = boxWidth !== undefined;\n\n // Re-measure rather than measuring once per `display`: the box is\n // `overflow-hidden`, so a web font landing after the first measurement leaves\n // the locked width too narrow for the wider glyphs and clips the number until\n // the value next changes, which for a headline figure may be never. Observing\n // covers a container change too. Same approach as `useCyclingTextTrackWidth`.\n React.useLayoutEffect(() => {\n const node = contentRef.current;\n if (!node || !display) {\n return;\n }\n\n const measure = () => {\n const measured = node.scrollWidth;\n if (measured) {\n setBoxWidth(measured);\n }\n };\n\n measure();\n\n if (typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, [display]);\n\n return (\n <span\n ref={ref}\n className={cn(\"inline-flex overflow-hidden tabular-nums\", className)}\n style={{\n width: boxWidth,\n transitionProperty: \"width\",\n transitionDuration: hasMeasured ? `${durationMs}ms` : \"0ms\",\n transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n }}\n {...props}\n >\n {/* The digit columns list 0-9 apiece, which assistive tech would read\n out in full, so expose the formatted value as text instead. */}\n <span className=\"sr-only\">{display}</span>\n <span ref={contentRef} aria-hidden className=\"inline-flex whitespace-pre\">\n {characters.map((char, index) =>\n isDigit(char) ? (\n <span\n // biome-ignore lint/suspicious/noArrayIndexKey: a column is a position in the number, so it must keep its identity (and animate) when its digit changes\n key={`digit-${index}`}\n className=\"relative inline-block overflow-hidden\"\n style={{ height: \"1em\", lineHeight: \"1em\" }}\n >\n <span\n className=\"flex flex-col\"\n style={{\n transform: `translateY(-${Number(char) * 10}%)`,\n transitionProperty: \"transform\",\n transitionDuration: `${durationMs}ms`,\n transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n }}\n >\n {DIGITS.map((digit) => (\n <span key={digit} style={{ height: \"1em\", lineHeight: \"1em\" }}>\n {digit}\n </span>\n ))}\n </span>\n </span>\n ) : (\n <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":[],"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,iBAAiB,MAAM;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,gBAAgB,wBAAA;AAEtB,QAAI,YAAY,QAAQ;AACtB,aACE;AAAA,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,WACE;AAAA,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,iBAAiB,MAAM;AAAA,EAC3B,CAAC,EAAE,OAAO,QAAQ,YAAY,WAAW,GAAG,MAAA,GAAS,QAAQ;AAC3D,UAAM,CAAC,cAAc,eAAe,IAAI,MAAM,SAAS,KAAK;AAK5D,UAAM,aAAa,MAAM,OAAO,KAAK;AAErC,UAAM,UAAU,MAAM;AACpB,YAAM,OAAO,WAAW;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,KAAK;AAAA,YAAA;AAAA,UAIzB,EAEJ,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,cAAc,cAAc;"}
|
|
@@ -134,7 +134,7 @@ const Autocomplete = React.forwardRef((props, ref) => {
|
|
|
134
134
|
)
|
|
135
135
|
] }),
|
|
136
136
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [
|
|
137
|
-
loading && /* @__PURE__ */ jsx(SpinnerIcon, {
|
|
137
|
+
loading && /* @__PURE__ */ jsx(SpinnerIcon, { size: 16, spin: true, className: "text-content-secondary" }),
|
|
138
138
|
clearable && ac.hasClearableValue && !disabled && /* @__PURE__ */ jsx(
|
|
139
139
|
"button",
|
|
140
140
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocomplete.mjs","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":["Popover"],"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;AAEA,MAAM,kBAAoD;AAAA,EACxD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,0BAA0B,OAAgB,WAAoB,gBAAyB;AAC9F,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,SAAS,CAAC,aAAa,CAAC,gBAAgB;AAC3C,cAAQ;AAAA,QACN;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AACF;AA4BO,MAAM,eAAe,MAAM,WAAgD,CAAC,OAAO,QAAQ;AAChG,QAAM;AAAA,IACJ;AAAA,IACA,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB;AAAA,IACA,OAAO;AAAA,IACP,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,KAAK,gBAAgB,KAAK;AAEhC,QAAM,oBAAoB,KAAK,MAAM,GAAG,SAAS,OAA2B;AAE5E,4BAA0B,OAAO,WAAW,cAAc;AAE1D,QAAM,aAAa,SAAS,eAAe,eAAe;AAE1D,SACE,oBAACA,iBAAQ,M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AiB,CAAC,MAAM,EAAE,eAAA;AAAA,YAC1B,kBAAkB,CAAC,MAAM,EAAE,eAAA;AAAA,YAC3B,OAAO,EAAE,QAAQ,sCAAA;AAAA,YACjB,WAAW;AAAA,cACT;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,YAGF,UAAA;AAAA,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,UAAA;AAAA,kBAAC;AAAA,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,cACC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,GAAG;AAAA,YACP,WAAW;AAAA,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;"}
|
|
1
|
+
{"version":3,"file":"Autocomplete.mjs","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":["Popover"],"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;AAEA,MAAM,kBAAoD;AAAA,EACxD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,0BAA0B,OAAgB,WAAoB,gBAAyB;AAC9F,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,SAAS,CAAC,aAAa,CAAC,gBAAgB;AAC3C,cAAQ;AAAA,QACN;AAAA,MAAA;AAAA,I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AAqB,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,cACC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,GAAG;AAAA,YACP,WAAW;AAAA,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;"}
|
|
@@ -27,7 +27,7 @@ function AutocompleteDropdownContent({
|
|
|
27
27
|
return (
|
|
28
28
|
// biome-ignore lint/a11y/useSemanticElements: <output> is not appropriate here; using role="status" for live region announcements
|
|
29
29
|
/* @__PURE__ */ jsxs("div", { role: "status", className: "flex items-center justify-center py-4", children: [
|
|
30
|
-
/* @__PURE__ */ jsx(SpinnerIcon, { className: "
|
|
30
|
+
/* @__PURE__ */ jsx(SpinnerIcon, { spin: true, className: "text-content-secondary" }),
|
|
31
31
|
loadingText && /* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-regular ml-2 text-content-secondary", children: loadingText })
|
|
32
32
|
] })
|
|
33
33
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteDropdownContent.mjs","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.mjs","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":[],"mappings":";;;;;AAkCA,SAAS,oBAAoB,EAAE,YAA2C;AACxE,SACE,oBAAC,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;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IAC7B,OAAO,IAAI,CAAC,SAAS,iBAAiB;AACrC,YAAM,YAAY,GAAG,SAAS,UAAU,QAAQ,MAAM,EAAE;AACxD,YAAM,cAAc,qBAChB,mBAAmB,QAAQ,KAAK,IAChC,QAAQ,MAAM;AAClB;AAAA;AAAA,QAEE;AAAA,UAAC;AAAA,UAAA;AAAA,YAEC,MAAK;AAAA,YACL,mBAAiB;AAAA,YACjB,WAAW;AAAA,cACT,eAAe,iBAAiB,KAAK;AAAA,YAAA;AAAA,YAGvC,UAAA;AAAA,cAAA,oBAAC,OAAA,EAAI,MAAK,gBAAe,IAAI,WAC1B,+BACC,cAEA,oBAAC,qBAAA,EAAqB,UAAA,YAAA,CAAY,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,oBACC,oBAAC,OAAA,EAAI,WAAU,yFACZ,UAAA,UAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
|
|
@@ -120,7 +120,7 @@ function getTextContent(node) {
|
|
|
120
120
|
return void 0;
|
|
121
121
|
}
|
|
122
122
|
const LoadingSpinner = ({ size }) => {
|
|
123
|
-
return /* @__PURE__ */ jsx("span", {
|
|
123
|
+
return /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx(SpinnerIcon, { spin: true, className: ICON_SIZE_CLASS[size], children: /* @__PURE__ */ jsx("title", { children: "Loading" }) }) });
|
|
124
124
|
};
|
|
125
125
|
function renderContent({
|
|
126
126
|
loading,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.mjs","sources":["../../../src/components/Button/Button.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport { SpinnerIcon } from \"../Icons/SpinnerIcon\";\n\n/** Visual style variant of the button. */\nexport type ButtonVariant =\n | \"primary\"\n | \"secondary\"\n | \"tertiary\"\n | \"outline\"\n | \"link\"\n | \"brand\"\n | \"destructive\"\n | \"white\"\n | \"alwaysBlack\"\n | \"ai\"\n | \"tertiaryDestructive\"\n | \"text\";\n\n/** Button height in pixels. */\nexport type ButtonSize = \"48\" | \"40\" | \"32\" | \"24\";\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Visual style variant of the button. @default \"primary\" */\n variant?: ButtonVariant;\n /** Height of the button in pixels. @default \"40\" */\n size?: ButtonSize;\n /**\n * Forces the dark-surface treatment regardless of theme. Only honored on\n * `primary`, `secondary`, `tertiary`, and `outline` variants; ignored on\n * all others. Use when placing the button on a dark background in a light\n * theme (e.g. an inverted hero or modal).\n * @default false\n */\n negative?: boolean;\n /** Icon element displayed before the label. */\n leftIcon?: React.ReactNode;\n /** Icon element displayed after the label. */\n rightIcon?: React.ReactNode;\n /** When `true`, replaces the label with a spinner and disables interaction. @default false */\n loading?: boolean;\n /** Merge props onto a child element instead of rendering a `<button>`. @default false */\n asChild?: boolean;\n /** Old price shown with a strikethrough before the current price. */\n discount?: string;\n /** Current price shown inside the button after the label and icons. */\n price?: string;\n /** When `true`, the button will take the full width of its container. @default false */\n fullWidth?: boolean;\n}\n\nconst NEGATIVE_AWARE_VARIANTS = new Set<ButtonVariant>([\n \"primary\",\n \"secondary\",\n \"tertiary\",\n \"outline\",\n]);\n\nconst SIZE_CLASSES: Record<ButtonSize, string> = {\n \"48\": \"h-12 px-6 py-3 typography-body-default-16px-semibold\",\n \"40\": \"h-10 px-4 py-2 typography-body-default-16px-semibold\",\n \"32\": \"h-8 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"24\": \"h-6 px-2 py-1 typography-body-small-14px-semibold\",\n};\n\nconst ICON_SIDE_PADDING_CLASSES: Record<ButtonSize, { left: string; right: string }> = {\n \"48\": { left: \"pl-5\", right: \"pr-5\" },\n \"40\": { left: \"pl-3\", right: \"pr-3\" },\n \"32\": { left: \"pl-2\", right: \"pr-2\" },\n \"24\": { left: \"pl-1\", right: \"pr-1\" },\n};\n\nconst ICON_SIZE_CLASS: Record<ButtonSize, string> = {\n \"48\": \"size-5\",\n \"40\": \"size-5\",\n \"32\": \"size-4\",\n \"24\": \"size-3.5\",\n};\n\n/** Targets only direct SVG children so non-icon content (e.g. Pill) can size naturally. */\nconst ICON_WRAPPER_CLASS: Record<ButtonSize, string> = {\n \"48\": \"[&>svg]:size-5\",\n \"40\": \"[&>svg]:size-5\",\n \"32\": \"[&>svg]:size-4\",\n \"24\": \"[&>svg]:size-3.5\",\n};\n\n/**\n * AI variant paints a flat fill over a fixed-angle gradient stroke. The fill is written\n * as a two-stop gradient of one colour because the border-box/padding-box clip trick\n * that draws the stroke requires both layers to be background images.\n */\nconst AI_GRADIENT =\n \"[background-clip:padding-box,border-box] [background-image:linear-gradient(var(--color-buttons-ai-default),var(--color-buttons-ai-default)),linear-gradient(50deg,var(--color-buttons-ai-stroke-start)_11.87%,var(--color-buttons-ai-stroke-end)_112.39%)] [background-origin:border-box] hover:[background-image:linear-gradient(var(--color-buttons-ai-hover),var(--color-buttons-ai-hover)),linear-gradient(50deg,var(--color-buttons-ai-stroke-start)_11.87%,var(--color-buttons-ai-stroke-end)_112.39%)]\";\n\nconst DISABLED_FILL = \"bg-buttons-disabled-default text-content-disabled\";\nconst DISABLED_FILL_NEGATIVE = \"bg-buttons-disabled-negative text-content-disabled\";\nconst DISABLED_TRANSPARENT = \"bg-transparent text-content-disabled\";\n\n/**\n * Class strings for each `ButtonVariant`, indexed by `negative` and `disabled`\n * state. `negative` and `negativeDisabled` are only honored when the variant\n * is in `NEGATIVE_AWARE_VARIANTS` — other variants fall back to the default /\n * disabled entries regardless of the `negative` prop.\n */\ntype VariantClasses = {\n default: string;\n disabled: string;\n negative?: string;\n negativeDisabled?: string;\n};\n\nconst VARIANT_CLASSES: Record<ButtonVariant, VariantClasses> = {\n primary: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted hover:bg-buttons-primary-hover hover:text-content-primary-inverted active:bg-buttons-primary-hover active:text-content-primary-inverted\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-primary-negative-default text-content-primary hover:bg-buttons-primary-negative-hover active:bg-buttons-primary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n secondary: {\n default:\n \"bg-buttons-secondary-default text-content-primary hover:bg-buttons-secondary-hover active:bg-buttons-secondary-hover\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-secondary-negative-default text-content-primary-inverted hover:bg-buttons-secondary-negative-hover active:bg-buttons-secondary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n tertiary: {\n default:\n \"bg-transparent text-content-primary hover:bg-buttons-tertiary-hover active:bg-buttons-tertiary-hover\",\n disabled: DISABLED_TRANSPARENT,\n negative:\n \"bg-transparent text-content-primary-inverted hover:bg-buttons-tertiary-negative-hover active:bg-buttons-tertiary-negative-hover\",\n negativeDisabled: DISABLED_TRANSPARENT,\n },\n outline: {\n default:\n \"border border-buttons-outline-default bg-transparent text-content-primary hover:bg-buttons-outline-hover active:bg-buttons-outline-hover\",\n disabled: \"border border-buttons-disabled-default bg-transparent text-content-disabled\",\n negative:\n \"border border-buttons-outline-negative-default bg-transparent text-content-primary-inverted hover:bg-buttons-outline-negative-hover active:bg-buttons-outline-negative-hover\",\n negativeDisabled:\n \"border border-buttons-disabled-negative bg-transparent text-content-disabled\",\n },\n brand: {\n default:\n \"bg-buttons-brand-default text-content-always-black hover:bg-buttons-brand-hover hover:text-content-always-black active:bg-buttons-brand-hover active:text-content-always-black\",\n disabled: DISABLED_FILL,\n },\n destructive: {\n default:\n \"bg-buttons-error-default text-content-always-white hover:bg-buttons-error-hover hover:text-content-always-white active:bg-buttons-error-hover active:text-content-always-white\",\n disabled: DISABLED_FILL,\n },\n white: {\n default:\n \"bg-buttons-always-white-default text-content-always-black hover:bg-buttons-always-white-hover hover:text-content-always-black active:bg-buttons-always-white-hover active:text-content-always-black\",\n disabled: DISABLED_FILL,\n },\n alwaysBlack: {\n default:\n \"bg-buttons-always-black-default text-content-always-white hover:bg-buttons-always-black-hover hover:text-content-always-white active:bg-buttons-always-black-hover active:text-content-always-white\",\n disabled: DISABLED_FILL,\n },\n ai: {\n default: `border border-transparent text-content-primary shadow-ai-button-glow ${AI_GRADIENT}`,\n disabled: DISABLED_FILL,\n },\n link: {\n default:\n \"bg-transparent text-content-primary underline decoration-solid hover:bg-buttons-tertiary-hover active:bg-buttons-tertiary-hover\",\n disabled: \"bg-transparent text-content-primary underline decoration-solid opacity-50\",\n },\n tertiaryDestructive: {\n default: \"bg-transparent text-error-content hover:bg-error-surface active:bg-error-surface\",\n disabled: \"bg-transparent text-error-content opacity-50\",\n },\n text: {\n default: \"bg-transparent text-content-primary hover:underline active:underline\",\n disabled: \"bg-transparent text-content-primary opacity-50\",\n },\n};\n\nfunction getVariantClasses(variant: ButtonVariant, negative: boolean, disabled: boolean): string {\n const spec = VARIANT_CLASSES[variant];\n const isNegative = NEGATIVE_AWARE_VARIANTS.has(variant) && negative;\n if (disabled) return (isNegative && spec.negativeDisabled) || spec.disabled;\n return (isNegative && spec.negative) || spec.default;\n}\n\nfunction getIconPaddingClasses(\n size: ButtonSize,\n hasLeftIcon: boolean,\n hasRightIcon: boolean,\n): string | undefined {\n const padding = ICON_SIDE_PADDING_CLASSES[size];\n return cn(hasLeftIcon && padding.left, hasRightIcon && padding.right);\n}\n\n/** Recursively extract text content from React nodes for accessible labels */\nfunction getTextContent(node: React.ReactNode): string | undefined {\n if (typeof node === \"string\") return node;\n if (typeof node === \"number\") return String(node);\n if (React.isValidElement(node)) {\n return getTextContent((node.props as { children?: React.ReactNode }).children);\n }\n if (Array.isArray(node)) {\n const text = node.map(getTextContent).filter(Boolean).join(\"\");\n return text || undefined;\n }\n return undefined;\n}\n\nconst LoadingSpinner = ({ size }: { size: ButtonSize }) => {\n return (\n <span className=\"animate-spin\" aria-hidden=\"true\">\n <SpinnerIcon className={ICON_SIZE_CLASS[size]}>\n <title>Loading</title>\n </SpinnerIcon>\n </span>\n );\n};\n\nfunction renderContent({\n loading,\n asChild,\n children,\n size,\n leftIcon,\n rightIcon,\n iconSizeClass,\n discount,\n price,\n}: {\n loading: boolean;\n asChild: boolean;\n children: React.ReactNode;\n size: ButtonSize;\n leftIcon: React.ReactNode;\n rightIcon: React.ReactNode;\n iconSizeClass: string;\n discount?: string;\n price?: string;\n fullWidth?: boolean;\n}) {\n if (loading) {\n if (asChild && React.isValidElement(children)) {\n return React.cloneElement(\n children as React.ReactElement<{ children?: React.ReactNode }>,\n undefined,\n <LoadingSpinner size={size} />,\n );\n }\n return (\n <>\n <LoadingSpinner size={size} />\n <span className=\"sr-only\">{children}</span>\n </>\n );\n }\n\n if (asChild) return children;\n\n return (\n <>\n {leftIcon && (\n <span\n className={cn(\"flex shrink-0 items-center justify-center\", iconSizeClass)}\n aria-hidden=\"true\"\n >\n {leftIcon}\n </span>\n )}\n {React.Children.map(children, (child) =>\n typeof child === \"string\" ? (\n child.trim() ? (\n <span className=\"min-w-0 truncate\">{child}</span>\n ) : null\n ) : typeof child === \"number\" ? (\n <span className=\"min-w-0 truncate\">{child}</span>\n ) : (\n child\n ),\n )}\n {rightIcon && (\n <span\n className={cn(\"flex shrink-0 items-center justify-center\", iconSizeClass)}\n aria-hidden=\"true\"\n >\n {rightIcon}\n </span>\n )}\n {(price || discount) && (\n <div>\n {discount && (\n <span className=\"typography-body-default-16px-regular line-through\" aria-hidden=\"true\">\n {discount}\n </span>\n )}\n {price && (\n <span className=\"ml-2\" aria-hidden=\"true\">\n {price}\n </span>\n )}\n </div>\n )}\n </>\n );\n}\n\n/**\n * A versatile button component with multiple visual variants, sizes, icon\n * slots, loading state, and optional pricing display.\n *\n * Pass `negative` when rendering on a dark surface to opt into the inverted\n * treatment for `primary`, `secondary`, `tertiary`, and `outline` variants.\n *\n * The `ai` variant ships with the AI sparkle icon baked in (locked at 16px\n * regardless of button size); pass `leftIcon` to override the default sparkle.\n *\n * @example\n * ```tsx\n * <Button variant=\"primary\" size=\"40\" leftIcon={<StarIcon />}>\n * Continue\n * </Button>\n * ```\n */\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n className,\n variant = \"primary\",\n size = \"40\",\n negative = false,\n leftIcon,\n rightIcon,\n loading = false,\n asChild = false,\n disabled,\n children,\n discount,\n price,\n fullWidth = false,\n ...props\n },\n ref,\n ) => {\n const Comp = asChild ? Slot : \"button\";\n const isDisabled = Boolean(disabled);\n const isInteractionDisabled = isDisabled || loading;\n const iconSizeClass = variant === \"ai\" ? \"[&>svg]:size-4\" : ICON_WRAPPER_CLASS[size];\n const effectiveLeftIcon = leftIcon ?? (variant === \"ai\" ? <AIIcon filled /> : undefined);\n const iconPaddingClasses = getIconPaddingClasses(\n size,\n Boolean(effectiveLeftIcon),\n Boolean(rightIcon),\n );\n\n const buttonSpecificProps = !asChild\n ? {\n type: \"button\" as const,\n \"data-testid\": \"button\",\n disabled: isInteractionDisabled,\n }\n : isInteractionDisabled\n ? { \"aria-disabled\": true }\n : {};\n\n const loadingLabelProps = loading && asChild ? { \"aria-label\": getTextContent(children) } : {};\n\n const content = renderContent({\n loading,\n asChild,\n children,\n size,\n leftIcon: effectiveLeftIcon,\n rightIcon,\n iconSizeClass,\n discount,\n price,\n });\n\n return (\n <Comp\n ref={ref}\n {...buttonSpecificProps}\n aria-busy={loading}\n {...loadingLabelProps}\n className={cn(\n \"inline-flex min-w-0 cursor-pointer items-center gap-2 whitespace-nowrap rounded-full transition-colors\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n isInteractionDisabled && \"pointer-events-none cursor-not-allowed\",\n `${price ? \"justify-between\" : \"justify-center\"}`,\n fullWidth && \"w-full\",\n SIZE_CLASSES[size],\n iconPaddingClasses,\n getVariantClasses(variant, negative, isDisabled),\n className,\n )}\n {...props}\n >\n {content}\n </Comp>\n );\n },\n);\n\nButton.displayName = \"Button\";\n"],"names":[],"mappings":";;;;;;;AAqDA,MAAM,8CAA8B,IAAmB;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,MAAM,eAA2C;AAAA,EAC/C,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,4BAAiF;AAAA,EACrF,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAAA,EAC7B,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAAA,EAC7B,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAAA,EAC7B,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAC/B;AAEA,MAAM,kBAA8C;AAAA,EAClD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,qBAAiD;AAAA,EACrD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,cACJ;AAEF,MAAM,gBAAgB;AACtB,MAAM,yBAAyB;AAC/B,MAAM,uBAAuB;AAe7B,MAAM,kBAAyD;AAAA,EAC7D,SAAS;AAAA,IACP,SACE;AAAA,IACF,UAAU;AAAA,IACV,UACE;AAAA,IACF,kBAAkB;AAAA,EAAA;AAAA,EAEpB,WAAW;AAAA,IACT,SACE;AAAA,IACF,UAAU;AAAA,IACV,UACE;AAAA,IACF,kBAAkB;AAAA,EAAA;AAAA,EAEpB,UAAU;AAAA,IACR,SACE;AAAA,IACF,UAAU;AAAA,IACV,UACE;AAAA,IACF,kBAAkB;AAAA,EAAA;AAAA,EAEpB,SAAS;AAAA,IACP,SACE;AAAA,IACF,UAAU;AAAA,IACV,UACE;AAAA,IACF,kBACE;AAAA,EAAA;AAAA,EAEJ,OAAO;AAAA,IACL,SACE;AAAA,IACF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ACV,GAAG;AAAA,QACJ,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA,yBAAyB;AAAA,UACzB,GAAG,QAAQ,oBAAoB,gBAAgB;AAAA,UAC/C,aAAa;AAAA,UACb,aAAa,IAAI;AAAA,UACjB;AAAA,UACA,kBAAkB,SAAS,UAAU,UAAU;AAAA,UAC/C;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AAEA,OAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Button.mjs","sources":["../../../src/components/Button/Button.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport { SpinnerIcon } from \"../Icons/SpinnerIcon\";\n\n/** Visual style variant of the button. */\nexport type ButtonVariant =\n | \"primary\"\n | \"secondary\"\n | \"tertiary\"\n | \"outline\"\n | \"link\"\n | \"brand\"\n | \"destructive\"\n | \"white\"\n | \"alwaysBlack\"\n | \"ai\"\n | \"tertiaryDestructive\"\n | \"text\";\n\n/** Button height in pixels. */\nexport type ButtonSize = \"48\" | \"40\" | \"32\" | \"24\";\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Visual style variant of the button. @default \"primary\" */\n variant?: ButtonVariant;\n /** Height of the button in pixels. @default \"40\" */\n size?: ButtonSize;\n /**\n * Forces the dark-surface treatment regardless of theme. Only honored on\n * `primary`, `secondary`, `tertiary`, and `outline` variants; ignored on\n * all others. Use when placing the button on a dark background in a light\n * theme (e.g. an inverted hero or modal).\n * @default false\n */\n negative?: boolean;\n /** Icon element displayed before the label. */\n leftIcon?: React.ReactNode;\n /** Icon element displayed after the label. */\n rightIcon?: React.ReactNode;\n /** When `true`, replaces the label with a spinner and disables interaction. @default false */\n loading?: boolean;\n /** Merge props onto a child element instead of rendering a `<button>`. @default false */\n asChild?: boolean;\n /** Old price shown with a strikethrough before the current price. */\n discount?: string;\n /** Current price shown inside the button after the label and icons. */\n price?: string;\n /** When `true`, the button will take the full width of its container. @default false */\n fullWidth?: boolean;\n}\n\nconst NEGATIVE_AWARE_VARIANTS = new Set<ButtonVariant>([\n \"primary\",\n \"secondary\",\n \"tertiary\",\n \"outline\",\n]);\n\nconst SIZE_CLASSES: Record<ButtonSize, string> = {\n \"48\": \"h-12 px-6 py-3 typography-body-default-16px-semibold\",\n \"40\": \"h-10 px-4 py-2 typography-body-default-16px-semibold\",\n \"32\": \"h-8 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"24\": \"h-6 px-2 py-1 typography-body-small-14px-semibold\",\n};\n\nconst ICON_SIDE_PADDING_CLASSES: Record<ButtonSize, { left: string; right: string }> = {\n \"48\": { left: \"pl-5\", right: \"pr-5\" },\n \"40\": { left: \"pl-3\", right: \"pr-3\" },\n \"32\": { left: \"pl-2\", right: \"pr-2\" },\n \"24\": { left: \"pl-1\", right: \"pr-1\" },\n};\n\nconst ICON_SIZE_CLASS: Record<ButtonSize, string> = {\n \"48\": \"size-5\",\n \"40\": \"size-5\",\n \"32\": \"size-4\",\n \"24\": \"size-3.5\",\n};\n\n/** Targets only direct SVG children so non-icon content (e.g. Pill) can size naturally. */\nconst ICON_WRAPPER_CLASS: Record<ButtonSize, string> = {\n \"48\": \"[&>svg]:size-5\",\n \"40\": \"[&>svg]:size-5\",\n \"32\": \"[&>svg]:size-4\",\n \"24\": \"[&>svg]:size-3.5\",\n};\n\n/**\n * AI variant paints a flat fill over a fixed-angle gradient stroke. The fill is written\n * as a two-stop gradient of one colour because the border-box/padding-box clip trick\n * that draws the stroke requires both layers to be background images.\n */\nconst AI_GRADIENT =\n \"[background-clip:padding-box,border-box] [background-image:linear-gradient(var(--color-buttons-ai-default),var(--color-buttons-ai-default)),linear-gradient(50deg,var(--color-buttons-ai-stroke-start)_11.87%,var(--color-buttons-ai-stroke-end)_112.39%)] [background-origin:border-box] hover:[background-image:linear-gradient(var(--color-buttons-ai-hover),var(--color-buttons-ai-hover)),linear-gradient(50deg,var(--color-buttons-ai-stroke-start)_11.87%,var(--color-buttons-ai-stroke-end)_112.39%)]\";\n\nconst DISABLED_FILL = \"bg-buttons-disabled-default text-content-disabled\";\nconst DISABLED_FILL_NEGATIVE = \"bg-buttons-disabled-negative text-content-disabled\";\nconst DISABLED_TRANSPARENT = \"bg-transparent text-content-disabled\";\n\n/**\n * Class strings for each `ButtonVariant`, indexed by `negative` and `disabled`\n * state. `negative` and `negativeDisabled` are only honored when the variant\n * is in `NEGATIVE_AWARE_VARIANTS` — other variants fall back to the default /\n * disabled entries regardless of the `negative` prop.\n */\ntype VariantClasses = {\n default: string;\n disabled: string;\n negative?: string;\n negativeDisabled?: string;\n};\n\nconst VARIANT_CLASSES: Record<ButtonVariant, VariantClasses> = {\n primary: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted hover:bg-buttons-primary-hover hover:text-content-primary-inverted active:bg-buttons-primary-hover active:text-content-primary-inverted\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-primary-negative-default text-content-primary hover:bg-buttons-primary-negative-hover active:bg-buttons-primary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n secondary: {\n default:\n \"bg-buttons-secondary-default text-content-primary hover:bg-buttons-secondary-hover active:bg-buttons-secondary-hover\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-secondary-negative-default text-content-primary-inverted hover:bg-buttons-secondary-negative-hover active:bg-buttons-secondary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n tertiary: {\n default:\n \"bg-transparent text-content-primary hover:bg-buttons-tertiary-hover active:bg-buttons-tertiary-hover\",\n disabled: DISABLED_TRANSPARENT,\n negative:\n \"bg-transparent text-content-primary-inverted hover:bg-buttons-tertiary-negative-hover active:bg-buttons-tertiary-negative-hover\",\n negativeDisabled: DISABLED_TRANSPARENT,\n },\n outline: {\n default:\n \"border border-buttons-outline-default bg-transparent text-content-primary hover:bg-buttons-outline-hover active:bg-buttons-outline-hover\",\n disabled: \"border border-buttons-disabled-default bg-transparent text-content-disabled\",\n negative:\n \"border border-buttons-outline-negative-default bg-transparent text-content-primary-inverted hover:bg-buttons-outline-negative-hover active:bg-buttons-outline-negative-hover\",\n negativeDisabled:\n \"border border-buttons-disabled-negative bg-transparent text-content-disabled\",\n },\n brand: {\n default:\n \"bg-buttons-brand-default text-content-always-black hover:bg-buttons-brand-hover hover:text-content-always-black active:bg-buttons-brand-hover active:text-content-always-black\",\n disabled: DISABLED_FILL,\n },\n destructive: {\n default:\n \"bg-buttons-error-default text-content-always-white hover:bg-buttons-error-hover hover:text-content-always-white active:bg-buttons-error-hover active:text-content-always-white\",\n disabled: DISABLED_FILL,\n },\n white: {\n default:\n \"bg-buttons-always-white-default text-content-always-black hover:bg-buttons-always-white-hover hover:text-content-always-black active:bg-buttons-always-white-hover active:text-content-always-black\",\n disabled: DISABLED_FILL,\n },\n alwaysBlack: {\n default:\n \"bg-buttons-always-black-default text-content-always-white hover:bg-buttons-always-black-hover hover:text-content-always-white active:bg-buttons-always-black-hover active:text-content-always-white\",\n disabled: DISABLED_FILL,\n },\n ai: {\n default: `border border-transparent text-content-primary shadow-ai-button-glow ${AI_GRADIENT}`,\n disabled: DISABLED_FILL,\n },\n link: {\n default:\n \"bg-transparent text-content-primary underline decoration-solid hover:bg-buttons-tertiary-hover active:bg-buttons-tertiary-hover\",\n disabled: \"bg-transparent text-content-primary underline decoration-solid opacity-50\",\n },\n tertiaryDestructive: {\n default: \"bg-transparent text-error-content hover:bg-error-surface active:bg-error-surface\",\n disabled: \"bg-transparent text-error-content opacity-50\",\n },\n text: {\n default: \"bg-transparent text-content-primary hover:underline active:underline\",\n disabled: \"bg-transparent text-content-primary opacity-50\",\n },\n};\n\nfunction getVariantClasses(variant: ButtonVariant, negative: boolean, disabled: boolean): string {\n const spec = VARIANT_CLASSES[variant];\n const isNegative = NEGATIVE_AWARE_VARIANTS.has(variant) && negative;\n if (disabled) return (isNegative && spec.negativeDisabled) || spec.disabled;\n return (isNegative && spec.negative) || spec.default;\n}\n\nfunction getIconPaddingClasses(\n size: ButtonSize,\n hasLeftIcon: boolean,\n hasRightIcon: boolean,\n): string | undefined {\n const padding = ICON_SIDE_PADDING_CLASSES[size];\n return cn(hasLeftIcon && padding.left, hasRightIcon && padding.right);\n}\n\n/** Recursively extract text content from React nodes for accessible labels */\nfunction getTextContent(node: React.ReactNode): string | undefined {\n if (typeof node === \"string\") return node;\n if (typeof node === \"number\") return String(node);\n if (React.isValidElement(node)) {\n return getTextContent((node.props as { children?: React.ReactNode }).children);\n }\n if (Array.isArray(node)) {\n const text = node.map(getTextContent).filter(Boolean).join(\"\");\n return text || undefined;\n }\n return undefined;\n}\n\nconst LoadingSpinner = ({ size }: { size: ButtonSize }) => {\n return (\n <span aria-hidden=\"true\">\n <SpinnerIcon spin className={ICON_SIZE_CLASS[size]}>\n <title>Loading</title>\n </SpinnerIcon>\n </span>\n );\n};\n\nfunction renderContent({\n loading,\n asChild,\n children,\n size,\n leftIcon,\n rightIcon,\n iconSizeClass,\n discount,\n price,\n}: {\n loading: boolean;\n asChild: boolean;\n children: React.ReactNode;\n size: ButtonSize;\n leftIcon: React.ReactNode;\n rightIcon: React.ReactNode;\n iconSizeClass: string;\n discount?: string;\n price?: string;\n fullWidth?: boolean;\n}) {\n if (loading) {\n if (asChild && React.isValidElement(children)) {\n return React.cloneElement(\n children as React.ReactElement<{ children?: React.ReactNode }>,\n undefined,\n <LoadingSpinner size={size} />,\n );\n }\n return (\n <>\n <LoadingSpinner size={size} />\n <span className=\"sr-only\">{children}</span>\n </>\n );\n }\n\n if (asChild) return children;\n\n return (\n <>\n {leftIcon && (\n <span\n className={cn(\"flex shrink-0 items-center justify-center\", iconSizeClass)}\n aria-hidden=\"true\"\n >\n {leftIcon}\n </span>\n )}\n {React.Children.map(children, (child) =>\n typeof child === \"string\" ? (\n child.trim() ? (\n <span className=\"min-w-0 truncate\">{child}</span>\n ) : null\n ) : typeof child === \"number\" ? (\n <span className=\"min-w-0 truncate\">{child}</span>\n ) : (\n child\n ),\n )}\n {rightIcon && (\n <span\n className={cn(\"flex shrink-0 items-center justify-center\", iconSizeClass)}\n aria-hidden=\"true\"\n >\n {rightIcon}\n </span>\n )}\n {(price || discount) && (\n <div>\n {discount && (\n <span className=\"typography-body-default-16px-regular line-through\" aria-hidden=\"true\">\n {discount}\n </span>\n )}\n {price && (\n <span className=\"ml-2\" aria-hidden=\"true\">\n {price}\n </span>\n )}\n </div>\n )}\n </>\n );\n}\n\n/**\n * A versatile button component with multiple visual variants, sizes, icon\n * slots, loading state, and optional pricing display.\n *\n * Pass `negative` when rendering on a dark surface to opt into the inverted\n * treatment for `primary`, `secondary`, `tertiary`, and `outline` variants.\n *\n * The `ai` variant ships with the AI sparkle icon baked in (locked at 16px\n * regardless of button size); pass `leftIcon` to override the default sparkle.\n *\n * @example\n * ```tsx\n * <Button variant=\"primary\" size=\"40\" leftIcon={<StarIcon />}>\n * Continue\n * </Button>\n * ```\n */\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n className,\n variant = \"primary\",\n size = \"40\",\n negative = false,\n leftIcon,\n rightIcon,\n loading = false,\n asChild = false,\n disabled,\n children,\n discount,\n price,\n fullWidth = false,\n ...props\n },\n ref,\n ) => {\n const Comp = asChild ? Slot : \"button\";\n const isDisabled = Boolean(disabled);\n const isInteractionDisabled = isDisabled || loading;\n const iconSizeClass = variant === \"ai\" ? \"[&>svg]:size-4\" : ICON_WRAPPER_CLASS[size];\n const effectiveLeftIcon = leftIcon ?? (variant === \"ai\" ? <AIIcon filled /> : undefined);\n const iconPaddingClasses = getIconPaddingClasses(\n size,\n Boolean(effectiveLeftIcon),\n Boolean(rightIcon),\n );\n\n const buttonSpecificProps = !asChild\n ? {\n type: \"button\" as const,\n \"data-testid\": \"button\",\n disabled: isInteractionDisabled,\n }\n : isInteractionDisabled\n ? { \"aria-disabled\": true }\n : {};\n\n const loadingLabelProps = loading && asChild ? { \"aria-label\": getTextContent(children) } : {};\n\n const content = renderContent({\n loading,\n asChild,\n children,\n size,\n leftIcon: effectiveLeftIcon,\n rightIcon,\n iconSizeClass,\n discount,\n price,\n });\n\n return (\n <Comp\n ref={ref}\n {...buttonSpecificProps}\n aria-busy={loading}\n {...loadingLabelProps}\n className={cn(\n \"inline-flex min-w-0 cursor-pointer items-center gap-2 whitespace-nowrap rounded-full transition-colors\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n isInteractionDisabled && \"pointer-events-none cursor-not-allowed\",\n `${price ? \"justify-between\" : \"justify-center\"}`,\n fullWidth && \"w-full\",\n SIZE_CLASSES[size],\n iconPaddingClasses,\n getVariantClasses(variant, negative, isDisabled),\n className,\n )}\n {...props}\n >\n {content}\n </Comp>\n );\n },\n);\n\nButton.displayName = \"Button\";\n"],"names":[],"mappings":";;;;;;;AAqDA,MAAM,8CAA8B,IAAmB;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,MAAM,eAA2C;AAAA,EAC/C,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,4BAAiF;AAAA,EACrF,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAAA,EAC7B,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAAA,EAC7B,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAAA,EAC7B,MAAM,EAAE,MAAM,QAAQ,OAAO,OAAA;AAC/B;AAEA,MAAM,kBAA8C;AAAA,EAClD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,qBAAiD;AAAA,EACrD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,cACJ;AAEF,MAAM,gBAAgB;AACtB,MAAM,yBAAyB;AA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SAAS;AAAA,IAAA;AAGnB,UAAM,sBAAsB,CAAC,UACzB;AAAA,MACE,MAAM;AAAA,MACN,eAAe;AAAA,MACf,UAAU;AAAA,IAAA,IAEZ,wBACE,EAAE,iBAAiB,KAAA,IACnB,CAAA;AAEN,UAAM,oBAAoB,WAAW,UAAU,EAAE,cAAc,eAAe,QAAQ,EAAA,IAAM,CAAA;AAE5F,UAAM,UAAU,cAAc;AAAA,MAC5B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAED,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACC,GAAG;AAAA,QACJ,aAAW;AAAA,QACV,GAAG;AAAA,QACJ,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA,yBAAyB;AAAA,UACzB,GAAG,QAAQ,oBAAoB,gBAAgB;AAAA,UAC/C,aAAa;AAAA,UACb,aAAa,IAAI;AAAA,UACjB;AAAA,UACA,kBAAkB,SAAS,UAAU,UAAU;AAAA,UAC/C;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AAEA,OAAO,cAAc;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CartesianGrid, DefaultZIndexes, ReferenceLine } from "recharts";
|
|
4
|
+
const GRID_STROKE = "var(--color-neutral-alphas-200)";
|
|
5
|
+
const BASELINE_STROKE = "var(--color-border-strong)";
|
|
6
|
+
const zeroRow = ({ yAxis }) => {
|
|
7
|
+
const y = yAxis?.scale?.map(0);
|
|
8
|
+
return typeof y === "number" && Number.isFinite(y) ? [y] : [];
|
|
9
|
+
};
|
|
10
|
+
function ChartGrid({ xAxisId, yAxisId, ...props }) {
|
|
11
|
+
const axes = { xAxisId, yAxisId };
|
|
12
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
13
|
+
/* @__PURE__ */ jsx(
|
|
14
|
+
CartesianGrid,
|
|
15
|
+
{
|
|
16
|
+
vertical: false,
|
|
17
|
+
...axes,
|
|
18
|
+
...props,
|
|
19
|
+
stroke: GRID_STROKE,
|
|
20
|
+
strokeOpacity: 0.4
|
|
21
|
+
}
|
|
22
|
+
),
|
|
23
|
+
/* @__PURE__ */ jsx(
|
|
24
|
+
CartesianGrid,
|
|
25
|
+
{
|
|
26
|
+
vertical: false,
|
|
27
|
+
...axes,
|
|
28
|
+
horizontalCoordinatesGenerator: zeroRow,
|
|
29
|
+
stroke: BASELINE_STROKE,
|
|
30
|
+
zIndex: DefaultZIndexes.line
|
|
31
|
+
}
|
|
32
|
+
),
|
|
33
|
+
/* @__PURE__ */ jsx(ReferenceLine, { ...axes, y: 0, stroke: "none", ifOverflow: "extendDomain" })
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
ChartGrid.displayName = "ChartGrid";
|
|
37
|
+
export {
|
|
38
|
+
ChartGrid
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=ChartGrid.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartGrid.mjs","sources":["../../../src/components/Chart/ChartGrid.tsx"],"sourcesContent":["import type * as React from \"react\";\nimport { CartesianGrid, DefaultZIndexes, ReferenceLine } from \"recharts\";\nimport type { HorizontalCoordinatesGenerator } from \"recharts/types/cartesian/CartesianGrid\";\n\n/**\n * Props for {@link ChartGrid}. Forwarded to Recharts' `CartesianGrid`; `xAxisId` and\n * `yAxisId` also place the zero baseline. The line colour, opacity and dash are fixed by\n * the design system, so `stroke`, `strokeOpacity` and `strokeDasharray` are not accepted.\n */\nexport type ChartGridProps = Omit<\n React.ComponentProps<typeof CartesianGrid>,\n \"stroke\" | \"strokeOpacity\" | \"strokeDasharray\"\n>;\n\nconst GRID_STROKE = \"var(--color-neutral-alphas-200)\";\nconst BASELINE_STROKE = \"var(--color-border-strong)\";\n\nconst zeroRow: HorizontalCoordinatesGenerator = ({ yAxis }) => {\n const y = yAxis?.scale?.map(0);\n return typeof y === \"number\" && Number.isFinite(y) ? [y] : [];\n};\n\n/**\n * The design-system grid for cartesian charts: faint solid horizontal lines\n * (`neutral-alphas-200` at 40%) and a stronger `border-strong` baseline at value 0.\n * Render it as a direct child of a Recharts `<LineChart>`, `<AreaChart>` or `<BarChart>`,\n * and leave `<YAxis domain>` at its default.\n *\n * The baseline is a one-row grid placed by the y scale, not a visible `ReferenceLine`,\n * because Recharts draws no `ReferenceLine` while `data` is empty (there is no x scale).\n * The hidden `ReferenceLine` only keeps 0 inside the y domain when every value is negative.\n *\n * @example\n * ```tsx\n * <ChartContainer config={chartConfig}>\n * <LineChart data={data}>\n * <ChartGrid />\n * <XAxis dataKey=\"day\" />\n * <YAxis />\n * <Line dataKey=\"net\" stroke=\"var(--color-net)\" />\n * </LineChart>\n * </ChartContainer>\n * ```\n */\nexport function ChartGrid({ xAxisId, yAxisId, ...props }: ChartGridProps) {\n const axes = { xAxisId, yAxisId };\n return (\n <>\n <CartesianGrid\n vertical={false}\n {...axes}\n {...props}\n stroke={GRID_STROKE}\n strokeOpacity={0.4}\n />\n <CartesianGrid\n vertical={false}\n {...axes}\n horizontalCoordinatesGenerator={zeroRow}\n stroke={BASELINE_STROKE}\n zIndex={DefaultZIndexes.line}\n />\n <ReferenceLine {...axes} y={0} stroke=\"none\" ifOverflow=\"extendDomain\" />\n </>\n );\n}\n\nChartGrid.displayName = \"ChartGrid\";\n"],"names":[],"mappings":";;;AAcA,MAAM,cAAc;AACpB,MAAM,kBAAkB;AAExB,MAAM,UAA0C,CAAC,EAAE,YAAY;AAC7D,QAAM,IAAI,OAAO,OAAO,IAAI,CAAC;AAC7B,SAAO,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAA;AAC7D;AAwBO,SAAS,UAAU,EAAE,SAAS,SAAS,GAAG,SAAyB;AACxE,QAAM,OAAO,EAAE,SAAS,QAAA;AACxB,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAU;AAAA,QACT,GAAG;AAAA,QACH,GAAG;AAAA,QACJ,QAAQ;AAAA,QACR,eAAe;AAAA,MAAA;AAAA,IAAA;AAAA,IAEjB;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAU;AAAA,QACT,GAAG;AAAA,QACJ,gCAAgC;AAAA,QAChC,QAAQ;AAAA,QACR,QAAQ,gBAAgB;AAAA,MAAA;AAAA,IAAA;AAAA,IAE1B,oBAAC,iBAAe,GAAG,MAAM,GAAG,GAAG,QAAO,QAAO,YAAW,eAAA,CAAe;AAAA,EAAA,GACzE;AAEJ;AAEA,UAAU,cAAc;"}
|