LoginSignup
0
1

More than 1 year has passed since last update.

Storybook で特定の Story で Controls を無効にする

Last updated at Posted at 2022-11-24

概要

Storybook のアドオンの一種である Controls を使用するストーリーとしないストーリーがある際に、使用しないストーリーでは Controls パネルを使用できないようにする。

モチベーション

粒度の小さいコンポーネントは1ストーリーで複数の props パターンをレンダリングすることがあり、その場合は Controls が不要になるため。

バージョン

  • @storybook/react 6.5.12

対応方法

各ストーリーの parameters フィールドで、 props ごとに Controls を無効化するための exclude オプションが使用できるが、ここで正規表現を用いることができるので、全ての props がマッチするようにする。

export default {
  title: 'SampleComponent',
  component: Component,
  parameters: {
    controls: {
      exclude: /.*/g
    }
  }

こんな感じになる。

スクリーンショット 2022-11-24 21.59.30.png

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1