Storybook: Request: Don't Show Wrapper Components In Story Source

Created on 19 Sep 2018  路  11Comments  路  Source: storybookjs/storybook

Currently any layout component used to wrap the Component will be included in the story Source, for example:

storiesOf(`Component`, module)
  .add(``, () => (
    <Wrapper>
      <Component />
    </Wrapper>
  ))

Will result in the following in the Story Source:

<Wrapper>
  <Component />
</Wrapper>

However this wrapper is only there for laying out the Component. It shouldn't appear in the story source as it has nothing to do with the story and is confusing for anybody reading the docs.

The Story Source should look like this:

<Component />

Most helpful comment

@samuelfullerthomas Create a decorator that wraps your component with whatever element(s) you need, then use addDecorator to apply it.

I'm using Styled Components.

DefaultLayoutDecorator

import React from 'react'
import styled from 'styled-components'
import VLayout from '../../components/layouts/VLayout'

const Layout = styled(VLayout).attrs({ spacing: 1 })``

const DefaultLayoutDecorator = storyFn => <Layout>{storyFn()}</Layout>

export default DefaultLayoutDecorator
storiesOf(`Example`, module)
  .addDecorator(DefaultLayoutDecorator)
  .add(`Default`, () => (
    <React.Fragment>
      <Example value={0} />
    </React.Fragment>
  ))

All 11 comments

Looks like you can get round this by using a decorator.

would you mind tell me how you solved this @Undistraction ? I want to do the same thing 馃槂

@samuelfullerthomas Create a decorator that wraps your component with whatever element(s) you need, then use addDecorator to apply it.

I'm using Styled Components.

DefaultLayoutDecorator

import React from 'react'
import styled from 'styled-components'
import VLayout from '../../components/layouts/VLayout'

const Layout = styled(VLayout).attrs({ spacing: 1 })``

const DefaultLayoutDecorator = storyFn => <Layout>{storyFn()}</Layout>

export default DefaultLayoutDecorator
storiesOf(`Example`, module)
  .addDecorator(DefaultLayoutDecorator)
  .add(`Default`, () => (
    <React.Fragment>
      <Example value={0} />
    </React.Fragment>
  ))

Thanks so much @Undistraction!

@Undistraction Your solution is not working for me. The decorator is added to the source as well :( Any idea why?

@lookapanda which version? It's possible this regressed

5.0.3 @shilman

Can confirm this also isn't working on 5.0.3

Yes, the issue persist, can this be reopened please?

@tomitrescak This issue is duplicate to #4801 which is open

@shilman thanks for letting me know. I found several issues on this and all of them were closed. Will follow that one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexanbj picture alexanbj  路  3Comments

tlrobinson picture tlrobinson  路  3Comments

sakulstra picture sakulstra  路  3Comments

ZigGreen picture ZigGreen  路  3Comments

arunoda picture arunoda  路  3Comments