What is @storybook/blocks?
@storybook/blocks is a package designed to enhance the Storybook experience by providing a set of reusable blocks for building and organizing stories. It allows developers to create more structured and maintainable storybooks with ease.
What are @storybook/blocks's main functionalities?
Creating Stories
This feature allows you to create and organize stories for your components. The code sample demonstrates how to define a story for a Button component using the Story and Meta blocks.
import { Story, Meta } from '@storybook/blocks';
export default {
title: 'Example/Button',
component: Button,
} as Meta;
const Template: Story<ButtonProps> = (args) => <Button {...args} />;
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
Adding Controls
This feature allows you to add controls to your stories, enabling dynamic interaction with component properties. The code sample shows how to add a color control for the backgroundColor property of a Button component.
import { Story, Meta } from '@storybook/blocks';
export default {
title: 'Example/Button',
component: Button,
argTypes: {
backgroundColor: { control: 'color' },
},
} as Meta;
const Template: Story<ButtonProps> = (args) => <Button {...args} />;
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
Documentation
This feature allows you to add documentation to your stories, making it easier for other developers to understand and use your components. The code sample demonstrates how to configure documentation for a Button component using DocsPage and DocsContainer.
import { Meta, Story, DocsPage, DocsContainer } from '@storybook/blocks';
export default {
title: 'Example/Button',
component: Button,
parameters: {
docs: {
container: DocsContainer,
page: DocsPage,
},
},
} as Meta;
const Template: Story<ButtonProps> = (args) => <Button {...args} />;
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
Other packages similar to @storybook/blocks
react-docgen
react-docgen is a CLI and library for extracting information from React components for documentation generation. It focuses on generating documentation from React components' source code, making it a good alternative for creating detailed component documentation.
docz
docz is a tool for creating beautiful and highly customizable documentation sites for your React components. It provides a similar experience to Storybook but with a stronger emphasis on creating full-fledged documentation sites.
Storybook Doc Blocks
Portable documentation components for building design systems in Storybook.
Blocks development
To bootstrap, in the monorepo root:
yarn start
To develop this package, in the monorepo root:
yarn build blocks --watch
To run storybook, in this directory:
yarn storybook
8.4.0
Storybook 8.4 comes with a ton of exciting new features designed to give you the best experience developing, testing, and debugging tests in the browser!
- ▶️ Unified UI for component testing
- 5️⃣ Svelte 5 and Svelte CSF support
- ⚛️ React Native Storybook 8 release
- 🏷️ Tags-based filtering to organize your Storybook
- 🫧 Dependency cleanup to reduce install footprint
- 💯 Hundreds more improvements
<details>
<summary>List of all updates</summary>
- Addon Test: Adjust file exports to be ESM/CJS compatible - #29471, thanks @valentinpalkovic!
- Addon Test: Error when addon interactions exists - #29434, thanks @valentinpalkovic!
- Addon Test: Escape XML when converting ANSI to HTML in test errors - #29446, thanks @ghengeveld!
- Addon Test: Fix hiding stacktrace for assertion errors in test panel - #29458, thanks @ghengeveld!
- Addon Test: Improve Error Handling - #29476, thanks @valentinpalkovic!
- Addon Test: Improve postinstall script - #29479, thanks @yannbf!
- Addon Test: Improve unsupported vitest message - #29486, thanks @valentinpalkovic!
- Addon Test: Only register testing module in Vite projects - #29472, thanks @yannbf!
- Addon Test: Throttle Vitest progress updates more heavily - #29482, thanks @ghengeveld!
- Addon-docs, blocks: Prebundle dependencies - #29301, thanks @JReinhold!
- Addon-Test: Support for
@vitest/browser
v2.1.2 - #29407, thanks @strozw! - Blocks: Prebundle
es-toolkit
- #29259, thanks @JReinhold! - Builder-vite: Replace .at() call with [] in codegen - #29048, thanks @Chudesnov!
- CLI: Don't add
@storybook/addon-links
by default - #29177, thanks @tobiasdiez! - CLI: Ensure
.gitignore
updated via CLI ends with a newline - #29124, thanks @3w36zj6! - CLI: Fix
yarn
detection - #29448, thanks @ndelangen! - CLI: Migrate from
chalk
to picocolors
- #28262, thanks @43081j! - CLI: Refactor NPMProxy error parsing logic - #29459, thanks @yannbf!
- ConfigFile: Fix
export { X }
parsing - #29344, thanks @vctqs1! - Core: Add unified UI Testing Module - #29241, thanks @yannbf!
- Core: Close story status menu when selecting an item - #29455, thanks @ghengeveld!
- Core: Fix building Storybook deleting project root files - #29371, thanks @JReinhold!
- Core: Fix race condition during empty folder init - #29490, thanks @valentinpalkovic!
- Core: Make
prettier
an optional peer dependency - #29223, thanks @JReinhold! - Core: Migrate from
express
to polka
- #29230, thanks @43081j! - Core: Migrate from
qs
to picoquery
- #28315, thanks @43081j! - Core: Open 'Component tests' addon panel when clicking a story status - #29456, thanks @ghengeveld!
- Core: Remove
handlebars
usage - #29208, thanks @ndelangen! - Core: Remove dependence on
file-system-cache
- #29256, thanks @ndelangen! - Core: Replace
fs-extra
with the native APIs - #29126, thanks @ziebam! - Core: Replace
lodash
with es-toolkit
- #28981, thanks @ndelangen! - Core: Show checkmark icon in story status dropdown and update status label for component tests - #29451, thanks @ghengeveld!
- Core: Show tooltip on filter toggles to clarify their purpose - #29447, thanks @ghengeveld!
- Core: Track test provider state in sessionStorage - #29450, thanks @ghengeveld!
- Core: Upgrade
esbuild
, broadening version range - #29254, thanks @ndelangen! - Dependencies: Upgrade VTA to v3.1.0 - #29449, thanks @ghengeveld!
- Dependencies: Upgrade VTA to v3.2.0 to resolve peerDep conflict - #29461, thanks @ghengeveld!
- Interactions: Escape xml of interactions errors - #29414, thanks @kasperpeulen!
- Maintenance: Fix broken and outdated documentation links - #29412, thanks @jonniebigodes!
- Manager: Add tags property to ComponentEntry objects - #29343, thanks @Sidnioulz!
- React: Prebundle all of
renderers/react
's dependencies - #29298, thanks @ndelangen! - Svelte: Improve argTypes inference with
svelte2tsx
- support runes - #29423, thanks @JReinhold! - Test: Remove unused
util
dependency - #29310, thanks @JReinhold! - UI: Brand image css class conflict causes image to resize on hot reloads - #29129, thanks @ShreySinha02!
- UI: Fix RefIndicator to use CheckIcon instead of string - #29209, thanks @JSMike!
- UI: Simple tag filtering - #29333, thanks @shilman!
- UI: Use production-mode
react
in manager - #29197, thanks @ndelangen! - Viewport-addon: Add InitialViewportKeys type to viewport addon - #29182, thanks @hyeongrok7874!
- Vite: Add jsdoc-type-pratt-parser to
optimizeDeps
- #29179, thanks @tobiasdiez! - Vite: Cleanup and prebundle dependencies - #29302, thanks @JReinhold!
- Webpack: Fix export 'act' (imported as 'React4') was not found in 'react' errors in webpack - #29235, thanks @kasperpeulen!
</details>