component-builder
A pattern-based tool for creating consistent, type-safe UI components using tailwind-variants.
Install
mkdir -p .claude/skills/component-builder && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/7669" && unzip -o skill.zip -d .claude/skills/component-builder && rm skill.zipInstalls to .claude/skills/component-builder
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Create UI components using tailwind-variants for type-safe styling. Use when creating or editing components in src/lib/ui/.Key capabilities
- →Define type-safe component variants
- →Standardize component styling
- →Implement boolean state variants
- →Create compound style combinations
- →Merge class names dynamically
How it works
The skill uses tailwind-variants to map component props to CSS classes, ensuring consistent styling and type safety across the UI library.
Inputs & outputs
When to use component-builder
- →Create new UI components from scratch
- →Refactor existing UI elements to use tailwind-variants
- →Add new size or style variants to existing components
About this skill
Component Builder
This skill documents the tailwind-variants pattern used for UI components in this project. All UI components should follow this pattern for consistency and type safety.
When to Use
Use this skill when:
- Creating new UI components in
src/lib/ui/ - Refactoring existing components to use tailwind-variants
- Adding new variants to existing components
Quick Start
Every component needs two files:
componentName.variants.ts- Variant definitionsComponentName.svelte- The component
Reference Files
- Canonical example:
src/lib/ui/Button.svelteandsrc/lib/ui/button.variants.ts - Compound variants example:
src/lib/ui/Tag.svelteandsrc/lib/ui/tag.variants.ts - Multi-variant example:
src/lib/ui/ContentCard.svelteandsrc/lib/ui/contentCard.variants.ts
Pattern Overview
Step 1: Create Variants File
// componentName.variants.ts
import { tv, type VariantProps } from 'tailwind-variants'
export const componentVariants = tv({
base: 'common-classes-for-all-variants',
variants: {
variant: {
primary: 'classes-for-primary',
secondary: 'classes-for-secondary'
},
size: {
sm: 'text-sm px-2',
md: 'text-base px-4',
lg: 'text-lg px-6'
}
},
defaultVariants: {
variant: 'primary',
size: 'md'
}
})
// Export types for each variant dimension
export type ComponentVariant = VariantProps<typeof componentVariants>['variant']
export type ComponentSize = VariantProps<typeof componentVariants>['size']
Step 2: Use in Component
<script lang="ts">
import type { ClassValue } from 'svelte/elements'
import { componentVariants, type ComponentVariant, type ComponentSize } from './componentName.variants'
type Props = {
variant?: ComponentVariant
size?: ComponentSize
class?: ClassValue
}
let { variant, size, class: className, ...rest }: Props = $props()
</script>
<div class={[componentVariants({ variant, size }), className]} {...rest}>
<!-- content -->
</div>
Key Patterns
Boolean Variants
For on/off states like active, disabled, error:
variants: {
active: {
true: 'bg-svelte-100 border-svelte-300',
false: ''
},
error: {
true: 'border-red-300 bg-red-50',
false: 'border-transparent'
}
}
Compound Variants
Apply styles only when specific combinations match:
compoundVariants: [
{
active: true,
removable: false,
class: 'hover:bg-svelte-200'
}
]
Class Merging
Always use array syntax to allow consumer overrides:
<div class={[componentVariants({ variant, size }), className]}>
Templates
For copy-paste templates, see TEMPLATES.md.
When not to use it
- →When styling simple elements without variants
Limitations
- →Requires adherence to the specific two-file pattern
How it compares
It enforces a strict separation between variant definitions and component logic compared to manual class string concatenation.
Compared to similar skills
component-builder side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| component-builder (this skill) | 1 | 7mo | No flags | Beginner |
| svelte | 3 | 2mo | No flags | Intermediate |
| admin-crud-page | 1 | 7mo | No flags | Intermediate |
| svelte-ui-design | 23 | 9mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by svelte-society
View all by svelte-society →You might also like
svelte
EpicenterHQ
Svelte 5 patterns including TanStack Query mutations, shadcn-svelte components, and component composition. Use when writing Svelte components, using TanStack Query, or working with shadcn-svelte UI.
admin-crud-page
svelte-society
Create admin dashboard pages with tables, forms, and actions
svelte-ui-design
XIYO
ALWAYS use this skill for ANY Svelte component styling, design, or UI work. Svelte 5 UI design system using Tailwind CSS 4, Skeleton Labs design tokens/presets/Tailwind Components, and Bits UI headless components. Covers class composition, color systems, interactive components, forms, overlays, and all visual design.
tanstack-form
exceptionless
TanStack Form with Zod validation in Svelte 5. Form state management, field validation, error handling, and ProblemDetails integration. Keywords: TanStack Form, createForm, Field, form validation, zod schema, form errors, onSubmit, onSubmitAsync, problemDetailsToFormErrors
tanstack-query
exceptionless
Data fetching and caching with TanStack Query in Svelte. Query patterns, mutations, cache invalidation, WebSocket-driven updates, and optimistic updates. Keywords: createQuery, createMutation, TanStack Query, query keys, cache invalidation, optimistic updates, refetch, stale time, @exceptionless/fetchclient, WebSocket
svelte-migrate
temporalio
Migrate a Svelte 4 component to Svelte 5 runes syntax. Use when asked to migrate, convert, or upgrade a .svelte file to Svelte 5.