简体   繁体   中英

How to wrap all the react examples in styleguidist with a custom theme provider?

Currently, Styleguidist uses ReactExample to render components. I want to wrap all the ReactExample components in a page with my custom theme provider. As you see below, all the ReactExample components fall outside of the root Styleguide Component.

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

Is there a way for me to configure or modify styleguidist to add a parent component that will wrap all the components of styleguidist?

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

You can wrap all components like this:

in styleguide.config.js :

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

components/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>
    )
  }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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