question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decorator Children Displayed In Story Source

See original GitHub issue

Describe the bug If a decorator itself uses child components, those components are displayed in the Story Source. This can be seen in the following example, where the decorator uses a child component to handle the layout. Prop Tables are also displayed for each of these components. There is no way to exclude these components using the withInfo addon as they are internal to the Component.

Screenshots src

Code snippets

Component

ProgressBar.js

import styled from 'styled-components'
import React from 'react'
import PropTypes from 'prop-types'
import { height, themeColor } from '../../styles/api/helpers'
import { ratioToPercentage } from '../../helpers/units'

const Layout = styled.div`
  ${height(1)};
  position: relative;
  width: 100%;
  background-color: ${themeColor(`inset`)};
  border-radius: 20px;
`

const Fill = styled.div`
  position: absolute;
  left: 0;
  height: 100%;
  background-color: ${themeColor(`primary`)};
  width: ${p => ratioToPercentage(p.progress)};
  border-radius: 20px;
`

const ProgressBar = ({ progress }) => (
  <Layout>
    <Fill progress={progress} />
  </Layout>
)

ProgressBar.propTypes = {
  progress: PropTypes.number,
}

ProgressBar.defaultProps = {
  progress: 0,
}

export default ProgressBar

Decorator

VerticalLayoutDecorator.js

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

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

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

export default VerticalLayoutDecorator

Story

ProgressBar.story.js

import React from 'react'
import { storiesOf } from '@storybook/react'
import VerticalLayoutDecorator from '../../storybook/decorators/VerticalLayoutDecorator'

import ProgressBar from './ProgressBar'

storiesOf(`ProgressBar`, module)
  .addDecorator(VerticalLayoutDecorator)
  .add(`Default`, () => (
    <React.Fragment>
      <ProgressBar progress={0} />
      <ProgressBar progress={0.25} />
      <ProgressBar progress={0.5} />
      <ProgressBar progress={1} />
    </React.Fragment>
  ))

Displayed In Story Source:

<VerticalLayoutDecorator__Layout>
  <Unknown>
    <ProgressBar/>
    <ProgressBar progress={0.25} />
    <ProgressBar progress={0.5} />
    <ProgressBar progress={1} />
  </Unknown>
</VerticalLayoutDecorator__Layout>

Expected behavior The Story Source Should Display:

<ProgressBar/>
<ProgressBar progress={0.25} />
<ProgressBar progress={0.5} />
<ProgressBar progress={1} />

System:

  • OS: OSX
  • Device: iMac
  • Browser: All
  • Framework: React
  • Addons:
    "@storybook/addon-a11y": "^4.0.7",
    "@storybook/addon-actions": "^4.0.7",
    "@storybook/addon-backgrounds": "^4.0.7",
    "@storybook/addon-info": "^4.0.7",
    "@storybook/addon-links": "^4.0.7",
    "@storybook/addon-notes": "^4.0.7",
    "@storybook/addon-options": "^4.0.7",
    "@storybook/addon-viewport": "^4.0.7",
    "@storybook/addons": "^4.0.7",
    
  • Version:
    "@storybook/react": "^4.0.7"
    

Additional context Possibly related to: https://github.com/storybooks/storybook/issues/4759

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:21
  • Comments:42 (8 by maintainers)

github_iconTop GitHub Comments

30reactions
hdnha11commented, Jan 8, 2019

Place withInfo decorator before other decorator works for me.

addDecorator(withInfo({
  inline: true,
  header: false,
}));

addDecorator(story => <Wrapper>{story()}</Wrapper>);
7reactions
Glavin001commented, Dec 8, 2018

I am also experiencing this problem. Please don’t close as inactive 😅!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >
Storybook. Decorators and Context in examples
A decorator is a way to wrap a story in extra “rendering” functionality. ... Storybook is an open source tool for building UI...
Read more >
Source: Dynamic snippets includes decorators #12022
I propose the following solution: (1) Allow users to configure where printing begins by providing an option to change the position of jsxDecorator...
Read more >
Sponsor a child | Sponsoring a child |
When you sponsor a child for $39 a month, you'll show God's love by helping establish sustainable access to basics like clean water,...
Read more >
Implementing a source code view in Storybook - krawaller
There is an addon to show the source of the story itself, but that's not nearly enough - I need to show the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found