Fireship · @fireship

Storybook in 100 Seconds

Uploaded June 27, 2022 · Length 2:19

Storybook in 100 Seconds

Summary

storybook tutorial: build, test, and visualize ui components in isolation with a guidebook and test runner.

  • storybook
  • ui components
  • testing
  • frontend development
  • component frameworks

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    storybook an open source tool used to

  2. 0:02

    build test and visualize ui components

  3. 0:05

    in isolation modern web developers love

  4. 0:07

    component frameworks because they

  5. 0:09

    organize html css and javascript code

  6. 0:12

    into reusable chunks like lego bricks

  7. 0:14

    however a complex codebase can still

  8. 0:16

    easily descend into chaos causing

  9. 0:18

    components to lose their meaning in life

  10. 0:20

    storybook allows developers to extract

  11. 0:22

    components into a sandbox where they can

  12. 0:24

    be explored and tested without

  13. 0:26

    distractions instead of viewing

  14. 0:27

    components through the lens of a giant

  15. 0:29

    complex component tree that is your

  16. 0:31

    application you get a guidebook that

  17. 0:33

    breaks everything down individually no

  18. 0:35

    need to worry about data dependencies or

  19. 0:37

    business logic this makes it much easier

  20. 0:38

    to share your work with other developers

  21. 0:40

    or clients who can validate that things

  22. 0:42

    actually work the way they're supposed

  23. 0:43

    to in addition it has a test runner

  24. 0:45

    based on jest and playwright that can

  25. 0:47

    automatically verify whether your

  26. 0:49

    component renders without errors and

  27. 0:50

    also validate concerns like

  28. 0:52

    accessibility measure performance and

  29. 0:54

    can even do visual regression testing in

  30. 0:56

    the cloud to pinpoint everything you

  31. 0:57

    broke with that last css tweak to get

  32. 1:00

    started create a project with your

  33. 1:01

    favorite front-end framework like react

  34. 1:03

    angular view spelt and so on or open an

  35. 1:05

    existing one then run npx storybook init

  36. 1:07

    next find a ui component then create a

  37. 1:09

    matching file ending dot stories.js a

  38. 1:12

    story is just a function that describes

  39. 1:14

    how to render the component in many

  40. 1:16

    cases a component will have multiple

  41. 1:18

    different variations to show in the

  42. 1:20

    story export a function for each one of

  43. 1:22

    these variations that works but we can

  44. 1:24

    actually change the arguments to a

  45. 1:26

    component dynamically directly in the ui

  46. 1:28

    by creating a template that maps

  47. 1:30

    arguments to the component we can now

  48. 1:31

    change the component's behavior on the

  49. 1:33

    fly directly in the storybook ui it's

  50. 1:35

    also possible to write stories in

  51. 1:37

    markdown with mdx this allows you to not

  52. 1:40

    only visualize the component but also

  53. 1:42

    document it at the same time and there's

  54. 1:44

    a huge collection of add-ons to

  55. 1:45

    customize the behavior of your storybook

  56. 1:47

    you might use actions to keep track of

  57. 1:49

    browser events or viewport to analyze

  58. 1:51

    components on responsive layouts and the

  59. 1:53

    measure add-on can help you visually

  60. 1:55

    debug css layout and alignment issues

  61. 1:57

    within your stories when it comes to

  62. 1:59

    testing you could spot check with your