@nswds/ui 4.6.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/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,IAEA,qEAAA;AAAA;AAAA,IAEA,gEAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,eA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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;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA,SAAA,EAAW;AAAA;AAAA,IAET,4CAAA;AAAA;A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;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"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
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 { BadgeProps } from './badge.js';
|
|
4
5
|
import { Link } from './link.js';
|
|
6
|
+
import '@base-ui/react/button';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Surface colours the header can be themed with, sharing the Masthead's and
|
|
@@ -60,6 +62,29 @@ type HeaderBrandProps = React__default.ComponentPropsWithoutRef<'div'> & {
|
|
|
60
62
|
* string to suppress.
|
|
61
63
|
*/
|
|
62
64
|
versionLabel?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Props forwarded to the version `Badge` — `size`, `color`, `variant`,
|
|
67
|
+
* `className` and the rest of its API. Use it when the badge has to meet a
|
|
68
|
+
* house rule the default does not, most often a minimum type size:
|
|
69
|
+
*
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <HeaderBrand version="2.1.0" badgeProps={{ size: 'lg' }} />
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* An explicit value always wins — including `color`, whose surface-aware
|
|
75
|
+
* default exists to stop the badge painting itself the same colour as a dark
|
|
76
|
+
* header. Overriding it is the same trade as supplying your own `logo` node:
|
|
77
|
+
* the contrast is then yours to check.
|
|
78
|
+
*
|
|
79
|
+
* `undefined` and `null` do *not* win: they fall back to the defaults, so a
|
|
80
|
+
* conditional like `{ color: cond ? 'accent' : undefined }` keeps the
|
|
81
|
+
* surface-aware colour on the falsy branch rather than dropping the badge to
|
|
82
|
+
* cva's own `primary` default.
|
|
83
|
+
*
|
|
84
|
+
* `children` is excluded — the badge's content is `version` and
|
|
85
|
+
* `versionLabel`.
|
|
86
|
+
*/
|
|
87
|
+
badgeProps?: Omit<BadgeProps, 'children'>;
|
|
63
88
|
/**
|
|
64
89
|
* `true` (default) renders the NSW Government waratah, `false` omits it, and
|
|
65
90
|
* a node replaces it — pass an agency lockup here.
|
|
@@ -83,7 +108,7 @@ type HeaderBrandProps = React__default.ComponentPropsWithoutRef<'div'> & {
|
|
|
83
108
|
* The link renders through `Link`, so it picks up the framework link component
|
|
84
109
|
* from `LinkProvider` (next/link et al) rather than hardcoding one.
|
|
85
110
|
*/
|
|
86
|
-
declare function HeaderBrand({ className, href, sitename, headingLevel, version, versionLabel, logo, label, children, ref, ...props }: HeaderBrandProps): React__default.JSX.Element;
|
|
111
|
+
declare function HeaderBrand({ className, href, sitename, headingLevel, version, versionLabel, badgeProps, logo, label, children, ref, ...props }: HeaderBrandProps): React__default.JSX.Element;
|
|
87
112
|
type HeaderActionsProps = React__default.ComponentPropsWithoutRef<'div'> & {
|
|
88
113
|
ref?: React__default.Ref<HTMLDivElement>;
|
|
89
114
|
};
|
|
@@ -84,6 +84,7 @@ function HeaderBrand({
|
|
|
84
84
|
headingLevel,
|
|
85
85
|
version,
|
|
86
86
|
versionLabel = "Version",
|
|
87
|
+
badgeProps,
|
|
87
88
|
logo = true,
|
|
88
89
|
label,
|
|
89
90
|
children,
|
|
@@ -149,8 +150,9 @@ function HeaderBrand({
|
|
|
149
150
|
Badge,
|
|
150
151
|
{
|
|
151
152
|
"data-slot": "header-version",
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
...badgeProps,
|
|
154
|
+
variant: badgeProps?.variant ?? "soft",
|
|
155
|
+
color: badgeProps?.color ?? (onDarkSurface ? "white" : "primary"),
|
|
154
156
|
children: [
|
|
155
157
|
versionLabel ? /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
|
|
156
158
|
versionLabel,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/header.tsx"],"names":[],"mappings":";;;;;;;;AA4BA,MAAM,YAAA,GAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,IAAA,EAAM,iFAAA;AAAA,EACN,KAAA,EACE,kIAAA;AAAA,EACF,KAAA,EACE,+HAAA;AAAA,EACF,IAAA,EAAM;AACR;AAMA,MAAM,oBAAA,GAAoC,OAAA;AAE1C,MAAM,cAAA,GAAiB,GAAA;AAAA,EACrB;AAAA,IACE,QAAA;AAAA;AAAA;AAAA;AAAA,IAIA,yEAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,KAAA,EAAO;AAAA;AACT;AAEJ;AAEA,MAAM,uBAAA,GAA0B,GAAA;AAAA,EAC9B;AAAA,IACE,iGAAA;AAAA;AAAA;AAAA;AAAA,IAIA,yBAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,SAAA,EAAW;AAAA;AAAA;AAAA,QAGT,KAAA,EAAO,sCAAA;AAAA;AAAA,QAEP,SAAA,EAAW;AAAA;AACb,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,SAAA,EAAW;AAAA;AACb;AAEJ;AASA,MAAM,kBAAA,GAAqB,KAAA,CAAM,aAAA,CAA2B,oBAAoB,CAAA;AAGhF,MAAM,sCAAsB,IAAI,GAAA,CAAiB,CAAC,MAAA,EAAQ,MAAM,CAAC,CAAA;AAqDjE,SAAS,qBAAA,CAAsB;AAAA,EAC7B,IAAA;AAAA,E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QAAA,kBAAA,GAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,WAAA,EAAU,kBAAA;AAAA,UACV,WAAW,EAAA,CAAG,uBAAA,CAAwB,EAAE,SAAA,EAAW,GAAG,kBAAkB,CAAA;AAAA,UAEvE;AAAA;AAAA,OACH,EACF;AAAA;AAAA,GACF;AAEJ","file":"header.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Badge } from '../components/badge.js'\nimport { Link } from '../components/link.js'\nimport { Logo } from '../components/logo.js'\n\n/**\n * Surface colours the header can be themed with, sharing the Masthead's and\n * SkipLink's four-name vocabulary (`dark`, `light`, `white`, `grey`) — the three\n * components stack at the top of the page and a service picks one word for the\n * whole chrome.\n *\n * Every pair is WCAG 2.2 AAA (1.4.6, 7:1), computed from the masterbrand oklch\n * tokens. Light mode: grey-800 on white 15.1:1, grey-800 on grey-100 13.8:1,\n * white on primary-800 14.4:1, white on grey-800 15.1:1. Dark mode deepens each\n * surface onto the same family's dark step and clears AAA more comfortably\n * still (17.2:1–20.2:1).\n *\n * Unlike the Masthead — a brand strip whose light/white/grey surfaces are frozen\n * across themes — the header is the page's own surface, so all four follow the\n * theme. Pair `Header color=\"dark\"` with `Masthead color=\"dark\"` when a service\n * wants the two to match in both modes.\n */\nconst headerColors = {\n // Ink values use the RAW masterbrand tokens (--grey-800) rather than\n // Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes an\n // unreferenced @theme key, and referencing one from inside an arbitrary\n // property is not a usage signal. Same reasoning as footer.tsx.\n // (--color-white is safe: `text-white` below is a real utility.)\n dark: 'bg-primary-800 text-white [--header-ink:var(--color-white)] dark:bg-primary-950',\n light:\n 'bg-grey-100 text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--header-ink:var(--color-white)]',\n white:\n 'bg-white text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--header-ink:var(--color-white)]',\n grey: 'bg-grey-800 text-white [--header-ink:var(--color-white)] dark:bg-grey-950',\n}\n\ntype HeaderColor = keyof typeof headerColors\n\n// Shared by cva's defaultVariants, the data-color attribute and the logo\n// context, so the four can't drift apart.\nconst DEFAULT_HEADER_COLOR: HeaderColor = 'white'\n\nconst headerVariants = cva(\n [\n 'w-full',\n // The hairline rule derives from the surface's own ink, so it follows every\n // colour variant and both themes from one value. Mirrors the color-mix\n // derivation in footer.tsx (--footer-border) and link.tsx (--link-halo).\n '[--header-border:color-mix(in_oklch,var(--header-ink)_15%,transparent)]',\n 'transition-shadow duration-300 motion-reduce:transition-none',\n ],\n {\n variants: {\n color: headerColors,\n },\n defaultVariants: {\n color: DEFAULT_HEADER_COLOR,\n },\n },\n)\n\nconst headerContainerVariants = cva(\n [\n 'mx-auto flex w-full flex-wrap items-center justify-between gap-x-4 gap-y-3 py-3 sm:py-4 lg:py-5',\n // Lateral padding funnels through --header-padding-x so an app can retune it\n // once (via the `style` prop or a utility class) without a new variant. Same\n // mechanism, and the same 16px → 24px → 48px rhythm, as Masthead and Footer.\n 'px-(--header-padding-x)',\n '[--header-padding-x:--spacing(4)] sm:[--header-padding-x:--spacing(6)] lg:[--header-padding-x:--spacing(12)]',\n ],\n {\n variants: {\n container: {\n // Full-bleed (nswds-app parity). --header-max-width is still read so a\n // shell app can constrain the inner wrapper without switching variants.\n fluid: 'max-w-[var(--header-max-width,none)]',\n // Centred content column, legacy nsw-container parity (1200px).\n contained: 'max-w-[var(--header-max-width,75rem)]',\n },\n },\n defaultVariants: {\n container: 'fluid',\n },\n },\n)\n\n/**\n * Lets `HeaderBrand` adapt its artwork to the surface it is drawn on — the\n * default `Logo` paints its wordmark `nsw-blue-800` and the version `Badge`\n * paints itself `primary-800`, both of which disappear on the `dark`\n * (primary-800) surface. A `logo` node supplied by the consumer overrides the\n * lockup entirely; at that point the choice is theirs.\n */\nconst HeaderColorContext = React.createContext<HeaderColor>(DEFAULT_HEADER_COLOR)\n\n/** Surfaces dark enough to need light-on-dark artwork. */\nconst DARK_SURFACE_COLORS = new Set<HeaderColor>(['dark', 'grey'])\n\ntype HeaderBrandProps = React.ComponentPropsWithoutRef<'div'> & {\n /** Home-page target for the brand link. Defaults to `/`. */\n href?: React.ComponentPropsWithoutRef<typeof Link>['href']\n /** Service or site name shown beside the logo. */\n sitename?: React.ReactNode\n /**\n * Heading level for `sitename`. Omit (the default) to render a `<span>`,\n * which is usually right: the page's own `<h1>` belongs to its main content,\n * and a site name repeated in the header on every page is not the heading\n * that describes this page. Supply a level only when a service deliberately\n * places the site name in the document outline.\n *\n * `1` is excluded for the reason above; `6` is the deepest heading HTML\n * defines.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n /**\n * Version string shown in a Badge beside the brand. Sits outside the link,\n * so it never becomes part of the home link's accessible name.\n */\n version?: React.ReactNode\n /**\n * Visually-hidden prefix announced before `version`, giving the bare number\n * context for screen readers (\"2.1.0\" → \"Version 2.1.0\"). Pass an empty\n * string to suppress.\n */\n versionLabel?: string\n /**\n * `true` (default) renders the NSW Government waratah, `false` omits it, and\n * a node replaces it — pass an agency lockup here.\n */\n logo?: boolean | React.ReactNode\n /**\n * Accessible name for the brand link. Left unset by default: the link's name\n * is then its visible content — \"NSW Government\" (from `Logo`'s\n * visually-hidden text) plus `sitename` — which keeps the visible label\n * inside the accessible name (WCAG 2.2, 2.5.3 Label in Name). Overriding it\n * with something like \"Home page\" would break that, so set it only when the\n * brand renders no text at all.\n */\n label?: string\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: the\n * default `Logo` carries a visually-hidden \"NSW Government\", so a brand with\n * neither it nor a `sitename` renders a link with no text at all, and reaches\n * assistive tech unnamed (WCAG 2.2, 4.1.2 Name, Role, Value). A consumer's own\n * logo node is assumed to carry its own text. No-op in production.\n */\nfunction warnIfBrandUnlabelled({\n logo,\n sitename,\n label,\n}: Pick<HeaderBrandProps, 'logo' | 'sitename' | 'label'>) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!logo && !sitename && !label) {\n console.warn(\n '[nswds/ui] HeaderBrand has no logo and no sitename, so its home link has no accessible name — pass `label`.',\n )\n }\n}\n\n/**\n * Logo, site name and optional version badge, linked to the home page. Sits at\n * the start of the `Header` row.\n *\n * The link renders through `Link`, so it picks up the framework link component\n * from `LinkProvider` (next/link et al) rather than hardcoding one.\n */\nfunction HeaderBrand({\n className,\n href = '/',\n sitename,\n headingLevel,\n version,\n versionLabel = 'Version',\n logo = true,\n label,\n children,\n ref,\n ...props\n}: HeaderBrandProps) {\n const color = React.useContext(HeaderColorContext)\n const onDarkSurface = DARK_SURFACE_COLORS.has(color)\n const Sitename = headingLevel ? (`h${headingLevel}` as const) : 'span'\n\n warnIfBrandUnlabelled({ logo, sitename, label })\n\n const logoNode =\n logo === true ? (\n <Logo\n logoType={onDarkSurface ? 'reversed' : 'default'}\n // 64px from lg, 56px below it — 56px is the floor, so the lockup stays\n // legible on a phone. Written as mutually exclusive breakpoint ranges\n // rather than `h-14 lg:h-16`: a bare `h-14` a consumer also uses is\n // re-emitted after ours by their own Tailwind build, and a media query\n // adds no specificity, so it would outrank the lg step and freeze the\n // logo at 56px.\n className='w-auto max-lg:h-14 lg:h-16'\n />\n ) : (\n // `false` / `null` fall through as the falsy nodes they are; anything\n // else is the consumer's own lockup.\n logo\n )\n\n return (\n <div\n data-slot='header-brand'\n {...props}\n className={cn('flex grow basis-0 items-center gap-3 sm:gap-4', className)}\n ref={ref}\n >\n {/* variant='unstyled' — a brand lockup takes no underline or link\n colour. outline-current resolves to the surface's ink on every\n variant, so the focus indicator contrasts with the header\n (WCAG 2.2, 2.4.13 Focus Appearance). The negative margin keeps the\n indicator from nudging the row. */}\n <Link\n variant='unstyled'\n href={href}\n aria-label={label}\n className='-m-1 flex items-center gap-3 rounded-sm p-1 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current sm:gap-4'\n >\n {logoNode}\n {sitename ? (\n // Brand-blue ink on the light surfaces (14.4:1 on white, 13.2:1 on\n // grey-100 — both WCAG 2.2 AAA). The `dark` surface *is* primary-800\n // and `grey` is nearly as deep, so those keep the header's own white\n // ink; dark mode does the same, matching the `dark:text-white` the\n // light/white variants already set on the surface.\n <Sitename\n className={cn(\n 'text-lg font-bold text-balance sm:text-xl',\n !onDarkSurface && 'text-primary-800 dark:text-white',\n )}\n >\n {sitename}\n </Sitename>\n ) : null}\n </Link>\n {version ? (\n // Badge's `primary` ink is primary-800 — the `dark` header's own\n // surface — so dark surfaces take the white badge instead.\n <Badge\n data-slot='header-version'\n variant='soft'\n color={onDarkSurface ? 'white' : 'primary'}\n >\n {versionLabel ? <span className='sr-only'>{versionLabel} </span> : null}\n {version}\n </Badge>\n ) : null}\n {children}\n </div>\n )\n}\n\ntype HeaderActionsProps = React.ComponentPropsWithoutRef<'div'> & {\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Trailing cluster of header controls — search, theme switcher, sign-in, and\n * the like. Deliberately unopinionated about what goes in it: site search and\n * theme switching are app concerns (they need routing and a theme provider),\n * so the design system supplies the slot and its spacing rather than the\n * widgets.\n *\n * Not a `nav` landmark: a row of controls is not a set of navigation links, and\n * an extra landmark on every page buries the ones that matter. Wrap genuine\n * navigation in your own `<nav>` inside `Header`.\n */\nfunction HeaderActions({ className, ref, ...props }: HeaderActionsProps) {\n return (\n <div\n data-slot='header-actions'\n {...props}\n className={cn('flex basis-0 items-center justify-end gap-2 sm:gap-4 md:grow', className)}\n ref={ref}\n />\n )\n}\n\ntype HeaderProps = React.ComponentPropsWithoutRef<'header'> &\n VariantProps<typeof headerVariants> &\n VariantProps<typeof headerContainerVariants> & {\n /** Stick to the top of the viewport as the page scrolls. Defaults to `true`. */\n sticky?: boolean\n /** Hairline rule along the bottom edge. Defaults to `true`. */\n border?: boolean\n /** Raise the header with a shadow once the page is scrolled. Defaults to `true`. */\n shadow?: boolean\n /** Classes applied to the inner width-constraining wrapper. */\n containerClassName?: string\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Top-of-page `banner` landmark: brand, site name and header controls. Render\n * it once in a shared layout, below `SkipLinks` and `Masthead`.\n *\n * - `color` themes the surface; all four pairs are WCAG 2.2 AAA and follow the\n * theme in dark mode (see `headerColors`). The bottom rule derives from the\n * surface's ink, so it follows automatically.\n * - `container` selects the inner wrapper layout: `fluid` (full-bleed,\n * nswds-app parity) or `contained` (centred 1200px column, legacy\n * `nsw-container` parity). Fine-tune either with the `--header-max-width`\n * and `--header-padding-x` custom properties.\n * - Scroll position is tracked and exposed as `data-scrolled`, which is what\n * the `shadow` treatment keys off. Style your own scrolled state with it.\n *\n * Compose the row from `HeaderBrand` and `HeaderActions`:\n *\n * ```tsx\n * <Header>\n * <HeaderBrand sitename=\"Design System\" version=\"2.1.0\" />\n * <HeaderActions>\n * <ThemeSwitcher />\n * </HeaderActions>\n * </Header>\n * ```\n *\n * The `banner` landmark comes from the native `<header>` element, which only\n * carries it outside `article`, `aside`, `main`, `nav` and `section` — wrapping\n * `div`s are fine. Keep it out of `<main>`.\n *\n * The default `id=\"nsw-header\"` is kept for compatibility with existing shells\n * that target it (override via the `id` prop).\n */\nfunction Header({\n className,\n color,\n container,\n containerClassName,\n sticky = true,\n border = true,\n shadow = true,\n children,\n ref,\n ...props\n}: HeaderProps) {\n const [isScrolled, setIsScrolled] = React.useState(false)\n\n React.useEffect(() => {\n function onScroll() {\n setIsScrolled(window.scrollY > 0)\n }\n // Read once on mount too: a page restored mid-scroll (back/forward, or a\n // deep link to a fragment) never fires a scroll event.\n onScroll()\n window.addEventListener('scroll', onScroll, { passive: true })\n return () => window.removeEventListener('scroll', onScroll)\n }, [])\n\n return (\n <header\n id='nsw-header'\n data-slot='header'\n data-color={color ?? DEFAULT_HEADER_COLOR}\n // Present-or-absent rather than \"true\"/\"false\", so it reads like Base\n // UI's data-disabled and Tailwind's bare `data-scrolled:` variant works.\n data-scrolled={isScrolled || undefined}\n {...props}\n className={cn(\n headerVariants({ color }),\n // z-40 sits below the z-50 SkipLinks: a sticky header at the same\n // level comes later in the DOM and would paint over a focused skip\n // link, hiding the page's bypass mechanism (WCAG 2.2, 2.4.1).\n sticky && 'sticky top-0 z-40',\n // Always drawn, so the scrolled state changes no box heights.\n border && 'border-b border-(--header-border)',\n // Shadows read as elevation on light surfaces only; in dark mode the\n // rule above carries the separation.\n shadow &&\n 'data-scrolled:shadow-md data-scrolled:shadow-black/5 dark:data-scrolled:shadow-none',\n className,\n )}\n ref={ref}\n >\n <HeaderColorContext.Provider value={color ?? DEFAULT_HEADER_COLOR}>\n <div\n data-slot='header-container'\n className={cn(headerContainerVariants({ container }), containerClassName)}\n >\n {children}\n </div>\n </HeaderColorContext.Provider>\n </header>\n )\n}\n\nexport { Header, HeaderActions, HeaderBrand, headerColors, headerContainerVariants, headerVariants }\nexport type { HeaderActionsProps, HeaderBrandProps, HeaderColor, HeaderProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/header.tsx"],"names":[],"mappings":";;;;;;;;AA4BA,MAAM,YAAA,GAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,IAAA,EAAM,iFAAA;AAAA,EACN,KAAA,EACE,kIAAA;AAAA,EACF,KAAA,EACE,+HAAA;AAAA,EACF,IAAA,EAAM;AACR;AAMA,MAAM,oBAAA,GAAoC,OAAA;AAE1C,MAAM,cAAA,GAAiB,GAAA;AAAA,EACrB;AAAA,IACE,QAAA;AAAA;AAAA;AAAA;AAAA,IAIA,yEAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,KAAA,EAAO;AAAA;AACT;AAEJ;AAEA,MAAM,uBAAA,GAA0B,GAAA;AAAA,EAC9B;AAAA,IACE,iGAAA;AAAA;AAAA;AAAA;AAAA,IAIA,yBAAA;AAAA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;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,EAAA,EAAG,YAAA;AAAA,MACH,WAAA,EAAU,QAAA;AAAA,MACV,cAAY,KAAA,IAAS,oBAAA;AAAA,MAGrB,iBAAe,UAAA,IAAc,MAAA;AAAA,MAC5B,GAAG,KAAA;AAAA,MACJ,SAAA,EAAW,EAAA;AAAA,QACT,cAAA,CAAe,EAAE,KAAA,EAAO,CAAA;AAAA;AAAA;AAAA;AAAA,QAIxB,MAAA,IAAU,mBAAA;AAAA;AAAA,QAEV,MAAA,IAAU,mCAAA;AAAA;AAAA;AAAA,QAGV,MAAA,IACE,qFAAA;AAAA,QACF;AAAA,OACF;AAAA,MACA,GAAA;AAAA,MAEA,8BAAC,kBAAA,CAAmB,QAAA,EAAnB,EAA4B,KAAA,EAAO,SAAS,oBAAA,EAC3C,QAAA,kBAAA,GAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,WAAA,EAAU,kBAAA;AAAA,UACV,WAAW,EAAA,CAAG,uBAAA,CAAwB,EAAE,SAAA,EAAW,GAAG,kBAAkB,CAAA;AAAA,UAEvE;AAAA;AAAA,OACH,EACF;AAAA;AAAA,GACF;AAEJ","file":"header.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Badge, type BadgeProps } from '../components/badge.js'\nimport { Link } from '../components/link.js'\nimport { Logo } from '../components/logo.js'\n\n/**\n * Surface colours the header can be themed with, sharing the Masthead's and\n * SkipLink's four-name vocabulary (`dark`, `light`, `white`, `grey`) — the three\n * components stack at the top of the page and a service picks one word for the\n * whole chrome.\n *\n * Every pair is WCAG 2.2 AAA (1.4.6, 7:1), computed from the masterbrand oklch\n * tokens. Light mode: grey-800 on white 15.1:1, grey-800 on grey-100 13.8:1,\n * white on primary-800 14.4:1, white on grey-800 15.1:1. Dark mode deepens each\n * surface onto the same family's dark step and clears AAA more comfortably\n * still (17.2:1–20.2:1).\n *\n * Unlike the Masthead — a brand strip whose light/white/grey surfaces are frozen\n * across themes — the header is the page's own surface, so all four follow the\n * theme. Pair `Header color=\"dark\"` with `Masthead color=\"dark\"` when a service\n * wants the two to match in both modes.\n */\nconst headerColors = {\n // Ink values use the RAW masterbrand tokens (--grey-800) rather than\n // Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes an\n // unreferenced @theme key, and referencing one from inside an arbitrary\n // property is not a usage signal. Same reasoning as footer.tsx.\n // (--color-white is safe: `text-white` below is a real utility.)\n dark: 'bg-primary-800 text-white [--header-ink:var(--color-white)] dark:bg-primary-950',\n light:\n 'bg-grey-100 text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-850 dark:text-white dark:[--header-ink:var(--color-white)]',\n white:\n 'bg-white text-grey-800 [--header-ink:var(--grey-800)] dark:bg-grey-900 dark:text-white dark:[--header-ink:var(--color-white)]',\n grey: 'bg-grey-800 text-white [--header-ink:var(--color-white)] dark:bg-grey-950',\n}\n\ntype HeaderColor = keyof typeof headerColors\n\n// Shared by cva's defaultVariants, the data-color attribute and the logo\n// context, so the four can't drift apart.\nconst DEFAULT_HEADER_COLOR: HeaderColor = 'white'\n\nconst headerVariants = cva(\n [\n 'w-full',\n // The hairline rule derives from the surface's own ink, so it follows every\n // colour variant and both themes from one value. Mirrors the color-mix\n // derivation in footer.tsx (--footer-border) and link.tsx (--link-halo).\n '[--header-border:color-mix(in_oklch,var(--header-ink)_15%,transparent)]',\n 'transition-shadow duration-300 motion-reduce:transition-none',\n ],\n {\n variants: {\n color: headerColors,\n },\n defaultVariants: {\n color: DEFAULT_HEADER_COLOR,\n },\n },\n)\n\nconst headerContainerVariants = cva(\n [\n 'mx-auto flex w-full flex-wrap items-center justify-between gap-x-4 gap-y-3 py-3 sm:py-4 lg:py-5',\n // Lateral padding funnels through --header-padding-x so an app can retune it\n // once (via the `style` prop or a utility class) without a new variant. Same\n // mechanism, and the same 16px → 24px → 48px rhythm, as Masthead and Footer.\n 'px-(--header-padding-x)',\n '[--header-padding-x:--spacing(4)] sm:[--header-padding-x:--spacing(6)] lg:[--header-padding-x:--spacing(12)]',\n ],\n {\n variants: {\n container: {\n // Full-bleed (nswds-app parity). --header-max-width is still read so a\n // shell app can constrain the inner wrapper without switching variants.\n fluid: 'max-w-[var(--header-max-width,none)]',\n // Centred content column, legacy nsw-container parity (1200px).\n contained: 'max-w-[var(--header-max-width,75rem)]',\n },\n },\n defaultVariants: {\n container: 'fluid',\n },\n },\n)\n\n/**\n * Lets `HeaderBrand` adapt its artwork to the surface it is drawn on — the\n * default `Logo` paints its wordmark `nsw-blue-800` and the version `Badge`\n * paints itself `primary-800`, both of which disappear on the `dark`\n * (primary-800) surface. A `logo` node supplied by the consumer overrides the\n * lockup entirely; at that point the choice is theirs.\n */\nconst HeaderColorContext = React.createContext<HeaderColor>(DEFAULT_HEADER_COLOR)\n\n/** Surfaces dark enough to need light-on-dark artwork. */\nconst DARK_SURFACE_COLORS = new Set<HeaderColor>(['dark', 'grey'])\n\ntype HeaderBrandProps = React.ComponentPropsWithoutRef<'div'> & {\n /** Home-page target for the brand link. Defaults to `/`. */\n href?: React.ComponentPropsWithoutRef<typeof Link>['href']\n /** Service or site name shown beside the logo. */\n sitename?: React.ReactNode\n /**\n * Heading level for `sitename`. Omit (the default) to render a `<span>`,\n * which is usually right: the page's own `<h1>` belongs to its main content,\n * and a site name repeated in the header on every page is not the heading\n * that describes this page. Supply a level only when a service deliberately\n * places the site name in the document outline.\n *\n * `1` is excluded for the reason above; `6` is the deepest heading HTML\n * defines.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n /**\n * Version string shown in a Badge beside the brand. Sits outside the link,\n * so it never becomes part of the home link's accessible name.\n */\n version?: React.ReactNode\n /**\n * Visually-hidden prefix announced before `version`, giving the bare number\n * context for screen readers (\"2.1.0\" → \"Version 2.1.0\"). Pass an empty\n * string to suppress.\n */\n versionLabel?: string\n /**\n * Props forwarded to the version `Badge` — `size`, `color`, `variant`,\n * `className` and the rest of its API. Use it when the badge has to meet a\n * house rule the default does not, most often a minimum type size:\n *\n * ```tsx\n * <HeaderBrand version=\"2.1.0\" badgeProps={{ size: 'lg' }} />\n * ```\n *\n * An explicit value always wins — including `color`, whose surface-aware\n * default exists to stop the badge painting itself the same colour as a dark\n * header. Overriding it is the same trade as supplying your own `logo` node:\n * the contrast is then yours to check.\n *\n * `undefined` and `null` do *not* win: they fall back to the defaults, so a\n * conditional like `{ color: cond ? 'accent' : undefined }` keeps the\n * surface-aware colour on the falsy branch rather than dropping the badge to\n * cva's own `primary` default.\n *\n * `children` is excluded — the badge's content is `version` and\n * `versionLabel`.\n */\n badgeProps?: Omit<BadgeProps, 'children'>\n /**\n * `true` (default) renders the NSW Government waratah, `false` omits it, and\n * a node replaces it — pass an agency lockup here.\n */\n logo?: boolean | React.ReactNode\n /**\n * Accessible name for the brand link. Left unset by default: the link's name\n * is then its visible content — \"NSW Government\" (from `Logo`'s\n * visually-hidden text) plus `sitename` — which keeps the visible label\n * inside the accessible name (WCAG 2.2, 2.5.3 Label in Name). Overriding it\n * with something like \"Home page\" would break that, so set it only when the\n * brand renders no text at all.\n */\n label?: string\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: the\n * default `Logo` carries a visually-hidden \"NSW Government\", so a brand with\n * neither it nor a `sitename` renders a link with no text at all, and reaches\n * assistive tech unnamed (WCAG 2.2, 4.1.2 Name, Role, Value). A consumer's own\n * logo node is assumed to carry its own text. No-op in production.\n */\nfunction warnIfBrandUnlabelled({\n logo,\n sitename,\n label,\n}: Pick<HeaderBrandProps, 'logo' | 'sitename' | 'label'>) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!logo && !sitename && !label) {\n console.warn(\n '[nswds/ui] HeaderBrand has no logo and no sitename, so its home link has no accessible name — pass `label`.',\n )\n }\n}\n\n/**\n * Logo, site name and optional version badge, linked to the home page. Sits at\n * the start of the `Header` row.\n *\n * The link renders through `Link`, so it picks up the framework link component\n * from `LinkProvider` (next/link et al) rather than hardcoding one.\n */\nfunction HeaderBrand({\n className,\n href = '/',\n sitename,\n headingLevel,\n version,\n versionLabel = 'Version',\n badgeProps,\n logo = true,\n label,\n children,\n ref,\n ...props\n}: HeaderBrandProps) {\n const color = React.useContext(HeaderColorContext)\n const onDarkSurface = DARK_SURFACE_COLORS.has(color)\n const Sitename = headingLevel ? (`h${headingLevel}` as const) : 'span'\n\n warnIfBrandUnlabelled({ logo, sitename, label })\n\n const logoNode =\n logo === true ? (\n <Logo\n logoType={onDarkSurface ? 'reversed' : 'default'}\n // 64px from lg, 56px below it — 56px is the floor, so the lockup stays\n // legible on a phone. Written as mutually exclusive breakpoint ranges\n // rather than `h-14 lg:h-16`: a bare `h-14` a consumer also uses is\n // re-emitted after ours by their own Tailwind build, and a media query\n // adds no specificity, so it would outrank the lg step and freeze the\n // logo at 56px.\n className='w-auto max-lg:h-14 lg:h-16'\n />\n ) : (\n // `false` / `null` fall through as the falsy nodes they are; anything\n // else is the consumer's own lockup.\n logo\n )\n\n return (\n <div\n data-slot='header-brand'\n {...props}\n className={cn('flex grow basis-0 items-center gap-3 sm:gap-4', className)}\n ref={ref}\n >\n {/* variant='unstyled' — a brand lockup takes no underline or link\n colour. outline-current resolves to the surface's ink on every\n variant, so the focus indicator contrasts with the header\n (WCAG 2.2, 2.4.13 Focus Appearance). The negative margin keeps the\n indicator from nudging the row. */}\n <Link\n variant='unstyled'\n href={href}\n aria-label={label}\n className='-m-1 flex items-center gap-3 rounded-sm p-1 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current sm:gap-4'\n >\n {logoNode}\n {sitename ? (\n // Brand-blue ink on the light surfaces (14.4:1 on white, 13.2:1 on\n // grey-100 — both WCAG 2.2 AAA). The `dark` surface *is* primary-800\n // and `grey` is nearly as deep, so those keep the header's own white\n // ink; dark mode does the same, matching the `dark:text-white` the\n // light/white variants already set on the surface.\n <Sitename\n className={cn(\n 'text-lg font-bold text-balance sm:text-xl',\n !onDarkSurface && 'text-primary-800 dark:text-white',\n )}\n >\n {sitename}\n </Sitename>\n ) : null}\n </Link>\n {version ? (\n // Badge's `primary` ink is primary-800 — the `dark` header's own\n // surface — so dark surfaces take the white badge instead.\n <Badge\n data-slot='header-version'\n {...badgeProps}\n // Derived after the spread rather than before it. Spreading last would\n // let a key that is merely *present* win, so\n // `badgeProps={{ color: cond ? 'accent' : undefined }}` would pass\n // `undefined` through to cva, which falls back to its own\n // `defaultVariants.color` of `primary` — and primary-800 is the dark\n // header's own background, so the badge would vanish into it. `??`\n // keeps explicit values winning while undefined (and null, which\n // cva's VariantProps permits and which would otherwise render an\n // unstyled badge) falls back to the surface-aware default.\n variant={badgeProps?.variant ?? 'soft'}\n color={badgeProps?.color ?? (onDarkSurface ? 'white' : 'primary')}\n >\n {versionLabel ? <span className='sr-only'>{versionLabel} </span> : null}\n {version}\n </Badge>\n ) : null}\n {children}\n </div>\n )\n}\n\ntype HeaderActionsProps = React.ComponentPropsWithoutRef<'div'> & {\n ref?: React.Ref<HTMLDivElement>\n}\n\n/**\n * Trailing cluster of header controls — search, theme switcher, sign-in, and\n * the like. Deliberately unopinionated about what goes in it: site search and\n * theme switching are app concerns (they need routing and a theme provider),\n * so the design system supplies the slot and its spacing rather than the\n * widgets.\n *\n * Not a `nav` landmark: a row of controls is not a set of navigation links, and\n * an extra landmark on every page buries the ones that matter. Wrap genuine\n * navigation in your own `<nav>` inside `Header`.\n */\nfunction HeaderActions({ className, ref, ...props }: HeaderActionsProps) {\n return (\n <div\n data-slot='header-actions'\n {...props}\n className={cn('flex basis-0 items-center justify-end gap-2 sm:gap-4 md:grow', className)}\n ref={ref}\n />\n )\n}\n\ntype HeaderProps = React.ComponentPropsWithoutRef<'header'> &\n VariantProps<typeof headerVariants> &\n VariantProps<typeof headerContainerVariants> & {\n /** Stick to the top of the viewport as the page scrolls. Defaults to `true`. */\n sticky?: boolean\n /** Hairline rule along the bottom edge. Defaults to `true`. */\n border?: boolean\n /** Raise the header with a shadow once the page is scrolled. Defaults to `true`. */\n shadow?: boolean\n /** Classes applied to the inner width-constraining wrapper. */\n containerClassName?: string\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Top-of-page `banner` landmark: brand, site name and header controls. Render\n * it once in a shared layout, below `SkipLinks` and `Masthead`.\n *\n * - `color` themes the surface; all four pairs are WCAG 2.2 AAA and follow the\n * theme in dark mode (see `headerColors`). The bottom rule derives from the\n * surface's ink, so it follows automatically.\n * - `container` selects the inner wrapper layout: `fluid` (full-bleed,\n * nswds-app parity) or `contained` (centred 1200px column, legacy\n * `nsw-container` parity). Fine-tune either with the `--header-max-width`\n * and `--header-padding-x` custom properties.\n * - Scroll position is tracked and exposed as `data-scrolled`, which is what\n * the `shadow` treatment keys off. Style your own scrolled state with it.\n *\n * Compose the row from `HeaderBrand` and `HeaderActions`:\n *\n * ```tsx\n * <Header>\n * <HeaderBrand sitename=\"Design System\" version=\"2.1.0\" />\n * <HeaderActions>\n * <ThemeSwitcher />\n * </HeaderActions>\n * </Header>\n * ```\n *\n * The `banner` landmark comes from the native `<header>` element, which only\n * carries it outside `article`, `aside`, `main`, `nav` and `section` — wrapping\n * `div`s are fine. Keep it out of `<main>`.\n *\n * The default `id=\"nsw-header\"` is kept for compatibility with existing shells\n * that target it (override via the `id` prop).\n */\nfunction Header({\n className,\n color,\n container,\n containerClassName,\n sticky = true,\n border = true,\n shadow = true,\n children,\n ref,\n ...props\n}: HeaderProps) {\n const [isScrolled, setIsScrolled] = React.useState(false)\n\n React.useEffect(() => {\n function onScroll() {\n setIsScrolled(window.scrollY > 0)\n }\n // Read once on mount too: a page restored mid-scroll (back/forward, or a\n // deep link to a fragment) never fires a scroll event.\n onScroll()\n window.addEventListener('scroll', onScroll, { passive: true })\n return () => window.removeEventListener('scroll', onScroll)\n }, [])\n\n return (\n <header\n id='nsw-header'\n data-slot='header'\n data-color={color ?? DEFAULT_HEADER_COLOR}\n // Present-or-absent rather than \"true\"/\"false\", so it reads like Base\n // UI's data-disabled and Tailwind's bare `data-scrolled:` variant works.\n data-scrolled={isScrolled || undefined}\n {...props}\n className={cn(\n headerVariants({ color }),\n // z-40 sits below the z-50 SkipLinks: a sticky header at the same\n // level comes later in the DOM and would paint over a focused skip\n // link, hiding the page's bypass mechanism (WCAG 2.2, 2.4.1).\n sticky && 'sticky top-0 z-40',\n // Always drawn, so the scrolled state changes no box heights.\n border && 'border-b border-(--header-border)',\n // Shadows read as elevation on light surfaces only; in dark mode the\n // rule above carries the separation.\n shadow &&\n 'data-scrolled:shadow-md data-scrolled:shadow-black/5 dark:data-scrolled:shadow-none',\n className,\n )}\n ref={ref}\n >\n <HeaderColorContext.Provider value={color ?? DEFAULT_HEADER_COLOR}>\n <div\n data-slot='header-container'\n className={cn(headerContainerVariants({ container }), containerClassName)}\n >\n {children}\n </div>\n </HeaderColorContext.Provider>\n </header>\n )\n}\n\nexport { Header, HeaderActions, HeaderBrand, headerColors, headerContainerVariants, headerVariants }\nexport type { HeaderActionsProps, HeaderBrandProps, HeaderColor, HeaderProps }\n"]}
|