Masthead
nswds-ui/mastheadFreeComponent
The "A NSW Government website" strip shown above the site header, with WCAG 2.2 AAA colour variants and fluid/contained width presets.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/digitalnsw/nswds-ui/main/apps/registry/public/r/masthead.jsonSource
1import { cva, type VariantProps } from 'class-variance-authority'2import React from 'react'34import { cn } from '@/lib/utils'56// Colour pairs are curated for WCAG 2.2 AAA (1.4.6 Contrast Enhanced): every7// text/background combination below resolves to at least 7:1. This is why the8// Masthead does not accept the full Button colour palette — accent/danger/9// warning backgrounds with white text sit under 7:1 and would silently break10// the AAA guarantee. Add new colours only with a verified pair.11const mastheadColors = {12 // Legacy .nsw-masthead (brand dark). Deepens in dark mode, matching the13 // original nswds-app implementation.14 dark: 'bg-primary-800 text-white dark:bg-primary-950',15 // Legacy .nsw-masthead--light (off-white). grey-100 is the same value as16 // the legacy --nsw-off-white (#f2f2f2).17 light: 'bg-grey-100 text-grey-900',18 white: 'bg-white text-grey-900',19 grey: 'bg-grey-800 text-white',20}2122const mastheadVariants = cva('w-full text-xs', {23 variants: {24 color: mastheadColors,25 },26 defaultVariants: {27 color: 'dark',28 },29})3031const mastheadContainerVariants = cva(32 [33 'mx-auto flex w-full items-center justify-between gap-x-4 py-2',34 // Lateral padding funnels through --masthead-padding-x so an app can35 // retune it once (via the `style` prop or a utility class) without a new36 // variant. Defaults reproduce the nswds-app rhythm: 16px → 24px → 48px.37 'px-(--masthead-padding-x)',38 '[--masthead-padding-x:--spacing(4)] sm:[--masthead-padding-x:--spacing(6)] lg:[--masthead-padding-x:--spacing(12)]',39 ],40 {41 variants: {42 container: {43 // Full-bleed (nswds-app style). --masthead-max-width is still read so44 // a shell app can constrain the inner wrapper without switching45 // variants (the archive/practice `#nsw-masthead > div` override).46 fluid: 'max-w-[var(--masthead-max-width,none)]',47 // Centred content column, legacy nsw-container parity (1200px).48 contained: 'max-w-[var(--masthead-max-width,75rem)]',49 },50 },51 defaultVariants: {52 container: 'fluid',53 },54 },55)5657type MastheadProps = React.ComponentPropsWithoutRef<'div'> &58 VariantProps<typeof mastheadVariants> &59 VariantProps<typeof mastheadContainerVariants> & {60 /** Classes applied to the inner width-constraining wrapper. */61 containerClassName?: string62 ref?: React.Ref<HTMLDivElement>63 }6465/**66 * The "A NSW Government website" strip shown above the site header on every67// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from @nswds/ui
All 46 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aspect Ratioaspect-ratio | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Badgebadge | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Buttonbutton | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Cardcard | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Collapsiblecollapsible | @nswds/ui | Components | Free | 1 dep | |
| Drawerdrawer | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Expandable Searchexpandable-search | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Fieldfield | @nswds/ui | Components | Free | 4 deps · 2 files |
