--- name: shadcn-svelte description: Manages shadcn-svelte components and projects — adding, updating, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn-svelte, the CLI, design-system presets, or any project with a components.json file. Also triggers for "shadcn-svelte init", "add component", or registry URLs. user-invocable: false allowed-tools: Bash(npx shadcn-svelte@latest *), Bash(pnpm dlx shadcn-svelte@latest *), Bash(bunx --bun shadcn-svelte@latest *) --- # shadcn-svelte A framework for building UI, components, and design systems for Svelte. Components are added as source to the user's project via the CLI. > **IMPORTANT:** Run all CLI commands using the project's package runner: `npx shadcn-svelte@latest`, `pnpm dlx shadcn-svelte@latest`, or `bunx --bun shadcn-svelte@latest` — based on the project's package manager. Examples below use `npx shadcn-svelte@latest` but substitute the correct runner for the project. ## Current Project Context Read `components.json` at the project root and, when you need the live file layout, list the directory given by the `aliases.ui` path (resolved with the same rules as the CLI). ## Imports (Svelte) Each component lives in its own folder with an `index.ts` barrel. Match the [installation docs](https://shadcn-svelte.com/docs/installation): - **Multi-part components** (dialog, select, card, field, tabs, …): `import * as Dialog from "$lib/components/ui/dialog"` then `Dialog.Content`, `Dialog.Title`, `Card.Root`, `Card.Header`, etc. — whatever the barrel exports (short names and/or `Root as …` aliases). - **Single-component barrels** (only one meaningful component in the folder): **named imports** — `import { Button } from "$lib/components/ui/button"` and `
U +20.1% ``` ## Component Selection | Need | Use | | -------------------------- | --------------------------------------------------------------------------------------------------- | | Button/action | `Button` with appropriate variant (`import { Button }`) | | Form inputs | `Input`, `Select`, `Combobox`, `Switch`, `Checkbox`, `RadioGroup`, `Textarea`, `InputOTP`, `Slider` | | Toggle between 2–5 options | `ToggleGroup.Root` + `ToggleGroup.Item` | | Data display | `Table`, `Card`, `Badge`, `Avatar` | | Navigation | `Sidebar`, `NavigationMenu`, `Breadcrumb`, `Tabs`, `Pagination` | | Overlays | `Dialog` (modal), `Sheet` (side panel), `Drawer` (bottom sheet), `AlertDialog` (confirmation) | | Feedback | `svelte-sonner` (toast), `Alert`, `Progress`, `Skeleton`, `Spinner` | | Command palette | `Command` inside `Dialog` | | Charts | `Chart` (LayerChart) | | Layout | `Card`, `Separator`, `Resizable`, `ScrollArea`, `Accordion`, `Collapsible` | | Empty states | `Empty` | | Menus | `DropdownMenu`, `ContextMenu`, `Menubar` | | Tooltips/info | `Tooltip`, `HoverCard`, `Popover` | ## Key Fields Use `components.json` and the filesystem — not a separate `info` command: - **`aliases`** → use the actual alias prefix from config (e.g. `$lib/`), never hardcode unrelated projects. - **`tailwind.css`** → the global CSS file where theme variables live. Edit this file for theme tweaks; don't add a second globals file unless the user already uses one. - **`style`** → visual treatment (e.g. `nova`, `vega`, …) and registry style path. - **`iconLibrary`** → determines icon packages (`@lucide/svelte`, `@tabler/icons-svelte`, etc.). Never assume `@lucide/svelte`. - **`registry`** → where the CLI fetches components; default official registry at `shadcn-svelte.com`. - **`resolvedPaths`** (conceptual) → the CLI resolves `aliases` to absolute paths; list `aliases.ui` on disk to see installed components. See [cli.md](./cli.md) for commands and flags. ## Component Docs, Examples, and Usage Open `https://shadcn-svelte.com/docs/components/.md` for docs and examples. **When creating, fixing, debugging, or using a component, read the official page first** so you follow the documented APIs. ## Workflow 1. **Get project context** — read `components.json` and list the UI components directory when needed. 2. **Check installed components first** — before running `add`, list files under the resolved `ui` path. Don't import components that haven't been added, and don't re-add ones already present unless updating. 3. **Discover components** — `npx shadcn-svelte@latest add` with no arguments (interactive list), or the docs site. 4. **Install or update** — `npx shadcn-svelte@latest add ` or a registry **URL**. To refresh existing files from the registry, use `npx shadcn-svelte@latest update` (see [cli.md](./cli.md)). 5. **Fix imports in third-party / URL-added items** — After adding from a custom registry URL, check for hardcoded paths that don't match the project's `aliases`. Rewrite imports to use the project's `ui` / `lib` aliases from `components.json`. 6. **Review added components** — After adding, **read the added files** and verify composition (groups, titles, validation attrs). Align icon imports with `iconLibrary`. 7. **Remote registry items** — Adding by URL is explicit; if the user wants a component from an unknown source, confirm the registry URL or item before running `add`. ## Updating Components Use the **`update`** command to pull the latest registry versions of components already in the project. Review changes with `git diff` after `update`. 1. Commit or stash local work. 2. Run `npx shadcn-svelte@latest update [component]` or `--all`. 3. Resolve merge conflicts if you had customized files. 4. **Never use `--overwrite` on `add` without the user's explicit approval** when it would destroy intentional edits. ## Quick Reference ```bash # Initialize shadcn-svelte in your project. npx shadcn-svelte@latest init # Initialize with a preset string from the docs site builder. npx shadcn-svelte@latest init --preset # Add components (interactive when run with no names). npx shadcn-svelte@latest add npx shadcn-svelte@latest add button card dialog npx shadcn-svelte@latest add --all # Update components already installed. npx shadcn-svelte@latest update button npx shadcn-svelte@latest update --all --yes # Build a custom registry (registry authors). npx shadcn-svelte@latest registry build ``` **Registry:** default `https://shadcn-svelte.com/registry` — override in `components.json` if needed. **Docs:** [shadcn-svelte.com](https://shadcn-svelte.com) ## Detailed References - [rules/forms.md](./rules/forms.md) — Field.FieldGroup, Field.Field, InputGroup, ToggleGroup, Field.FieldSet, validation states - [rules/composition.md](./rules/composition.md) — Groups, overlays, Card, Tabs, Avatar, Alert, Empty, Toast, Separator, Skeleton, Badge, Button loading - [rules/icons.md](./rules/icons.md) — data-icon, icon sizing, passing icon components - [rules/styling.md](./rules/styling.md) — Semantic colors, variants, class, spacing, size, truncate, dark mode, cn(), z-index - [cli.md](./cli.md) — Commands, flags, registry - [customization.md](./customization.md) — Theming, CSS variables, extending components