Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add storybook to cli #1561

Closed
wants to merge 189 commits into from

Conversation

lloydrichards
Copy link

@lloydrichards lloydrichards commented Sep 19, 2023

Goals/Scope

This is extension of PR #11 regarding adding stories for storybook through the CLI. A lot of work was already done by XavierGeerinck to get this going, but the PR seems to have been lost despite renewed interest and push to get this feature added. I've created this renewed PR with the hope of getting some attention and momentum in adding this to the CLI.

For the sake of narrowing the scope of this PR, i've removed the typography component so we can focus on just storybook.

Description

There are two main areas that have been changed in this PR, first is the addition of a storybook folder in the /registry which contain *.story.tsx files for most of the component (some are still missing). Second is I've added an additional option to the component.tsx which should allow for the stories to be loaded in through the CLI when adding a component (still need to test)

Screenshot 2024-02-13 at 20 18 41

Component Stories

The stories are added to the registry folder in the *.story.tsx files. While most of the components follow the examples in the shadcn/ui docs, some of the examples needed to be simplified or broken up into multiple stories to make them more readable. Below you will find a list of the components and their stories.

Expand Component Table
Checkbox Name Link to Storybook
accordion Storybook
alert Storybook
alert-dialog Storybook
aspect-ratio Storybook
avatar Storybook
badge Storybook
breadcrumb Storybook
button Storybook
calendar Storybook
card Storybook
carousel Storybook
checkbox Storybook
collapsible Storybook
command Storybook
context-menu Storybook
dialog Storybook
drawer Storybook
dropdown-menu Storybook
form Storybook
hover-card Storybook
input-otp Storybook
input Storybook
label Storybook
menubar Storybook
navigation-menu Storybook
pagination Storybook
popover Storybook
progress Storybook
radio-group Storybook
resizable Storybook
scroll-area Storybook
select Storybook
separator Storybook
sheet Storybook
skeleton Storybook
slider Storybook
sonner Storybook
switch Storybook
table Storybook
tabs Storybook
textarea Storybook
toast Storybook
toggle Storybook
toggle-group Storybook
tooltip Storybook
Bonus Name Link to Stories
⭐️ color - functional Storybook
⭐️ color - tailwind Storybook
⭐️ radius Storybook
⭐️ shadow Storybook
⭐️ padding Storybook
⭐️ typography - font family Storybook
⭐️ typography - font size Storybook
⭐️ typography - font weight Storybook

Comments

I'm very happy for support with getting this PR through so if anyone would like to review the stories, or add new ones, or help with upgrading the CLI, please join the conversation in the comments 🙇

if you would like to add a missing story, you can create the .story.tsx file in the /apps/www/registry/stories/ directory and add the file to the apps/www/public/registry/index.json for the correct component.


@vercel
Copy link

vercel bot commented Sep 19, 2023

@lloydrichards is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@csartor
Copy link

csartor commented Sep 22, 2023

I believe!!!

@Jared-Dahlke
Copy link

Jared-Dahlke commented Sep 27, 2023

@lloydrichards did you have any trouble with the code blocks showing corrupted code? Happens to me with <Source/> and just the auto docs
image

@lloydrichards
Copy link
Author

lloydrichards commented Sep 28, 2023

@lloydrichards did you have any trouble with the code blocks showing corrupted code? Happens to me with <Source/> and just the auto docs

I had a look and things loook correct in the code block for my dev env, but i've gone and upgraded storybook to v7.4.5 incase there was some bug in there somewhere. are you using pnpm storybook to spin it up?

@Jared-Dahlke
Copy link

@lloydrichards did you have any trouble with the code blocks showing corrupted code? Happens to me with <Source/> and just the auto docs

I had a look and things loook correct in the code block for my dev env, but i've gone and upgraded storybook to v7.4.5 incase there was some bug in there somewhere. are you using pnpm storybook to spin it up?

i implemented a lot of stories myself before i found your repo. Now i cloned yours and am running it and got this error:

image

just fyi. Seems like awesome work though. I've also built tests for about half of the components so far. i will have to write tests for all of them soon

@lloydrichards
Copy link
Author

lloydrichards commented Sep 28, 2023

i implemented a lot of stories myself before i found your repo. Now i cloned yours and am running it and got this error:

I think the issue is using npm vs pnpm. i usually use yarn and was running into issues with yarn install, but noticed the pnpm.lock so tried using pnpm install instead.

@Jared-Dahlke
Copy link

ahhh nevermind, i was on main, i needed to git checkout feat/storybook-cli

now it works

@Jared-Dahlke
Copy link

Jared-Dahlke commented Sep 28, 2023

@lloydrichards what do you think is the easiest way to add the import code block on each story at the top. like this:

import { Button } from 'mylibrary/button'`

Right now i'm having to make a .mdx for each story and put that at the top manually like this:

image

@lloydrichards
Copy link
Author

The way its done through the CLI, is that within the /registry/ui components they reference using aliases:

import { buttonVariants } from "@/registry/default/ui/button"

and then later in the CLI process there is a pretty cool transform-import function (/packages/cli/src/utils/transformers/transform-import.ts) that swaps out the @/registry/default with the config from component.ts

This should also apply to the .stories.tsx files so if you use the @/registry/default alias for importing then the CLI process will fix it to your mylibrary/

@ShaunEvening
Copy link

@lloydrichards This looks great!!! 😁 is there anything that you need from me or the Storybook team to wrap up?

@lloydrichards
Copy link
Author

is there anything that you need from me or the Storybook team to wrap up?

One piece of the puzzle that is still missing is bring able to infer the arg types better for the components. Normally in a story the Meta does a pretty good job building out the controls, but i've noticed with the Radix components that this only works if you specify a prop in the Story.args. Do you know if there is a better way to infer the argTypes, otherwise its a manual process of picking which props are most useful for each story

@lloydrichards
Copy link
Author

@shadcn Would it be possible to have a look and see if the changes im proposing here to the CLI and the inclusion o Storybook is inline with you roadmap with shadch/ui? So far I've achieved the core of what i want to do with this PR:

  • write storybook files for all ui components
  • integrate the stories into the CLI so they can be loaded when added
  • keep the PR up to date with the latest main and storybook versions

next steps for me really depend if there is any pushback from your side or any requests for changes. just let me know or if you don't have time, maybe ping another maintainer so I can try test the CLI? 🙏

@kylegach
Copy link

kylegach commented Oct 2, 2023

One piece of the puzzle that is still missing is bring able to infer the arg types better for the components. Normally in a story the Meta does a pretty good job building out the controls, but i've noticed with the Radix components that this only works if you specify a prop in the Story.args. Do you know if there is a better way to infer the argTypes, otherwise its a manual process of picking which props are most useful for each story

@lloydrichards

This is most likely because Storybook, by default, filters out all props sourced from node_modules (otherwise, you end up with every prop from, say, @types/react, which includes all valid HTML attributes).

Try adjusting the prop filter like so:

// .storybook/main.ts
import type { StorybookConfig } from "@storybook/nextjs"

const config: StorybookConfig = {
  // ...
  typescript: {
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      // 👇 Adjusted prop filter
      propFilter: (prop) =>
        prop.parent ? !/node_modules\/(?!@radix-ui)/.test(prop.parent.fileName) : true,
    },
  },
}
export default config

Copy link

@0pilatos0 0pilatos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great effort!

Would love to see this changed merged, as adding the storybooks by hand takes up some valuable time.

Copy link

@linkb15 linkb15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support for more deep object in colors

colors: {
  primary: {
    someKey: {
      DEFAULT: "***",
      ...
      500: "***"
    }
  ...
  }
...
}

.map(([name, colors]) => {
return {
name,
colors: typeof colors === "string" ? { [name]: colors } : colors,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not cover when user update the config to be more have more object in their color systems.

Maybe we can do flatten the object here instead?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/hughsk/flat/blob/master/index.js

can use util function from "flat" to flatten the object.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
colors: typeof colors === "string" ? { [name]: colors } : colors,
colors: typeof colors === "string" ? { [name]: colors } : flatten(colors),

lloydrichards and others added 3 commits October 9, 2024 08:57
drawer meta has both ´satisfies Meta<typeof Drawer>´ and ´:Meta<typeof Drawer>´
haydenbleasel added a commit to haydenbleasel/next-forge that referenced this pull request Nov 15, 2024
haydenbleasel added a commit to haydenbleasel/next-forge that referenced this pull request Nov 17, 2024
@VoidHum
Copy link

VoidHum commented Nov 18, 2024

@shadcn
Any idea when this will be implemented ?

haydenbleasel added a commit to haydenbleasel/next-forge that referenced this pull request Nov 25, 2024
haydenbleasel added a commit to haydenbleasel/next-forge that referenced this pull request Nov 25, 2024
* Scaffold next app

* Init storybook on top of Next

* Add shadcn/ui stories

* Update structure.mdx

* Update package.json

* Remove eslint

* Update package.json

* Keep working on implementation

* Flatten stories

* Start fixing story contexts

* Fix fonts

* Start working on stories

* Add stories from later PR

shadcn-ui/ui#1561

* Update toast.stories.tsx

* Update pnpm-lock.yaml

* Create storybook.mdx
@andreasss55
Copy link

this should be a high priority than any other task

@Saravanan90
Copy link

+1 eagerly awaiting for storybook support

@lloydrichards
Copy link
Author

For anyone interested in a sneak-peak into the future, I've been putting together a registry for all the stories made so far. There is a full list as well as some easy to copy commands at registry.lloydrichards.dev but for warn that things are a wip so no judgement on styling atm 🙏

If you want to add one of these stories to your own repo its easy, just add in the registry url for the story you want into the command below:

npx shadcn@latest add <Registry URL>

This will add the story and any missing components to your repo, but its important to check file and make sure the imports are correct incase you have a different ui path.

Name Registry URL
Accordion Story https://registry.lloydrichards.dev/r/accordion-story.json
Alert Story https://registry.lloydrichards.dev/r/alert-story.json
Alert Dialog Story https://registry.lloydrichards.dev/r/alert-dialog-story.json
Aspect Ratio Story https://registry.lloydrichards.dev/r/aspect-ratio-story.json
Avatar Story https://registry.lloydrichards.dev/r/avatar-story.json
Badge Story https://registry.lloydrichards.dev/r/badge-story.json
Breadcrumb Story https://registry.lloydrichards.dev/r/breadcrumb-story.json
Button Story https://registry.lloydrichards.dev/r/button-story.json
Calendar Story https://registry.lloydrichards.dev/r/calendar-story.json
Card Story https://registry.lloydrichards.dev/r/card-story.json
Carousel Story https://registry.lloydrichards.dev/r/carousel-story.json
Chart Story https://registry.lloydrichards.dev/r/chart-story.json
Checkbox Story https://registry.lloydrichards.dev/r/checkbox-story.json
Collapsible Story https://registry.lloydrichards.dev/r/collapsible-story.json
Command Story https://registry.lloydrichards.dev/r/command-story.json
Context Menu Story https://registry.lloydrichards.dev/r/context-menu-story.json
Dialog Story https://registry.lloydrichards.dev/r/dialog-story.json
Drawer Story https://registry.lloydrichards.dev/r/drawer-story.json
Dropdown Menu Story https://registry.lloydrichards.dev/r/dropdown-menu-story.json
Form Story https://registry.lloydrichards.dev/r/form-story.json
Hover Card Story https://registry.lloydrichards.dev/r/hover-card-story.json
Input Story https://registry.lloydrichards.dev/r/input-story.json
Input OTP Story https://registry.lloydrichards.dev/r/input-otp-story.json
Label Story https://registry.lloydrichards.dev/r/label-story.json
Menubar Story https://registry.lloydrichards.dev/r/menubar-story.json
Navigation Menu Story https://registry.lloydrichards.dev/r/navigation-menu-story.json
Pagination Story https://registry.lloydrichards.dev/r/pagination-story.json
Popover Story https://registry.lloydrichards.dev/r/popover-story.json
Progress Story https://registry.lloydrichards.dev/r/progress-story.json
Radio Group Story https://registry.lloydrichards.dev/r/radio-group-story.json
Resizable Story https://registry.lloydrichards.dev/r/resizable-story.json
Scroll Area Story https://registry.lloydrichards.dev/r/scroll-area-story.json
Select Story https://registry.lloydrichards.dev/r/select-story.json
Separator Story https://registry.lloydrichards.dev/r/separator-story.json
Sheet Story https://registry.lloydrichards.dev/r/sheet-story.json
Skeleton Story https://registry.lloydrichards.dev/r/skeleton-story.json
Slider Story https://registry.lloydrichards.dev/r/slider-story.json
Sonner Story https://registry.lloydrichards.dev/r/sonner-story.json
Switch Story https://registry.lloydrichards.dev/r/switch-story.json
Table Story https://registry.lloydrichards.dev/r/table-story.json
Tabs Story https://registry.lloydrichards.dev/r/tabs-story.json
Textarea Story https://registry.lloydrichards.dev/r/textarea-story.json
Toast Story https://registry.lloydrichards.dev/r/toast-story.json
Toggle Story https://registry.lloydrichards.dev/r/toggle-story.json
Toggle Group Story https://registry.lloydrichards.dev/r/toggle-group-story.json
Tooltip Story https://registry.lloydrichards.dev/r/tooltip-story.json

I've made the repo pubic so if you have any suggestions or issues, feel free to add them there 👍

keiespro pushed a commit to keiespro/nextjs_forge that referenced this pull request Jan 20, 2025
* Scaffold next app

* Init storybook on top of Next

* Add shadcn/ui stories

* Update structure.mdx

* Update package.json

* Remove eslint

* Update package.json

* Keep working on implementation

* Flatten stories

* Start fixing story contexts

* Fix fonts

* Start working on stories

* Add stories from later PR

shadcn-ui/ui#1561

* Update toast.stories.tsx

* Update pnpm-lock.yaml

* Create storybook.mdx
anatoliidev228 added a commit to anatoliidev228/next-forge that referenced this pull request Jan 30, 2025
* Scaffold next app

* Init storybook on top of Next

* Add shadcn/ui stories

* Update structure.mdx

* Update package.json

* Remove eslint

* Update package.json

* Keep working on implementation

* Flatten stories

* Start fixing story contexts

* Fix fonts

* Start working on stories

* Add stories from later PR

shadcn-ui/ui#1561

* Update toast.stories.tsx

* Update pnpm-lock.yaml

* Create storybook.mdx
@lloydrichards
Copy link
Author

lloydrichards commented Jan 30, 2025

Firstly I want to thank everyone who has subscribes and been part of the conversation to try and get this PR merged in 🫶 Its been a lot of fun the last 18 months keeping up with the merge commits and tweaking the stories.

That said, and with the release of v2.3.0, it more evident then ever that this PR is not going to be merged and instead the focus is to build a robust ecosystem of components rather then a monolithic repository. I personally feel this is the correct path forward for shadcn/ui as it elevates the pressure of constant component and block requests and shifts responsibility of maintenance towards registries.

Next steps for Stories

As mentioned in the previous comment 👆 I've used the new registry documentations to build out a place for the stories I've build and will continue to maintain and use them from here. If you haven't already, check out the website for lists of cli commands or visit the repo if you want to help contribute through issues or PRs

https://registry.lloydrichards.dev/

This might also be a good time for Storybook (@kylegach 👀 ) to fork or take over this initiative with their own registry, but no pressure or hard feelings either way. Just happy to have been part of the journey 🫡

Next step for this PR

This is where it would be great to get the final input from @shadcn (but I know is super busy with Tailwind v4 issues atm) but my thoughts are that this PR is now stale and can be closed to help reduce the entropy a bit in the open PRs. Unless i hear otherwise, I'll close the PR myself in ~1 week 🙏

Thanks again for the support and look forward to helping out in the repo in other ways in the future ❤️

@adamfratino
Copy link

@lloydrichards amazing contribution to the community, regardless of merge status. thank you for all your good work! 👏👏👏

@superhighfives
Copy link

Seconding that—I've been following this issue, I think since its inception, and it's a testament to your commitment to open source and to the community that you've stuck with it, @lloydrichards. Awesome work, much appreciated. 🙌

@kylegach
Copy link

Thank you, Lloyd. Your work creating and maintaining this PR has been incredible. I especially appreciate how receptive you were to making sure anyone using this would get the latest Storybook best practices.

I've raised this with the Storybook team, and I'll let you know what comes of that as soon as we're able.

@kylegach
Copy link

kylegach commented Feb 3, 2025

@lloydrichards — Can you please email me at [email protected], so we can discuss next steps?

(Sorry for the notification spam, everyone else. 🙃)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: roadmap This looks great. We'll add it to the roadmap, review and merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.