Storybook: Build component-driven UIs faster

Storybook: Build component-driven UIs faster

2022-10-12 0 773
Resource Number 45259 Last Updated 2025-02-24
¥ 0USD 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/kyym/storybook-build-component-driven-uis-faster.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service