Skip to main content
command

svelte-component — Claude Code command: what it does, how to install

Generates typed Svelte components and matching unit tests based on your project configuration.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --command svelte/svelte-component
Open on GitHub

What svelte-component does

The command inspects your setup via Read, checking for svelte.config.js and tsconfig.json. It targets folders like src/components/ or src/lib/. Output markup includes semantic tags and ARIA attributes for accessibility.

The template enforces a clean structure. Script blocks declare typed props alongside $bindable state values, followed by markup and scoped styles. If Vitest or Jest is present, Claude Code writes a companion test file and updates the module export.

Execution requires Read, Write, and Edit permissions. Without an existing Svelte config file in the project root, the command cannot automatically resolve component directories.

What it helps with

  • scaffold accessible Svelte components with ARIA attributes
  • configure typed props and $bindable reactive state
  • generate Vitest or Jest test files alongside component code
  • create Storybook stories for new interface elements

Example prompts for the agent

  • /svelte-component Modal --typescript --story
  • /svelte-component Button --typescript
  • Create a Modal component with customizable header, footer slots, and close functionality

How to install svelte-component

1claude-code-templates

npx claude-code-templates@latest --command svelte/svelte-component

2Manually: put the files in place

.claude/commands/svelte-component.md

Call it with /svelte-component. For all projects use ~/.claude/commands/

Questions about svelte-component

How do I install svelte-component in Claude Code?

Run npx claude-code-templates@latest --command svelte/svelte-component in your terminal. This creates .claude/commands/svelte-component.md in your project.

What does svelte-component do?

It inspects your repository layout and generates complete Svelte components with tests, types, and accessible markup.

What arguments does svelte-component support?

It expects a component name followed by optional --typescript and --story flags to produce TypeScript code and Storybook files.

Source text

svelte-component.md · MIT
---
allowed-tools: Read, Write, Edit
argument-hint: "[component-name] [--typescript] [--story]"
description: Create new Svelte components with best practices, TypeScript support, and testing
---

# Create Svelte Component

Create new Svelte component: $ARGUMENTS

## Current Svelte Project

- Svelte config: @svelte.config.js or @vite.config.js (if exists)
- Components directory: @src/components/ or @src/lib/ (if exists)
- TypeScript config: @tsconfig.json (detect TypeScript usage)
- Testing setup: @vitest.config.js or @jest.config.js (if exists)

## Task

Create Svelte component with best practices. When creating components:

1. **Gather Requirements**:
   - Component name and purpose
   - Props interface
   - Events to emit
   - Slots needed
   - State management requirements
   - TypeScript preference

2. **Component Structure**:
   ```svelte
   <script lang="ts">
     // Imports
     // Type definitions
     // Props
     // State
     // Derived values
     // Effects
     // Functions
   </script>
   
   <!-- Markup -->
   
   <style>
     /* Scoped styles */
   </style>
   ```

3. **Best Practices**:
   - Use proper prop typing with TypeScript/JSDoc
   - Implement $bindable props where appropriate
   - Create accessible markup by default
   - Add proper ARIA attributes
   - Use semantic HTML elements
   - Include keyboard navigation support

4. **Component Types to Create**:
   - **UI Components**: Buttons, Cards, Modals, etc.
   - **Form Components**: Inputs with validation, custom form controls
   - **Layout Components**: Headers, Sidebars, Grids
   - **Data Components**: Tables, Lists, Data visualizations
   - **Utility Components**: Portals, Transitions, Error boundaries

5. **Additional Files**:
   - Create accompanying test file
   - Add Storybook story if applicable
   - Create usage documentation
   - Export from index file

## Example Usage

User: "Create a Modal component with customizable header, footer slots, and close functionality"

Assistant will:
- Create Modal.svelte with proper structure
- Implement focus trap and keyboard handling
- Add transition effects
- Create Modal.test.js with basic tests
- Provide usage examples
- Suggest accessibility improvements

© davila7 · MIT · davila7/claude-code-templates

Similar slash commands

All slash commands for Frontend and UI →

From the same set804

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor