reactjs - 如何使用自定义主题提供程序包装 styleguidist 中的所有反应示例?

标签 reactjs react-styleguidist

目前,Styleguidist 使用 ReactExample 来渲染组件。我想用我的自定义主题提供程序将所有 ReactExample 组件包装在一个页面中。正如您在下面看到的,所有 ReactExample 组件都在根 Styleguide 组件之外。

 <StyleGuide />
 <ReactExample />
 <ReactExample />
 <ReactExample />

有没有办法让我配置或修改 styleguidist 以添加一个父组件来包装 styleguidist 的所有组件?

<ThemeProvider>
  <StyleGuide />
  <ReactExample />
  <ReactExample />
  <ReactExample />
</ThemeProvider>

最佳答案

您可以像这样包装所有组件:

styleguide.config.js 中:

const path = require('path')
module.exports = {
  styleguideComponents: {
    Wrapper: path.join(__dirname, 'src/styleguide/Wrapper')
  }
}

组件/包装器:

import React, { Component } from 'react'
import { IntlProvider } from 'react-intl'
export default class Wrapper extends Component {
  render() {
    return (
      <IntlProvider locale="en">{this.props.children}</IntlProvider>
    )
  }
}

参见:https://github.com/styleguidist/react-styleguidist/blob/master/docs/Cookbook.md#how-to-change-the-layout-of-a-style-guide

关于reactjs - 如何使用自定义主题提供程序包装 styleguidist 中的所有反应示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64018443/

相关文章:

babeljs - babel 7.x - 无法解析 'core-js/modules/es.array.concat'

reactjs - 即使 flex : 1,React Native 文本输入字段也不会全宽

javascript - React Styleguidist 开始懒散

css - 调整窗口大小时如何在 React 中缩小表格中不断增长的图表

javascript - 发出警报时,Sweet alert 2 未显示为模态

reactjs - GraphQL 查询适用于 Gatsby 页面,但不适用于类组件

javascript - 如何让这个 React 方法返回语句/变量?

reactjs - 在对话框 Material ui 上 react 滚动