reactjs - Storybook addDecorator 不适用于 config.js?
问题描述
为了实验,我将以下装饰器放入我的 Button.stories.tsx
const stories = storiesOf('Button', module)
stories.addDecorator(story => <div style={{backgroundColor: 'red', width: '500px', height: '100px'}}>{story()}</div>)
stories.add('with text', () => <Button>Hello Button</Button>)
它按预期在红色矩形顶部显示按钮。但是当我像这样在 .storybook/config.js 中放置相同的装饰器时
import { addDecorator } from '@storybook/react'
addDecorator(story => <div style={{backgroundColor: 'red', width: '500px', height: '100px'}}>{story()}</div>)
它没有任何效果!问题可能是由@storybook/react 版本引起的吗?当我尝试使用 typescript 制作故事书时,我不得不将此包从 3.4.8 版本升级到 4.0.0-alpha.10。以下是我的 package.json 中的一些版本:
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts-ts": "2.16.0",
"@storybook/react": "4.0.0-alpha.10",
解决方案
我认为您应该使用以下makeDecorator
功能@storybook/addons
:
见:
https ://storybook.js.org/addons/writing-addons/#the-addon
还要记住在以下位置注册插件.storybook/addons.js
:
https ://storybook.js.org/addons/writing-addons/#register-the-addon
推荐阅读
- api - Twitter API 不返回所有关注者,即使使用光标和避免速率限制
- php - 为什么从前端更新元需要我得到旧值?
- db2 - 如何禁用旧应用程序使用 XA 数据源?
- java - IllegalMonitorStateException:对象未在 wait() 之前被线程锁定
- dns - docker swarm 如何使用 dns 获取所有容器 ip?
- json.net - .netcore 和 Azure 的 Newtonsoft 版本问题
- r - 在 GAM 零膨胀泊松 (ziP) 模型中使用偏移量
- r - R ggplot2标签排序(geom_text)
- html - Odoo 10 QWeb 报告
- git - git squash 在另一个分支上(除了master)