Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@storybook/addon-knobs

Package Overview
Dependencies
Maintainers
11
Versions
819
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/addon-knobs

Storybook addon for editing props

  • 8.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
11
Created

What is @storybook/addon-knobs?

@storybook/addon-knobs is a Storybook addon that allows you to dynamically edit React component props using the Storybook UI. This makes it easier to experiment with different prop values and see the results in real-time.

What are @storybook/addon-knobs's main functionalities?

Text Knob

The Text Knob allows you to edit text props dynamically. In this example, the 'label' prop of MyComponent can be edited in the Storybook UI.

import React from 'react';
import { withKnobs, text } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';

const MyComponent = ({ label }) => <div>{label}</div>;

storiesOf('MyComponent', module)
  .addDecorator(withKnobs)
  .add('default', () => <MyComponent label={text('Label', 'Hello Storybook')} />);

Boolean Knob

The Boolean Knob allows you to toggle boolean props dynamically. In this example, the 'isVisible' prop of MyComponent can be toggled in the Storybook UI.

import React from 'react';
import { withKnobs, boolean } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';

const MyComponent = ({ isVisible }) => (isVisible ? <div>Visible</div> : <div>Hidden</div>);

storiesOf('MyComponent', module)
  .addDecorator(withKnobs)
  .add('default', () => <MyComponent isVisible={boolean('Is Visible', true)} />);

Number Knob

The Number Knob allows you to edit number props dynamically. In this example, the 'count' prop of MyComponent can be edited in the Storybook UI.

import React from 'react';
import { withKnobs, number } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';

const MyComponent = ({ count }) => <div>Count: {count}</div>;

storiesOf('MyComponent', module)
  .addDecorator(withKnobs)
  .add('default', () => <MyComponent count={number('Count', 42)} />);

Select Knob

The Select Knob allows you to choose from a set of predefined options. In this example, the 'color' prop of MyComponent can be selected from a list of colors in the Storybook UI.

import React from 'react';
import { withKnobs, select } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';

const MyComponent = ({ color }) => <div style={{ color }}>Colored Text</div>;

const options = {
  Red: 'red',
  Blue: 'blue',
  Green: 'green'
};

storiesOf('MyComponent', module)
  .addDecorator(withKnobs)
  .add('default', () => <MyComponent color={select('Color', options, 'red')} />);

Other packages similar to @storybook/addon-knobs

Keywords

FAQs

Package last updated on 19 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc