# @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 & Production Templates --- ## 1. CORE MENTAL MODEL & TWO-TIER ARCHITECTURE `@shavin/ui` is an enterprise-grade React design system delivering a strict two-tier token architecture, WCAG 2.1 AAA accessible primitives, a live theme configurator, and an integrated Model Context Protocol (MCP) server for zero-hallucination AI-assisted UI development. ### 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`, `--accent`, `--hairline`), remapped per theme (`:root` = light, `.dark` = dark). 3. **The Invariant Law**: Every component and template 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 | |---|---|---|---| | `accentColor` | `string` | `"monochrome"` | One of the 24 curated accent 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. | ### Available Accent 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). | | `--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. | | `--accent` | `bg-accent` / `text-accent` | Active brand/theme accent color. | | `--accent-hover` | `bg-accent-hover` | Hover variant for accent-filled elements. | | `--accent-fg` | `text-accent-fg` | Contrast-safe foreground on top of solid accent fill. | | `--accent-subtle` | `bg-accent-subtle` | 10% tinted accent background fill for soft buttons and tags. | | `--accent-contrast` | `text-accent-contrast` | Contrast-safe accent 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(0, R_{\text{outer}} - \text{Padding})}$$ 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"|"accent"` | | `` | Em | `` | Inline italic emphasis. | | `` | Strong | `` | Inline bold text. | | `` | Quote | `` | Inline curly quotes. | | `

` | Blockquote | `
` | Pull quote block with left accent 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 (21 components) #### `` - **Documentation**: [https://docs.shavin.cc/foundations/app-shell](https://docs.shavin.cc/foundations/app-shell) - **Description**: Application layout shell frame components providing collapsible sidebar navigation rail, section headings, and profile triggers. - **Import**: `import { AppFrame, NavItem, NavRail, NavSectionLabel, ProfileTrigger } from "@shavin/ui";` - **Props**: `sidebar` (required): `ReactNode`, `children` (required): `ReactNode` - **Best Practices**: - ✅ DO: Use AppFrame and NavRail for application dashboards, admin consoles, and SaaS app shells. - ❌ DON'T: Do not use NavRail for simple single-page marketing websites. - **Sample Declaration**: ```tsx }>Dashboard}>
Main Dashboard Content
``` #### `` - **Documentation**: [https://docs.shavin.cc/foundations/aspect-ratio](https://docs.shavin.cc/foundations/aspect-ratio) - **Description**: Ratio layout wrapper primitive built on Radix AspectRatio for reserving media element proportions. - **Import**: `import { AspectRatio } from "@shavin/ui";` - **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**: Generic div-based container primitive with translucent panel support and background media props. Useful for media-backed panels and callout boxes. - **Import**: `import { Box } from "@shavin/ui";` - **Props**: `bgVideo`: `string`, `bgImage`: `string`, `bgSize`: `"cover" | "contain"`, `bgOverlays`: `string`, `bgVideoPaused`: `boolean`, `as`: `ElementType`, `translucent`: `boolean`, `surface`: `Surface` - **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
``` #### `` - **Documentation**: [https://docs.shavin.cc/foundations/app-shell](https://docs.shavin.cc/foundations/app-shell) - **Description**: Application layout shell frame components providing collapsible sidebar navigation rail, section headings, and profile triggers. - **Import**: `import { AppFrame, NavItem, NavRail, NavSectionLabel, ProfileTrigger } from "@shavin/ui";` - **Props**: `children` (required): `ReactNode`, `className`: `string` - **Best Practices**: - ✅ DO: Use AppFrame and NavRail for application dashboards, admin consoles, and SaaS app shells. - ❌ DON'T: Do not use NavRail for simple single-page marketing websites. - **Sample Declaration**: ```tsx }>Dashboard}>
Main Dashboard Content
``` #### `` - **Documentation**: [https://docs.shavin.cc/foundations/app-shell](https://docs.shavin.cc/foundations/app-shell) - **Description**: Application layout shell frame components providing collapsible sidebar navigation rail, section headings, and profile triggers. - **Import**: `import { AppFrame, NavItem, NavRail, NavSectionLabel, ProfileTrigger } from "@shavin/ui";` - **Props**: `name` (required): `string`, `avatarUrl`: `string | null` - **Best Practices**: - ✅ DO: Use AppFrame and NavRail for application dashboards, admin consoles, and SaaS app shells. - ❌ DON'T: Do not use NavRail for simple single-page marketing websites. - **Sample Declaration**: ```tsx }>Dashboard}>
Main Dashboard Content
``` #### `
` - **Documentation**: [https://docs.shavin.cc/components/section](https://docs.shavin.cc/components/section) - **Description**: Vertical-rhythm section primitive with padding presets (1-4) and background media props. Ideal for full-bleed hero bands with bgVideo or bgImage. - **Import**: `import { Section } from "@shavin/ui";` - **Variants**: `size` ("1" | "2" | "3" | "4") - **Default Variants**: {"size":"2"} - **Props**: `bgVideo`: `string`, `bgImage`: `string`, `bgSize`: `"cover" | "contain"`, `bgOverlays`: `string`, `bgVideoPaused`: `boolean`, `as`: `ElementType`, `translucent`: `boolean`, `surface`: `Surface` - **Best Practices**: - ✅ DO: Use Section for page-level vertical rhythm bands — combine with Container inside for content width constraint. - ✅ DO: Use bgVideo + bgOverlays=\"dark-50\" + surface=\"dark\" for full-bleed hero sections with readable white text. - ❌ DON'T: Do not manually position