简体   繁体   English

反应故事书插件旋钮未显示

[英]react storybook addon knobs not showing

I cant seem to be getting the @storybook addon knobs working?我似乎无法让@storybook 插件旋钮工作? It doesnt seem to be decorating the actual story.它似乎并没有装饰实际的故事。 Pretty much followed this几乎遵循这个

My code below.. Im using getstorybook with create-react-app下面是我的代码..我使用 getstorybook 和 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.这应该是没有道理的,但没有运气。

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.不知何故,故事书在我的localStorage['storybook-layout']存储了一个错误的值,因此插件被放置在屏幕外。 Running the following fixed it.运行以下修复它。

localStorage.removeItem('storybook-layout')

You probably need to create the addons.js file on the storybook config folder.您可能需要在 storybook 配置文件夹中创建 addons.js 文件。 (By default .storybook). (默认为 .storybook)。

Check the Docs for knobs you need to add the following:检查文档以获取您需要添加以下内容的旋钮

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

Try removing all the query string on the url尝试删除 url 上的所有查询字符串

eg.例如。 http://localhost:6006/?knob-is_block=false&knob-Disabled=false&knob-disabled=false&knob-Style%20lite=false&knob-show=true&knob-Size=md&knob-readOnly=false&knob-Style=default&knob-icon%20name=vertical&knob-Label=Hello%20Button&knob-Active=false&knob-is_loading=false&selectedKind=Button&selectedStory=default%20style&full=0&addons=0&stories=1&panelRight=0&addonPanel=storybooks%2Fstorybook-addon-knobs

to http://localhost:6006http://localhost:6006

This worked for me.这对我有用。

  • Hitting D on your keyboard toggles the layout // Ray Brown按键盘上的D切换布局 // Ray Brown

or

  • You should also be able to expand the sidebar by clicking and dragging on the right side.您还应该能够通过单击并拖动右侧来展开侧边栏。

在此处输入图片说明

In Storybook 6.5 I was facing the same issue after manually adding the addon:在 Storybook 6.5 中,手动添加插件后我遇到了同样的问题:

npm i @storybook/addon-knobs --dev

All I needed to do is to go to the main.js file inside the .storybook folder and add the following:我需要做的就是将 go 放到.storybook文件夹内的main.js文件中,并添加以下内容:

"addons": ["@storybook/addon-knobs"] 

Then I stopped the already running storybook in the terminal using ctrl/cmd + c and then re-run the storybook:然后我使用ctrl/cmd + c在终端中停止已经运行的故事书,然后重新运行故事书:

npm run storybook

Hope it helps.希望能帮助到你。 Thank you.谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM