Link
nswds-ui/linkFreeComponent
A link primitive with a provider for app router link components.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/digitalnsw/nswds-ui/main/apps/registry/public/r/link.jsonSource
1'use client'23import { cva, type VariantProps } from 'class-variance-authority'4import React, { createContext, useContext } from 'react'56import { cn } from '@/lib/utils'78// Shared visual base for all *styled* variants. Pulled out so the `unstyled`9// variant can omit it entirely (otherwise it wouldn't actually be unstyled).10const styledBase = [11 // Typography + transition12 'font-medium underline decoration-current underline-offset-4 motion-safe:transition-colors',13 // Text colour derives from --link-color; --link-halo and --link-halo-active14 // derive from --link-color via color-mix so each variant only sets the one15 // token and the hover/active halos follow automatically.16 'text-(--link-color)',17 '[--link-halo:color-mix(in_oklch,var(--link-color)_10%,transparent)]',18 '[--link-halo-active:color-mix(in_oklch,var(--link-color)_18%,transparent)]',19 // Hover / active halos use box-shadow + background-color rather than20 // padding, so inline links sit flush against surrounding text. The21 // shadows extend the halo 2px above and 4px below the line box, matching22 // the GOV.UK Design System focus pattern.23 'hover:bg-(--link-halo) hover:decoration-2',24 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',25 // Wrapped lines each get their own halo26 '[box-decoration-break:clone] [-webkit-box-decoration-break:clone]',27 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--link-color)',28 // Default sizing for icon children — without this, an unsized SVG inside29 // a Link collapses to 0×0 in flex layouts. `vertical-align: -0.15em`30 // aligns the icon's box to the text's x-height for inline-flow usage;31 // flex contexts ignore vertical-align and should set `items-baseline` (or32 // similar) on the Link itself. Consumers can override per-icon by passing33 // a `size-*` or `align-*` class on the icon itself.34 '*:data-[slot=icon]:inline-block *:data-[slot=icon]:size-[1em] *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:align-[-0.15em]',35]3637const linkVariants = cva('', {38 variants: {39 variant: {40 primary: [41 ...styledBase,42 // Link43 '[--link-color:var(--color-primary-800)] dark:[--link-color:var(--color-primary-200)]',44 // Visited — set the text colour directly. `:visited` is restricted by45 // browsers to a small set of paint-only properties (color, *-color,46 // fill, stroke) and ignores custom properties, so we can't shift47// … 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 |
