Watch on YouTubePlayPlays from YouTube. Google's privacy policy (opens in a new tab) applies.
Adam explains what Storybook is, where it lives and how you open it, then has Claude set it up in the team's codebase and document its shared UI components. He tours the result: a foundations page with the design tokens, a docs page per component and controls to try each variant.
What you'll learn
- Storybook documents your real components the way you'd document them in Figma, with variants you can click through and tweak.
- It's installed in the codebase for the whole team and opened locally, by default at
localhost:6006, withnpm run storybook. - Each component gets a stories file next to it, defining its docs page, its variants and the props you can change.
- Untouched shadcn components already have their own docs; document only the ones you changed or use in your own way.
- Agree on Storybook with the engineers before adding it, since it's for everyone in the repo.
- Let Claude handle the install and the first set of stories, then judge the result and refine it.
- Decide which components belong in Storybook, and keep an eye on AI agents over-documenting everything.
- Documented components give AI coding agents guidance they're more likely to follow.
Chapters
- 00:00What Storybook is
- 01:55Where Storybook lives and runs
- 03:27Stories, and when to skip them
- 05:37Setting it up with Claude
- 09:51Which components to document
- 12:58Exploring your new Storybook
- 15:44Where the stories live
- 00:00In previous videos in this module, we talked about two things.
- 00:04First was documenting your high-level design system patterns using rules.
- 00:10And then second of all, we talked about creating your local UI playgrounds, throwaway UI playgrounds.
- 00:16But what if you need to document a specific way to use a component, a specific UI component, and you need this documentation to be available to everyone else, and
- 00:26specifically the AI decoding AI agents of order engineers?
- 00:30Well, you could keep using rule files for those or maybe ask Claude to create comments within like directly within your UI component TypeScript files.
- 00:42But there is actually a very nice tool that addresses this need and it's widely adopted within the industry, and it's called Storybook.
- 00:49You might have heard the term, and in this video we are going to unpack what Storybook is, how you can use it, and then we are go also going
- 00:57to install it over here in our mature version of the parking application that we clone in one of the previous modules.
- 01:05So let's start by unpacking what is Storybook.
- 01:09So you know how you can document your components within Figma.
- 01:13You can, you know, basically add layers of text, documenting the do's and don'ts of these components, accessibility considerations, and other things along these lines, and just maybe some example
- 01:25of of real-life usage for these components.
- 01:29Storybook does the exact same thing, except rather than doing this against pixels in Figma, it's going to do it against your living breathing codebase.
- 01:38It's going to use real code, and it's going to allow you to document your real components and document different ways to use it, and also show different variants of
- 01:47these components that are a little bit easier to read but to you like both you as a human but also your AI coding agents as well.
- 01:56Now Uh thing that is particularly tricky Storybook to grasp by other designers is how you can start using it and where do you look for Storybook, because it isn't
- 02:07really an application that you download and install on your computer.
- 02:12It also isn't isn't something that you can, you know, create an account within and keep using in your browser in some sort of third-party application.
- 02:21Instead, Storybook is that add-on that you install right within your codebase, and it's living over there.
- 02:28And then there is a separate command that you can run in your terminal that's going to open up Storybook locally.
- 02:36By default, it's going to be this localhost with a port of 6006.
- 02:42Now, of course, there are ways to configure Storybook to also be available on your live deployment.
- 02:48So, for example, you might have a URL that says something like stash/storybook, or, you know, sometimes you would use, I don't know, something like design system or design.
- 03:00That's your URL. But the default setup and one that is very common is keeping Storybook local so that it doesn't really make it doesn't really make its way over
- 03:11to production for everybody else to see.
- 03:14So, in other words, to use Storybook, you would really need most of the time to have access to the codebase, and you would need to be able to run
- 03:22it locally, which is something we have already discussed in previous modules.
- 03:27Now, with Storybook, you get this additional mini application within your codebase with this sort of UI, which is something you can also customize if you want.
- 03:37And the way it works is for each UI component you have at a basic level, for each UI component you have, you create a new story file with story
- 03:47as an extension or stories, I believe.
- 03:49And then there is a specific way for creating these stories file.
- 03:53It's very well documented over here in the documentation, how you can create these stories, and it's going to allow you to create these different you know, usage examples.
- 04:03It's going to let you define controls that you can change or like you can tweak to see the different styling and then it's also going to write to let
- 04:12you write these documentation pages as I don't know some sort of notion documents.
- 04:18There are many other things that Storybook is also giving you such as the ability to run these automated visual tests and other things, but in this video we are
- 04:27only going to cover like the basic usage of Storybook because it is already great on its own right out of the box.
- 04:34Now one more thing to mention and this is so also something that that we talked about on one of the previous videos.
- 04:42When you use out of the box primitive UI components like for example from the shadcn UI library which we also talked about in one of the previous videos and
- 04:52you don't really like do a lot of custom tweaking or any tweaking at all to these UI components you just import them from shadcn and you know you use
- 05:01them just like they are they were designed to be used and there really isn't anything specific about your design system that and the way you use this component you
- 05:11might actually consider not using Storybook for that because you really don't want to be creating documentation for something that is already properly documented on a page such as the
- 05:20shadcn. But if there are any custom modifications that you might have made to your button component or your toast component or you need your design system to use it
- 05:32in a very specific way, Storybook is actually a great place to document all of that.
- 05:38Now you can actually install Storybook by by running this command, but it's actually going to be a little bit easier to let us to let Claude walk us through
- 05:47this because depending on our setups and our code bases there might be different quirkiness and things to work around and Claude is really great at solving these things.
- 05:56Before you do anything though, it's important to remember one thing that I mentioned at the beginning.
- 06:02Storybook is something you would install for everyone else in your codebase repository.
- 06:08That is the spirit of how a Storybook has been designed to be used.
- 06:12So before you do anything, it's probably a good idea to consult it first with with other engineers on your team or just your other stakeholders and make sure you
- 06:21get their buy-in. Perhaps there are ways that other engineers would like you to use Storybook you know to match their specific working style.
- 06:32So good idea to have a brief conversation with everyone else before you go and make that first step.
- 06:38But for our purposes you know it's just a demo application.
- 06:42We are the only engineers in that mature version for now of the of the repo application.
- 06:47What I'm going to do I'm going to go into this new session.
- 06:52I'm going to set the effort to medium.
- 06:55Again making sure I'm starting off on this mature version of the application and I'm starting off of the main branch.
- 07:01And all I really need to say to Claude is that I would like you to help me set up Storybook in this repository or in this codebase perhaps.
- 07:16And I would like you to document all of our shared UI primitive components.
- 07:29Right. And I'm going to I going to switch over to the plan mode.
- 07:40And I I don't really need to specify anything else about this really.
- 07:43Storybook is such a widely adopted tool.
- 07:46You know Claude is very like all of the Claude models but not just Claude models like most of the current popular models are I'm sure very well trained on
- 07:58what this tool is and how to use it.
- 08:00I'm going to trust this AI agent in within Claude code to um first on and start by reading um by fetching the Storybook documentation.
- 08:12Um yeah and then it's going to come up with a plan on how to document these components.
- 08:20Now I don't have any specific plan in my head right now as I'm recording this video.
- 08:24In your case however there might be very specific way in which you'd like your components to be documented.
- 08:31Uh maybe you have this one particular um documentation template in mind.
- 08:36Maybe you want to be able to tweak only certain values or variants of your specific UI components.
- 08:43If that's the thing you might want to consider including this in your first prompt.
- 08:48Otherwise if you are starting fresh maybe it's a good idea to just let Claude do its work, evaluate the results and like see what is your taste, what are
- 08:57your likings and based on that you can either just continue refining within this conversation or you can scrap it all together um like disregard this work and start a
- 09:08new chat and ask Claude to install Storybook again but this time with your specific um recommendations in mind.
- 09:15Let's see there are three questions that Claude has for me.
- 09:18Your shared UI primitives are the six components in SRC components UI.
- 09:23Um the page frame is a layout piece not a primitive.
- 09:27Which Storybook which Storybook document?
- 09:30So I'm going to of course go with just the six primitives.
- 09:33Besides the components should Storybook also have a foundations page showing the design tokens from global CSS?
- 09:39Very nice idea. Yes please.
- 09:42And then how detailed should each component's page be?
- 09:45Every variant plus states let's just go with the defaults and let's see what's going to come out of this.
- 09:51And ask Claude is working on a plan.
- 09:54Um let me share one gotcha with you from from my own personal experience.
- 10:01So UI components can live everywhere in your codebase.
- 10:05So of course we have talked about you know in the case of Next.js applications, we talked about this very common pattern or convention of keeping UI, primitive UI components
- 10:17in this SRC components folder.
- 10:20And this is where you would want to keep okay, let me just accept this plan in the meantime.
- 10:26I'm sure it's good.
- 10:28We can like keep working our way up from there.
- 10:31So it's a very common pattern for the shared UI components.
- 10:34Shared UI components being the ones that get imported, you know, regardless of what kind of feature it is, to be documented over here.
- 10:42What AI agents sometimes can be you know, can be puzzled by is whether they should also document other kinds of UI components that had been created for specific features.
- 10:59And this is a decision for you to make, like how deep you like to go.
- 11:04So my personal preference is that I don't really want to pollute my storybook with documentation for these very simple one of UI components that were created to be used
- 11:14in just one specific feature, one specific dialogue, because that isn't really a pattern that I know is going to be reused anywhere else.
- 11:23Unless there is something very specific about this UI component, then I wouldn't really want to keep it over here in my storybook.
- 11:31But your case might be slightly different.
- 11:33So one decision for you to make when you consider adopting storybook in your codebase, if there isn't one installed already, is just how deep you want to go, not
- 11:43just how like you should like you would like your documentation to look like, but also what kind of UI components you even want to have documented in that first
- 11:52place. And then after installing or adopting storybook, the next thing you want to keep an eye on is how it's being used by not just your AI agents, coding
- 12:03agents, but other like coding agents of other engineers, because you might very quickly realize that the moment the storybook is installed, their AI agents come to a conclusion, okay,
- 12:14well, we should now start documenting everything there is to document.
- 12:18And Claude models have this [laughter] are well known for like over documenting everything.
- 12:25So if that is the case, you might need to revisit your Storybook every now and then, clean it up and perhaps you can consider actually writing down a
- 12:34rule in your CLAUDE.md file or in your rules folder to teach your AI agents or AI agents of orders, you know, when it makes when it actually makes
- 12:44sense to document um um a component in your Storybook and when it doesn't.
- 12:50Um so yeah, with that uh let's give it a second to see what Claude is going to come up with.
- 12:57Okay, and that first implementation is ready and Storybook Storybook is already running over here.
- 13:03Um if it wasn't running, um you can either ask Claude to open it up or there is actually a very simple command that you can do.
- 13:11Um you already know the NPM run dev.
- 13:14So for Storybook, it's NPM run Storybook and that's all you need to remember.
- 13:20You press enter and it's going to open up Storybook.
- 13:23Um in our case, let's go ahead and see um what we have.
- 13:28So first, we have that foundations page, which is awesome.
- 13:30All of the colors nicely documented.
- 13:33Um our, you know, um text styles over here really nice uh with support for uh Latin extend Latin extended set of characters, really nice.
- 13:44Um and then let's see uh a couple of components.
- 13:47So it's a classic setup.
- 13:49For each component, I can see Claude opted to create a one documentation page um which like goes to show different variants and then for each variant, we can actually
- 14:01click over here uh into these like different stories to have and like to to be able to um like observe this component and maybe tweak the tweak the variants.
- 14:13Let me actually change the layer over here, um to be on the right-hand side.
- 14:21And then I'm I can actually see that I can change the different variant like variants for this component and observe how it changes.
- 14:30Okay, really nice. Yeah, and that's really that's really mostly it.
- 14:37The first implementation of Storybook in your codebase is going to tell you a lot about what it is and it's going to give you a lot of the ideas
- 14:45on how you can adopt it in your own codebase, in your own product.
- 14:49So make sure to spend some time with it.
- 14:51And once the Storybook is set up properly, there is one more really important advantage of keeping Storybook around because it gives you an opportunity to document these patterns on
- 15:04how you would like your AI your UI components to be used and it's documenting them for your AI coding agents, which now have access to these documentations that are
- 15:14a little bit more likely to follow these recommendations.
- 15:18If you want to go a step further, there are some skills that Storybook is offering and I believe they also offer some MCP servers, if I'm not mistaken.
- 15:30So there is definitely an opportunity for you to tighten this integration a lot more and make the most out of Storybook and your AI agents workflow if you want
- 15:42to go down that route.
- 15:44One more thing that makes sense to take a look at before we go anywhere is just to understand like where do the like where this documentation now lives within
- 15:54our codebase, within our files.
- 15:57So going back to Claude, if I go into files, I can already see, you know, green color coding, which is showing us where new files have been added and
- 16:05you can now get the gist of like how it works.
- 16:08So basically, for each component, there is now in the same folder a new Stories file with documentation for um um for how this um like for for like for
- 16:21everything that there is to document for this particular component.
- 16:25And everything that's in this file um is um defining you know both the docs page as well as these different variants and the props that you can uh click
- 16:36through and you know test.
- 16:38Um it's not really a necessity to uh keep these stories file right next to your components files.
- 16:45You can organize it differently, but that is this right out of the box convention um um that you might uh be seeing most often when uh onboarding yourself to
- 16:57code bases that already have Storybook and are installed.
- 17:01So with that um spend your time with Storybook, set it up to suit your likings and your needs.
- 17:07Uh make sure to comment frequently, raise a PR, consult with engineers, merge it and then keep an eye on what's happening with Storybook in your code base because that
- 17:16is also an important part of integrating it into um everybody else's workflow.
- 17:22And with that I'm going to see you in the next video.
- 17:25Thank you.