npm.io
4.2.0 • Published 2 weeks ago

@knapsack/design-system

Licence
MIT
Version
4.2.0
Deps
0
Vulns
0
Weekly
0

@knapsack/design-system

The Knapsack React design system: shadcn/ui on Base UI in shadcn's nova style, with lucide-react icons and cva variants, styled with Tailwind v4 against design tokens from @knapsack/tokens. Published as built ESM, type declarations and CSS in dist/. Stack and Text are the system's layout and type primitives; the color-scheme API handles light and dark.

Using it in an app: start at docs/getting-started.md. The whole consumer guide is indexed in docs/README.md, DESIGN.md is the short entry point for an agent, and agent skills ship in skills/ (TanStack Intent layout).

What you need to know first

Nothing is styled by a value that is not a token. Colour, spacing, radius, type, motion, opacity and control sizing all come from @knapsack/tokens; elevation is flat by rule (a ring, a border, a scrim) and has no token.

Use the utility, not the variable. Colours are shadcn's role names, so bg-primary text-primary-foreground, border-input and ring-ring are tokens. Scales generate utilities too (p-lg, gap-sm, text-md, font-medium, rounded-xl, rounded-full, ease-standard). Where Tailwind has no namespace, use the arbitrary form: h-(--size-target-md), size-(--size-icon-md), opacity-(--opacity-disabled), duration-(--transition-duration-fast), border-(length:--border-width-thin). A bare transition-* utility already runs on the fast duration and ease-standard, because @knapsack/tokens points Tailwind's default transition there.

Both stylesheets are needed. An app imports @knapsack/design-system/shadcn.css after the token and theme stylesheets, and points Tailwind's @source at this package, because Tailwind's detection skips node_modules. docs/getting-started.md has the exact lines.

Brands and the colour scheme

Two independent axes, both normally on <html>:

  • Brand: data-theme="<id>" on <html> for the app, or on any element for a subtree. Themes nest.
  • Scheme: the dark class, shadcn's convention, so dark: utilities work. It combines with any brand: each brand defines every role in both schemes.

In an app, mount ColorSchemeProvider once at the root and inline COLOR_SCHEME_BOOT_SCRIPT in <head> before any stylesheet, so a dark-scheme user never sees a light flash. ColorSchemeToggle offers Light, Dark and System; useColorScheme() returns { preference, scheme, setPreference }. The choice persists in localStorage under COLOR_SCHEME_STORAGE_KEY (ks-color-scheme); system follows prefers-color-scheme live. The provider never touches data-theme.

What a component accepts

The shadcn components keep shadcn's open surface: the element's props, spread, and shadcn's compound names (Card, CardHeader, CardTitle, CardContent, CardFooter). Button takes onClick and disabled; a trigger composes another element through Base UI's render prop (<DropdownMenuTrigger render={<Button variant="ghost" />} />).

Stack and Text stay closed, on ConsumerProps: id, className, ref, role, children, aria-*, data-*, and tabIndex as -1 | 0 only. No style, no handlers. as is a union: Stack takes div | section | nav | ul | ol | li, Text takes p | span | h1..h6 | pre.

Every component merges className with cn() (exported as cn), so a consumer's class wins.

Licence

MIT, in LICENSE. The Golos Text fonts in dist/fonts/ are under the SIL Open Font License.

Keywords