Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Story Args and Controls | Writing and Organizing Stories
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Building UI Systems in React with Storybook

bookStory Args and Controls

When you want to make your stories in Storybook interactive and customizable, you use Args and Controls. Args allow you to define the values that get passed as props to your React components in each story. This means you can write a single story and let users change the props in real time through the Storybook UI, without having to rewrite or duplicate story code for every possible prop combination.

Controls are the part of the Storybook UI that let users interact with these args. When you define args for your story, Storybook automatically generates UI controls—like text fields, color pickers, or dropdowns—based on the type of each arg. This way, you and your teammates can experiment with different prop values, see the results instantly, and better understand how your components behave in different scenarios.

Suppose you have a simple Button component that takes label and backgroundColor as props. You can write a story that uses args to make both of these props adjustable from the Storybook UI. Here's what the code for such a story might look like:

import React from "react";
import { Button } from "./Button";

export default {
  title: "Example/Button",
  component: Button,
  argTypes: {
    backgroundColor: { control: "color" },
    label: { control: "text" },
  },
};

const Template = (args) => <Button {...args} />;

export const Primary = Template.bind({});
Primary.args = {
  label: "Click me",
  backgroundColor: "#1ea7fd",
};

With this setup, when you view the Primary button story in Storybook, you'll see controls for both the label and backgroundColor props. You can type a new label or pick a different color, and the button will update instantly in the preview pane. This makes it easy to test your component's flexibility and appearance, and it helps designers and developers collaborate more effectively.

Note
Study More

For advanced usage and more examples, visit the Storybook Controls documentation.

question mark

Which statement best describes how Args and Controls work together in Storybook?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you explain how to add more controls for other props?

What happens if I don't define argTypes in my story?

How do I use args and controls with non-React components?

bookStory Args and Controls

Свайпніть щоб показати меню

When you want to make your stories in Storybook interactive and customizable, you use Args and Controls. Args allow you to define the values that get passed as props to your React components in each story. This means you can write a single story and let users change the props in real time through the Storybook UI, without having to rewrite or duplicate story code for every possible prop combination.

Controls are the part of the Storybook UI that let users interact with these args. When you define args for your story, Storybook automatically generates UI controls—like text fields, color pickers, or dropdowns—based on the type of each arg. This way, you and your teammates can experiment with different prop values, see the results instantly, and better understand how your components behave in different scenarios.

Suppose you have a simple Button component that takes label and backgroundColor as props. You can write a story that uses args to make both of these props adjustable from the Storybook UI. Here's what the code for such a story might look like:

import React from "react";
import { Button } from "./Button";

export default {
  title: "Example/Button",
  component: Button,
  argTypes: {
    backgroundColor: { control: "color" },
    label: { control: "text" },
  },
};

const Template = (args) => <Button {...args} />;

export const Primary = Template.bind({});
Primary.args = {
  label: "Click me",
  backgroundColor: "#1ea7fd",
};

With this setup, when you view the Primary button story in Storybook, you'll see controls for both the label and backgroundColor props. You can type a new label or pick a different color, and the button will update instantly in the preview pane. This makes it easy to test your component's flexibility and appearance, and it helps designers and developers collaborate more effectively.

Note
Study More

For advanced usage and more examples, visit the Storybook Controls documentation.

question mark

Which statement best describes how Args and Controls work together in Storybook?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 2
some-alt