Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react storybook addon knobs not showing

I cant seem to be getting the @storybook addon knobs working? It doesnt seem to be decorating the actual story. Pretty much followed this

My code below.. Im using getstorybook with create-react-app

Using below packages:

@storybook/addon-actions": "^3.1.2,
@storybook/addon-info": "^3.1.4,
@storybook/addon-knobs": "^3.1.2,
@storybook/react": "^3.1.3

my setup

//.storybook/addons.js
import '@storybook/addon-knobs/register'

//.config
import { configure, setAddon, addDecorator } from '@storybook/react';
import infoAddon from '@storybook/addon-info';

setAddon(infoAddon);

function loadStories() {
  require('../stories');
}

configure(loadStories, module);

//stories/index.js
import React from 'react';
import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/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>
  ))

This should be a no brainer, but no suck luck.

like image 236
KornholioBeavis Avatar asked Jun 19 '17 06:06

KornholioBeavis


People also ask

Are storybook knobs deprecated?

Knobs is utterly broken in the newest Storybook versions, so knobs is no longer deprecated. It's effectively removed. As it's been removed, users are required to stay on older versions, or migrate to controls.

What are knobs in storybook?

Storybook Addon Knobs allow you to edit props dynamically using the Storybook UI. You can also use Knobs as a dynamic variable inside stories in Storybook. Framework Support. This is what Knobs looks like: Checkout the above Live Storybook or watch this video.


2 Answers

Hope this helps someone, but for some reason my addons panel suddenly disappeared from view and I couldn't figure out how to get it back. I could see the addons markup being rendered in the "elements" pane in my dev tools - so I knew things were working. Somehow storybook stored a bad value in my localStorage['storybook-layout'] so that the addons were positioned waaaaayyy off screen. Running the following fixed it.

localStorage.removeItem('storybook-layout')
like image 185
Ryan Wheale Avatar answered Oct 02 '22 10:10

Ryan Wheale


You probably need to create the addons.js file on the storybook config folder. (By default .storybook).

Check the Docs for knobs you need to add the following:

import '@storybook/addon-knobs/register';
like image 44
FabioCosta Avatar answered Oct 02 '22 11:10

FabioCosta