mcpField
S
shadcn-svelte

shadcn-svelte

github.com/antstanley设计与 UI675 次安装38 周前更新
代码仓库

关于 shadcn-svelte

这是面向 Svelte 5 和 SvelteKit 的 shadcn/ui 移植组件库,基于 Bits UI 和 Tailwind CSS 构建。它提供无障碍 UI 组件,并附有安装、表单、主题和组件用法文档。

主要功能

  1. 01Svelte 5 与 SvelteKit 组件
  2. 02无障碍 UI 组件
  3. 03Bits UI 与 Tailwind CSS
  4. 04通过 CLI 安装组件
  5. 05表单与主题指南

适用场景

  1. 01构建 SvelteKit 界面
  2. 02添加对话框、按钮和卡片
  3. 03实现带验证的表单
  4. 04配置主题与暗色模式

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/antstanley/shadcn-svelte-skill --skill shadcn-svelte

安装后在 Claude Code 中输入/shadcn-svelte确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
about.md
changelog.md
cli.md
components-json.md
references/components/
accordion.md
alert-dialog.md
alert.md
aspect-ratio.md
avatar.md
badge.md
breadcrumb.md
button-group.md
button.md
calendar.md
card.md
carousel.md
chart.md
checkbox.md
collapsible.md
combobox.md
command.md
context-menu.md
data-table.md
date-picker.md
dialog.md
drawer.md
dropdown-menu.md
empty.md
field.md
form.md

详细介绍

shadcn-svelte

shadcn/ui 的 Svelte 5 / SvelteKit 移植版本,使用 Bits UI 和 Tailwind CSS 构建,设计精美且易于访问的组件。

快速开始

安装
# SvelteKit
pnpm dlx shadcn-svelte@latest init

# Add components
pnpm dlx shadcn-svelte@latest add button card dialog
基本用法

组件使用命名空间导入:

<script lang="ts">
  import * as Card from "$lib/components/ui/card/index.js";
  import { Button } from "$lib/components/ui/button/index.js";
</script>

<Card.Root>
  <Card.Header>
    <Card.Title>Title</Card.Title>
    <Card.Description>Description</Card.Description>
  </Card.Header>
  <Card.Content>Content here</Card.Content>
  <Card.Footer>
    <Button>Action</Button>
  </Card.Footer>
</Card.Root>

关键模式

组件导入模式

import * as Dialog from "$lib/components/ui/dialog/index.js";


import { Button } from "$lib/components/ui/button/index.js";
import { Input } from "$lib/components/ui/input/index.js";
表单实现

使用 Superforms + Formsnap 构建表单:

<script lang="ts">
  import * as Form from "$lib/components/ui/form/index.js";
  import { superForm } from "sveltekit-superforms";

  let { data } = $props();
  const form = superForm(data.form);
</script>

<form method="POST" use:form.enhance>
  <Form.Field {form} name="email">
    <Form.Control>
      {#snippet children({ props })}
        <Input {...props} type="email" />
      {/snippet}
    </Form.Control>
    <Form.FieldErrors />
  </Form.Field>
</form>
深色模式

<script lang="ts">
  import { ModeWatcher } from "mode-watcher";
</script>

<ModeWatcher />
{@render children()}

使用 mode-watcher 的 toggleMode()、setMode("dark") 或 resetMode() 切换。

参考文档

详细文档整理在 references/ 中:

  • 概览:about.md、cli.md、components-json.md、theming.md
  • 安装:installation/sveltekit.md、installation/astro.md、installation/vite.md
  • 组件:components/[name].md — 59 篇组件指南
  • 深色模式:dark-mode/svelte.md、dark-mode/astro.md
  • 迁移:migration/svelte-5.md、migration/tailwind-v4.md
  • 注册表:registry/getting-started.md — 自定义注册表创建指南
查找组件文档

对于任何组件,请阅读 references/components/[component-name].md:

  • Button → references/components/button.md
  • Dialog → references/components/dialog.md
  • Data Table → references/components/data-table.md

常见任务

任务参考
添加组件pnpm dlx shadcn-svelte@latest add [name]
表单验证references/components/form.md
数据表格references/components/data-table.md
主题/颜色references/theming.md
深色模式references/dark-mode/svelte.md
自定义注册表references/registry/getting-started.md

评论

支持 Markdown