Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to render stories to individual HTML files? #9455

Closed
kalinchernev opened this issue Jan 15, 2020 · 24 comments
Closed

How to render stories to individual HTML files? #9455

kalinchernev opened this issue Jan 15, 2020 · 24 comments

Comments

@kalinchernev
Copy link

Versions

  • @storybook/addon-a11y: 5.2.8,
  • @storybook/addon-cssresources: 5.2.8,
  • @storybook/addon-knobs: 5.2.8,
  • @storybook/addon-options: 5.2.8,
  • @storybook/addon-viewport: 5.2.8,
  • @storybook/addons: 5.2.8,
  • @storybook/react: 5.2.8,
  • @storybook/theming: 5.2.8,

Hello, I'm looking for a way to provide rendered HTML files for each story defined withing a project.

The current syntax is StoriesOf, for example:

/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, text } from '@storybook/addon-knobs';
import StoryWrapper from '@ecl/story-wrapper';
import demoContent from '@ecl/ec-specs-accordion2/demo/data';

import { Accordion2 } from '../src/Accordion2';
import { Accordion2Item } from '../src/Accordion2Item';

storiesOf('Components|Accordion', module)
  .addDecorator(withKnobs)
  .addDecorator(story => (
    <StoryWrapper
      afterMount={() => {
        if (!window.ECL) return {};

        const components = window.ECL.autoInit();
        return { components };
      }}
      beforeUnmount={context => {
        if (context.components) {
          context.components.forEach(c => c.destroy());
        }
      }}
    >
      {story()}
    </StoryWrapper>
  ))
  .add('default', () => {
    const toggle1 = {
      ...demoContent.items[0].toggle,
      label: text('Toggle 1', demoContent.items[0].toggle.label),
    };

    const toggle2 = {
      ...demoContent.items[1].toggle,
      label: text('Toggle 2', demoContent.items[1].toggle.label),
    };

    const toggle3 = {
      ...demoContent.items[2].toggle,
      label: text('Toggle 3', demoContent.items[2].toggle.label),
    };

    return (
      <Accordion2 data-ecl-auto-init="Accordion2">
        <Accordion2Item
          toggle={toggle1}
          id={demoContent.items[0].id}
          level={demoContent.items[0].level}
        >
          {text('Content 1', demoContent.items[0].content)}
        </Accordion2Item>
        <Accordion2Item
          toggle={toggle2}
          id={demoContent.items[1].id}
          level={demoContent.items[1].level}
        >
          {text('Content 2', demoContent.items[1].content)}
        </Accordion2Item>
        <Accordion2Item
          toggle={toggle3}
          id={demoContent.items[2].id}
          level={demoContent.items[2].level}
        >
          {text('Content 3', demoContent.items[2].content)}
        </Accordion2Item>
      </Accordion2>
    );
  });

And the config file is with an older organization, such as this:

import { configure, addDecorator, addParameters } from '@storybook/react';

// addDecorator() ...

// addParameters() ...

const contexts = [
  require.context('../../templates', true, /stories.*\.jsx?$/),
  require.context('../../page-structure', true, /stories.*\.jsx?$/),
  require.context('../../layout', true, /stories.*\.jsx?$/),
  require.context('../../components', true, /stories.*\.jsx?$/),
  require.context('../../utilities', true, /stories.*\.jsx?$/),
  require.context('../../deprecated', true, /stories.*\.jsx?$/),
];

configure(() => {
  contexts.forEach(context => {
    context
      .keys()
      .filter(key => !key.includes('node_modules'))
      .forEach(context);
  });
}, module);

A given story and context is accessible through a makeDecorator() API but I can't figure a way to have a function with these parameters out of Storybook's context.

What I'm trying to achieve is to load all stories from node and use ReactDOMServer to render stories with their contexts.

Would it be possible with 5.2.8? Would I need to first migrate to 5.3 as suggested here? (the hint is one of the last points about "Creating a separate page per component")

Thanks in advance for any hints!

@kalinchernev kalinchernev changed the title How to render stories to individual files? How to render stories to individual HTML files? Jan 15, 2020
@kalinchernev
Copy link
Author

Possibly related #9221

Maybe an example of #775 (comment) will be helpful enough.

@kalinchernev
Copy link
Author

Another issue I found which could be related: #8009

I tried to use getStorybook from storybook and get a list of stories during the process of "sourcing" the information in the configuration file. It's a client API though and I don't quite want to have the need to load the storybook in the browser in order to click on a button to get a list of stories and possibly render them later.

@stale
Copy link

stale bot commented Feb 6, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Feb 6, 2020
@kalinchernev
Copy link
Author

It's still a valid question.

@stale stale bot removed the inactive label Feb 6, 2020
@stale
Copy link

stale bot commented Feb 27, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Feb 27, 2020
@kalinchernev
Copy link
Author

kalinchernev commented Feb 27, 2020 via email

@stale stale bot removed the inactive label Feb 27, 2020
@shilman
Copy link
Member

shilman commented Feb 28, 2020

@kalinchernev AFAIK there's no way to do this currently

@kalinchernev
Copy link
Author

Hi @shilman in a project where I need this, I have already migrated configurations to latest recommended structure, as well as stories format.

I made a small attempt last week to use the stories glob pattern from the config which was ok, and I also validated that the custom babel config for the storybook is usable outside the storybook (duh :))

In a week or two I plan to setup a webpack to follow the babel config or possibly the overrides coming from storybook and I still have hope that stories being react components, with react's server side rendering it might be some how possible.

Do you think this way of thinking is wrong or there have been similar failed attempts?

@shilman
Copy link
Member

shilman commented Feb 28, 2020

@kalinchernev I'm not aware of any efforts here yet. You've commented on #9382 which is a similar issue/concern (can I close this and we continue the conversation there?). It should be possible, with work, and @ndelangen would be the right person to collaborate with on this.

@ndelangen
Copy link
Member

@kalinchernev I've been giving the following some thought recently:

What if storybook had a command to generate a data.json which would include the stories? Would that help your case?

@kalinchernev
Copy link
Author

kalinchernev commented Mar 2, 2020 via email

@kalinchernev
Copy link
Author

kalinchernev commented Mar 2, 2020 via email

@ndelangen
Copy link
Member

@kalinchernev
Copy link
Author

kalinchernev commented Mar 2, 2020 via email

@ndelangen
Copy link
Member

@kalinchernev I'd be open to an online meeting discussing this, and perhaps helping you in the right direction.

https://calendly.com/ndelangen/storybook

@kalinchernev
Copy link
Author

kalinchernev commented Mar 2, 2020 via email

@ndelangen
Copy link
Member

@kalinchernev

Topic: Norbert de Langen's Personal Meeting Room
Date: Mar 9, 2020 03:04 PM Amsterdam

Meeting Recording:
https://zoom.us/rec/share/2MZ7Kozo-U1LZs-R10H4U7wxG57rX6a8hnNKrqINmE5x_3HCu8_bsfHWIQxvdm7P

@kalinchernev
Copy link
Author

Thank you again for the time @ndelangen !

@stale
Copy link

stale bot commented Mar 31, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Mar 31, 2020
@stale
Copy link

stale bot commented Apr 30, 2020

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Apr 30, 2020
@aghan
Copy link

aghan commented Mar 11, 2021

Hello All,

I wanted to do something similar. Is there a way we could render stories and export them into HTML files? I read the comments and it seems there is no way to do this but still wanted to check.

@michaellouviere
Copy link

I am also looking to do this. Seems there's some demand in the industry to solve for this.

@muratcorlu
Copy link
Contributor

@kalinchernev

Topic: Norbert de Langen's Personal Meeting Room Date: Mar 9, 2020 03:04 PM Amsterdam

Meeting Recording: https://zoom.us/rec/share/2MZ7Kozo-U1LZs-R10H4U7wxG57rX6a8hnNKrqINmE5x_3HCu8_bsfHWIQxvdm7P

@ndelangen @kalinchernev Can you share a summary of your discussion? Zoom link doesn't work anymore. I'm also very interested in with this. Is there any blocker?

@kalinchernev
Copy link
Author

The meeting was a bit more than 2 years ago. From the technical discussions I remember https://storybook.js.org/docs/react/sharing/storybook-composition being mentioned as a potential solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants