npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nlabs/storybook-addon-knobs

v3.4.3

Published

Storybook Addon Prop Editor Component

Readme

Storybook Addon Knobs

Build Status on CircleCI CodeFactor Known Vulnerabilities BCH compliance codecov

This addon works with Storybook for: React. React Native.


Storybook Addon Knobs allow you to edit React props dynamically using the Storybook UI. You can also use Knobs as a dynamic variable inside stories in Storybook.

This addon works with Storybook for:

This is how Knobs look like:

Storybook Knobs Demo

Checkout the above Live Storybook or watch this video.

Getting Started

First of all, you need to install knobs into your project as a dev dependency.

npm install @nlabs/storybook-addon-knobs --save-dev

Then, configure it as an addon by adding it to your addons.js file (located in the Storybook config directory).

import '@nlabs/storybook-addon-knobs/register'

Now, write your stories with knobs.

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

const stories = storiesOf('Storybook Knobs', module);

// Add the `withKnobs` decorator to add knobs support to your stories.
// You can also configure `withKnobs` as a global decorator.
stories.addDecorator(withKnobs);

// Knobs for React props
stories.add('with a button', () => (
  <button disabled={boolean('Disabled', false)} >
    {text('Label', 'Hello Button')}
  </button>
));

// Knobs as dynamic variables.
stories.add('as dynamic variables', () => {
  const name = text('Name', 'Arunoda Susiripala');
  const age = number('Age', 89);

  const content = `I am ${name} and I'm ${age} years old.`;
  return (<div>{content}</div>);
});

In the case of React-Native, use these imports:

import { storiesOf } from '@nlabs/storybook-react-native';
import { withKnobs, text, boolean, number } from '@nlabs/storybook-addon-knobs/react';

You can see your Knobs in a Storybook panel as shown below.

Additional Links

Available Knobs

These are the knobs available for you to use. You can import these Knobs from the @nlabs/storybook-addon-knobs module. Here's how to import the text Knob.

import { text } from '@nlabs/storybook-addon-knobs';

Just like that, you can import any other following Knobs:

text

Allows you to get some text from the user.

import { text } from '@nlabs/storybook-addon-knobs/react';

const label = 'Your Name';
const defaultValue = 'Arunoda Susiripala';

const value = text(label, defaultValue);

boolean

Allows you to get a boolean value from the user.

import { boolean } from '@nlabs/storybook-addon-knobs/react';

const label = 'Agree?';
const defaultValue = false;

const value = boolean(label, defaultValue);

number

Allows you to get a number from the user.

import { number } from '@nlabs/storybook-addon-knobs/react';

const label = 'Age';
const defaultValue = 78;

const value = number(label, defaultValue);

number bound by range

Allows you to get a number from the user using a range slider.

import { number } from '@nlabs/storybook-addon-knobs/react';

const label = 'Temperature';
const defaultValue = 73;
const options = {
   range: true,
   min: 60,
   max: 90,
   step: 1,
};

const value = number(label, defaultValue, options);

color

Allows you to get a colour from the user.

import { color } from '@nlabs/storybook-addon-knobs/react';

const label = 'Color';
const defaultValue = '#ff00ff';

const value = color(label, defaultValue);

object

Allows you to get a JSON object or array from the user.

import { object } from '@nlabs/storybook-addon-knobs/react';

const label = 'Styles';
const defaultValue = {
  backgroundColor: 'red'
};

const value = object(label, defaultValue);

Make sure to enter valid JSON syntax while editing values inside the knob.

array

Allows you to get an array of strings from the user.

import { array } from '@nlabs/storybook-addon-knobs/react';

const label = 'Styles';
const defaultValue = ['Red']

const value = array(label, defaultValue);

While editing values inside the knob, you will need to use a separator. By default it's a comma, but this can be override by passing a separator variable.

import { array } from '@nlabs/storybook-addon-knobs/react';

const label = 'Styles';
const defaultValue = ['Red'];
const separator = ':';
const value = array(label, defaultValue, separator);

select

Allows you to get a value from a select box from the user.

import { select } from '@nlabs/storybook-addon-knobs/react';

const label = 'Colors';
const options = {
  red: 'Red',
  blue: 'Blue',
  yellow: 'Yellow',
};
const defaultValue = 'red';

const value = select(label, options, defaultValue);

You can also provide options as an array like this: ['red', 'blue', 'yellow']

date

Allow you to get date (and time) from the user.

import { date } from '@nlabs/storybook-addon-knobs/react';

const label = 'Event Date';
const defaultValue = new Date('Jan 20 2017');
const value = date(label, defaultValue);

Note: the default value must not change - e.g., do not do date('Label', new Date()) or date('Label')

The date knob returns the selected date as stringified Unix timestamp (e.g. "1510913096516"). If your component needs the date in a different form you can wrap the date function:

function myDateKnob(name, defaultValue) {
  const stringTimestamp = date(name, defaultValue)
  return new Date(stringTimestamp)
}

button

Allows you to include a button and associated handler.

import { button } from '@nlabs/storybook-addon-knobs';

const label = 'Do Something';
const handler = () => doSomething('foobar');
button(label, handler);

withKnobs vs withKnobsOptions

If you feel like this addon is not performing well enough there is an option to use withKnobsOptions instead of withKnobs. Usage:

import { storiesOf } from '@nlabs/storybook-react';

const stories = storiesOf('Storybook Knobs', module);

stories.addDecorator(withKnobsOptions({
  debounce: { wait: number, leading: boolean}, // Same as lodash debounce.
  timestamps: true // Doesn't emit events while user is typing.
}));

Typescript

If you are using typescript, make sure you have the type definitions installed for the following libs:

  • node
  • react

You can install them using npm install -save @types/node @types/react, assuming you are using Typescript >2.0.