svelte-component — Claude Code command: what it does, how to install
Generates typed Svelte components and matching unit tests based on your project configuration.
npx claude-code-templates@latest --command svelte/svelte-componentWhat 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
$bindablereactive 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-component2Manually: put the files in place
.claude/commands/svelte-component.mdCall it with /svelte-component. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/svelte-component.mdCall it with /prompts:svelte-component. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/svelte-component.prompt.mdManually: put the files in place
.gemini/commands/svelte-component.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
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