linfini
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Storybook overview === ## I. What is storybook Storybook is an open source tool for building UI components and pages in isolation. This means that you can create something similar to a UI library, deploy it and import it to use in different projects. I think it’s a great tool for company that has their own products, where they have similar design system across their apps. It is good because storybook not only help the process of creating component easier but it also help to manage and document the component. But even if you just want to create a reusable component within your project, it’s worth the try because to my own experience, using an existing UI library isn’t ideal, the component layout adjustment is not always easy and most of the time, we install the whole library but use only a few components. ## II. Overview 1. Workshop ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zed61608vruaotxup6ja.png) Normally, if you just create a component, you’ll only need a .js and a stylesheet. Then, to see if how the component look like, you need to import it in your page to see changes. However, with Storybook, after installing and run, a page (i’ll call it workshop) will run locally on a certain port which will help you see how your component looks like and all the changes while you’re developing it. That’s what the `.stories.js` does. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbtf99du4hc39eq7kx9k.png) > A `*.stories.js` file defines all the stories for a component. Each story has a corresponding sidebar item. When you click on a story, it renders in the Canvas an isolated preview iframe. ① The `Button` and `Header` from the side menu below are the component that were created as an example from strorybook, these are called **stories**. ② Inside each component are variants , just like you see on Material UI or Bootstrap. ③ is how your component looks like. And, the `Controls` and `Actions` tabs are for you to experiment your component. The properies in `Controls` section can be adjusted as you wish. 2. Inside the main component The main component is like any other reusable component that you know. It receive the props so that layout and actions of the component would be in correspondence to them. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5fr96gljok5dwd0n9qb.png) As mentioned earlier, the Controls and Actions tab from the “workshop” can be adjusted. Check below, FYR, all the propTypes that were included in the main component will appear in the Controlstab. These propTypes are necessary for controlling the props that was tranfer from parent component because we don’t want to break anything. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4machd6lzn4uze6kner8.png) Last part is default value for those props, if nothing was passed to this Button component, these values will be used. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/457or08ptqokjd2ljkpf.png) 3. Inside the story The story is the file that Storybook uses to render your component to the “workshop” page. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66hvchtlmak5qaw1u387.png) In “export default” object: - The title is the directory that you can see on the “workshop” page. This is especially helpful if you’re creating a whole design system to keep everything in order, and everyone in the team no matter if they’re newcomers or not can easily check how many components existing, what are the variant they can use and so on. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4t6p8dfa4qfwz8sla9un.png) - The component is just the component that you want Storybook to render on “workshop” page - The argTypes are something that you don’t need to have, because it will refer to the propTypes that you have declare in the main component. This argTypes are for changing the control type of the props on “workshop” page. As you can see, button size was defined as one of the specific options in Button.jsx propTypes, so on the “workshop” page, it appears to be radio button and you don’t have to define it again in the argTypes in Button.stories.js file. ``` size: PropTypes.oneOf([‘small’, ‘medium’, ‘large’]), ``` ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmd8p74irkal57ufjngg.png) If you want to change the way it appears on “workshop” page, change control type of the argTypes, like this. Now you can see, the size display as a select dropdown. ``` argTypes: { backgroundColor: { control: 'color' }, size: { control: 'select'} }, ``` ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91rvmzj1369exz65d2q3.png) Last but not least in the story file is the variant. This is also not obligatory, but one of the main reason to use storybook is to help document all the component you created, which is easy for someone else in your team to read and understand. Variant is a copy of the main component with some predefined arguments. Once you declared, it’ll show up on the sidebar. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azon8tk4e7ndngaedce2.png) ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tlscsrnk3nj778v03doc.png) **4. Writting documents using .mdx** If you want to create a document for you component, you can use .mdx file, the file allows you to write markdown syntax together with you component in the same file. Storybook has dedicated a whole page for this, you can check it out. https://storybook.js.org/docs/react/writing-docs/mdx ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7o2n82humoohff9qfyv.png) ## III. Get started It’s not difficult to set up basic storybook to your project, just install it and you’re good to go, unless you’re want other advanced setup. `npx -p @storybook/cli sb init` This CLI will detect project and does installation on it’s own. Here’s what the step looks like: <u>Step 1:</u> Install Storybook on existing project. <u>Step 2:</u> Delete uneccessary components and stories from storybook example or keep it FYR. <u>Step 3:</u> Create you component. <u>Step 4:</u> Create story to render your component on “workshop” page. <u>Step 5:</u> Adjust your component and see the change on “workshop” page. ## IV. Conclusion I didn’t want to create a tutorial on how to create something with storybook because there’re plenty of them and the storybook’s document itself is very clear and well written. The point is to understand what storybook does and why it’s worth the try. I hope this help you get the main idea of Storybook so you can decide whether to use it or not. <small> Published date: 2022-01-27 <br/> Also published <a href="https://medium.com/goalist-blog/storybook-overview-7b8039c70852">here</a>. </small>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully