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.

Decorators on stories are placed around the inline-view of the info-addon

See original GitHub issue

I’m trying to use a combination of the Info-addon with inline: true and a decorator that limits the width of my component to X pixels.

What I currently have is

import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';

storiesOf('MyComponent', module)
  .addDecorator(story => (
    <div style={{ width: 300, margin: '1em' }}>
      {story()}
    </div>
  ))
  .add('Instance',
    withInfo({
      text: 'A descriptive test',
      inline: true,
    })(() => (
      <MyComponent />
    )));

What I expected was that the inline info (header + source + prop-tables) was rendered in full width, and only MyComponent was wrapped in the decorator limiting its width to 300px. However, the decorator is applied around the entire inline info view, also limiting the width of the header, source and prop-table.

The markup that ends up being inserted is the following:

<div data-reactroot="" style="width: 300px; margin: 1em;">
  <div>
    <div><!-- the info-addon header --></div>
    <!-- my component -->
    <div><!-- the info-addon source + prop-table --></div>
  </div>
</div>

What I was expecting was something like

<div>
  <div><!-- the info-addon header --></div>
  <div style="width: 300px; margin: 1em;">
    <!-- my component -->
  </div>
  <div><!-- the info-addon source + prop-table --></div>
</div>

Is there a way to use decorators to only decorate the component, and not the inline view too?

As far as I remember, the old addWithInfo-API didn’t have the same problem/behaviour.

Versions: storybook/addon-info = ^3.2.9, storybook/react = ^3.2.8

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dan-kezcommented, Feb 21, 2018

I am also experiencing the same issue. I wrap some of my components in divs with set width and it’s affecting the addon.

1reaction
usulprocommented, Sep 28, 2017

At this stage withInfo is exactly the same decorator as any other you adding with addDecorator. It just works with a story prop passed to him. story could be wrapped to another decorator, but withInfo has no information about that.

It is important to declare this decorator as the first decorator, otherwise it won’t work well.

I guess better to say that it should be the root decorator (actually the last one because each decorator wraps all previous)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorators on stories are placed around the inline-view of the info ...
I'm trying to use a combination of the Info-addon with inline: true and a decorator that limits the width of my component to...
Read more >
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 for Angular - Medium
A decorator in Storybook is a function that can modify a story's HTML, CSS and JavaScript to make it look or act differently...
Read more >
Documenting design systems with Storybook Docs
It's a great tool to help designers, project managers, and developers understand and visualize components in the system with clear documentation ...
Read more >
JavaScript Decorators: What They Are and When to Use Them
In its simplest form, a decorator is simply a way of wrapping one piece of code with another — literally “decorating” it. This...
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