首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用自定义主题提供程序包装styleguidist中的所有react示例?

如何使用自定义主题提供程序包装styleguidist中的所有react示例?
EN

Stack Overflow用户
提问于 2020-09-23 06:23:06
回答 1查看 410关注 0票数 3

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

代码语言:javascript
复制
 <StyleGuide />
 <ReactExample />
 <ReactExample />
 <ReactExample />

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

代码语言:javascript
复制
<ThemeProvider>
  <StyleGuide />
  <ReactExample />
  <ReactExample />
  <ReactExample />
</ThemeProvider>
EN

回答 1

Stack Overflow用户

发布于 2020-09-23 14:30:36

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

styleguide.config.js

代码语言:javascript
复制
const path = require('path')
module.exports = {
  styleguideComponents: {
    Wrapper: path.join(__dirname, 'src/styleguide/Wrapper')
  }
}

components/Wrapper

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64018443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档