@14ch/svelte-ui

中文文档
0.0.83发布于 2026/11/04MITTypeScriptESM + CJS近 30 天下载 2366

Modern Svelte UI components library with TypeScript support

原始使用文档
文档目录32 节
  1. Features
  2. Installation
  3. Setup
  4. 1. Import Styles
  5. 2. Basic Usage
  6. Available Components
  7. Form Components
  8. Layout & Navigation
  9. Modals
  10. Popups & Menus
  11. Notifications & Feedback
  12. Skeleton Loaders
  13. Icons & Buttons
  14. Component Examples
  15. Button Variants
  16. Form Validation
  17. Checkbox & Radio Groups
  18. Skeleton Loaders
  19. Dialog with Confirmation
  20. Dark Theme
  21. Customization
  22. CSS Custom Properties
  23. Customizing Dark Mode Colors
  24. TypeScript Support
  25. Accessibility
  26. Browser Support
  27. License
  28. Changelog
  29. v0.0.5
  30. v0.0.3
  31. v0.0.2
  32. v0.0.1

Svelte UI

A Svelte component library with TypeScript support and Material Design-inspired styling.

⚠️ Preview Release: This library is in preview. APIs may change before the stable 1.0 release.

Features

  • Material Design-inspired components
  • ARIA support and keyboard navigation
  • Touch-optimized for mobile devices
  • Dark mode and high contrast mode support
  • TypeScript definitions included
  • Tree-shakeable ES modules
  • Built with Svelte 5 runes API

Installation

npm install @14ch/svelte-ui
# or
pnpm install @14ch/svelte-ui
# or
yarn add @14ch/svelte-ui

Setup

1. Import Styles

Components read their colors and sizes from --svelte-ui-* CSS variables, so the design tokens must be loaded.

For an app, import everything (recommended):

// Icon fonts + design tokens + app-wide base rules
import '@14ch/svelte-ui/styles';

For a package that embeds svelte-ui components into other apps, import only what the components need, so nothing leaks into the host page:

// Design tokens only: CSS variables on :where(:root) and the dark/high-contrast switches.
// No external requests, no rules on elements.
import '@14ch/svelte-ui/styles/tokens';

// Material Symbols fonts (loaded from Google Fonts).
// Needed only when components render an icon: Icon, IconButton, Fab, the `icon` props,
// and built-in icons such as clear buttons, popup arrows, pickers and PopupMenu check marks.
import '@14ch/svelte-ui/styles/icons';

Components render the same with styles/tokens alone as with the full styles. The full import additionally applies these base rules to the whole page: box-sizing: border-box on every element, a reset for button, color: inherit for dialog, font-weight: normal for label, the autofill background fix for input, and the .sr-only class.

Optional extras (Sass sources; your build needs sass):

import '@14ch/svelte-ui/styles/optional/fonts.scss'; // Roboto, Noto Sans JP, YakuHanJP
import '@14ch/svelte-ui/styles/optional/reset.scss'; // CSS reset

2. Basic Usage

<script>
    import { Button, Input, Dialog } from '@14ch/svelte-ui';

    let dialogRef;
    let inputValue = $state('');
</script>

<Input bind:value={inputValue} placeholder="Enter your name" />

<Button onclick={() => dialogRef.open()}>Open Dialog</Button>

<Dialog bind:this={dialogRef} title="Greeting">
    <p>Hello {inputValue}!</p>
    <p>Welcome to Svelte UI Component Library.</p>
    {#snippet footer()}
        <Button onclick={() => dialogRef.close()}>Close</Button>
    {/snippet}
</Dialog>

Available Components

Form Components

  • Button - Various button styles and states
  • Input - Text input with validation support
  • Textarea - Multi-line text input
  • Checkbox - Checkbox with custom styling
  • CheckboxGroup - Multiple checkbox selection group
  • Radio - Radio button groups
  • RadioGroup - Radio button group wrapper
  • Select - Dropdown selection
  • Combobox - Searchable dropdown
  • Slider - Range slider input
  • Switch - Toggle switch
  • ColorPicker - Color selection input
  • Datepicker - Date selection with calendar
  • FileUploader - File upload with drag & drop
  • ImageUploader - Image upload with preview

Layout & Navigation

  • Tab / TabItem - Tab navigation
  • Pagination - Page navigation

Modals

  • Dialog - Modal dialogs
  • ConfirmDialog - Confirmation dialogs
  • Drawer - Side drawer

Popups & Menus

  • Popup - Popover content
  • PopupMenu / PopupMenuButton - Context menus

Notifications & Feedback

  • Snackbar / SnackbarItem - Toast notifications
  • LoadingSpinner - Loading indicators

Skeleton Loaders

  • Skeleton - Loading placeholders with preset patterns

Icons & Buttons

  • Icon - Material Symbols icons
  • IconButton - Icon-based buttons
  • Fab - Floating Action Button

Component Examples

Button Variants

<script>
    import { Button } from '@14ch/svelte-ui';
</script>

<!-- Different variants -->
<Button variant="filled">Filled Button</Button>
<Button variant="outlined">Outlined Button</Button>
<Button variant="text">Text Button</Button>

<!-- With icons -->
<Button icon="add">Add Item</Button>

<!-- Different sizes -->
<Button size="small">Small</Button>
<Button size="medium">Medium</Button>
<Button size="large">Large</Button>

<!-- States -->
<Button disabled>Disabled</Button>
<Button loading>Loading...</Button>

Form Validation

<script>
    import { Input, Checkbox, Button } from '@14ch/svelte-ui';

    let email = $state('');
    let password = $state('');
    let agreed = $state(false);

    const handleSubmit = () => {
        if (!email || !password || !agreed) {
            alert('Please fill all fields');
            return;
        }
        // Handle form submission
    };
</script>

<Input bind:value={email} type="email" placeholder="Email" required />

<Input bind:value={password} type="password" placeholder="Password" required />

<Checkbox bind:value={agreed}>I agree to the terms and conditions</Checkbox>

<Button onclick={handleSubmit} disabled={!agreed}>Sign Up</Button>

Checkbox & Radio Groups

<script>
    import { CheckboxGroup, RadioGroup } from '@14ch/svelte-ui';

    const options = [
        { label: 'Option 1', value: 'opt1' },
        { label: 'Option 2', value: 'opt2' },
        { label: 'Option 3', value: 'opt3' }
    ];

    let selectedCheckboxes = $state([]);
    let selectedRadio = $state(null);
</script>

<CheckboxGroup bind:value={selectedCheckboxes} {options} direction="vertical" gap="16px" />

<RadioGroup bind:value={selectedRadio} {options} direction="horizontal" gap="24px" />

Skeleton Loaders

<script>
    import { Skeleton, SkeletonBox, SkeletonText, SkeletonAvatar } from '@14ch/svelte-ui';
</script>

<!-- Using preset patterns -->
<Skeleton patterns={[{ type: 'article-list' }]} repeat={3} />
<Skeleton patterns={[{ type: 'product-list' }]} repeat={4} />

<!-- Using individual components for custom layouts -->
<div>
    <SkeletonAvatar showName={true} />
    <SkeletonBox width="100%" height="200px" />
    <SkeletonText lines={3} />
</div>

Dialog with Confirmation

<script>
    import { Button, ConfirmDialog } from '@14ch/svelte-ui';

    let confirmDialogRef;

    const handleDelete = () => {
        confirmDialogRef.open();
    };

    const onConfirm = () => {
        // Delete logic here
        console.log('Item deleted');
        confirmDialogRef.close();
    };
</script>

<Button variant="outlined" onclick={handleDelete}>Delete Item</Button>

<ConfirmDialog
    bind:this={confirmDialogRef}
    title="Confirm Delete"
    message="Are you sure you want to delete this item? This action cannot be undone."
    onconfirm={onConfirm}
    oncancel={() => confirmDialogRef.close()}
/>

Dark Theme

Apply dark mode by setting the data-theme attribute:

<script>
    import { Button } from '@14ch/svelte-ui';
    import { onMount } from 'svelte';

    let theme = $state('light');

    const toggleTheme = () => {
        theme = theme === 'light' ? 'dark' : 'light';
        document.body.setAttribute('data-theme', theme);
    };

    onMount(() => {
        document.body.setAttribute('data-theme', theme);
    });
</script>

<Button onclick={toggleTheme}>Toggle Theme</Button>

You can also apply dark mode to specific sections:

<div data-theme="dark">
    <!-- This section and its children will use dark mode -->
    <Button>Dark Mode Button</Button>
</div>

Customization

CSS Custom Properties

The library uses CSS custom properties for easy theming:

:root {
    --svelte-ui-primary-color: #1976d2;
    --svelte-ui-surface-color: #ffffff;
    --svelte-ui-text-color: #1f1f1f;
    --svelte-ui-border-radius: 8px;
    /* ... and many more */
}

Customizing Dark Mode Colors

You can customize dark mode colors by overriding CSS variables:

[data-theme='dark'] {
    --svelte-ui-primary-color: #90caf9;
    --svelte-ui-surface-color: #121212;
    --svelte-ui-text-color: #ffffff;
    /* ... customize other colors as needed */
}

TypeScript Support

All components come with full TypeScript definitions:

import type { MenuItem } from '@14ch/svelte-ui';

const menuItems: MenuItem[] = [
    { title: 'Home', href: '/' },
    { title: 'About', href: '/about' },
    { title: 'Contact', href: '/contact' }
];

Accessibility

This library is built with accessibility in mind:

  • Proper ARIA attributes
  • Keyboard navigation support
  • Screen reader announcements
  • Focus management
  • High contrast mode support

Browser Support

  • Chrome/Edge 88+
  • Firefox 78+
  • Safari 14+

License

MIT License - see the LICENSE file for details.

Changelog

v0.0.5

  • Improved TabItem hover behavior: replaced background color with indicator bar opacity change
  • TabItem now shows selected text color and indicator bar on hover for better visual feedback
  • Breaking change: Replaced variant prop with inline prop in Combobox, Datepicker, and Select components

v0.0.3

  • Improved text vertical alignment in Button, Fab, TabItem, Checkbox, and Radio components using text-box-trim
  • Text labels now appear more visually centered within their containers

v0.0.2

(Previous release notes...)

v0.0.1

  • Initial release
  • 40+ components (Button, Input, Dialog, Skeleton loaders, etc.)
  • CheckboxGroup and RadioGroup
  • Skeleton component with preset patterns
  • Material Design-inspired styling
  • TypeScript support
  • ARIA, keyboard navigation, screen reader support
  • High contrast mode support
  • Svelte 5 runes API

版本与发布记录

@14ch/svelte-ui 共发布 83 个版本,首次发布于 2025/10/13;过去 12 个月发布了 81 个版本。

版本发布日期距今
0.0.83latest2026/11/043 天前
0.0.822026/11/043 天前
0.0.812026/11/034 天前
0.0.802026/11/035 天前
0.0.792026/11/035 天前
0.0.782026/11/025 天前

关于 @14ch/svelte-ui 的常见问题

@14ch/svelte-ui 是什么?

Modern Svelte UI components library with TypeScript support

如何安装 @14ch/svelte-ui?

在项目目录运行 npm install @14ch/svelte-ui,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:svelte(^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@14ch/svelte-ui 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@14ch/svelte-ui 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@14ch/svelte-ui 可以商用吗?

@14ch/svelte-ui 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@14ch/svelte-ui 的下载量有多少?

根据 npm 官方下载统计,@14ch/svelte-ui 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,366 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@14ch/svelte-ui 还在维护吗?

最新版本 0.0.83 发布于 2026/11/04(3 天前);至今共发布 83 个版本,其中过去 12 个月发布了 81 个;首次发布于 2025/10/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。