# @shavin/ui — Comprehensive LLM Context & Technical Specification > **Target Audience**: AI Agents, LLMs, and Engineers generating, auditing, or refactoring code using `@shavin/ui`. > **Official Docs Hub**: https://docs.shavin.cc > **Marketing Site**: https://www.shavin.cc --- ## TABLE OF CONTENTS 1. Core Mental Model & Two-Tier Architecture 2. Installation, Tailwind Setup & Wiring 3. ThemeProvider Configuration & Props Reference 4. Complete Design Token Reference Dictionary 5. Typography System & Guidelines 6. Comprehensive Component Reference (All 139 Primitives & Exports) 7. Strict Architectural Do's, Don'ts & Anti-Patterns 8. Model Context Protocol (MCP) Server & AI Integration 9. Pre-Built Blocks --- ## 1. CORE MENTAL MODEL & TWO-TIER ARCHITECTURE `@shavin/ui` is a React design system for teams that ship with AI agents: a two-tier token architecture, accessible primitives tested against WCAG 2.2 AA, a live theme configurator, and an integrated Model Context Protocol (MCP) server that gives agents the real API and checks what they write. ### The Two Tiers 1. **Foundation Tokens**: Raw neutral gray palette scale (`--n-0` through `--n-1000`) defined in `src/styles/global.css`. **Never reference `--n-*` outside `global.css`.** 2. **Semantic Tokens**: Role-based variables (`--bg-canvas`, `--bg-surface`, `--fg`, `--brand`, `--hairline`), remapped per theme (`:root` = light, `.dark` = dark). 3. **The Invariant Law**: Every component and block MUST use ONLY semantic Tailwind utility classes (`bg-surface`, `text-fg`, `border-hairline`). - **ZERO hex codes** (`#123456` is forbidden). - **ZERO `rgb()` or `hsl()` literals** in layout or component markup. - **ZERO `--n-*` foundation variables** in JSX. ### Directory Layout & Import Rule - **Standard**: Monorepo with `packages/ui`, `packages/mcp-server`, `packages/cli`, `apps/docs`, `apps/studio`, and `apps/website`. - **IMPORT RULE**: ALWAYS import from `@shavin/ui` root. ```tsx // ✅ CORRECT: import { Button, Card, TextField, Heading, Text, ThemeProvider } from "@shavin/ui"; // ❌ FORBIDDEN: import { Button } from "@shavin/ui/primitives/Button"; import { Card } from "@shavin/ui/src/primitives/Card"; ``` --- ## 2. INSTALLATION, TAILWIND SETUP & WIRING ### Method A: Automated 1-Command Setup (Recommended) Run the automated CLI initializer in your project root: ```bash npx @shavin/cli init ``` This single command automatically: 1. **Framework Detection**: Inspects whether you are using Next.js (App or Pages Router), Vite, or Remix. 2. **Dependency Installation**: Installs `@shavin/ui` and necessary peer dependencies. 3. **Tailwind Configuration**: Adds `presets: [require("@shavin/ui/tailwind-preset")]` to `tailwind.config.ts`. 4. **CSS Stylesheet Injection**: Injects `@import "@shavin/ui/styles.css";` into your root stylesheet (`globals.css`). 5. **Next.js Transpilation**: Adds `transpilePackages: ["@shavin/ui"]` into `next.config.mjs` (when on Next.js). 6. **Root Provider Scaffolding**: Detects your root layout (`app/layout.tsx`, `pages/_app.tsx`, or `src/App.tsx`) and wraps your application in ``. --- ### Method B: Manual Step-by-Step Installation #### Step 1: Install Package ```bash npm install @shavin/ui # or pnpm add @shavin/ui # or yarn add @shavin/ui ``` #### Step 2: Configure Tailwind CSS Preset Add `@shavin/ui/tailwind-preset` to your `tailwind.config.ts`: ```ts import type { Config } from "tailwindcss"; const config: Config = { content: [ "./src/**/*.{js,ts,jsx,tsx,mdx}", "./node_modules/@shavin/ui/dist/**/*.{js,mjs}", ], presets: [require("@shavin/ui/tailwind-preset")], }; export default config; ``` #### Step 3: Import Stylesheet In your root CSS file (`src/app/globals.css` or `src/styles/global.css`): ```css @import "@shavin/ui/styles.css"; ``` #### Step 4: Transpile Packages (Next.js App or Pages Router) In `next.config.mjs`: ```js /** @type {import('next').NextConfig} */ const nextConfig = { transpilePackages: ["@shavin/ui"], }; export default nextConfig; ``` #### Step 5: Wrap Root Layout in ThemeProvider In your root layout (`app/layout.tsx`): ```tsx import "@shavin/ui/styles.css"; import "./globals.css"; import { ThemeProvider } from "@shavin/ui"; export default function RootLayout({ children, }: { children: React.ReactNode; }) { return ( {children} ); } ``` --- ## 3. THEMEPROVIDER CONFIGURATION & PROPS REFERENCE `ThemeProvider` is the top-level configuration engine for `@shavin/ui`. It applies CSS custom properties dynamically to `:root` and mounts `ShavinDevInspector` in development mode. ### ThemeProvider Props Reference | Prop | Type | Default | Description | |---|---|---|---| | `brandColor` | `string` | `"monochrome"` | One of the 24 curated brand colors. Controls primary buttons, active tabs, focus rings, and selection indicators. | | `grayColor` | `string` | `"neutral"` | Neutral gray scale family (Zinc, Slate, Gray, Neutral, Stone). Maps `--n-0` through `--n-1000`. | | `radius` | `"none" | "small" | "medium" | "large" | "full"` | `"medium"` | Base radius scale preset. Controls `--radius-lg` (controls) and `--radius-panel` (containers). | | `scaling` | `"90%" | "95%" | "100%" | "105%" | "110%"` | `"100%"` | Global typographic and spatial scaling factor. High-density dashboards use `95%`. | | `panelBackground` | `"solid" | "translucent"` | `"solid"` | Determines whether dialogs, popovers, and menus use opaque fills or frosted translucent backdrop blur. | | `displayFont` | `string` | `"Inter"` | Display headline font family loaded dynamically from Google Fonts. | | `bodyFont` | `string` | `"Inter"` | Body prose font family loaded dynamically from Google Fonts. | | `subheadingFont` | `"body" | "display" | string` | `"body"` | Font for h3-h6 headings. h1/h2 always use the display font; `"display"` makes subheadings follow it too. | ### Available Brand Palettes (24 Curated Presets) - **Monochrome** (`#000000`) - **Tomato** (`#e54d2e`) - **Red** (`#e5484d`) - **Ruby** (`#e54666`) - **Crimson** (`#e93d82`) - **Pink** (`#d6409f`) - **Plum** (`#ab4aba`) - **Purple** (`#8e4ec6`) - **Violet** (`#6e56cf`) - **Iris** (`#5b5bd6`) - **Indigo** (`#3e63dd`) - **Blue** (`#0090ff`) - **Cyan** (`#00a2c7`) - **Teal** (`#12a594`) - **Jade** (`#29a383`) - **Green** (`#30a46c`) - **Grass** (`#46a758`) - **Lime** (`#bdee63`) - **Mint** (`#86ead4`) - **Sky** (`#7ce2fe`) - **Amber** (`#ffc53d`) - **Gold** (`#978365`) - **Bronze** (`#a18072`) - **Brown** (`#ad7f58`) ### Available Gray Scales (5 Neutral Families) - **Zinc** (`#71717a`): Cool, balanced modern tech neutral. - **Slate** (`#64748b`): Crisp oceanic slate with blue undertones. - **Gray** (`#6b7280`): True neutral balanced gray. - **Neutral** (`#737373`): Unbiased pure neutral gray. - **Stone** (`#78716c`): Warm architectural earth-tone gray. ### Radius Presets & Geometry Map | Preset | Control Radius (`--radius-lg`) | Panel Radius (`--radius-panel`) | Visual Character | |---|---|---|---| | `none` | `0px` | `0px` | Sharp industrial/brutalist geometry. | | `small` | `0.25rem` (4px) | `0.5rem` (8px) | Tight compact data density. | | `medium` | `0.5rem` (8px) | `1.0rem` (16px) | Standard balanced enterprise desktop. | | `large` | `0.75rem` (12px) | `1.5rem` (24px) | Friendly modern consumer software. | | `full` | `9999px` (Pill) | `1.5rem` (24px) | Pill-shaped controls while containers remain safely capped at 24px curve. | ### Preventing Flash of Unstyled Content (SSR) Render `` inside your `` to instantly read `localStorage` before React hydration: ```tsx import { ThemeScript } from "@shavin/ui"; export default function Document() { return ( ... ); } ``` --- ## 4. COMPLETE DESIGN TOKEN REFERENCE DICTIONARY ### Semantic Color Tokens | Semantic Token | Tailwind Class | Semantic Purpose / Role | |---|---|---| | `--bg-canvas` | `bg-canvas` | Furthest-back background surface behind all layouts. | | `--bg-surface` | `bg-surface` | Default content surface (cards, inputs, panels) sitting on canvas. | | `--bg-surface-hover` | `bg-surface-hover` | Hover / active fill for interactive surface rows and cards. | | `--bg-surface-raised` | `bg-surface-raised` | Elevated cards or panels needing one level of step-up. | | `--bg-elevated` | `bg-elevated` | Floating surface fill (Dialog, Menu, Popover, Select dropdown). | | `--bg-elevated-hover` | `bg-elevated-hover` | Highlighted row inside a floating surface (menu items, select options). | | `--hairline` | `border-hairline` | Default 1px subtle divider and border line. | | `--hairline-strong` | `border-hairline-strong` | Higher contrast border for active states, card headers, or hover. | | `--fg` | `text-fg` | Primary text and high-contrast glyphs. | | `--fg-subtle` | `text-fg-subtle` | Paired descriptions, field helper texts, sub-headers. | | `--fg-muted` | `text-fg-muted` | Standalone meta, timestamps, badge labels. | | `--brand` | `bg-brand` / `text-brand` | Active brand/theme brand color. | | `--brand-hover` | `bg-brand-hover` | Hover variant for brand-filled elements. | | `--brand-fg` | `text-brand-fg` | Contrast-safe foreground on top of solid brand fill. | | `--brand-subtle` | `bg-brand-subtle` | 10% tinted brand background fill for soft buttons and tags. | | `--brand-contrast` | `text-brand-contrast` | Contrast-safe brand text on light/soft surfaces. | | `--success` | `bg-success` / `text-success` | Positive status indicator, success badges, checkmarks. | | `--warning` | `bg-warning` / `text-warning` | Caution, attention, pending review indicators. | | `--danger` | `bg-danger` / `text-danger` | Destructive actions, delete buttons, error validation. | | `--link` | `text-link` | Hyperlink color with underline affordance. | ### Concentric Radius System 1. **Controls** (`rounded-[var(--radius-lg)]`): Single-line inputs, buttons, badges, chips, switches. Go pill-shaped at "Full" preset. 2. **Panels & Containers** (`rounded-[var(--radius-panel)]`): Cards, dialogs, popovers, menus, accordions, callouts. Intentionally capped at finite curve — **NEVER** use `--radius-lg` on containers or accordions. 3. **Concentric Nesting Formula**: $$\mathbf{R_{\text{inner}} = \max(\text{floor}, R_{\text{outer}} - \text{Padding})}$$ where `floor = min(radius-lg, radius-panel / 2)` — inner corners are never square inside a rounded container (only when the theme radius itself is 0). 4. **Tailwind Concentric Utilities**: - `rounded-panel-p3`: Use when outer container has `p-3` padding ($R_{inner} = R_{panel} - 12px$). - `rounded-panel-p5`: Use when outer container has `p-5` padding ($R_{inner} = R_{panel} - 20px$). - `rounded-panel-inner`: Nested element inside standard container. ### Elevation Shadows - `shadow-panel`: Default elevation shadow for cards, popovers, and dropdown menus. - `shadow-modal`: Deep backdrop elevation shadow for modal Dialog and AlertDialog surfaces. ### Physics & Easing - Out Easing: `cubic-bezier(0.23, 1, 0.32, 1)` (spring-like deceleration for all opening and entering choreography). - Standard Duration: `< 250ms` for responsive interactions; `< 150ms` for micro-interactions. --- ## 5. TYPOGRAPHY SYSTEM & GUIDELINES ### Typography Primitives Table | Tag | Component | Semantics | Key Props | |---|---|---|---| | `` | Heading | `

`–`

` | `as="h1"|"h2"|"h3"|"h4"|"h5"|"h6"`, `size="xs"|"sm"|"md"|"lg"|"xl"|"2xl"|"3xl"`, `weight`, `align`, `color` | | `` | Text | `

` / `` | `as="p"|"span"|"div"|"label"`, `size="xs"|"sm"|"base"|"md"|"lg"|"xl"`, `weight`, `color="default"|"subtle"|"muted"|"brand"` | | `` | Em | `` | Inline italic emphasis. | | `` | Strong | `` | Inline bold text. | | `` | Quote | `` | Inline curly quotes. | | `

` | Blockquote | `
` | Pull quote block with left brand hairline. | | `` | Code | `` | Inline monospace code snippet badge. | | `` | Kbd | `` | Keyboard shortcut key indicator (⌘K, Ctrl+P). | | `` | Link | `` | Hyperlink anchor with token styles and hover underline. | ### Strict Typographic Contrast & Layout Rules 1. **The Contrast Law**: - Primary Title / Header: `text-fg` (or `` default). - Paired Description / Subtitle: MUST use `text-fg-subtle` (or ``). - Meta / Timestamp / Secondary Label: MUST use `text-fg-muted` (or ``). - **Violation**: Never pair `text-fg` directly with `text-fg-muted` — the contrast gap is too steep and illegible. 2. **Text Balance**: All display and section headings MUST include `text-balance` to eliminate typographic orphans. 3. **Text Pretty**: All body text paragraphs MUST include `text-pretty` for optimal multi-line word wrapping. 4. **Measure Limit**: Limit prose measure to `max-w-2xl` (680px). Never allow body paragraphs to span full viewport width. 5. **Tabular Numerals**: All numbers, metrics, financial values, and data counters MUST use `tabular-nums font-mono` to avoid layout jitter during updates. --- ## 6. COMPREHENSIVE COMPONENT REFERENCE (ALL 139 PRIMITIVES & EXPORTS) Each entry contains the component tag, import statement, variants, props, concrete copy-paste TSX declaration, and documentation link. ### Layout & Shell (16 components) #### `` - **Documentation**: [https://docs.shavin.cc/components/app-shell](https://docs.shavin.cc/components/app-shell) - **Description**: Application shell: a Sidebar plus a main column. The frame measures its own width, so the same markup works on a phone, in a narrow window and in a Studio device preview. When it runs out of room the Sidebar becomes a slide-in drawer, written once, with no breakpoint classes, hamburger state or second copy of the navigation. - **Import**: `import { AppFrame, useAppFrame } from "@shavin/ui";` - **Props**: `sidebar` (required): `ReactNode`, `children` (required): `ReactNode`, `compactBelow`: `"md" | "lg"`, `navLabel`: `string`, `routeKey`: `string`, `className`: `string` - **Best Practices**: - ✅ DO: Build app screens as …}>……. Write the navigation once. - ✅ DO: Pass routeKey={usePathname()} (or your router's equivalent) so the drawer closes after navigation. Put in the TopBar. Do not hand-write hidden md:block / md:hidden wrappers, a hamburger IconButton, a navOpen state or a second Drawer copy of the navigation. - ✅ DO: Inside the main column, size content with Grid columns="auto" and Flex wrap so it reflows when the sidebar opens, collapses or becomes a drawer. - ✅ DO: To show something only when the frame is compact (a logo in the TopBar while the sidebar is a drawer) use className="shavin-frame-compact-only"; to hide it then (a breadcrumb parent), use "shavin-frame-wide-only". Both follow the frame width and compactBelow, never the window, so they stay right in a narrow panel or a Studio preview. Do not use md:hidden or hidden md:block inside an AppFrame. - ❌ DON'T: Do not use AppFrame for marketing pages or simple single-column sites. - **Sample Declaration**: ```tsx function Shell() { const [view, setView] = React.useState("overview"); return (
Acme setView("overview")} /> setView("reports")} /> } > {view}
OneTwoThree
); } ``` #### `` - **Documentation**: [https://docs.shavin.cc/components/aspect-ratio](https://docs.shavin.cc/components/aspect-ratio) - **Description**: Keeps its content at a fixed width-to-height ratio, such as 16:9, so images and video hold their space while they load. - **Import**: `import { AspectRatio } from "@shavin/ui";` - **Props**: `asChild`: `boolean`, `ratio`: `number` - **Best Practices**: - ✅ DO: Use AspectRatio around images, video embeds, and map containers. - ❌ DON'T: Do not leave media elements without aspect ratio preservation — use AspectRatio to prevent layout shifts. - **Sample Declaration**: ```tsx Video thumbnail ``` #### `` - **Documentation**: [https://docs.shavin.cc/components/box](https://docs.shavin.cc/components/box) - **Description**: A plain container for anything that needs a wrapper. It can render as any HTML tag, become a translucent panel, carry a background image or video, and be resized by the user. - **Import**: `import { Box } from "@shavin/ui";` - **Props**: `bgVideo`: `string`, `bgImage`: `string`, `bgSize`: `"cover" | "contain"`, `bgOverlays`: `string`, `bgVideoPaused`: `boolean`, `resizable`: `ResizableEdges`, `minWidth`: `number`, `maxWidth`: `number`, `minHeight`: `number`, `maxHeight`: `number`, `resizeStep`: `number`, `snap`: `number`, `lockAspectRatio`: `boolean`, `persistKey`: `string`, `onResize`: `(size: ResizeSize) => void`, `onResizeEnd`: `(size: ResizeSize) => void`, `resizeHandle`: `ResizeHandleVariant`, `resizeColor`: `ResizeHandleColor`, `as`: `ElementType`, `translucent`: `boolean`, `surface`: `Surface`, `ref`: `Ref` - **Best Practices**: - ✅ DO: Use Box as a generic container when Flex or Grid structure is not needed. - ✅ DO: Use bgImage with gradient-bottom overlay for media panels with bottom-aligned text. - ❌ DON'T: Do not nest