@nswds/ui 4.5.0 → 4.7.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 +24 -0
- package/dist/components/badge.js +25 -5
- package/dist/components/badge.js.map +1 -1
- package/dist/components/button.d.ts +22 -7
- package/dist/components/button.js +15 -6
- package/dist/components/button.js.map +1 -1
- package/dist/components/footer.d.ts +13 -7
- package/dist/components/footer.js.map +1 -1
- package/dist/components/header.d.ts +26 -1
- package/dist/components/header.js +4 -2
- package/dist/components/header.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,30 @@ export function Toolbar() {
|
|
|
69
69
|
}
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
### Icons in a React Server Component
|
|
73
|
+
|
|
74
|
+
Icon slots — `leadingVisual`, `trailingVisual`, `trailingAction`, and `Footer`'s `socialLinks[].icon` — take **either the component or an element**. In a server component, pass the element:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
// app/page.tsx — a server component, no 'use client'
|
|
78
|
+
import { ButtonLink } from '@nswds/ui'
|
|
79
|
+
import { IconDownload } from '@nswds/ui/icons'
|
|
80
|
+
|
|
81
|
+
export default function Page() {
|
|
82
|
+
return (
|
|
83
|
+
<ButtonLink href='/report.pdf' leadingVisual={<IconDownload />}>
|
|
84
|
+
Download
|
|
85
|
+
</ButtonLink>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Passing the component itself (`leadingVisual={IconDownload}`) throws there:
|
|
91
|
+
|
|
92
|
+
> Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
|
|
93
|
+
|
|
94
|
+
`Button`, `ButtonLink` and `FooterSocialLink` are client components; the icon modules deliberately are not, so they stay server-renderable and a `<IconDownload />` on a server page ships no JavaScript. That means a bare icon function is just a function value, and functions do not serialise across the RSC boundary — an element does. Client components ("use client") can use either form.
|
|
95
|
+
|
|
72
96
|
## Components
|
|
73
97
|
|
|
74
98
|
Badge, Button, ButtonLink, Card, DescriptionList, Field, Input, Label, LabeledSeparator, Link, Logo (NSW Government logo), Separator, Spinner — plus the icon set under `@nswds/ui/icons`.
|
package/dist/components/badge.js
CHANGED
|
@@ -97,8 +97,8 @@ const styles = {
|
|
|
97
97
|
base: [
|
|
98
98
|
// Base
|
|
99
99
|
"relative isolate inline-flex items-center rounded-sm font-normal border forced-colors:outline transition-all motion-reduce:transition-none h-fit shrink-0",
|
|
100
|
-
// Icon
|
|
101
|
-
"*:data-[slot=icon]:size-4 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center
|
|
100
|
+
// Icon — one flat size, for the same reason the type scale below is flat.
|
|
101
|
+
"*:data-[slot=icon]:size-4 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center"
|
|
102
102
|
],
|
|
103
103
|
solid: [
|
|
104
104
|
// Text color
|
|
@@ -299,10 +299,30 @@ const styles = {
|
|
|
299
299
|
"dark:[--badge-hover-overlay:var(--color-accent-500)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10"
|
|
300
300
|
]
|
|
301
301
|
},
|
|
302
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
303
|
+
// Type scale (flat — do not reintroduce a `sm:` shrink)
|
|
304
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
305
|
+
//
|
|
306
|
+
// Each size holds one font-size at every viewport. Sizes are chosen from the
|
|
307
|
+
// hierarchy field.tsx documents: 16px is the body-copy ideal, 14px reads as
|
|
308
|
+
// supporting information, and 12px is below the NSW Government digital
|
|
309
|
+
// service standards minimum body-text size.
|
|
310
|
+
//
|
|
311
|
+
// These variants used to shrink at `sm:` (640px) — `text-sm/5 sm:text-xs/5`
|
|
312
|
+
// and `text-base/5 sm:text-sm/5` — inherited from the Catalyst-derived
|
|
313
|
+
// scaffolding this component started life as (4889aba). That put `default`
|
|
314
|
+
// and `sm` badges at 12px from 640px up, i.e. under the floor precisely where
|
|
315
|
+
// there is the most room, and capped `lg` at 14px so no badge in the system
|
|
316
|
+
// could meet a 16px minimum on desktop. Buttons — which badges sit beside in
|
|
317
|
+
// the header — have always been a flat `text-base/7`, so the shrink was also
|
|
318
|
+
// out of step with its closest sibling.
|
|
319
|
+
//
|
|
320
|
+
// Below 640px nothing changed: every value here is the size that breakpoint
|
|
321
|
+
// already rendered.
|
|
302
322
|
size: {
|
|
303
|
-
default: "py-[calc(--spacing(1))] px-[calc(--spacing(2))] gap-[calc(--spacing(1)*1.5)] text-sm/5
|
|
304
|
-
sm: "py-[calc(--spacing(1)*0.5)] px-[calc(--spacing(1)*1.5)] gap-[calc(--spacing(1)*1.5)] text-sm/5
|
|
305
|
-
lg: "py-[calc(--spacing(1))] px-[calc(--spacing(2)*1.25)] gap-[calc(--spacing(2))] text-base/5
|
|
323
|
+
default: "py-[calc(--spacing(1))] px-[calc(--spacing(2))] gap-[calc(--spacing(1)*1.5)] text-sm/5",
|
|
324
|
+
sm: "py-[calc(--spacing(1)*0.5)] px-[calc(--spacing(1)*1.5)] gap-[calc(--spacing(1)*1.5)] text-sm/5",
|
|
325
|
+
lg: "py-[calc(--spacing(1))] px-[calc(--spacing(2)*1.25)] gap-[calc(--spacing(2))] text-base/5"
|
|
306
326
|
}
|
|
307
327
|
};
|
|
308
328
|
const badgeVariants = cva(styles.base, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/badge.tsx"],"names":["ButtonPrimitive"],"mappings":";;;;;;;;AAWA,MAAM,YAAA,GAAe;AAAA,EACnB,cAAA,EAAgB;AAAA;AAAA,IAEd,4CAAA;AAAA;AAAA,IAEA,8CAAA;AAAA;AAAA,IAEA,mEAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,KAAA,EAAO;AAAA;AAAA,IAEL,yCAAA;AAAA;AAAA,IAEA,8CAAA;AAAA;AAAA,I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EAAE,KAAA,EAAO,WAAW,CAAA;AAAA,MACnD,GAAA;AAAA,MAEA,QAAA,kBAAA,GAAA,CAAC,WAAA,EAAA,EACC,QAAA,kBAAA,GAAA,CAAC,KAAA,EAAA,EAAM,OAAA,EAAkB,OAAO,KAAA,IAAS,MAAA,EAAW,IAAA,EACjD,QAAA,EACH,CAAA,EACF;AAAA;AAAA,GACF;AAEJ","file":"badge.js","sourcesContent":["'use client'\n\nimport { Button as ButtonPrimitive } from '@base-ui/react/button'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport clsx from 'clsx'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\nimport { TouchTarget } from './button.js'\nimport { Link } from './link.js'\n\nconst focusOutline = {\n 'primary/grey': [\n // Base\n '[--focus-outline:var(--color-primary-800)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-grey-600)]',\n // Soft, Surface and outline\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/20',\n // Soft, Surface and outline dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/30',\n ],\n light: [\n // Base\n '[--focus-outline:var(--color-grey-300)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-grey-100)]',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/30',\n // Surface\n 'data-[variant=surface]:[--focus-outline:var(--color-grey-600)]',\n // Surface dark mode\n 'dark:data-[variant=surface]:[--focus-outline:var(--color-white)]/70',\n ],\n 'primary/white': [\n // Base\n '[--focus-outline:var(--color-primary-800)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-white)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/30',\n ],\n grey: [\n // Base\n '[--focus-outline:var(--color-grey-600)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-grey-500)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-grey-600)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/20',\n // Outline dark mode\n 'dark:data-[variant=outline]:[--focus-outline:var(--color-grey-100)]/30',\n // Surface dark mode\n 'dark:data-[variant=surface]:[--focus-outline:var(--color-grey-200)]/20',\n ],\n white: [\n // Base\n '[--focus-outline:var(--color-white)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-white)]/20',\n ],\n primary: [\n // Base\n '[--focus-outline:var(--color-primary-800)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/60',\n ],\n secondary: [\n // Base\n '[--focus-outline:var(--color-primary-200)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-200)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-primary-200)]/60',\n ],\n tertiary: [\n // Base\n '[--focus-outline:var(--color-primary-600)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-600)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-primary-600)]/60',\n ],\n accent: [\n // Base\n '[--focus-outline:var(--color-accent-600)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-accent-600)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-accent-600)]/60',\n ],\n}\n\nconst styles = {\n base: [\n // Base\n 'relative isolate inline-flex items-center rounded-sm font-normal border forced-colors:outline transition-all motion-reduce:transition-none h-fit shrink-0',\n // Icon\n '*:data-[slot=icon]:size-4 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center sm:*:data-[slot=icon]:size-3',\n ],\n solid: [\n // Text color\n 'text-(--badge-text)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--badge-border)',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--badge-bg)',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--badge-bg)',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n soft: [\n // Text color\n 'text-(--badge-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--badge-bg)/5',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--badge-bg)/20',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--badge-bg)/5',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:bg-white/5',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n surface: [\n // Text color\n 'text-(--badge-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-(--badge-bg)/50 bg-(--badge-bg)/5',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--badge-bg)/30',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--badge-bg)/5',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--badge-bg)/50',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // Border color on hover\n 'group-active:border-(--badge-bg) group-hover:border-(--badge-bg)',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n outline: [\n // Text color\n 'border-(--badge-bg) text-(--badge-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'bg-transparent',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-transparent',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--badge-bg)',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n colors: {\n 'primary/grey': [\n // Base\n '[--badge-bg:var(--color-primary-800)] [--badge-border:var(--color-primary-800)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-grey-600)] dark:[--badge-border:var(--color-grey-600)]/90 dark:[--badge-text:var(--color-white)] dark:text-white',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-grey-200)]/20',\n ],\n light: [\n // Base\n '[--badge-bg:var(--color-grey-200)] [--badge-border:var(--color-grey-200)]/90 [--badge-text:var(--color-grey-800)]',\n 'text-grey-800',\n // Soft\n 'data-[variant=soft]:[--badge-bg:var(--color-grey-500)]',\n // Surface\n 'data-[variant=surface]:[--badge-bg:var(--color-grey-500)]',\n // States\n '[--badge-hover-overlay:var(--color-grey-200)]/10 data-[variant=outline]:[--badge-hover-overlay:var(--color-grey-200)]/20 data-[variant=solid]:[--badge-hover-overlay:var(--color-grey-400)]/50',\n // Dark mode\n 'dark:text-grey-200 dark:data-[variant=solid]:text-grey-800',\n // Dark mode states\n '',\n ],\n 'primary/white': [\n // Base\n '[--badge-bg:var(--color-primary-800)] [--badge-border:var(--color-primary-800)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-white)] dark:[--badge-border:var(--color-white)]/90 dark:[--badge-text:var(--color-grey-800)]',\n // Dark mode states\n '',\n ],\n grey: [\n // Base\n '[--badge-bg:var(--color-grey-600)] [--badge-border:var(--color-grey-600)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:text-white',\n // Dark mode states\n '',\n ],\n white: [\n // Base\n '[--badge-bg:var(--color-white)] [--badge-border:var(--color-white)]/90 text-white data-[variant=solid]:text-grey-800',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:text-grey-200 dark:data-[variant=solid]:text-grey-800',\n // Dark mode states\n '',\n ],\n primary: [\n // Base\n '[--badge-bg:var(--color-primary-800)] [--badge-border:var(--color-primary-800)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:text-white dark:bg-(--badge-bg)/40 dark:data-[variant=solid]:bg-(--badge-bg)',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-primary-800)]/50 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/5',\n // Dark border\n 'dark:data-[variant=surface]:border-(--badge-border)/60',\n 'dark:data-[variant=outline]:border-(--badge-border)',\n // Dark border states\n 'dark:data-[variant=surface]:active:border-(--badge-border)',\n 'dark:data-[variant=surface]:hover:border-(--badge-border)',\n ],\n secondary: [\n // Base\n '[--badge-bg:var(--color-primary-200)] [--badge-border:var(--color-primary-200)]/90 [--badge-text:var(--color-primary-800)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-200)]/30 data-[variant=solid]:[--badge-hover-overlay:var(--color-primary-250)]',\n // Dark mode\n 'dark:[--badge-bg:var(--color-primary-400)] dark:[--badge-border:var(--color-primary-400)]/90 dark:[--badge-text:white]',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-primary-400)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n ],\n tertiary: [\n // Base\n '[--badge-bg:var(--color-primary-600)] [--badge-border:var(--color-primary-600)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-600)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-primary-500)] dark:[--badge-border:var(--color-primary-500)]/90 dark:[--badge-text:white]',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-primary-500)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n ],\n accent: [\n // Base\n '[--badge-bg:var(--color-accent-600)] [--badge-border:var(--color-accent-600)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-accent-600)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-accent-500)] dark:[--badge-border:var(--color-accent-500)]/90 dark:[--badge-text:white]',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-accent-500)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n ],\n },\n size: {\n default:\n 'py-[calc(--spacing(1))] px-[calc(--spacing(2))] gap-[calc(--spacing(1)*1.5)] text-sm/5 sm:text-xs/5',\n sm: 'py-[calc(--spacing(1)*0.5)] px-[calc(--spacing(1)*1.5)] gap-[calc(--spacing(1)*1.5)] text-sm/5 sm:text-xs/5',\n lg: 'py-[calc(--spacing(1))] px-[calc(--spacing(2)*1.25)] gap-[calc(--spacing(2))] text-base/5 sm:text-sm/5',\n },\n}\n\nconst badgeVariants = cva(styles.base, {\n variants: {\n variant: {\n solid: styles.solid,\n soft: styles.soft,\n surface: styles.surface,\n outline: styles.outline,\n },\n color: {\n 'primary/grey': styles.colors['primary/grey'],\n light: styles.colors.light,\n 'primary/white': styles.colors['primary/white'],\n white: styles.colors.white,\n grey: styles.colors.grey,\n primary: styles.colors.primary,\n secondary: styles.colors.secondary,\n tertiary: styles.colors.tertiary,\n accent: styles.colors.accent,\n },\n size: {\n default: styles.size.default,\n sm: styles.size.sm,\n lg: styles.size.lg,\n },\n },\n defaultVariants: {\n variant: 'soft',\n color: 'primary',\n size: 'default',\n },\n})\n\ntype BadgeProps = VariantProps<typeof badgeVariants> &\n React.ComponentPropsWithoutRef<'span'> & { ref?: React.Ref<HTMLSpanElement> }\n\nfunction Badge({ variant, color, size, className, ref, ...props }: BadgeProps) {\n return (\n <span\n {...props}\n data-variant={variant}\n className={cn(badgeVariants({ variant, color, size }), className)}\n ref={ref}\n />\n )\n}\n\n/** Visual/content props shared by `BadgeButton` and `BadgeLink`. */\ntype BadgeOwnProps = VariantProps<typeof badgeVariants> & {\n className?: string\n children: React.ReactNode\n}\n\ntype BadgeButtonProps = BadgeOwnProps & Omit<ButtonPrimitive.Props, 'className'>\n\ntype BadgeLinkProps = BadgeOwnProps &\n Omit<React.ComponentPropsWithoutRef<typeof Link>, 'className' | 'variant'> & {\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nfunction badgeWrapperClasses({ color, className }: Pick<BadgeOwnProps, 'color' | 'className'>) {\n return clsx(className, focusOutline[(color ?? undefined) as keyof typeof focusOutline], [\n // Base\n 'group relative inline-flex rounded-sm',\n // Focus\n 'focus:outline-1 focus:outline-offset-1 focus:outline-(--focus-outline)',\n // Disabled\n 'disabled:pointer-events-none disabled:opacity-50',\n ])\n}\n\n/**\n * Interactive badge on the Base UI button primitive. For badge-styled\n * navigation, use `BadgeLink` — the `href` polymorphism that previously\n * lived on this component was removed in v2.\n */\nfunction BadgeButton({\n variant,\n color,\n size,\n className,\n children,\n ref,\n ...props\n}: BadgeButtonProps) {\n return (\n <ButtonPrimitive\n data-variant={variant}\n {...props}\n className={clsx(badgeWrapperClasses({ color, className }), 'cursor-pointer')}\n ref={ref}\n >\n <TouchTarget>\n <Badge variant={variant} color={color ?? undefined} size={size}>\n {children}\n </Badge>\n </TouchTarget>\n </ButtonPrimitive>\n )\n}\n\n/** Badge-styled anchor; renders through `Link` (so `LinkProvider` applies). */\nfunction BadgeLink({ variant, color, size, className, children, ref, ...props }: BadgeLinkProps) {\n return (\n <Link\n // Opt out of Link's built-in styling — BadgeLink wraps the inner\n // Badge with its own focus ring / hit target and doesn't want Link's\n // underline, halo, or icon defaults composing on top.\n variant='unstyled'\n data-variant={variant}\n {...props}\n className={badgeWrapperClasses({ color, className })}\n ref={ref}\n >\n <TouchTarget>\n <Badge variant={variant} color={color ?? undefined} size={size}>\n {children}\n </Badge>\n </TouchTarget>\n </Link>\n )\n}\n\nexport { Badge, BadgeButton, BadgeLink, badgeVariants }\nexport type { BadgeButtonProps, BadgeLinkProps, BadgeProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/badge.tsx"],"names":["ButtonPrimitive"],"mappings":";;;;;;;;AAWA,MAAM,YAAA,GAAe;AAAA,EACnB,cAAA,EAAgB;AAAA;AAAA,IAEd,4CAAA;AAAA;AAAA,IAEA,8CAAA;AAAA;AAAA,IAEA,mEAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,KAAA,EAAO;AAAA;AAAA,IAEL,yCAAA;AAAA;AAAA,IAEA,8CAAA;AAAA;AAAA,IAEA,qEAAA;AAAA;AAAA,IAEA,gEAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,eAAA,EAAiB;AAAA;AAAA,IAEf,4CAAA;AAAA;AAAA,IAEA,2CAAA;AAAA;AAAA,IAEA,mEAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,IAAA,EAAM;AAAA;AAAA,IAEJ,yCAAA;AAAA;AAAA,IAEA,8CAAA;AAAA;AAAA,IAEA,gEAAA;AAAA;AAAA,IAEA,qEAAA;AAAA;AAAA,IAEA,wEAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,KAAA,EAAO;AAAA;AAAA,IAEL,sCAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,OAAA,EAAS;AAAA;AAAA,IAEP,4CAAA;AAAA;AAAA,IAEA,mEAAA;AAA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A,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAqB;AACnB,EAAA,uBACE,GAAA;AAAA,IAACA,MAAA;AAAA,IAAA;AAAA,MACC,cAAA,EAAc,OAAA;AAAA,MACb,GAAG,KAAA;AAAA,MACJ,SAAA,EAAW,KAAK,mBAAA,CAAoB,EAAE,OAAO,SAAA,EAAW,GAAG,gBAAgB,CAAA;AAAA,MAC3E,GAAA;AAAA,MAEA,QAAA,kBAAA,GAAA,CAAC,WAAA,EAAA,EACC,QAAA,kBAAA,GAAA,CAAC,KAAA,EAAA,EAAM,OAAA,EAAkB,OAAO,KAAA,IAAS,MAAA,EAAW,IAAA,EACjD,QAAA,EACH,CAAA,EACF;AAAA;AAAA,GACF;AAEJ;AAGA,SAAS,SAAA,CAAU,EAAE,OAAA,EAAS,KAAA,EAAO,IAAA,EAAM,WAAW,QAAA,EAAU,GAAA,EAAK,GAAG,KAAA,EAAM,EAAmB;AAC/F,EAAA,uBACE,GAAA;AAAA,IAAC,IAAA;AAAA,IAAA;AAAA,MAIC,OAAA,EAAQ,UAAA;AAAA,MACR,cAAA,EAAc,OAAA;AAAA,MACb,GAAG,KAAA;AAAA,MACJ,SAAA,EAAW,mBAAA,CAAoB,EAAE,KAAA,EAAO,WAAW,CAAA;AAAA,MACnD,GAAA;AAAA,MAEA,QAAA,kBAAA,GAAA,CAAC,WAAA,EAAA,EACC,QAAA,kBAAA,GAAA,CAAC,KAAA,EAAA,EAAM,OAAA,EAAkB,OAAO,KAAA,IAAS,MAAA,EAAW,IAAA,EACjD,QAAA,EACH,CAAA,EACF;AAAA;AAAA,GACF;AAEJ","file":"badge.js","sourcesContent":["'use client'\n\nimport { Button as ButtonPrimitive } from '@base-ui/react/button'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport clsx from 'clsx'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\nimport { TouchTarget } from './button.js'\nimport { Link } from './link.js'\n\nconst focusOutline = {\n 'primary/grey': [\n // Base\n '[--focus-outline:var(--color-primary-800)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-grey-600)]',\n // Soft, Surface and outline\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/20',\n // Soft, Surface and outline dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/30',\n ],\n light: [\n // Base\n '[--focus-outline:var(--color-grey-300)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-grey-100)]',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/30',\n // Surface\n 'data-[variant=surface]:[--focus-outline:var(--color-grey-600)]',\n // Surface dark mode\n 'dark:data-[variant=surface]:[--focus-outline:var(--color-white)]/70',\n ],\n 'primary/white': [\n // Base\n '[--focus-outline:var(--color-primary-800)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-white)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/30',\n ],\n grey: [\n // Base\n '[--focus-outline:var(--color-grey-600)]',\n // Base dark mode\n 'dark:[--focus-outline:var(--color-grey-500)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-grey-600)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-grey-200)]/20',\n // Outline dark mode\n 'dark:data-[variant=outline]:[--focus-outline:var(--color-grey-100)]/30',\n // Surface dark mode\n 'dark:data-[variant=surface]:[--focus-outline:var(--color-grey-200)]/20',\n ],\n white: [\n // Base\n '[--focus-outline:var(--color-white)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-white)]/20',\n ],\n primary: [\n // Base\n '[--focus-outline:var(--color-primary-800)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-primary-800)]/60',\n ],\n secondary: [\n // Base\n '[--focus-outline:var(--color-primary-200)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-200)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-primary-200)]/60',\n ],\n tertiary: [\n // Base\n '[--focus-outline:var(--color-primary-600)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-primary-600)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-primary-600)]/60',\n ],\n accent: [\n // Base\n '[--focus-outline:var(--color-accent-600)]',\n // Soft\n 'data-[variant=soft]:[--focus-outline:var(--color-accent-600)]/20',\n // Soft dark mode\n 'dark:data-[variant=soft]:[--focus-outline:var(--color-accent-600)]/60',\n ],\n}\n\nconst styles = {\n base: [\n // Base\n 'relative isolate inline-flex items-center rounded-sm font-normal border forced-colors:outline transition-all motion-reduce:transition-none h-fit shrink-0',\n // Icon — one flat size, for the same reason the type scale below is flat.\n '*:data-[slot=icon]:size-4 *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center',\n ],\n solid: [\n // Text color\n 'text-(--badge-text)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--badge-border)',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--badge-bg)',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--badge-bg)',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n soft: [\n // Text color\n 'text-(--badge-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--badge-bg)/5',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--badge-bg)/20',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--badge-bg)/5',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:bg-white/5',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n surface: [\n // Text color\n 'text-(--badge-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-(--badge-bg)/50 bg-(--badge-bg)/5',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--badge-bg)/30',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--badge-bg)/5',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--badge-bg)/50',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // Border color on hover\n 'group-active:border-(--badge-bg) group-hover:border-(--badge-bg)',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n outline: [\n // Text color\n 'border-(--badge-bg) text-(--badge-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'bg-transparent',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-transparent',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--badge-bg)',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // White overlay on hover\n 'group-active:after:bg-(--badge-hover-overlay) group-hover:after:bg-(--badge-hover-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n colors: {\n 'primary/grey': [\n // Base\n '[--badge-bg:var(--color-primary-800)] [--badge-border:var(--color-primary-800)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-grey-600)] dark:[--badge-border:var(--color-grey-600)]/90 dark:[--badge-text:var(--color-white)] dark:text-white',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-grey-200)]/20',\n ],\n light: [\n // Base\n '[--badge-bg:var(--color-grey-200)] [--badge-border:var(--color-grey-200)]/90 [--badge-text:var(--color-grey-800)]',\n 'text-grey-800',\n // Soft\n 'data-[variant=soft]:[--badge-bg:var(--color-grey-500)]',\n // Surface\n 'data-[variant=surface]:[--badge-bg:var(--color-grey-500)]',\n // States\n '[--badge-hover-overlay:var(--color-grey-200)]/10 data-[variant=outline]:[--badge-hover-overlay:var(--color-grey-200)]/20 data-[variant=solid]:[--badge-hover-overlay:var(--color-grey-400)]/50',\n // Dark mode\n 'dark:text-grey-200 dark:data-[variant=solid]:text-grey-800',\n // Dark mode states\n '',\n ],\n 'primary/white': [\n // Base\n '[--badge-bg:var(--color-primary-800)] [--badge-border:var(--color-primary-800)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-white)] dark:[--badge-border:var(--color-white)]/90 dark:[--badge-text:var(--color-grey-800)]',\n // Dark mode states\n '',\n ],\n grey: [\n // Base\n '[--badge-bg:var(--color-grey-600)] [--badge-border:var(--color-grey-600)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:text-white',\n // Dark mode states\n '',\n ],\n white: [\n // Base\n '[--badge-bg:var(--color-white)] [--badge-border:var(--color-white)]/90 text-white data-[variant=solid]:text-grey-800',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:text-grey-200 dark:data-[variant=solid]:text-grey-800',\n // Dark mode states\n '',\n ],\n primary: [\n // Base\n '[--badge-bg:var(--color-primary-800)] [--badge-border:var(--color-primary-800)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-800)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:text-white dark:bg-(--badge-bg)/40 dark:data-[variant=solid]:bg-(--badge-bg)',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-primary-800)]/50 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/5',\n // Dark border\n 'dark:data-[variant=surface]:border-(--badge-border)/60',\n 'dark:data-[variant=outline]:border-(--badge-border)',\n // Dark border states\n 'dark:data-[variant=surface]:active:border-(--badge-border)',\n 'dark:data-[variant=surface]:hover:border-(--badge-border)',\n ],\n secondary: [\n // Base\n '[--badge-bg:var(--color-primary-200)] [--badge-border:var(--color-primary-200)]/90 [--badge-text:var(--color-primary-800)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-200)]/30 data-[variant=solid]:[--badge-hover-overlay:var(--color-primary-250)]',\n // Dark mode\n 'dark:[--badge-bg:var(--color-primary-400)] dark:[--badge-border:var(--color-primary-400)]/90 dark:[--badge-text:white]',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-primary-400)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n ],\n tertiary: [\n // Base\n '[--badge-bg:var(--color-primary-600)] [--badge-border:var(--color-primary-600)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-primary-600)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-primary-500)] dark:[--badge-border:var(--color-primary-500)]/90 dark:[--badge-text:white]',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-primary-500)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n ],\n accent: [\n // Base\n '[--badge-bg:var(--color-accent-600)] [--badge-border:var(--color-accent-600)]/90 [--badge-text:var(--color-white)]',\n // States\n '[--badge-hover-overlay:var(--color-accent-600)]/10 data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n // Dark mode\n 'dark:[--badge-bg:var(--color-accent-500)] dark:[--badge-border:var(--color-accent-500)]/90 dark:[--badge-text:white]',\n // Dark mode states\n 'dark:[--badge-hover-overlay:var(--color-accent-500)]/30 dark:data-[variant=solid]:[--badge-hover-overlay:var(--color-white)]/10',\n ],\n },\n // ───────────────────────────────────────────────────────────────────────────\n // Type scale (flat — do not reintroduce a `sm:` shrink)\n // ───────────────────────────────────────────────────────────────────────────\n //\n // Each size holds one font-size at every viewport. Sizes are chosen from the\n // hierarchy field.tsx documents: 16px is the body-copy ideal, 14px reads as\n // supporting information, and 12px is below the NSW Government digital\n // service standards minimum body-text size.\n //\n // These variants used to shrink at `sm:` (640px) — `text-sm/5 sm:text-xs/5`\n // and `text-base/5 sm:text-sm/5` — inherited from the Catalyst-derived\n // scaffolding this component started life as (4889aba). That put `default`\n // and `sm` badges at 12px from 640px up, i.e. under the floor precisely where\n // there is the most room, and capped `lg` at 14px so no badge in the system\n // could meet a 16px minimum on desktop. Buttons — which badges sit beside in\n // the header — have always been a flat `text-base/7`, so the shrink was also\n // out of step with its closest sibling.\n //\n // Below 640px nothing changed: every value here is the size that breakpoint\n // already rendered.\n size: {\n default:\n 'py-[calc(--spacing(1))] px-[calc(--spacing(2))] gap-[calc(--spacing(1)*1.5)] text-sm/5',\n sm: 'py-[calc(--spacing(1)*0.5)] px-[calc(--spacing(1)*1.5)] gap-[calc(--spacing(1)*1.5)] text-sm/5',\n lg: 'py-[calc(--spacing(1))] px-[calc(--spacing(2)*1.25)] gap-[calc(--spacing(2))] text-base/5',\n },\n}\n\nconst badgeVariants = cva(styles.base, {\n variants: {\n variant: {\n solid: styles.solid,\n soft: styles.soft,\n surface: styles.surface,\n outline: styles.outline,\n },\n color: {\n 'primary/grey': styles.colors['primary/grey'],\n light: styles.colors.light,\n 'primary/white': styles.colors['primary/white'],\n white: styles.colors.white,\n grey: styles.colors.grey,\n primary: styles.colors.primary,\n secondary: styles.colors.secondary,\n tertiary: styles.colors.tertiary,\n accent: styles.colors.accent,\n },\n size: {\n default: styles.size.default,\n sm: styles.size.sm,\n lg: styles.size.lg,\n },\n },\n defaultVariants: {\n variant: 'soft',\n color: 'primary',\n size: 'default',\n },\n})\n\ntype BadgeProps = VariantProps<typeof badgeVariants> &\n React.ComponentPropsWithoutRef<'span'> & { ref?: React.Ref<HTMLSpanElement> }\n\nfunction Badge({ variant, color, size, className, ref, ...props }: BadgeProps) {\n return (\n <span\n {...props}\n data-variant={variant}\n className={cn(badgeVariants({ variant, color, size }), className)}\n ref={ref}\n />\n )\n}\n\n/** Visual/content props shared by `BadgeButton` and `BadgeLink`. */\ntype BadgeOwnProps = VariantProps<typeof badgeVariants> & {\n className?: string\n children: React.ReactNode\n}\n\ntype BadgeButtonProps = BadgeOwnProps & Omit<ButtonPrimitive.Props, 'className'>\n\ntype BadgeLinkProps = BadgeOwnProps &\n Omit<React.ComponentPropsWithoutRef<typeof Link>, 'className' | 'variant'> & {\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nfunction badgeWrapperClasses({ color, className }: Pick<BadgeOwnProps, 'color' | 'className'>) {\n return clsx(className, focusOutline[(color ?? undefined) as keyof typeof focusOutline], [\n // Base\n 'group relative inline-flex rounded-sm',\n // Focus\n 'focus:outline-1 focus:outline-offset-1 focus:outline-(--focus-outline)',\n // Disabled\n 'disabled:pointer-events-none disabled:opacity-50',\n ])\n}\n\n/**\n * Interactive badge on the Base UI button primitive. For badge-styled\n * navigation, use `BadgeLink` — the `href` polymorphism that previously\n * lived on this component was removed in v2.\n */\nfunction BadgeButton({\n variant,\n color,\n size,\n className,\n children,\n ref,\n ...props\n}: BadgeButtonProps) {\n return (\n <ButtonPrimitive\n data-variant={variant}\n {...props}\n className={clsx(badgeWrapperClasses({ color, className }), 'cursor-pointer')}\n ref={ref}\n >\n <TouchTarget>\n <Badge variant={variant} color={color ?? undefined} size={size}>\n {children}\n </Badge>\n </TouchTarget>\n </ButtonPrimitive>\n )\n}\n\n/** Badge-styled anchor; renders through `Link` (so `LinkProvider` applies). */\nfunction BadgeLink({ variant, color, size, className, children, ref, ...props }: BadgeLinkProps) {\n return (\n <Link\n // Opt out of Link's built-in styling — BadgeLink wraps the inner\n // Badge with its own focus ring / hit target and doesn't want Link's\n // underline, halo, or icon defaults composing on top.\n variant='unstyled'\n data-variant={variant}\n {...props}\n className={badgeWrapperClasses({ color, className })}\n ref={ref}\n >\n <TouchTarget>\n <Badge variant={variant} color={color ?? undefined} size={size}>\n {children}\n </Badge>\n </TouchTarget>\n </Link>\n )\n}\n\nexport { Badge, BadgeButton, BadgeLink, badgeVariants }\nexport type { BadgeButtonProps, BadgeLinkProps, BadgeProps }\n"]}
|
|
@@ -10,6 +10,21 @@ declare const buttonVariants: (props?: ({
|
|
|
10
10
|
size?: "default" | "sm" | "lg" | "icon" | null | undefined;
|
|
11
11
|
iconOnly?: boolean | null | undefined;
|
|
12
12
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
13
|
+
/**
|
|
14
|
+
* An icon slot. Takes either form:
|
|
15
|
+
*
|
|
16
|
+
* - the component itself — `leadingVisual={IconDownload}`
|
|
17
|
+
* - a rendered element — `leadingVisual={<IconDownload />}`
|
|
18
|
+
*
|
|
19
|
+
* **From a React Server Component, use the element form.** `Button` and
|
|
20
|
+
* `ButtonLink` are `'use client'` modules, while the icon modules carry no
|
|
21
|
+
* directive — deliberately, so an icon stays server-renderable and ships no
|
|
22
|
+
* JavaScript. That means in a server component `IconDownload` is an ordinary
|
|
23
|
+
* function value, and functions cannot cross the RSC boundary into a client
|
|
24
|
+
* component ("Functions cannot be passed directly to Client Components"). A
|
|
25
|
+
* React element can, because it serialises. Client components can use either.
|
|
26
|
+
*/
|
|
27
|
+
type IconSlot = React__default.ElementType | React__default.ReactElement;
|
|
13
28
|
/** Visual/content props shared by `Button` and `ButtonLink`. */
|
|
14
29
|
type ButtonOwnProps = Omit<VariantProps<typeof buttonVariants>, 'size' | 'iconOnly'> & {
|
|
15
30
|
/**
|
|
@@ -44,12 +59,12 @@ type ButtonOwnProps = Omit<VariantProps<typeof buttonVariants>, 'size' | 'iconOn
|
|
|
44
59
|
/** Horizontal alignment of button content. */
|
|
45
60
|
alignContent?: 'center' | 'start';
|
|
46
61
|
disabled?: boolean;
|
|
47
|
-
/** Icon
|
|
48
|
-
leadingVisual?:
|
|
49
|
-
/** Icon
|
|
50
|
-
trailingVisual?:
|
|
51
|
-
/** Icon
|
|
52
|
-
trailingAction?:
|
|
62
|
+
/** Icon rendered before the label. Component or element — see `IconSlot`. */
|
|
63
|
+
leadingVisual?: IconSlot;
|
|
64
|
+
/** Icon rendered after the label. Component or element — see `IconSlot`. */
|
|
65
|
+
trailingVisual?: IconSlot;
|
|
66
|
+
/** Icon rendered as a trailing action (far end). Component or element. */
|
|
67
|
+
trailingAction?: IconSlot;
|
|
53
68
|
/** Allow the button label to wrap onto multiple lines. Defaults to true. */
|
|
54
69
|
labelWrap?: boolean;
|
|
55
70
|
/** Optional numeric badge rendered after the label. */
|
|
@@ -89,4 +104,4 @@ declare function TouchTarget({ children }: {
|
|
|
89
104
|
children: React__default.ReactNode;
|
|
90
105
|
}): React__default.JSX.Element;
|
|
91
106
|
|
|
92
|
-
export { Button, ButtonLink, type ButtonLinkProps, type ButtonProps, TouchTarget, buttonVariants };
|
|
107
|
+
export { Button, ButtonLink, type ButtonLinkProps, type ButtonProps, type IconSlot, TouchTarget, buttonVariants };
|
|
@@ -3,6 +3,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
3
3
|
import { Button as Button$1 } from '@base-ui/react/button';
|
|
4
4
|
import { cva } from 'class-variance-authority';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
+
import React from 'react';
|
|
6
7
|
import { cn } from '../lib/utils.js';
|
|
7
8
|
import { Link } from '../components/link.js';
|
|
8
9
|
import { Spinner } from '../components/spinner.js';
|
|
@@ -372,6 +373,14 @@ const buttonVariants = cva(styles.base, {
|
|
|
372
373
|
size: "default"
|
|
373
374
|
}
|
|
374
375
|
});
|
|
376
|
+
function renderIconSlot(slot) {
|
|
377
|
+
if (!slot) return null;
|
|
378
|
+
if (React.isValidElement(slot)) {
|
|
379
|
+
return React.cloneElement(slot, { "data-slot": slot.props["data-slot"] ?? "icon" });
|
|
380
|
+
}
|
|
381
|
+
const Icon = slot;
|
|
382
|
+
return /* @__PURE__ */ jsx(Icon, { "data-slot": "icon" });
|
|
383
|
+
}
|
|
375
384
|
function buttonClasses({
|
|
376
385
|
variant,
|
|
377
386
|
color,
|
|
@@ -394,9 +403,9 @@ function buttonClasses({
|
|
|
394
403
|
}
|
|
395
404
|
function ButtonContent({
|
|
396
405
|
loading,
|
|
397
|
-
leadingVisual
|
|
398
|
-
trailingVisual
|
|
399
|
-
trailingAction
|
|
406
|
+
leadingVisual,
|
|
407
|
+
trailingVisual,
|
|
408
|
+
trailingAction,
|
|
400
409
|
labelWrap,
|
|
401
410
|
count,
|
|
402
411
|
countLabel,
|
|
@@ -414,7 +423,7 @@ function ButtonContent({
|
|
|
414
423
|
svgClassName: "block size-full"
|
|
415
424
|
}
|
|
416
425
|
),
|
|
417
|
-
|
|
426
|
+
renderIconSlot(leadingVisual),
|
|
418
427
|
labelWrap === false ? /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap", children }) : children,
|
|
419
428
|
count !== void 0 && /* @__PURE__ */ jsxs("span", { className: "rounded-full px-1.5 py-0.5 text-xs font-medium tabular-nums opacity-75", children: [
|
|
420
429
|
count,
|
|
@@ -423,8 +432,8 @@ function ButtonContent({
|
|
|
423
432
|
countLabel
|
|
424
433
|
] }) : null
|
|
425
434
|
] }),
|
|
426
|
-
|
|
427
|
-
|
|
435
|
+
renderIconSlot(trailingVisual),
|
|
436
|
+
renderIconSlot(trailingAction)
|
|
428
437
|
] });
|
|
429
438
|
}
|
|
430
439
|
function warnIfIconButtonUnlabelled(size, iconOnly, props) {
|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AAA,EAAU,8IAAA;AAAA,QACV,aAAA,EAAY;AAAA;AAAA,KACd;AAAA,IACC;AAAA,GAAA,EACH,CAAA;AAEJ","file":"button.js","sourcesContent":["'use client'\n\nimport { Button as ButtonPrimitive } from '@base-ui/react/button'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport clsx from 'clsx'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Link } from '../components/link.js'\nimport { Spinner } from '../components/spinner.js'\n\nconst styles = {\n base: [\n // Base\n 'relative isolate inline-flex items-baseline justify-center gap-x-2 rounded-sm border text-base/7 font-bold transition-all motion-reduce:transition-none',\n // Height floor, published per size step as `--btn-h` (see `styles.size`).\n // A floor rather than a fixed height so a wrapped label can still grow.\n 'min-h-(--btn-h)',\n // Border width, so the size steps can subtract it from their padding and\n // keep the outer box identical across variants. `outline` and `surface`\n // draw a 2px border and raise this to match; everything else stays 1px.\n // Without it the steps subtracted a hard-coded 1px and those two variants\n // came out 2px taller than `solid` at every step and breakpoint.\n '[--btn-border-w:1px]',\n // Focus — deliberately `focus:` (paints on pointer clicks too), unlike\n // Link/Input which use `focus-visible:`. Buttons give click feedback with\n // the ring; links only ring for keyboard/AT focus. Do not \"unify\" this.\n 'focus:outline focus:outline-2 focus:outline-offset-2 focus:outline-(--btn-bg)',\n // Disabled\n 'data-disabled:opacity-50 data-disabled:pointer-events-none',\n // Glyph size beside a label: one value for every step and breakpoint.\n // Every step sets `text-base/7`, so the label is 16px whatever the step —\n // only the padding changes. An icon next to it has to match the *text*,\n // not the box, so scaling it per step pairs a growing glyph with type that\n // never moves: at `lg` a 28px icon sat beside a 16px word, two and a half\n // times its cap height. 24px is 1.5x the label at every step, and the same\n // number `size='icon'` uses. `iconOnly` overrides this per step in\n // `compoundVariants` — with no label to match, it scales with its box.\n '[--btn-icon-size:--spacing(6)]',\n // Icon. No vertical margin: the glyph is `self-center` in a baseline-aligned\n // row, so margin buys it nothing optically and only inflates the flex line.\n // It was inert at `sm`/`default` (glyph + margin stayed inside the 1.75rem\n // line box) but pushed `lg` 2px past its own height below `sm:`, so a `lg`\n // button measured 70px with an icon and 68px without.\n '*:data-[slot=icon]:-mx-0.25 *:data-[slot=icon]:size-(--btn-icon-size) *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center *:data-[slot=icon]:text-(--btn-icon) forced-colors:[--btn-icon:ButtonText] forced-colors:hover:[--btn-icon:ButtonText]',\n ],\n solid: [\n // Text color\n 'text-(--btn-text)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--btn-border)',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--btn-bg)',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-bg)',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n soft: [\n // Text color\n 'text-(--btn-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--btn-bg)/10',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--btn-bg)/20',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-bg)/10',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:bg-white/5',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n surface: [\n // Text color\n 'text-(--btn-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-(--btn-bg)/50 border-2 bg-(--btn-bg)/5 [--btn-border-w:2px]',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--btn-bg)/30',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-bg)/5',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--btn-bg)/50',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // Border color on hover\n 'active:border-(--btn-bg) hover:border-(--btn-bg)',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n outline: [\n // Text color\n 'border-(--btn-bg) text-(--btn-bg) border-2 [--btn-border-w:2px]',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'bg-transparent',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-transparent',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--btn-bg)',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n ghost: [\n // Text color\n 'text-(--btn-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--btn-transparent)',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-transparent)',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n link: [\n // Text color — inherits from color token, no background or border\n 'text-(--btn-bg) border-transparent bg-transparent',\n // Halo tokens derive from the colour token via color-mix, mirroring Link\n '[--link-halo:color-mix(in_oklch,var(--btn-bg)_10%,transparent)]',\n '[--link-halo-active:color-mix(in_oklch,var(--btn-bg)_18%,transparent)]',\n // Resting underline, thickened on interaction — matching Link\n 'underline underline-offset-4 hover:decoration-2 active:decoration-2',\n // Hover / active halos match the GOV.UK-style halo on Link (see link.tsx\n // styledBase): the fill is painted on the `after` layer — consistent with\n // the other variants' hover overlays — and the box-shadow extends it 2px\n // above and 4px below the line box\n 'after:absolute after:inset-0 after:-z-10',\n 'hover:after:bg-(--link-halo) active:after:bg-(--link-halo-active)',\n 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',\n 'active:shadow-[0_-2px_0_var(--link-halo-active),0_4px_0_var(--link-halo-active)]',\n ],\n colors: {\n grey: [\n // Base\n '[--btn-bg:var(--color-grey-600)] [--btn-border:var(--color-grey-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-grey-600)]/10 [--btn-active-overlay:var(--color-grey-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n white: [\n // Base\n '[--btn-bg:var(--color-white)] [--btn-border:var(--color-white)]/90 [--btn-text:var(--color-grey-800)]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-white)]/10 [--btn-active-overlay:var(--color-white)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-black)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n primary: [\n // Base\n '[--btn-bg:var(--color-primary-800)] [--btn-border:var(--color-primary-800)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-primary-800)]/10 [--btn-active-overlay:var(--color-primary-800)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n secondary: [\n // Base\n '[--btn-bg:var(--color-primary-200)] [--btn-border:var(--color-primary-200)]/90 [--btn-text:var(--color-primary-800)]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-primary-200)]/10 [--btn-active-overlay:var(--color-primary-200)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/15',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-primary-800)]/10',\n ],\n tertiary: [\n // Base\n '[--btn-bg:var(--color-primary-600)] [--btn-border:var(--color-primary-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-primary-600)]/10 [--btn-active-overlay:var(--color-primary-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n accent: [\n // Base\n '[--btn-bg:var(--color-accent-600)] [--btn-border:var(--color-accent-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-accent-600)]/10 [--btn-active-overlay:var(--color-accent-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n // Semantic colours use the raw NSW token names (--danger-600, --success-600,\n // --warning-600) rather than Tailwind's `--color-*` bridge aliases. The\n // bridge aliases are tree-shaken by Tailwind v4 unless a matching utility\n // class is detected in scanned source, and arbitrary-property usages like\n // `[--btn-bg:var(--color-success-600)]` do NOT count as a usage signal.\n // The raw tokens are defined on :root by @nswds/tokens (a plain CSS import,\n // not a Tailwind theme), so they always resolve.\n danger: [\n // Base\n '[--btn-bg:var(--danger-600)] [--btn-border:var(--danger-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--danger-600)]/10 [--btn-active-overlay:var(--danger-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n success: [\n // Base\n '[--btn-bg:var(--success-600)] [--btn-border:var(--success-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--success-600)]/10 [--btn-active-overlay:var(--success-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n warning: [\n // Base\n '[--btn-bg:var(--warning-600)] [--btn-border:var(--warning-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--warning-600)]/10 [--btn-active-overlay:var(--warning-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n },\n // Each step publishes its own height as `--btn-h`, built from the same two\n // numbers that produce its box: one line box (`text-base/7` — Tailwind's\n // `/7` is `--spacing(7)`, so this is the same token, not a matching literal)\n // plus twice the vertical padding. `styles.base` pins it with `min-h`, and\n // `styles.iconOnly` reads it as both dimensions of the square — so an\n // icon-only button is exactly as tall as the text button beside it by\n // construction, and stays that way if a step is ever retuned.\n //\n // The border cancels out of that sum: padding is `--spacing(n) -\n // --btn-border-w` and the border adds `--btn-border-w` back, so every\n // variant lands on `--btn-h` whether it draws a 1px or 2px edge, and the\n // outer geometry stays put while the label shifts 1px to make room.\n //\n // The steps set padding and height only. Glyph size lives on the base (one\n // value beside a label) and in `compoundVariants` (per step when icon-only).\n size: {\n default:\n 'px-[calc(--spacing(6)-var(--btn-border-w))] py-[calc(--spacing(4)-var(--btn-border-w))] sm:px-[calc(--spacing(5.5)-var(--btn-border-w))] sm:py-[calc(--spacing(3)-var(--btn-border-w))] [--btn-h:calc(--spacing(7)+--spacing(4)*2)] sm:[--btn-h:calc(--spacing(7)+--spacing(3)*2)]',\n sm: 'px-[calc(--spacing(5)-var(--btn-border-w))] py-[calc(--spacing(3)-var(--btn-border-w))] sm:px-[calc(--spacing(4.5)-var(--btn-border-w))] sm:py-[calc(--spacing(2)-var(--btn-border-w))] [--btn-h:calc(--spacing(7)+--spacing(3)*2)] sm:[--btn-h:calc(--spacing(7)+--spacing(2)*2)]',\n lg: 'px-[calc(--spacing(7)-var(--btn-border-w))] py-[calc(--spacing(5)-var(--btn-border-w))] sm:px-[calc(--spacing(6.5)-var(--btn-border-w))] sm:py-[calc(--spacing(4)-var(--btn-border-w))] [--btn-h:calc(--spacing(7)+--spacing(5)*2)] sm:[--btn-h:calc(--spacing(7)+--spacing(4)*2)]',\n // A compact chrome square that deliberately sits below the text steps —\n // header actions, dialog close buttons, footer social links. For an icon\n // button that must line up with text buttons beside it, use `iconOnly`\n // with `sm`/`default`/`lg` instead. Its glyph is the base 24px.\n icon: 'w-10 h-10 flex-none [--btn-h:--spacing(10)]',\n },\n // Square the button at the current step and drop the horizontal padding, so\n // the scale step and \"is this icon-only\" are independent axes. The glyph\n // needs no adjustment — the step already sizes it off the ladder.\n iconOnly: 'size-(--btn-h) flex-none p-0 sm:p-0',\n}\n\nconst buttonVariants = cva(styles.base, {\n variants: {\n variant: {\n solid: styles.solid,\n soft: styles.soft,\n surface: styles.surface,\n outline: styles.outline,\n ghost: styles.ghost,\n link: styles.link,\n },\n color: {\n white: styles.colors.white,\n grey: styles.colors.grey,\n primary: styles.colors.primary,\n secondary: styles.colors.secondary,\n tertiary: styles.colors.tertiary,\n accent: styles.colors.accent,\n danger: styles.colors.danger,\n success: styles.colors.success,\n warning: styles.colors.warning,\n },\n size: {\n default: styles.size.default,\n sm: styles.size.sm,\n lg: styles.size.lg,\n icon: styles.size.icon,\n },\n // Declared after `size` so its `p-0` reaches `cn()` downstream of the\n // step's `px-*`/`py-*` and wins the tailwind-merge conflict.\n iconOnly: {\n true: styles.iconOnly,\n false: '',\n },\n },\n compoundVariants: [\n // ── Icon-only glyph sizes ────────────────────────────────────────────\n //\n // With no label beside it the glyph has nothing to match, so here — and\n // only here — it scales with its box, off the icon ladder: 20 / 24 / 28 /\n // 32 / 36 / 40px, i.e. `--spacing(5)` through `--spacing(10)`. Every level\n // is a multiple of 4, so glyphs share the grid with the padding and\n // heights around them and land on whole device pixels at 1x. A discrete\n // ladder rather than a proportion of the box, because a glyph is only\n // crisp at the sizes it was drawn for — \"40% of the box\" would ask for\n // sizes no glyph exists at.\n //\n // One value per step, not per breakpoint: the square never gets smaller\n // on a wider viewport, so neither should what sits inside it.\n { size: 'sm', iconOnly: true, className: '[--btn-icon-size:--spacing(5)]' },\n { size: 'default', iconOnly: true, className: '[--btn-icon-size:--spacing(6)]' },\n { size: 'lg', iconOnly: true, className: '[--btn-icon-size:--spacing(7)]' },\n // The link variant reads as an inline Link despite the <button> tag:\n // strip the button chrome (padding from `size`, border, radius, bold\n // weight) and adopt Link's typography and 1em icon sizing so the hover\n // halo hugs the text instead of filling a button-shaped box.\n {\n variant: 'link',\n className: [\n 'rounded-none border-0 p-0 sm:p-0',\n // Release the step's height floor too — an inline link hugs its line\n // box, it does not stand a button's worth of space tall.\n 'min-h-0',\n // Hug the label even in stretching grid/flex contexts so the hover\n // halo wraps the text like an inline Link, not the allocated box.\n // `block` still wins — its w-full is applied after this in cn().\n 'w-fit',\n 'text-[length:inherit] font-medium',\n '*:data-[slot=icon]:size-[1em]',\n ],\n },\n ],\n defaultVariants: {\n variant: 'solid',\n color: 'primary',\n size: 'default',\n },\n})\n\n/** Visual/content props shared by `Button` and `ButtonLink`. */\ntype ButtonOwnProps = Omit<VariantProps<typeof buttonVariants>, 'size' | 'iconOnly'> & {\n /**\n * Scale step. `sm` / `default` / `lg` render 52 / 60 / 68px tall below\n * `sm:` and 44 / 52 / 60px at or above it. The step changes padding only —\n * the label is 16px and an icon beside it 24px at every step.\n *\n * `icon` is not a fourth step on that ramp — it is a flat 40×40 chrome\n * square (header actions, dialog close buttons, footer social links) that\n * lines up with none of them. For an icon-only button that must sit level\n * with text buttons beside it, pair `iconOnly` with `sm`/`default`/`lg`.\n */\n size?: 'sm' | 'default' | 'lg' | 'icon' | null\n /**\n * Render as a square containing only the icon, at the height of the current\n * `size` step — so `iconOnly` beside a `size='default'` button matches it\n * exactly. Supply an `aria-label`, since there is no visible text.\n *\n * With no label to match, the glyph scales with the square instead of\n * holding the 24px used beside text: 20px at `sm`, 24px at `default`, 28px\n * at `lg`, the same at every breakpoint. For a denser icon button that does\n * not line up with the text steps, use `size='icon'` (24px in a 40×40 box).\n */\n iconOnly?: boolean | null\n className?: string\n /** Button label. Optional for icon-only buttons (supply an `aria-label`). */\n children?: React.ReactNode\n /** Stretch button to fill its container width. */\n block?: boolean\n /** Show a spinner and disable interaction. */\n loading?: boolean\n /** Horizontal alignment of button content. */\n alignContent?: 'center' | 'start'\n disabled?: boolean\n /** Icon component rendered before the label. */\n leadingVisual?: React.ElementType\n /** Icon component rendered after the label. */\n trailingVisual?: React.ElementType\n /** Icon component rendered as a trailing action (far end). */\n trailingAction?: React.ElementType\n /** Allow the button label to wrap onto multiple lines. Defaults to true. */\n labelWrap?: boolean\n /** Optional numeric badge rendered after the label. */\n count?: number\n /**\n * Visually-hidden suffix announced after `count`, giving the bare number\n * context for screen readers (e.g. \"unread messages\" → \"Inbox 3 unread\n * messages\").\n */\n countLabel?: string\n}\n\ntype ButtonProps = ButtonOwnProps & Omit<ButtonPrimitive.Props, 'className' | 'disabled'>\n\ntype ButtonLinkProps = ButtonOwnProps &\n Omit<React.ComponentPropsWithoutRef<typeof Link>, 'className' | 'variant'> & {\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nfunction buttonClasses({\n variant,\n color,\n size,\n iconOnly,\n block,\n alignContent,\n className,\n effectiveDisabled,\n}: ButtonOwnProps & { effectiveDisabled?: boolean }) {\n return clsx(\n cn(\n buttonVariants({ variant, color, size, iconOnly }),\n block && 'w-full',\n alignContent === 'start' && 'justify-start',\n className,\n ),\n effectiveDisabled ? 'cursor-not-allowed' : 'cursor-pointer',\n )\n}\n\n/** Shared inner layout: spinner, visuals, label, count, touch target. */\nfunction ButtonContent({\n loading,\n leadingVisual: LeadingVisual,\n trailingVisual: TrailingVisual,\n trailingAction: TrailingAction,\n labelWrap,\n count,\n countLabel,\n children,\n}: Pick<\n ButtonOwnProps,\n | 'loading'\n | 'leadingVisual'\n | 'trailingVisual'\n | 'trailingAction'\n | 'labelWrap'\n | 'count'\n | 'countLabel'\n | 'children'\n>) {\n return (\n <TouchTarget>\n {loading && (\n <Spinner\n data-slot='icon'\n role={undefined}\n aria-hidden\n color='current'\n // The button's own label + aria-busy convey the busy state; the\n // spinner's default \"Loading\" announcement would be redundant.\n label=''\n // `block` overrides Spinner's default `inline` so the svg isn't\n // pushed below centre by the button's line-height; `size-full` fills\n // the icon-sized, self-centred wrapper span.\n svgClassName='block size-full'\n />\n )}\n {LeadingVisual && <LeadingVisual data-slot='icon' />}\n {labelWrap === false ? <span className='whitespace-nowrap'>{children}</span> : children}\n {count !== undefined && (\n <span className='rounded-full px-1.5 py-0.5 text-xs font-medium tabular-nums opacity-75'>\n {count}\n {countLabel ? <span className='sr-only'> {countLabel}</span> : null}\n </span>\n )}\n {TrailingVisual && <TrailingVisual data-slot='icon' />}\n {TrailingAction && <TrailingAction data-slot='icon' />}\n </TouchTarget>\n )\n}\n\n/**\n * Dev-only guard shared by `Button` and `ButtonLink`: an icon-only button\n * (`size=\"icon\"` or `iconOnly`) renders no visible text, so it must carry an\n * explicit accessible name. Warns in development when one is missing; a no-op\n * in production. A falsy `aria-label` (including `\"\"`) counts as missing.\n */\nfunction warnIfIconButtonUnlabelled(\n size: ButtonOwnProps['size'],\n iconOnly: ButtonOwnProps['iconOnly'],\n props: { 'aria-label'?: unknown; 'aria-labelledby'?: unknown },\n) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if ((size === 'icon' || iconOnly) && !props['aria-label'] && !props['aria-labelledby']) {\n console.warn(\n '[nswds/ui] Icon-only buttons (size=\"icon\" or iconOnly) have no visible label — pass aria-label or aria-labelledby so the control has an accessible name.',\n )\n }\n}\n\n/**\n * Action button on the Base UI button primitive. For button-styled\n * navigation, use `ButtonLink` — the `href` polymorphism that previously\n * lived on this component was removed in v2.\n *\n * Base UI's `render` prop is available for composition (e.g. rendering a\n * framework-specific element while keeping Button behaviour).\n */\nfunction Button({\n className,\n variant,\n color,\n size,\n iconOnly,\n children,\n block,\n loading,\n alignContent = 'center',\n disabled,\n leadingVisual,\n trailingVisual,\n trailingAction,\n labelWrap,\n count,\n countLabel,\n ref,\n ...props\n}: ButtonProps) {\n const effectiveDisabled = disabled || loading\n\n warnIfIconButtonUnlabelled(size, iconOnly, props)\n\n return (\n <ButtonPrimitive\n data-variant={variant}\n aria-busy={loading || undefined}\n {...props}\n disabled={effectiveDisabled}\n className={buttonClasses({\n variant,\n color,\n size,\n iconOnly,\n block,\n alignContent,\n className,\n effectiveDisabled,\n })}\n ref={ref}\n >\n <ButtonContent\n loading={loading}\n leadingVisual={leadingVisual}\n trailingVisual={trailingVisual}\n trailingAction={trailingAction}\n labelWrap={labelWrap}\n count={count}\n countLabel={countLabel}\n >\n {children}\n </ButtonContent>\n </ButtonPrimitive>\n )\n}\n\n/**\n * Button-styled anchor. Renders through `Link`, so it picks up the\n * framework link component from `LinkProvider` (e.g. next/link) and accepts\n * all anchor props. Disabled/loading states are conveyed with\n * `aria-disabled` and a click guard, since anchors have no `disabled`\n * attribute.\n */\nfunction ButtonLink({\n className,\n variant,\n color,\n size,\n iconOnly,\n children,\n block,\n loading,\n alignContent = 'center',\n disabled,\n leadingVisual,\n trailingVisual,\n trailingAction,\n labelWrap,\n count,\n countLabel,\n ref,\n ...props\n}: ButtonLinkProps) {\n const effectiveDisabled = disabled || loading\n\n warnIfIconButtonUnlabelled(size, iconOnly, props)\n\n return (\n <Link\n // Opt out of Link's built-in styling — ButtonLink supplies its own\n // complete visual treatment (background, border, focus ring, icon\n // sizing) and any Link styling layered on top would conflict.\n variant='unstyled'\n data-variant={variant}\n aria-busy={loading || undefined}\n {...props}\n {...(effectiveDisabled\n ? {\n 'aria-disabled': true,\n 'data-disabled': '',\n tabIndex: -1,\n onClick: (e: React.MouseEvent<HTMLAnchorElement>) => e.preventDefault(),\n }\n : {})}\n className={buttonClasses({\n variant,\n color,\n size,\n iconOnly,\n block,\n alignContent,\n className,\n effectiveDisabled,\n })}\n ref={ref}\n >\n <ButtonContent\n loading={loading}\n leadingVisual={leadingVisual}\n trailingVisual={trailingVisual}\n trailingAction={trailingAction}\n labelWrap={labelWrap}\n count={count}\n countLabel={countLabel}\n >\n {children}\n </ButtonContent>\n </Link>\n )\n}\n\n/**\n * Expand the hit area to at least 44×44px on touch devices\n */\nfunction TouchTarget({ children }: { children: React.ReactNode }) {\n return (\n <>\n <span\n className='absolute top-1/2 left-1/2 size-[max(100%,2.75rem)] -translate-x-1/2 -translate-y-1/2 rounded-sm bg-transparent [@media(pointer:fine)]:hidden'\n aria-hidden='true'\n />\n {children}\n </>\n )\n}\n\nexport { Button, ButtonLink, buttonVariants, TouchTarget }\nexport type { ButtonLinkProps, ButtonProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/button.tsx"],"names":["ButtonPrimitive"],"mappings":";;;;;;;;;AAYA,MAAM,MAAA,GAAS;AAAA,EACb,IAAA,EAAM;AAAA;AAAA,IAEJ,yJAAA;AAAA;AAAA;AAAA,IAGA,iBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,sBAAA;AAAA;AAAA;AAAA;AAAA,IAIA,+EAAA;AAAA;AAAA,IAEA,4DAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IASA,gCAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA;AAAA,GACF;AAAA,EACA,KAAA,EAAO;AAAA;AAAA,IAEL,mBAAA;AAAA;AAAA,IAEA,sCAAA;AAAA;AAAA,IAEA,oBAAA;AAAA;AAAA,IAEA,8GAAA;AAAA;AAAA,IAEA,kBAAA;AAAA;AAAA,IAEA,oBAAA;AAAA;AAAA,IAEA,qBAAA;AAAA;AAAA,IAEA,qFAAA;AAAA;AAAA,IAEA,6EAAA;AAAA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,IAAA;AAAA,QACjB,eAAA,EAAiB,EAAA;AAAA,QACjB,QAAA,EAAU,EAAA;AAAA,QACV,OAAA,EAAS,CAAC,CAAA,KAA2C,CAAA,CAAE,cAAA;AAAe,UAExE,EAAC;AAAA,MACL,WAAW,aAAA,CAAc;AAAA,QACvB,OAAA;AAAA,QACA,KAAA;AAAA,QACA,IAAA;AAAA,QACA,QAAA;AAAA,QACA,KAAA;AAAA,QACA,YAAA;AAAA,QACA,SAAA;AAAA,QACA;AAAA,OACD,CAAA;AAAA,MACD,GAAA;AAAA,MAEA,QAAA,kBAAA,GAAA;AAAA,QAAC,aAAA;AAAA,QAAA;AAAA,UACC,OAAA;AAAA,UACA,aAAA;AAAA,UACA,cAAA;AAAA,UACA,cAAA;AAAA,UACA,SAAA;AAAA,UACA,KAAA;AAAA,UACA,UAAA;AAAA,UAEC;AAAA;AAAA;AACH;AAAA,GACF;AAEJ;AAKA,SAAS,WAAA,CAAY,EAAE,QAAA,EAAS,EAAkC;AAChE,EAAA,uBACE,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,oBAAA,GAAA;AAAA,MAAC,MAAA;AAAA,MAAA;AAAA,QACC,SAAA,EAAU,8IAAA;AAAA,QACV,aAAA,EAAY;AAAA;AAAA,KACd;AAAA,IACC;AAAA,GAAA,EACH,CAAA;AAEJ","file":"button.js","sourcesContent":["'use client'\n\nimport { Button as ButtonPrimitive } from '@base-ui/react/button'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport clsx from 'clsx'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Link } from '../components/link.js'\nimport { Spinner } from '../components/spinner.js'\n\nconst styles = {\n base: [\n // Base\n 'relative isolate inline-flex items-baseline justify-center gap-x-2 rounded-sm border text-base/7 font-bold transition-all motion-reduce:transition-none',\n // Height floor, published per size step as `--btn-h` (see `styles.size`).\n // A floor rather than a fixed height so a wrapped label can still grow.\n 'min-h-(--btn-h)',\n // Border width, so the size steps can subtract it from their padding and\n // keep the outer box identical across variants. `outline` and `surface`\n // draw a 2px border and raise this to match; everything else stays 1px.\n // Without it the steps subtracted a hard-coded 1px and those two variants\n // came out 2px taller than `solid` at every step and breakpoint.\n '[--btn-border-w:1px]',\n // Focus — deliberately `focus:` (paints on pointer clicks too), unlike\n // Link/Input which use `focus-visible:`. Buttons give click feedback with\n // the ring; links only ring for keyboard/AT focus. Do not \"unify\" this.\n 'focus:outline focus:outline-2 focus:outline-offset-2 focus:outline-(--btn-bg)',\n // Disabled\n 'data-disabled:opacity-50 data-disabled:pointer-events-none',\n // Glyph size beside a label: one value for every step and breakpoint.\n // Every step sets `text-base/7`, so the label is 16px whatever the step —\n // only the padding changes. An icon next to it has to match the *text*,\n // not the box, so scaling it per step pairs a growing glyph with type that\n // never moves: at `lg` a 28px icon sat beside a 16px word, two and a half\n // times its cap height. 24px is 1.5x the label at every step, and the same\n // number `size='icon'` uses. `iconOnly` overrides this per step in\n // `compoundVariants` — with no label to match, it scales with its box.\n '[--btn-icon-size:--spacing(6)]',\n // Icon. No vertical margin: the glyph is `self-center` in a baseline-aligned\n // row, so margin buys it nothing optically and only inflates the flex line.\n // It was inert at `sm`/`default` (glyph + margin stayed inside the 1.75rem\n // line box) but pushed `lg` 2px past its own height below `sm:`, so a `lg`\n // button measured 70px with an icon and 68px without.\n '*:data-[slot=icon]:-mx-0.25 *:data-[slot=icon]:size-(--btn-icon-size) *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:self-center *:data-[slot=icon]:text-(--btn-icon) forced-colors:[--btn-icon:ButtonText] forced-colors:hover:[--btn-icon:ButtonText]',\n ],\n solid: [\n // Text color\n 'text-(--btn-text)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--btn-border)',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--btn-bg)',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-bg)',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n soft: [\n // Text color\n 'text-(--btn-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--btn-bg)/10',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--btn-bg)/20',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-bg)/10',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:bg-white/5',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n surface: [\n // Text color\n 'text-(--btn-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-(--btn-bg)/50 border-2 bg-(--btn-bg)/5 [--btn-border-w:2px]',\n // Dark mode: border is rendered on `after` so background is set to button background\n 'dark:bg-(--btn-bg)/30',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-bg)/5',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--btn-bg)/50',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // Border color on hover\n 'active:border-(--btn-bg) hover:border-(--btn-bg)',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n outline: [\n // Text color\n 'border-(--btn-bg) text-(--btn-bg) border-2 [--btn-border-w:2px]',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'bg-transparent',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-transparent',\n // Drop shadow, applied to the inset `before` layer so it blends with the border\n 'before:shadow-sm',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-(--btn-bg)',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n ghost: [\n // Text color\n 'text-(--btn-bg)',\n // Optical border, implemented as the button background to avoid corner artifacts\n 'border-transparent bg-(--btn-transparent)',\n // Button background, implemented as foreground layer to stack on top of pseudo-border layer\n 'before:absolute before:inset-0 before:-z-10 before:rounded-[calc(var(--radius-sm)-1px)] before:bg-(--btn-transparent)',\n // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo\n 'dark:before:hidden',\n // Dark mode: Subtle white outline is applied using a border\n 'dark:border-white/5',\n // Shim/overlay, inset to match button foreground and used for hover state + highlight shadow\n 'after:absolute after:inset-0 after:-z-10 after:rounded-[calc(var(--radius-sm)-1px)]',\n // State overlays\n 'hover:after:bg-(--btn-hover-overlay) active:after:bg-(--btn-active-overlay)',\n // Dark mode: `after` layer expands to cover entire button\n 'dark:after:-inset-px dark:after:rounded-sm',\n // Disabled\n 'data-disabled:before:shadow-none data-disabled:after:shadow-none',\n ],\n link: [\n // Text color — inherits from color token, no background or border\n 'text-(--btn-bg) border-transparent bg-transparent',\n // Halo tokens derive from the colour token via color-mix, mirroring Link\n '[--link-halo:color-mix(in_oklch,var(--btn-bg)_10%,transparent)]',\n '[--link-halo-active:color-mix(in_oklch,var(--btn-bg)_18%,transparent)]',\n // Resting underline, thickened on interaction — matching Link\n 'underline underline-offset-4 hover:decoration-2 active:decoration-2',\n // Hover / active halos match the GOV.UK-style halo on Link (see link.tsx\n // styledBase): the fill is painted on the `after` layer — consistent with\n // the other variants' hover overlays — and the box-shadow extends it 2px\n // above and 4px below the line box\n 'after:absolute after:inset-0 after:-z-10',\n 'hover:after:bg-(--link-halo) active:after:bg-(--link-halo-active)',\n 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',\n 'active:shadow-[0_-2px_0_var(--link-halo-active),0_4px_0_var(--link-halo-active)]',\n ],\n colors: {\n grey: [\n // Base\n '[--btn-bg:var(--color-grey-600)] [--btn-border:var(--color-grey-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-grey-600)]/10 [--btn-active-overlay:var(--color-grey-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n white: [\n // Base\n '[--btn-bg:var(--color-white)] [--btn-border:var(--color-white)]/90 [--btn-text:var(--color-grey-800)]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-white)]/10 [--btn-active-overlay:var(--color-white)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-black)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n primary: [\n // Base\n '[--btn-bg:var(--color-primary-800)] [--btn-border:var(--color-primary-800)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-primary-800)]/10 [--btn-active-overlay:var(--color-primary-800)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n secondary: [\n // Base\n '[--btn-bg:var(--color-primary-200)] [--btn-border:var(--color-primary-200)]/90 [--btn-text:var(--color-primary-800)]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-primary-200)]/10 [--btn-active-overlay:var(--color-primary-200)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/15',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-primary-800)]/10',\n ],\n tertiary: [\n // Base\n '[--btn-bg:var(--color-primary-600)] [--btn-border:var(--color-primary-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-primary-600)]/10 [--btn-active-overlay:var(--color-primary-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n accent: [\n // Base\n '[--btn-bg:var(--color-accent-600)] [--btn-border:var(--color-accent-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--color-accent-600)]/10 [--btn-active-overlay:var(--color-accent-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n // Semantic colours use the raw NSW token names (--danger-600, --success-600,\n // --warning-600) rather than Tailwind's `--color-*` bridge aliases. The\n // bridge aliases are tree-shaken by Tailwind v4 unless a matching utility\n // class is detected in scanned source, and arbitrary-property usages like\n // `[--btn-bg:var(--color-success-600)]` do NOT count as a usage signal.\n // The raw tokens are defined on :root by @nswds/tokens (a plain CSS import,\n // not a Tailwind theme), so they always resolve.\n danger: [\n // Base\n '[--btn-bg:var(--danger-600)] [--btn-border:var(--danger-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--danger-600)]/10 [--btn-active-overlay:var(--danger-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n success: [\n // Base\n '[--btn-bg:var(--success-600)] [--btn-border:var(--success-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--success-600)]/10 [--btn-active-overlay:var(--success-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n warning: [\n // Base\n '[--btn-bg:var(--warning-600)] [--btn-border:var(--warning-600)]/90 [--btn-text:white]',\n // State: Hover\n '[--btn-hover-overlay:var(--warning-600)]/10 [--btn-active-overlay:var(--warning-600)]/20',\n 'data-[variant=solid]:[--btn-hover-overlay:var(--color-white)]/10',\n // State: Active\n 'data-[variant=solid]:[--btn-active-overlay:var(--color-black)]/15',\n ],\n },\n // Each step publishes its own height as `--btn-h`, built from the same two\n // numbers that produce its box: one line box (`text-base/7` — Tailwind's\n // `/7` is `--spacing(7)`, so this is the same token, not a matching literal)\n // plus twice the vertical padding. `styles.base` pins it with `min-h`, and\n // `styles.iconOnly` reads it as both dimensions of the square — so an\n // icon-only button is exactly as tall as the text button beside it by\n // construction, and stays that way if a step is ever retuned.\n //\n // The border cancels out of that sum: padding is `--spacing(n) -\n // --btn-border-w` and the border adds `--btn-border-w` back, so every\n // variant lands on `--btn-h` whether it draws a 1px or 2px edge, and the\n // outer geometry stays put while the label shifts 1px to make room.\n //\n // The steps set padding and height only. Glyph size lives on the base (one\n // value beside a label) and in `compoundVariants` (per step when icon-only).\n size: {\n default:\n 'px-[calc(--spacing(6)-var(--btn-border-w))] py-[calc(--spacing(4)-var(--btn-border-w))] sm:px-[calc(--spacing(5.5)-var(--btn-border-w))] sm:py-[calc(--spacing(3)-var(--btn-border-w))] [--btn-h:calc(--spacing(7)+--spacing(4)*2)] sm:[--btn-h:calc(--spacing(7)+--spacing(3)*2)]',\n sm: 'px-[calc(--spacing(5)-var(--btn-border-w))] py-[calc(--spacing(3)-var(--btn-border-w))] sm:px-[calc(--spacing(4.5)-var(--btn-border-w))] sm:py-[calc(--spacing(2)-var(--btn-border-w))] [--btn-h:calc(--spacing(7)+--spacing(3)*2)] sm:[--btn-h:calc(--spacing(7)+--spacing(2)*2)]',\n lg: 'px-[calc(--spacing(7)-var(--btn-border-w))] py-[calc(--spacing(5)-var(--btn-border-w))] sm:px-[calc(--spacing(6.5)-var(--btn-border-w))] sm:py-[calc(--spacing(4)-var(--btn-border-w))] [--btn-h:calc(--spacing(7)+--spacing(5)*2)] sm:[--btn-h:calc(--spacing(7)+--spacing(4)*2)]',\n // A compact chrome square that deliberately sits below the text steps —\n // header actions, dialog close buttons, footer social links. For an icon\n // button that must line up with text buttons beside it, use `iconOnly`\n // with `sm`/`default`/`lg` instead. Its glyph is the base 24px.\n icon: 'w-10 h-10 flex-none [--btn-h:--spacing(10)]',\n },\n // Square the button at the current step and drop the horizontal padding, so\n // the scale step and \"is this icon-only\" are independent axes. The glyph\n // needs no adjustment — the step already sizes it off the ladder.\n iconOnly: 'size-(--btn-h) flex-none p-0 sm:p-0',\n}\n\nconst buttonVariants = cva(styles.base, {\n variants: {\n variant: {\n solid: styles.solid,\n soft: styles.soft,\n surface: styles.surface,\n outline: styles.outline,\n ghost: styles.ghost,\n link: styles.link,\n },\n color: {\n white: styles.colors.white,\n grey: styles.colors.grey,\n primary: styles.colors.primary,\n secondary: styles.colors.secondary,\n tertiary: styles.colors.tertiary,\n accent: styles.colors.accent,\n danger: styles.colors.danger,\n success: styles.colors.success,\n warning: styles.colors.warning,\n },\n size: {\n default: styles.size.default,\n sm: styles.size.sm,\n lg: styles.size.lg,\n icon: styles.size.icon,\n },\n // Declared after `size` so its `p-0` reaches `cn()` downstream of the\n // step's `px-*`/`py-*` and wins the tailwind-merge conflict.\n iconOnly: {\n true: styles.iconOnly,\n false: '',\n },\n },\n compoundVariants: [\n // ── Icon-only glyph sizes ────────────────────────────────────────────\n //\n // With no label beside it the glyph has nothing to match, so here — and\n // only here — it scales with its box, off the icon ladder: 20 / 24 / 28 /\n // 32 / 36 / 40px, i.e. `--spacing(5)` through `--spacing(10)`. Every level\n // is a multiple of 4, so glyphs share the grid with the padding and\n // heights around them and land on whole device pixels at 1x. A discrete\n // ladder rather than a proportion of the box, because a glyph is only\n // crisp at the sizes it was drawn for — \"40% of the box\" would ask for\n // sizes no glyph exists at.\n //\n // One value per step, not per breakpoint: the square never gets smaller\n // on a wider viewport, so neither should what sits inside it.\n { size: 'sm', iconOnly: true, className: '[--btn-icon-size:--spacing(5)]' },\n { size: 'default', iconOnly: true, className: '[--btn-icon-size:--spacing(6)]' },\n { size: 'lg', iconOnly: true, className: '[--btn-icon-size:--spacing(7)]' },\n // The link variant reads as an inline Link despite the <button> tag:\n // strip the button chrome (padding from `size`, border, radius, bold\n // weight) and adopt Link's typography and 1em icon sizing so the hover\n // halo hugs the text instead of filling a button-shaped box.\n {\n variant: 'link',\n className: [\n 'rounded-none border-0 p-0 sm:p-0',\n // Release the step's height floor too — an inline link hugs its line\n // box, it does not stand a button's worth of space tall.\n 'min-h-0',\n // Hug the label even in stretching grid/flex contexts so the hover\n // halo wraps the text like an inline Link, not the allocated box.\n // `block` still wins — its w-full is applied after this in cn().\n 'w-fit',\n 'text-[length:inherit] font-medium',\n '*:data-[slot=icon]:size-[1em]',\n ],\n },\n ],\n defaultVariants: {\n variant: 'solid',\n color: 'primary',\n size: 'default',\n },\n})\n\n/**\n * An icon slot. Takes either form:\n *\n * - the component itself — `leadingVisual={IconDownload}`\n * - a rendered element — `leadingVisual={<IconDownload />}`\n *\n * **From a React Server Component, use the element form.** `Button` and\n * `ButtonLink` are `'use client'` modules, while the icon modules carry no\n * directive — deliberately, so an icon stays server-renderable and ships no\n * JavaScript. That means in a server component `IconDownload` is an ordinary\n * function value, and functions cannot cross the RSC boundary into a client\n * component (\"Functions cannot be passed directly to Client Components\"). A\n * React element can, because it serialises. Client components can use either.\n */\ntype IconSlot = React.ElementType | React.ReactElement\n\n/**\n * Renders an icon slot in whichever form it arrived, stamping `data-slot='icon'`\n * so the `*:data-[slot=icon]:…` rules above size and colour it. An element that\n * sets its own `data-slot` to an actual value keeps it — a consumer who named one\n * deliberately meant it. `undefined` and `null` count as unset and get the stamp,\n * because forwarding an optional prop that happens to be absent is idiomatic React\n * and must not silently strip the icon's sizing and colour.\n *\n * Passing only the key we intend to set is deliberate: `cloneElement` already seeds\n * its props from `slot.props`, so spreading them back into the config would be a\n * no-op — except that React 19 copies every config key across with no undefined-skip\n * (`defaultProps` having been removed), which is exactly how a forwarded\n * `data-slot={undefined}` would erase the stamp.\n */\nfunction renderIconSlot(slot: IconSlot | undefined | null): React.ReactNode {\n if (!slot) return null\n if (React.isValidElement<{ 'data-slot'?: string }>(slot)) {\n return React.cloneElement(slot, { 'data-slot': slot.props['data-slot'] ?? 'icon' })\n }\n // `isValidElement` is a type guard, but its false branch does not subtract\n // ReactElement from the union — TS keeps both members — so name the remaining\n // case explicitly. Anything that is not a valid element is a component type.\n const Icon = slot as React.ElementType\n return <Icon data-slot='icon' />\n}\n\n/** Visual/content props shared by `Button` and `ButtonLink`. */\ntype ButtonOwnProps = Omit<VariantProps<typeof buttonVariants>, 'size' | 'iconOnly'> & {\n /**\n * Scale step. `sm` / `default` / `lg` render 52 / 60 / 68px tall below\n * `sm:` and 44 / 52 / 60px at or above it. The step changes padding only —\n * the label is 16px and an icon beside it 24px at every step.\n *\n * `icon` is not a fourth step on that ramp — it is a flat 40×40 chrome\n * square (header actions, dialog close buttons, footer social links) that\n * lines up with none of them. For an icon-only button that must sit level\n * with text buttons beside it, pair `iconOnly` with `sm`/`default`/`lg`.\n */\n size?: 'sm' | 'default' | 'lg' | 'icon' | null\n /**\n * Render as a square containing only the icon, at the height of the current\n * `size` step — so `iconOnly` beside a `size='default'` button matches it\n * exactly. Supply an `aria-label`, since there is no visible text.\n *\n * With no label to match, the glyph scales with the square instead of\n * holding the 24px used beside text: 20px at `sm`, 24px at `default`, 28px\n * at `lg`, the same at every breakpoint. For a denser icon button that does\n * not line up with the text steps, use `size='icon'` (24px in a 40×40 box).\n */\n iconOnly?: boolean | null\n className?: string\n /** Button label. Optional for icon-only buttons (supply an `aria-label`). */\n children?: React.ReactNode\n /** Stretch button to fill its container width. */\n block?: boolean\n /** Show a spinner and disable interaction. */\n loading?: boolean\n /** Horizontal alignment of button content. */\n alignContent?: 'center' | 'start'\n disabled?: boolean\n /** Icon rendered before the label. Component or element — see `IconSlot`. */\n leadingVisual?: IconSlot\n /** Icon rendered after the label. Component or element — see `IconSlot`. */\n trailingVisual?: IconSlot\n /** Icon rendered as a trailing action (far end). Component or element. */\n trailingAction?: IconSlot\n /** Allow the button label to wrap onto multiple lines. Defaults to true. */\n labelWrap?: boolean\n /** Optional numeric badge rendered after the label. */\n count?: number\n /**\n * Visually-hidden suffix announced after `count`, giving the bare number\n * context for screen readers (e.g. \"unread messages\" → \"Inbox 3 unread\n * messages\").\n */\n countLabel?: string\n}\n\ntype ButtonProps = ButtonOwnProps & Omit<ButtonPrimitive.Props, 'className' | 'disabled'>\n\ntype ButtonLinkProps = ButtonOwnProps &\n Omit<React.ComponentPropsWithoutRef<typeof Link>, 'className' | 'variant'> & {\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nfunction buttonClasses({\n variant,\n color,\n size,\n iconOnly,\n block,\n alignContent,\n className,\n effectiveDisabled,\n}: ButtonOwnProps & { effectiveDisabled?: boolean }) {\n return clsx(\n cn(\n buttonVariants({ variant, color, size, iconOnly }),\n block && 'w-full',\n alignContent === 'start' && 'justify-start',\n className,\n ),\n effectiveDisabled ? 'cursor-not-allowed' : 'cursor-pointer',\n )\n}\n\n/** Shared inner layout: spinner, visuals, label, count, touch target. */\nfunction ButtonContent({\n loading,\n leadingVisual,\n trailingVisual,\n trailingAction,\n labelWrap,\n count,\n countLabel,\n children,\n}: Pick<\n ButtonOwnProps,\n | 'loading'\n | 'leadingVisual'\n | 'trailingVisual'\n | 'trailingAction'\n | 'labelWrap'\n | 'count'\n | 'countLabel'\n | 'children'\n>) {\n return (\n <TouchTarget>\n {loading && (\n <Spinner\n data-slot='icon'\n role={undefined}\n aria-hidden\n color='current'\n // The button's own label + aria-busy convey the busy state; the\n // spinner's default \"Loading\" announcement would be redundant.\n label=''\n // `block` overrides Spinner's default `inline` so the svg isn't\n // pushed below centre by the button's line-height; `size-full` fills\n // the icon-sized, self-centred wrapper span.\n svgClassName='block size-full'\n />\n )}\n {renderIconSlot(leadingVisual)}\n {labelWrap === false ? <span className='whitespace-nowrap'>{children}</span> : children}\n {count !== undefined && (\n <span className='rounded-full px-1.5 py-0.5 text-xs font-medium tabular-nums opacity-75'>\n {count}\n {countLabel ? <span className='sr-only'> {countLabel}</span> : null}\n </span>\n )}\n {renderIconSlot(trailingVisual)}\n {renderIconSlot(trailingAction)}\n </TouchTarget>\n )\n}\n\n/**\n * Dev-only guard shared by `Button` and `ButtonLink`: an icon-only button\n * (`size=\"icon\"` or `iconOnly`) renders no visible text, so it must carry an\n * explicit accessible name. Warns in development when one is missing; a no-op\n * in production. A falsy `aria-label` (including `\"\"`) counts as missing.\n */\nfunction warnIfIconButtonUnlabelled(\n size: ButtonOwnProps['size'],\n iconOnly: ButtonOwnProps['iconOnly'],\n props: { 'aria-label'?: unknown; 'aria-labelledby'?: unknown },\n) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if ((size === 'icon' || iconOnly) && !props['aria-label'] && !props['aria-labelledby']) {\n console.warn(\n '[nswds/ui] Icon-only buttons (size=\"icon\" or iconOnly) have no visible label — pass aria-label or aria-labelledby so the control has an accessible name.',\n )\n }\n}\n\n/**\n * Action button on the Base UI button primitive. For button-styled\n * navigation, use `ButtonLink` — the `href` polymorphism that previously\n * lived on this component was removed in v2.\n *\n * Base UI's `render` prop is available for composition (e.g. rendering a\n * framework-specific element while keeping Button behaviour).\n */\nfunction Button({\n className,\n variant,\n color,\n size,\n iconOnly,\n children,\n block,\n loading,\n alignContent = 'center',\n disabled,\n leadingVisual,\n trailingVisual,\n trailingAction,\n labelWrap,\n count,\n countLabel,\n ref,\n ...props\n}: ButtonProps) {\n const effectiveDisabled = disabled || loading\n\n warnIfIconButtonUnlabelled(size, iconOnly, props)\n\n return (\n <ButtonPrimitive\n data-variant={variant}\n aria-busy={loading || undefined}\n {...props}\n disabled={effectiveDisabled}\n className={buttonClasses({\n variant,\n color,\n size,\n iconOnly,\n block,\n alignContent,\n className,\n effectiveDisabled,\n })}\n ref={ref}\n >\n <ButtonContent\n loading={loading}\n leadingVisual={leadingVisual}\n trailingVisual={trailingVisual}\n trailingAction={trailingAction}\n labelWrap={labelWrap}\n count={count}\n countLabel={countLabel}\n >\n {children}\n </ButtonContent>\n </ButtonPrimitive>\n )\n}\n\n/**\n * Button-styled anchor. Renders through `Link`, so it picks up the\n * framework link component from `LinkProvider` (e.g. next/link) and accepts\n * all anchor props. Disabled/loading states are conveyed with\n * `aria-disabled` and a click guard, since anchors have no `disabled`\n * attribute.\n */\nfunction ButtonLink({\n className,\n variant,\n color,\n size,\n iconOnly,\n children,\n block,\n loading,\n alignContent = 'center',\n disabled,\n leadingVisual,\n trailingVisual,\n trailingAction,\n labelWrap,\n count,\n countLabel,\n ref,\n ...props\n}: ButtonLinkProps) {\n const effectiveDisabled = disabled || loading\n\n warnIfIconButtonUnlabelled(size, iconOnly, props)\n\n return (\n <Link\n // Opt out of Link's built-in styling — ButtonLink supplies its own\n // complete visual treatment (background, border, focus ring, icon\n // sizing) and any Link styling layered on top would conflict.\n variant='unstyled'\n data-variant={variant}\n aria-busy={loading || undefined}\n {...props}\n {...(effectiveDisabled\n ? {\n 'aria-disabled': true,\n 'data-disabled': '',\n tabIndex: -1,\n onClick: (e: React.MouseEvent<HTMLAnchorElement>) => e.preventDefault(),\n }\n : {})}\n className={buttonClasses({\n variant,\n color,\n size,\n iconOnly,\n block,\n alignContent,\n className,\n effectiveDisabled,\n })}\n ref={ref}\n >\n <ButtonContent\n loading={loading}\n leadingVisual={leadingVisual}\n trailingVisual={trailingVisual}\n trailingAction={trailingAction}\n labelWrap={labelWrap}\n count={count}\n countLabel={countLabel}\n >\n {children}\n </ButtonContent>\n </Link>\n )\n}\n\n/**\n * Expand the hit area to at least 44×44px on touch devices\n */\nfunction TouchTarget({ children }: { children: React.ReactNode }) {\n return (\n <>\n <span\n className='absolute top-1/2 left-1/2 size-[max(100%,2.75rem)] -translate-x-1/2 -translate-y-1/2 rounded-sm bg-transparent [@media(pointer:fine)]:hidden'\n aria-hidden='true'\n />\n {children}\n </>\n )\n}\n\nexport { Button, ButtonLink, buttonVariants, TouchTarget }\nexport type { ButtonLinkProps, ButtonProps, IconSlot }\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
2
2
|
import { VariantProps } from 'class-variance-authority';
|
|
3
3
|
import React__default from 'react';
|
|
4
|
-
import { ButtonLink } from './button.js';
|
|
4
|
+
import { IconSlot, ButtonLink } from './button.js';
|
|
5
5
|
import { Link } from './link.js';
|
|
6
6
|
import '@base-ui/react/button';
|
|
7
7
|
|
|
@@ -43,19 +43,25 @@ type FooterSocialLinkItem = {
|
|
|
43
43
|
name: string;
|
|
44
44
|
href: string;
|
|
45
45
|
/**
|
|
46
|
-
* Icon
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Icon for the channel — the component (`IconLinkedIn`) or an element
|
|
47
|
+
* (`<IconLinkedIn />`). Brand marks (LinkedIn, X, Facebook…) are not part of
|
|
48
|
+
* the NSWDS icon set — which is Material Symbols — so the mark is supplied by
|
|
49
|
+
* the consuming app. It is rendered through `ButtonLink`'s `leadingVisual`
|
|
50
|
+
* slot, which sizes and colours it.
|
|
51
|
+
*
|
|
52
|
+
* `Footer` is server-compatible but `ButtonLink` is not, so a React Server
|
|
53
|
+
* Component assembling `socialLinks` must use the element form; the component
|
|
54
|
+
* form cannot cross the RSC boundary. See `IconSlot`.
|
|
50
55
|
*/
|
|
51
|
-
icon:
|
|
56
|
+
icon: IconSlot;
|
|
52
57
|
/**
|
|
53
58
|
* Accessible name for the link. Defaults to `Follow us on {name}`.
|
|
54
59
|
*/
|
|
55
60
|
label?: string;
|
|
56
61
|
};
|
|
57
62
|
type FooterSocialLinkProps = Omit<React__default.ComponentPropsWithoutRef<typeof ButtonLink>, 'children' | 'color' | 'leadingVisual' | 'size' | 'variant'> & {
|
|
58
|
-
|
|
63
|
+
/** Channel mark — component or element. See `IconSlot`. */
|
|
64
|
+
icon: IconSlot;
|
|
59
65
|
/** Accessible name, e.g. "Follow us on LinkedIn". */
|
|
60
66
|
label: string;
|
|
61
67
|
};
|