component-creation

Create React components with TypeScript, CSS Modules, Storybook, and vitest tests.

2|1|Updated Jan 7, 2021
One-click install
npx skills add https://github.com/lsst-sqre/squareone --skill component-creation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: component-creation
Source: https://github.com/lsst-sqre/squareone/tree/main/.claude/skills/component-creation
Command: npx skills add https://github.com/lsst-sqre/squareone --skill component-creation

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires react, vitest, storybook, @testing-library/react, user-event, @radix-ui/react-dialog.

What problem does it solve?

Creating new React components that adhere to best practices, maintain consistency, and are easily testable can be challenging. This skill provides a comprehensive guide to component creation, covering everything from file structure and TypeScript patterns to styling, testing, and Storybook integration.

Core Features & Use Cases

  • Standardized Component Structure: Defines a clear file structure for components, including .tsx, .module.css, .stories.tsx, and .test.tsx files.
  • TypeScript & Styling Best Practices: Enforces type over interface, avoids React.FC, and mandates CSS Modules with full design token integration for consistent styling.
  • Testing & Documentation: Guides on writing robust vitest tests and comprehensive Storybook stories, including interactive story tests.
  • Use Case: When starting a new UI feature, use this skill to create a new component, ensuring it follows the monorepo's TypeScript and styling conventions, has proper tests, and is documented in Storybook.

Quick Start

Create a new React component named MyButton with basic styling and a Storybook entry. Create MyButton.tsx, MyButton.module.css, MyButton.stories.tsx, MyButton.test.tsx in a new 'MyButton' directory.

Frequently Asked Questions about component-creation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a new React component with TypeScript and CSS Modules?

Create a component directory with four files: a `.tsx` file for the component logic using `type` over `interface`, a `.module.css` file for styling with design tokens, a `.stories.tsx` file for Storybook documentation, and a `.test.tsx` file for vitest tests. This standardized structure ensures consistency across your monorepo and makes components easily testable and documented.

What's the best way to write accessible React components with Storybook and vitest?

Use Radix UI primitives like `@radix-ui/react-dialog` for built-in accessibility, document interactive states in Storybook stories with `@testing-library/react` and `user-event`, and write vitest tests that verify component behavior and accessibility. This approach creates components that are accessible by default and thoroughly tested before reaching production.

Can I use CSS Modules with design tokens in React component files?

Yes. CSS Modules integrate fully with design tokens in your component's `.module.css` file, enabling consistent styling without inline styles or utility classes. Import the styles into your `.tsx` component file and apply token-based classes to ensure design consistency across your component library.

Do I need to write Storybook stories for every React component?

Yes, Storybook stories are part of the standardized component structure. They serve as interactive documentation and enable story-based testing with vitest, making components easier to develop, review, and maintain while providing a living style guide for your team.

How do I avoid common TypeScript patterns when creating React components?

Prefer `type` aliases over `interface` declarations and avoid `React.FC` in favor of direct function declarations with explicit return types. These conventions reduce boilerplate, improve type inference, and align with modern React and TypeScript best practices enforced across the monorepo.

What dependencies do I need to set up component testing and documentation?

You'll need vitest for unit testing, `@testing-library/react` and `user-event` for testing user interactions, Storybook for interactive component documentation, and `@radix-ui/react-dialog` for accessible component primitives. These tools work together to create testable, documented, and accessible components.