Skip to content

commandFrontend

Scaffold Component

Creates a new UI component with props, styles, a test and a story, copying the folder layout your project already uses.

npx workspacetemplates add scaffold-component --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/scaffold-component.md15 lines · 1.1 KBFile
---
description: Creates a new UI component with props, styles, a test and a story, copying the folder layout your project already uses.
argument-hint: "[ComponentName and a short description]"
---

Scaffold a component named and described by: $ARGUMENTS

1. Find two or three existing components of similar size (`Glob` for `*.tsx`, `*.vue`, `*.svelte`). Note the folder layout, naming case, styling approach (CSS modules, Tailwind, styled), prop typing, and how tests and stories are named.
2. If the name collides with an existing component, stop and ask.
3. Create the folder and files exactly as the neighbors do: component, styles, test, story, and an index export if siblings have one.
4. Type the props with sensible defaults, forward `className` and refs when siblings do, and use semantic elements with labels for anything interactive.
5. The test renders the component, checks one default case and one prop variation. The story shows each variant.
6. Run the project's lint, type check and the new test only.

List the files created and the commands that passed. Do not modify existing components; if a shared file needs a change, show the diff and ask first.

What it does

A new component usually starts by copying a neighbor and renaming things, which drags old props and stale styles along. This command studies how existing components are laid out and builds the new one to the same pattern.

It generates the component file, its style file, a test and a story when the project has Storybook. Nothing outside the new folder is edited, except an index export when the project keeps one.

Example

you › /scaffold-component Badge small status pill with success, warning and error tones

agent › Created src/components/Badge/Badge.tsx, Badge.module.css, Badge.test.tsx, Badge.stories.tsx and added an export to src/components/index.ts.
Props: tone ("success" | "warning" | "error"), children, className.
Passed: tsc --noEmit, eslint, vitest Badge.

Questions

How does it know my conventions?
It reads a few similar components first and copies their folder layout, naming and styling method instead of using a generic template.
Will it change existing files?
Only the new folder is written. If a barrel file needs one new export line, it shows that diff before applying it.
  • A11y Check

    CommandFrontend

    Free
  • Add Form Validation

    CommandFrontend

    Free
  • Add Loading States

    CommandFrontend

    Free
  • Check Responsive

    CommandFrontend

    Free