From 8b00d0710ceaa102770a53dd752ab660cbc57559 Mon Sep 17 00:00:00 2001 From: Noah Gentile Date: Mon, 15 Dec 2025 16:36:52 -0800 Subject: [PATCH] feat: add `sanity-ui` skill --- AGENTS.md | 1 + README.md | 2 + rules/sanity-ui.mdc | 518 ++++++++++++++++++++++++ sanity-plugin/skills/sanity-ui/SKILL.md | 158 ++++++++ 4 files changed, 679 insertions(+) create mode 100644 rules/sanity-ui.mdc create mode 100644 sanity-plugin/skills/sanity-ui/SKILL.md diff --git a/AGENTS.md b/AGENTS.md index bf461df..a93b4e9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -49,6 +49,7 @@ If the Sanity MCP server (`https://mcp.sanity.io`) is available, use `list_sanit | **Shopify/Hydrogen** | `shopify`, `hydrogen`, `e-commerce`, `storefront`, `sanity connect` | `rules/sanity-hydrogen.mdc` | | **GROQ** | `groq`, `query`, `defineQuery`, `projection`, `filter`, `order` | `rules/sanity-groq.mdc` | | **TypeGen** | `typegen`, `typescript`, `types`, `infer`, `satisfies`, `type generation` | `rules/sanity-typegen.mdc` | +| **Sanity UI** | `ui`, `component`, `theme`, `design system`, `studio plugin`, `custom tool`, `@sanity/ui` | `rules/sanity-ui.mdc` | ### Using the Knowledge Router diff --git a/README.md b/README.md index 0d4dc57..39a3102 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ Skills guide the AI through multi-step workflows in your codebase. | **Schema Manager** | Handles the full lifecycle: scaffolding, safe deprecation, and migrations. | "Deprecate the 'body' field" | | **GROQ Assistant** | Writes optimized queries using `defineQuery` and proper projections. | "Write a query for recent posts" | | **TypeGen Fixer** | Diagnoses and fixes TypeScript generation issues. | "Why are my types missing?" | +| **Sanity UI Builder** | Guide for building React UIs with Sanity's design system and component library. | "Build a custom Studio tool UI" | | **Install Rules** | Copies context rules to your project for local agent guidance. | "Install Sanity rules locally" | ### Getting started flow @@ -172,6 +173,7 @@ These files provide passive knowledge to the AI, ensuring generated code follows - **`sanity-typegen.mdc`**: TypeScript type generation from schema. - **`sanity-project-structure.mdc`**: File organization for Studio and monorepos. - **`sanity-get-started.mdc`**: Interactive 3-phase onboarding guide. +- **`sanity-ui.mdc`**: Complete component reference for building with @sanity/ui design system.
diff --git a/rules/sanity-ui.mdc b/rules/sanity-ui.mdc new file mode 100644 index 0000000..eb27840 --- /dev/null +++ b/rules/sanity-ui.mdc @@ -0,0 +1,518 @@ +--- +description: Guide for building React interfaces with @sanity/ui, Sanity's official design system. Focuses on design system fundamentals, component selection, and Sanity-specific patterns. +globs: **/*.tsx, **/*.ts +alwaysApply: false +--- + +# Sanity UI Component Library & Design System + +Guide for building React interfaces with Sanity UI (@sanity/ui). + +**For detailed component API reference, see:** https://www.sanity.io/ui + +## Quick Start + +Install Sanity UI: + +```bash +npm install @sanity/ui styled-components +``` + +### ThemeProvider Setup + +**Important:** ThemeProvider is only needed for standalone apps, NOT for Studio plugins/tools. + +#### Building Studio Plugins or Tools? (No Setup Needed) + +Studio automatically provides ThemeProvider. Just import and use components directly: + +```tsx +import {Stack, Card, Text, Button} from '@sanity/ui' + +// No ThemeProvider needed - Studio provides it +export function MyStudioTool() { + return ( + + + Content + + + ) +} +``` + +#### Building Standalone Apps? (ThemeProvider Required) + +For apps using App SDK (`@sanity/sdk-react`) without full Studio, wrap with ThemeProvider: + +```tsx +import {ThemeProvider, studioTheme} from '@sanity/ui' +import {SanityApp} from '@sanity/sdk-react' + +function App() { + return ( + + + {/* Your app UI */} + + + ) +} +``` + +#### Embedded Studio (Optional Outer ThemeProvider) + +When embedding Studio in a larger app, Studio provides its own ThemeProvider internally. You may optionally add an outer ThemeProvider for UI outside the Studio boundary: + +```tsx +import {ThemeProvider, studioTheme} from '@sanity/ui' +import {Studio} from 'sanity' + +function App() { + return ( + {/* Optional: for app UI outside Studio */} + {/* Uses outer ThemeProvider */} + {/* Has its own ThemeProvider internally */} + + ) +} +``` + +## Design System Fundamentals + +### Spacing Scale (0-7) + +Uses 4px base unit: + +| Value | Pixels | Usage | +|-------|--------|-------| +| 0 | 0px | No spacing | +| 1 | 4px | Extra tight | +| 2 | 8px | Tight | +| 3 | 12px | Compact | +| 4 | 16px | Default/comfortable | +| 5 | 24px | Spacious | +| 6 | 48px | Very spacious | +| 7 | 96px | Extra spacious | + +```tsx + {/* 16px padding */} + {/* 12px between items */} + {/* 8px grid gap */} +``` + +### Semantic Tones + +Use tones to communicate state and intent: + +- `default` - Standard neutral appearance +- `primary` - Primary brand color +- `positive` - Success states (green) +- `caution` - Warning states (yellow) +- `critical` - Error/danger states (red) +- `transparent` - Transparent background +- `inherit` - Inherit from parent + +```tsx +