Working with Storybook

Working with Storybook

I’m a HUGE fan of Storybook. It’s a great way to:

  • Build components in isolation

  • Create living documentation of your code

Up and Running with Storybook

Within your Redwood project, using Storybook is as simple as running a single command:

yarn rw storybook

The first time you run this command, it will take a little longer since Redwood still needs to download Storybook’s dependencies.

Once you’re up and running, you should be able to open Storybook within the browser on port 7910

A Storybook File

Everytime you generate a component, cell, layout, or page within Redwood, it will generate (1) a component file, (2) a Storybook file, and (3) a test file.

A Storybook file, is named COMPONENT.stories.tsx (or .jsx if you’re not using TypeScript).

Here’s what the boiler plate code looks like for a component called RsvpStatus

// Pass props to your component by passing an `args` object to your story
//
// ```tsx
// export const Primary: Story = {
//  args: {
//    propName: propValue
//  }
// }
// ```
//
// See <https://storybook.js.org/docs/react/writing-stories/args>.

import type { Meta, StoryObj } from '@storybook/react'

import RsvpStatus from './RsvpStatus'

const meta: Meta<typeof RsvpStatus> = {
  component: RsvpStatus,
}

export default meta

type Story = StoryObj<typeof RsvpStatus>

export const Primary: Story = {}

You can pass in props by adding an args object. For example:

export const Primary: Story = {
  args: {
    count: 0,
    status: 'success',
    heading: 'Attending',
  },
}

You can also create additional “stories” — which are just variations of your component — by exporting out additional constants:

export const Disabled: Story = {
  args: {
    count: 0,
    disabled: true,
    status: 'success',
    heading: 'Attending',
  },
}

export const withClearFilter: Story = {
  args: {
    clearFilter: {
      isShowing: true,
      handleClick: () => {},
    },
    count: 0,
    status: 'success',
    heading: 'Attending',
  },
}

I have a video on YouTube, dedicated to working with Storybook and Redwood.

Advent of CSS 2023

Buy nowLearn more

👋 Welcome

  • START HERE!2
  • Setting up your Project2

Challenge #1 - Building An Icon Component

  • Challenge #18
  • Project Files
  • Solution #16

Challenge #2 - Building an Avatar Component

  • Challenge #2
  • Project Files
  • Solution #25

Challenge #3 - Form Fields and CSS Only Validation

  • Challenge #34
  • Project Files
  • Solution #35

Challenge #4 - Show / Hide Password

  • Challenge #4
  • Project Files
  • Solution #4

Challenge #5 - Login Layout

  • Challenge #5
  • Project Files1
  • Solution #5

Challenge #6 - Slide up Footer

  • Challenge #6
  • Project Files
  • Solution #6

Challenge #7 - Hamburger Menu

  • Challenge #7
  • Project Files
  • Solution #7

Challenge #8 - Slide Out Navigation

  • Challenge #8
  • Project Files
  • Solution #8

Challenge #9 - Dropdown Menu

  • Challenge #9
  • Project Files
  • Solution #9

Challenge #10 - Interior Page Layout

  • Challenge #10
  • Project Files
  • Solution #10

Challenge #11 - Custom Checkbox

  • Challenge #11
  • Project Files
  • Solution #111

Challenge #12 - RSVP Pages

  • Challenge #12
  • Project Files
  • Solution #12

Challenge #13: Invite Card

  • Challenge #13
  • Project Files
  • Solution #13

Challenge #14 - Invite Group Form

  • Challenge #14
  • Project Files
  • Solution #14

Challenge #15 - Modal

  • Challenge #15
  • Project Files
  • Solution #15

Challenge #16 - Create your wishlist

  • Challenge #16
  • Project Files
  • Solution #16

Challenge #17 - Slide Out Panel

  • Challenge #17
  • Project Files
  • Solution #17

Challenge #18 - View Your Wish List Layout

  • Challenge #18
  • Project Files3

Challenge #19 - Expanding and Collapsing Accordion

  • Challenge #19
  • Project Files

Challenge #20 - Dashboard Page

  • Challenge #20
  • Project Files1

Challenge #21 - Pairing

  • Challenge #21
  • Project Files

Challenge #22 - Thank You Note

  • Challenge #22
  • Project Files

Challenge #23 - Spinner for the Loading State

  • Challenge #23
  • Project Files

Challenge #24 - Light and Dark Theme Switcher

  • Challenge #24
  • Project Files

Appendix

  • Getting Help and Support
  • Working with GitHub
  • Working with Gitpod2
  • Working with Storybook
  • Working with Redwood
  • Testimonials
  • Want more? Where to go from here?