Skip to content

Mini Component Library

Medium ~50 min

What you'll build

A set of 4 reusable components with variants (sizes, colors), a design token file, and a Storybook-like demo page.

Goals

  • Design a consistent API for multiple components
  • Use design tokens for colors, spacing, and typography
  • Support variants (primary/secondary, sizes) via props
  • Compose components into a demo page

Prerequisites

  • React function components and props
  • CSS or a styling solution (CSS Modules, Tailwind, etc.)
  • Component composition (children prop)

Steps

  1. 1

    Define design tokens

    Create a tokens file with colors (primary, secondary, danger), spacing (xs, sm, md, lg), and font sizes. These are the single source of truth for styling. Acceptance: all components reference tokens, not hardcoded values.

  2. 2

    Build the Button component

    Create a Button with variant (primary/secondary/danger) and size (sm/md/lg) props. Use the tokens for all styling. Acceptance: all 9 combinations (3 variants × 3 sizes) look consistent.

  3. 3

    Build Input and Card

    Create an Input with label, error, and helper text props, and a Card with header, body, and footer slots (using children). Acceptance: both compose well with Button.

  4. 4

    Build a Modal component

    Create a Modal with open/onClose props, a backdrop, and Escape-to-close. Use a portal (createPortal) so the modal renders outside the DOM tree. Acceptance: modal traps focus and closes on Escape and backdrop click.

  5. 5

    Build a demo page

    Create a page that showcases every component and variant — like a mini Storybook. Include a form (Input + Button), a card with content, and a modal triggered by a button. Acceptance: the demo demonstrates all components working together.

Try it yourself

What you learned

You built a component library with a design system — the foundation of scalable UIs. Consistent tokens and component APIs are what make teams productive and UIs coherent.

Related Resources

Related Lessons

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to topic