Jagadeesh Avvaru
Jagadeesh Avvaru

Reputation: 31

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>

Upvotes: 3

Views: 1051

Answers (1)

Capuchin
Capuchin

Reputation: 3775

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

Upvotes: 1

Related Questions