Storybook: Build component-driven UIs faster

Storybook: Build component-driven UIs faster

2022-10-12 0 1,131
Resource Number 45259 Last Updated 2025-02-24
¥ 0HKD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

The Storybook recommended in this issue is an open source tool for building UI components and pages individually. It simplifies UI development, testing, and documentation.

Storybook: Build component-driven UIs faster插图

Storybook is a UI development tool. It makes development faster and easier by isolating components. This allows you to work on one component at a time. You can develop the entire UI without having to launch a complex development stack, force some data into the database, or navigate through the application.

Storybook helps you document components for reuse and automatically visually test components to prevent errors. Extend your Storybook with an ecosystem of plug-ins to help you do things like fine-tune responsive layouts or verify accessibility.

Installing Storybook

Install it in a single command using the Storybook CLI. Run it in the root directory of your existing project:

# Add Storybook:
npx sb init

Storybook will look at your project’s dependencies during the installation process and provide you with the best configuration available.

The above command will make the following changes to your local environment:

  • Install the required dependencies.
  • Sets the scripts needed to run and build the Storybook.
  • Add the default Storybook configuration.
  • Add some boilerplate stories to help you get started.

According to your framework, first, build your application, and then check that everything works by running it:

# Starts Storybook in development  mode
npm run storybook

It will start the Storybook locally and output the address. Depending on your system configuration, it will automatically open the address in a new browser TAB, and then you will see a welcome screen.

Storybook: Build component-driven UIs faster插图1

Here are some notable items:

The Storybook recommended in this issue is an open source tool for building UI components and pages individually. It simplifies UI development, testing, and documentation.

Storybook: Build component-driven UIs faster插图2

Storybook is a UI development tool. It makes development faster and easier by isolating components. This allows you to work on one component at a time. You can develop the entire UI without having to launch a complex development stack, force some data into the database, or navigate through the application.

Storybook helps you document components for reuse and automatically visually test components to prevent errors. Extend your Storybook with an ecosystem of plug-ins to help you do things like fine-tune responsive layouts or verify accessibility.

Installing Storybook

Install it in a single command using the Storybook CLI. Run it in the root directory of your existing project:

# Add Storybook:
npx sb init

Storybook will look at your project’s dependencies during the installation process and provide you with the best configuration available.

The above command will make the following changes to your local environment:

  • Install the required dependencies.
  • Sets the scripts needed to run and build the Storybook.
  • Add the default Storybook configuration.
  • Add some boilerplate stories to help you get started.

According to your framework, first, build your application, and then check that everything works by running it:

# Starts Storybook in development   mode
npm run storybook

It will start the Storybook locally and output the address. Depending on your system configuration, it will automatically open the address in a new browser TAB, and then you will see a welcome screen.

Storybook: Build component-driven UIs faster插图3

Here are some notable items:

从你的项目中选择一个简单的组件,比如一个 Button,然后编写一个.stories.js, 或一个.stories.mdx文件来配合它。它可能看起来像这样:

// YourComponent.stories.js|jsx

import { YourComponent } from './YourComponent';

// This default export determines where your story goes in the story list
export default {
  /*  The title prop is optional.
  * See https://storybook.js.org/docs/react/configure/overview#configure-story-loading
  * to learn how to generate automatic titles
  */
  title: 'YourComponent',
  component: YourComponent,
};

// We create a “template” of how args map to rendering
const Template = (args) => <YourComponent {...args} />;

export const FirstStory = {
  args: {
    // The args you need here will depend on your component
  },
};

Go to Storybook to see the rendered components, it’s okay if it looks a little unusual right now. Depending on the technology stack, you may also need to configure your Storybook environment further.

< Configure your Storybook project

The main configuration file is main.js. This file controls the behavior of the Storybook server, so you must restart the Storybook process when you make changes. It contains the following:

// .storybook/main.js

module.exports = {
addons: ['@storybook/addon-essentials'],
babel: async (options) =>  ({
// Update your babel configuration here
... options,
}),
framework: '@storybook/react',
stories: ['../src/**/*.stories.@(js|mdx)'],
webpackFinal: async (config, { configType }) =>  {
// Make whatever fine-grained changes you need
// Return the altered config
return config;
},
}; 

The

configuration main.js file is a default and therefore has a powerful interface, but the key fields in it are:

  • stories- a set representing the location of the Story file, relative to main.js.
  • addons- List of plug-ins in use.
  • webpackFinal- Get used to webpack configuration.
  • babel- Get used to babel configuration.
  • framework- Framework specific configuration to help with the loading and build process.

Configuration story loading

By default, Storybook will load Story from the project according to glob (pattern matching string),.storybook/main.js where matches all extensions in the project.stories.*. The purpose is that you put the Story file together with the components it records.

•
└── components
├── Button.js
└── Button.stories.js

If you want to use a different naming convention, you can change the glob pico match using the supported syntax.

For example, if you wanted to extract the.md and.js files my-project/src/components from a directory, you could write:

// .storybook/main.js

module.exports = {
stories: ['../my-project/src/components/*.@(js|md)'],
}; 

How to record components

Storybook gives you tools to extend this basic document with prose and layouts that highlight your components and stories. This allows you to create UI library usage guides, design system sites, and more.

Storybook: Build component-driven UIs faster插图4

If you include Storybook in your project for the first time, we provide you with a document page, a document template that lists all the stories of the components and associated metadata. It extrapolates metadata values from source code, types, and JSDoc comments. If desired, you can customize this page to create your own custom templates.

If you are already using Storybook and want to update to the latest version, we recommend that you install @
storybook/addon-essentials, include this and other great features in your project.

—END—

Open Source License: MIT License

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free Source Code Storybook: Build component-driven UIs faster https://ictcoder.com/storybook-build-component-driven-uis-faster/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services