Git Product home page Git Product logo

storybook-readme's Introduction

Storybook README addon

NOTE: This README is only for version ^5.0.0. For older versions README_V4.md

All previous api should work correctly at ^5.0.0 and above. But vue users will need to change their import path, as vue commands have been moved to their own folder.


Storybook README addon

This addon is compatible with:

Live demo

Features:

  • Automatically generate props table (only for React)
  • 100% markdown support
  • Code highlighting
  • Possible to add docs to addons panel or around the story
  • Accept multiple README (useful for hoc component - add component's and original component's README)
  • Looks like Github's README
  • Supports <docs/> tags for vue components (example-vue/components/MyButton/MyButton.vue).

Also it very useful because most projects and components already have README.md files. Now it is easy to add them into your Storybook.

Stories will be added with .addWithInfo method if Storybook Info Addon is installed.

Install

npm install --save-dev storybook-readme

or

yarn add --dev storybook-readme

Webpack Configuration for React Storybook

Nothing to do :)

But if you are using Typescript with React you need to add markdown-loader in your webpack config

{
  test: /\.md$/,
  use: [
    {
      loader: 'markdown-loader',
    }
  ]
}

Webpack Configuration for Vue Storybook

Only for Single File Components with <docs> tag used for documentation.

module.exports = storybookBaseConfig => {
  storybookBaseConfig.module.rules.push({
    resourceQuery: /blockType=docs/,
    use: ['storybook-readme/vue/docs-loader', 'html-loader', 'markdown-loader'],
  });
};

Define <docs> tag inside vue module:

<docs>
Docs inside vue module 
</docs>

<template>
  <button class="button">
    <slot></slot>
  </button>
</template>

Use it to define docs at story:

import MyButton from '../components/MyButton/MyButton.vue';

storiesOf('Vue <docs>', module).addParameters({
  readme: {
    content: MyButton.__docs,
  },
});

Setup

Register addon at .storybook/addons.js

import 'storybook-readme/register';

NOTE: It is possible to set addon's panel title

import registerWithPanelTitle from 'storybook-readme/registerWithPanelTitle';

registerWithPanelTitle('Docs');

Add decorator at .storybook/config.js

import { addDecorator, configure } from '@storybook/react';
import { addReadme } from 'storybook-readme';

// for Vue storybook
import { addReadme } from 'storybook-readme/vue'; // <---- vue subpackage

// for HTML storybook
import { addReadme } from 'storybook-readme/html'; // <---- html subpackage

addDecorator(addReadme);

function loadStories() {
  require('../stories/index.js');
}

configure(loadStories, module);

NOTE: for html storybook only sidebar docs are available.

Usage

Hope it is very simple.

import React from 'react';
import { storiesOf } from '@storybook/react';

import Button from '../components/Button';
import ButtonReadme from '../components/Button/README.md';

storiesOf('Buttons', module)
  .addDecorator(withKnobs)
  .addParameters({
    readme: {
      // Show readme before story
      content: ButtonReadme,
      // Show readme at the addons panel
      sidebar: ButtonReadme,
    },
  })
  .add('Button', () => <Button />);

It is possible to override docs for story

import React from 'react';
import { storiesOf } from '@storybook/react';

import Button from '../components/Button';
import ButtonReadme from '../components/Button/README.md';

storiesOf('Buttons', module)
  .addDecorator(withKnobs)
  .addParameters({
    readme: {
      content: ButtonReadme,
      sidebar: ButtonReadme,
    },
  })
  .add('Button', () => <Button />)
  .add('Button', () => <Button />)
  .add('Button', () => <Button />, {
    readme: {
      // override docs
      content: CustomButtonReadme,
      sidebar: CustomButtonReadme,
    },
  });

Full list of options

Will be applied for series of stories.

.addParameters({
    readme: {
      /**
       * Accepts string (markdown) or array of strings
       * string | Array<string>
       */
      content: Readme,

      /**
       * Accepts string (markdown) or array of strings
       * string | Array<string>
       */
      sidebar: Readme,

      /**
       * Enable / disable code highlighting for sidebar. true by default
       */
      highlightSidebar: true,

      /**
       * Enable / disable code highlighting for content. true by default
       */
      highlightContent: true,

      /**
       * Override theme values
       *
       * All theme values https://github.com/tuchk4/storybook-readme/blob/master/packages/storybook-readme/src/styles/githubMarkdownCss.js#L436

       */
      theme: {},

      /**
       * Prism code theme
       * Full list of theme https://github.com/PrismJS/prism-themes
       * To be used with storybook-readme, naming of the code theme should be used in one of these styles. https://github.com/tuchk4/storybook-readme/tree/master/packages/storybook-readme/src/styles/prismCodeThemes
       */
      codeTheme: 'github',

      /**
       * You can include prop tables locally here. See `propTables` example
       * for more information
       */
      includePropTables: [YourImportedReactComponent],

      /**
       * Wrapper for story. Usually used to set some styles
       * NOTE: will be applied only for content docs (docs around the story)
       *
       * React: React.ReactNode
       * Vue: Vue component
       */
      StoryPreview: ({ children}) => <div>{children}</div>

      /**
       * Wrapper for header docs. Usually used to set some styles
       * NOTE: will be applied only for content docs (docs around the story)
       *
       * React: React.ReactNode
       * Vue: Vue component
       */
      HeaderPreview: ({ children}) => <div>{children}</div>

      /**
       * Wrapper for footer docs. Usually used to set some styles
       * NOTE: will be applied only for content docs (docs around the story)
       *
       * React: React.ReactNode
       * Vue: Vue component
       */
      FooterPreview: ({ children}) => <div>{children}</div>

      /**
       * Wrapper for content and sidebar docs. Usually used to set some styles
       * NOTE: will be applied only for content docs (docs around the story)
       *
       * React: React.ReactNode
       * Vue: Vue component
       */
      DocPreview: ({ children}) => <div>{children}</div>
    },
  })

Global configuration

Will be applied for all stories. NOTE: that global configuration is applied only for content docs (docs around the story).

import { addParameters } from '@storybook/react'; // or @storybook/vue for vuejs
import { configureReadme } from 'storybook-readme';

configureReadme({
  /**
   * Wrapper for story. Usually used to set some styles
   * React: React.ReactNode
   * Vue: Vue component
   */
  StoryPreview: ({ children }) => <div>{children}</div>,

  /**
   * Wrapper for content and sidebar docs. Usually used to set some styles
   * React: React.ReactNode
   * Vue: Vue component
   */
  DocPreview: ({ children }) => (
    <div style={{ background: '#000' }}> {children}</div>
  ),

  /**
   * Wrapper for header docs. Usually used to set some styles
   * React: React.ReactNode
   * Vue: Vue component
   */
  HeaderPreview: ({ children }) => (
    <div style={{ background: 'red' }}>{children}</div>
  ),

  /**
   * Wrapper for footer docs. Usually used to set some styles
   * React: React.ReactNode
   * Vue: Vue component
   */
  FooterPreview: ({ children }) => <div>{children}</div>,

  /**
   * Header docs in markdown format
   */
  header: '',

  /**
   * Footer docs in markdown format
   */
  footer: '',
});

addParameters({
  readme: {
    // You can set a code theme globally.
    codeTheme: 'github',

    // You can exclude prop tables globally here. See `propTables` example
    // for more information
    excludePropTables: [YourImportedReactComponent],
  },
});

Readme placeholders

  • <!-- STORY --> placeholder for story
  • <!-- SOURCE --> placeholder for story source
  • <!-- STORY_SOURCE --> placeholder for story source
  • <!-- PROPS --> placeholder for props table. There are some issue with props parsing. Clarification issue#137
  • <!-- STORY HIDE START -->, <!-- STORY HIDE END --> content enclosed by the tags won't be shown in stories
Button variants could be imported separately.

\`\`\`js import { OutlinedButton, ContainedButton, TextButton } from 'Button'; \`\`\`

<!-- PROPS -->

Example:

<!-- STORY -->
<!-- SOURCE -->

<!-- STORY HIDE START -->

content here won't be shown in stories

<!-- STORY HIDE END -->

Some docs after story

Emoji

Use shortcodes between colon to insert emoji into the docs. For example

Here is rocket πŸš€

Here is rocket πŸš€

List of all shortcodes could be found at Emojipedia or at Gist/rxaviers

  • πŸš€
  • πŸ˜€
  • πŸ’

Feel free to suggest new features or report bugs :)

Api from v4.

Full docs for previous api are at README_V4.md

TL;DR:

Accepts README or array of README in markdown format. Multiple README is useful when you develop higher order components and want to add multiple READMEs along with the original component docs.

withReadme

Renders README at the addons panel.

import { withReadme } from 'storybook-readme';
import withReadme from 'storybook-readme/with-readme';

// as HigherOrder Component
storiesOf('Button', module).add(
  'Default',
  withReadme(ButtonReadme, () => <Button />),
);
// as Decorator
storiesOf('Button', module)
  .addDecorator(withReadme(ButtonReadme))
  .add('Default', () => <Button />);

withDocs

Renders README around the story.

import { withDocs } from 'storybook-readme';
import withDocs from 'storybook-readme/with-docs';

// as HigherOrder Component
storiesOf('Button', module).add(
  'Default',
  withDocs(ButtonReadme, () => <Button />),
);
// as Decorator
storiesOf('Button', module)
  .addDecorator(withDocs(ButtonReadme))
  .add('Default', () => <Button />);

doc

Renders README in main frame without story.

import { doc } from 'storybook-readme';

storiesOf('Button', module).add('Default', () => doc(ButtonReadme));

storybook-readme's People

Contributors

aaron-pool avatar adamhenson avatar alexmckinnon avatar andrei-ilyukovich avatar batazor avatar christianulrich avatar clemmakesapps avatar deini avatar delianides avatar dependabot[bot] avatar jptredoux avatar juliuxu avatar kakadiadarpan avatar lonyele avatar lychyi avatar matheus1lva avatar mayank23 avatar mgtitimoli avatar micahgodbolt avatar moimikey avatar mostafanawara avatar ndelangen avatar ng-hai avatar robcresswell avatar schalkventer avatar sjoerdbeentjes avatar spenserj avatar swernerx avatar tuchk4 avatar w33ble avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storybook-readme's Issues

Avoid using setAddon API

I mean this one:

import { setAddon } from '@kadira/storybook';

We've deprecated it by removing it from the docs.
Instead, provide this functionality as a React Component or a wrapper function.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

Got error when using vue support

Error message

Cannot add property components, object is not extensible
    
      TypeError: Cannot add property components, object is not extensible
    at eval (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/client_api.js:127:39)
    at story (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/client_api.js:124:22)
    at eval (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/client_api.js:128:70)
    at renderMain (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/render.js:104:27)
    at renderPreview (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/render.js:132:12)
    at renderUI (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/index.js:88:26)
    at Object.dispatch (webpack-internal:///./node_modules/redux/es/createStore.js:178:7)
    at ConfigApi._renderMain (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/config_api.js:47:24)
    at render (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/config_api.js:66:17)
    at ConfigApi.configure (webpack-internal:///./node_modules/@storybook/vue/dist/client/preview/config_api.js:91:9)

snippet

    const story = () => {
      return {
        render () {
          return <story onAction={action(`${storyName}/${componentName}`)} />
        },
        components: {
          'story': Component
        }
      }
    }

    let storyWithAddons = story

    storyWithAddons = withDocs(Component.__docs || '<!-- STORY -->', storyWithAddons)

    storiesOf(storyName, module).add(componentName, storyWithAddons)

Something todo with components: { 'story': Component } ?

Cant read MD files?

Follow all the instructions to the last details and I get:

ERROR in ./components/Button/README.md
Module parse failed: /Users/myname/IdeaProjects/storybooktest/components/Button/README.md Unexpected token (1:5)
You may need an appropriate loader to handle this file type.

string.raw not supported on IE11

Hey,

I've noticed that storybook-readme doesn't work on IE11.

It displays a message saying that string.raw was not found.

That's because this method is used on storybook-readme but it is not supported on IE11.

Can this be fixed without us users having to add polyfills ?

100% markdown support

Hey there! You state you have 100% markdown support, yet it appears to have issues rendering JSX, which would seem like the most common use case for a storybook UI library. Even in the image on your README.md you can see the styling doesn't appear correctly.

Example Github Output:

import {
  FloatingBox,
  FloatingBoxItem,
  FloatingBoxText,
  FloatingBoxContent,
  ResetIcon,
  TrashIcon,
  Input
} from 'example';

// Example of just regular text
<FloatingBox>
  <FloatingBoxText>Hey there!</FloatingBoxText>
</FloatingBox>

// Example with some selectable items
<FloatingBox>
  <FloatingBoxItem onClick={ handleSelect } icon={<ResetIcon />}>Reset Password</FloatingBoxItem>
  <FloatingBoxItem onClick={ handleSelect } icon={<TrashIcon />}>Delete User</FloatingBoxItem>
</FloatingBox>

// Example with dynamic content

<FloatingBox>
  <FloatingBoxContent>
    <Input placeholder="Search..." search></Input>
  </FloatingBoxContent>
  <FloatingBoxItem style={{ marginTop: '10px' }} onClick={ handleReset } icon={<ResetIcon />}>Reset password</FloatingBoxItem>
  <FloatingBoxItem onClick={ handleReset } icon={<ResetIcon />}>Reset password</FloatingBoxItem>
</FloatingBox>

Has no issue rendering jsx markdown.

Yet this appears completely broken in the actual readme in storybook.

image

Get addons channel right before emitting

Hey there!

I am trying to use the extension in React Native, but I'm getting this error:

image

After digging a while, I noticed the channel is being cached outside the main function.

I set some conditional breakpoints that allowed me to try solving the issue by getting the channel right before emitting, and indeed this did the magic.

This issue is happening due the fact that the channel is set in the provider constructor and this happens after the extension is parsed, so at that time addons.getChannel() returns null.

I was wondering if you find anything wrong with this solution, and if not, I would like to submit a PR with this fix.

Thanks!

Please allow Emoji's

Hi @tuchk4,

first of all thank you for this addon, it's really helpful πŸ˜„

As you can see at the end of the line above emoji's are really important these days.

For Example I would like to add a changelog to storybook. To make it as easy as possible to separate the different kinds of changes I use something like this:

πŸš€ Features

which is currently rendered as sting:
2018-05-04_1408

What do you think, is it possible?

Best,
Simon

Why is `@kadira/storybook-addons` peer dependency?

When installing with Yarn I get this warning:

warning "[email protected]" has unmet peer dependency "@kadira/storybook-addons@^1.5.0".

It's a dependency for @kadira/storybook but I was able to get it to work just fine without using @kadira/storybook-addons explicitly. So is it really necessary to have is as a peer dependency?

Error: Can't resolve 'storybook-readme'

Webpack is unable to resolve the module.

When I go to node_modules/storybook-readme the package.json does not have a main key.

Manually adding this fixes the issue. It seems like it is in the current package.json.

Is the current build not published yet? Does the build negate that for some reason? Maybe I am just messing something up?

Error when using storyshots and storybook-readme together.

Hi,
thank you for creating this nice addon, I am using it a lot.
It somehow breaks the storyshots with the current latest stable versions.
@storybook/*@3.3.12
[email protected]

Do you have any idea of what could be going on?

I am also using the workaround for jest described here: #41 (comment)

Having a look at doc it seems to be an object when I run jest. Also the storybook app works fine with the specified versions. Would appreciate some pointers on how to resolve the issue.
Maybe an addition to storybook-readme's readme about how to use it with jest/storyshots would be beneficial.

Thank you in advance for getting back to me!

` FAIL ./storyshots.test.js
● Test suite failed to run

TypeError: doc.split is not a function
  
  at normalized.reduce.docsBeforePreview (node_modules/storybook-readme/services/normalizeDocs.js:31:26)
  at Array.reduce (native)
  at Object.<anonymous>.exports.default (node_modules/storybook-readme/services/normalizeDocs.js:27:28)
  at node_modules/storybook-readme/index.js:101:45
  at withReadme (node_modules/storybook-readme/index.js:117:70)
  at Object.<anonymous> (stories/controls/Button.js:17:26)
  at Object.<anonymous> (stories/controls/index.js:1:103)
  at Object.<anonymous> (stories/index.js:2:1)
  at newRequire (node_modules/@storybook/addon-storyshots/dist/require_context.js:73:14)
  at loadStories (evalmachine.<anonymous>:15:3)
  at ConfigApi.configure (node_modules/@storybook/react/dist/client/preview/config_api.js:93:9)
  at evalmachine.<anonymous>:18:22
  at runWithRequireContext (node_modules/@storybook/addon-storyshots/dist/require_context.js:102:3)
  at testStorySnapshots (node_modules/@storybook/addon-storyshots/dist/index.js:120:35)
  at Object.<anonymous> (storyshots.test.js:3:31)

`

Can't seem to get this to work at all.

I've followed your instructions word for word, and am getting this error.

ERROR in ./src/lib/atoms/Button/README.md
Module parse failed: C:\Users\Andrew\code\tokein-ui\src\lib\atoms\Button\README.md Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.

Storybook IS picking up the custom webpack.config.js I added to the .storybook folder...

I've tried updating the export as well, to force use the loader. I've tried use: 'raw', use: 'raw-loader', loaders: ["raw" and "raw-loader"], loader: "raw", loader: "raw-loader", etc etc.

module.exports = {
  module: {
    loaders: [{
      test: /\.md$/,
      use: "raw-loader"
    }]
  }
};

The CLI does show "Extend" mode being used.

> start-storybook -p 9001 -c .storybook

@storybook/react v3.1.7

=> Loading custom .babelrc
=> Loading custom addons config.
=> Loading custom webpack config (extending mode).

Which wasn't there before I started, so I know it has to be working.

the README.md is:

# Test

Some component example.

Being imported like:

import React from 'react';
import { storiesOf } from '@storybook/react';
import withReadme from 'storybook-readme/with-readme';
import { action } from '@storybook/addon-actions';
import { Center } from '../../../decorators';
import Button from './Button';
import BUTTON_README from './README.md';

storiesOf('Button', module)
  .addDecorator(withReadme(BUTTON_README))
  .addDecorator(Center)
  .add('primary', () => <Button primary onClick={action('clicked')}>Save</Button>)
  .add('secondary', () => <Button secondary onClick={action('clicked')}>Save</Button>);

How should I use Readme and theming together?

I'm opening a new issue as I do not have rights to re-open the previous one.

I'm trying to add Readmes to my Storybook. But it uses theming, and the addon give error

Expecting a valid React element from the story: "test" of "Button".
Seems like you are not returning a correct React element from the story.
Could you double check that?

This is how I write the story:

import React from 'react'
import { withTheme } from 'utils'
import { storiesOf } from '@storybook/react'
import ButtonReadme from './README.md'
import { withReadme, withDocs }  from 'storybook-readme';

storiesOf('Button', module)
  .add('test', withReadme(ButtonReadme, () => {
    return withTheme(() => <div>Hello world</div>)
  }))

You can reproduce the error in this branch: https://github.com/SC5/ds-workshop-storybook-boilerplate/tree/storybook-readme
If you run npm start, and when it's ready navigate to http://localhost:6005/?selectedKind=Button&selectedStory=test&full=0&down=1&left=1&panelRight=0&downPanel=REACT_STORYBOOK%2Freadme%2Fpanel you can see the error.

The withTheme is a function which is needed for wrapping with ThemeProvider https://github.com/SC5/ds-workshop-storybook-boilerplate/blob/storybook-readme/src/utils.js
The same approach is used in some other libraries, for example in Coderbox https://github.com/coderboxapp/coderbox-atoms/blob/master/src/utils.js

Prrevious issue: #44

Support for webpack@4

What about webpack@4 support? Can we expect new version compatible with newest webpack and storybook packages?

Cannot read property 'emit' of null

Hi,
I'm having this problem after upgrade to "@storybook/react": "^3.1.8":
" TypeError: Cannot read property 'emit' of null
at emitAddReadme (with-readme.js:26)
at with-readme.js:38
at client_api.js:109
at client_api.js:110
at WrapStory.render (WrapStory.js:65)
at ReactCompositeComponent.js:796
at measureLifeCyclePerf (ReactCompositeComponent.js:75)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:795)
at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:822)
at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:362)"
Before the update the addon was working fine

Addon breaks storybook builds

Followed the simple setup instructions and when I try to start storybook I am getting the following error:

ERROR in ./~/css-loader!./~/stylus-loader!./~/github-markdown-css/github-markdown.css
Module build failed: ParseError: /Users/thesisb/project/node_modules/github-markdown-css/github-markdown.css:3:22
   1| @font-face {
   2|   font-family: octicons-link;
   3|   src: url(data:font/woff;charset=utf-8;base64,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) format('woff');
---------------------------^
   4| }
   5|
   6| .markdown-body {

expected ")", got ";"

I tried excluding storybook-readme from my webpack's css processing to no avail:

  {
    test: /\.(styl|css)?$/,
    exclude: ['storybook-readme', 'github-markdown-css'],
    loader: 'style!css!stylus',
    include: path.resolve(__dirname, '../')
  },

Any help is appreciated.

Syntax highlighting for code not working when switching stories

First I need to thank you for this awesome addon.

Issue Details

The syntax highlighting for code is correctly displayed for the first time loading the storybook, but when I switch to another story and I have a markdown in a withDocs or withReadme function the highlighting is not correctly on this story. Finally when I switch back to the old story which was displayed correctly before, the syntax highlighting is gone. When I do a complete reload cmd + r of the browser window the syntax highlighting is there again, but only for the current story. When switching again to another story the highlighting is gone again. See the gif below

Steps to Reproduce

Create a 2 markdown files with a code snippet using ```jsx``` and import it to your story.

import MarkdownWithCode from '../path/to/markdown.md';
import MarkdownWithCode2 from '../path/to/markdown2.md';

storiesOf('example', module)
  .add('test 1', withDocs(MarkdownWithCode, () => (<div>test1 component</div>)));
  .add('test 2', withDocs(MarkdownWithCode, () => (<div>test2 component</div>)));

Versions

  • storybook-readme 3.2.1 (edit wrong version)
  • @storybook/addon-options 3.3.12
  • @storybook/addons 3.3.11
  • @storybook/react 3.3.11

Screen Recording

kap

Angular Support

Storybook now supports Angular, as such it would be awesome if this library were to implement it too.

Please add Typescript support

I am trying to use the module with Typescript and I attempted to load @types/storybook-readme but it's not available.

Module not found: Error: Can't resolve 'storybook-readme'

I'm unable to use this addon at all. It doesn't seem to find it.

I've installed different addons (some namespaced @storybook/module and some not) and they all work, it's just storybook-readme the one I can't load. I'm not sure if it's a compatibility issue. I've tried with both the beta branch and the stable release to no avail.

I have quite a few dependencies in my package.json:

  "devDependencies": {
    "@storybook/addon-actions": "^3.2.12",
    "@storybook/react": "^3.2.12",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.1",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.7",
    "eslint": "^4.9.0",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.7.0",
    "postcss": "^6.0.13",
    "postcss-color-function": "^4.0.0",
    "postcss-cssnext": "^3.0.2",
    "postcss-custom-properties": "^6.2.0",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.8",
    "prop-types": "^15.6.0",
    "raw-loader": "^0.5.1",
    "rimraf": "^2.6.2",
    "storybook-host": "^4.1.4",
    "storybook-readme": "3.1.0-beta2",
    "style-loader": "^0.19.0",
    "stylelint": "^8.2.0",
    "webpack": "^3.8.1",
    "yargs": "^9.0.1"
  },
  "dependencies": {
    "react": "^16.0.0",
    "react-dom": "^16.0.0"
  }

I've added the import '@storybook/addon-actions/register' line to my .storybook/addons.js file, but the moment I try to import { withReadme, withDocs } from 'storybook-readme' on my stories files, the error is thrown.

I'm not sure what's going on. Any help would be appreciated.

Old version of Storybook support

For some reason, i used old Storybook (v2.35.3) to build components and i'd like to use new feature of storybook-readme, such as withDoc. So, could you consider to make the latest version to support old Storybook?

Use extend in webpack.config.js

Hi and thanks for this addon.

I had some trouble using the webpack.config.js from the README.
The given example overrides the defaults so you have to repeat everything.

The solution was to use the extend feature:

npm install --save-dev storybook-readme raw-loader
const path = require('path')
const genDefaultConfig = require('@kadira/storybook/dist/server/config/defaults/webpack.config.js')

module.exports = function (storybookBaseConfig, configType) {
    const config = genDefaultConfig(storybookBaseConfig, configType)
    config.module.loaders.unshift({
        test: /\.md$/,
        loader: require.resolve('raw-loader'),
        include: path.resolve(__dirname, '../src')
    })

    return config
}

When Using Backticks in ".md" Files - Unicode Characters are Broken on the Page

How to reproduce:

I reproduced this in the demo, by changing any of the bolded words in readme.md files like this **emphasized words** with this `emphasized words`. Backticks are commonly used by developers in documentation.

I've identified the issue, which relates to the handling of unicode in CSS content stored in a JavaScript template string. I have a very simple solution and will submit a PR shortly.

Navigate to particular section of READ-ME file

Hi Valerii,

I am working on a project with Storybook, I have a situation I have a single README file documenting all controls.

Is it possible to show a specific section of README file in the README addon section when a particular story is selected from the stories panel?

E.g. I select button from the stories panel and README panel will get updated with the button section from README file.

Thanks in advance.
Amit

Current version?

Hello,

I am confused about the current version of this project. It seems like the current version is 3.1.1, but the code hosted here at github is referencing 3.0.6 as the latest version. I would like to fork the project, but cannot find the latest version of the code (which is different than what is hosted here).

What I am trying to do is add an export to the DefaultPreview component. When using this library with the "Info" addon, the propTables in addon show ""DefaultPreview" Component No propTypes defined!" as well as ""ReadmeContainer" Component No propTypes defined!". As a fix, I am importing ReadmeContainer into config.js and using the option for "propTablesExclude" from the Info addon, but I cannot import "DefaultPreview", as it is not exported in the code (and I cannot find any reference to it in the currently hosted version).

Thanks!

How should I use Readme and theming together?

I'm trying to add Readmes to my Storybook. But it uses theming, and the addon give error

Expecting a valid React element from the story: "test" of "Button".
Seems like you are not returning a correct React element from the story.
Could you double check that?

This is how I write the story:

import React from 'react'
import { withTheme } from 'utils'
import { storiesOf } from '@storybook/react'
import ButtonReadme from './README.md'
import { withReadme, withDocs }  from 'storybook-readme';

storiesOf('Button', module)
  .add('test', withReadme(ButtonReadme, () => {
    return withTheme(() => <div>Hello world</div>)
  }))

Remove Prismjs sources

Instead use

import Prism from 'prismjs';
import 'prismjs/components/prism-javascript';

Support with jest and storyshots

Hello, I'm using .withDocs() to load some markdown for a story, which works fine. But when I try to run our jest tests, the test suite fails. Any ideas? Apologies if I'm missing something basic.

test console:

Test suite failed to run
README.md: Unexpected character '#' (1:0)

It's failing because the jest runner doesn't know how to interpret the README.md:

import readme from '../README.md';

Thanks

Override prism styles

Any suggestions on how i would override the prism stylesheets? it seems the second i import the withDocs HOC it will also pull in your styles which lay on top of mine. Basically i want to use a custom prism stylesheet in place of the one that gets bundled with this lib.

createClass deprecation warning

This project uses react-remarkable, which uses the deprecated React.createClass function. This means that this addon will not work with React 16.x. react-remarkable hasn't been updated in several years, so I wouldn't expect a fix on that end.

The @storybook/addons-info addon uses marksy for rendering Markdown, so perhaps that would be a viable alternative.

Styles not applied in a CSS-Modules project

My project uses CSS Modules. Following the Readme instructions, I have a webpack.config like this...

module.exports = {
  module: {
    loaders: [
      {
        test: /\.md$/,
        loader: 'raw'
      }, {
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.css$/,
        exclude: 'storybook-readme',
        loader: 'style!css?modules&localIdentName=[name]__[local]___[hash:base64:5]',
      }
    ]
  }
};

But the outputted Readme text renders un-styled. The formatting is correct, but the styles are not applied.

issue with rendering MD

Hey,

My markdown files are rendering with module.exports = "# .

I'm using "storybook-readme": "^3.2.0" and "@storybook/react": "^3.3.6"

and implementing it like

const stories = storiesOf('Avatar', module);
stories.addDecorator(withReadme(README));

Any idea?

Vue support

Just wondering if there's any near-future plans to support Vue?

Thanks!

Markdown backticks render as block elements

First off, thanks for the great work on this add-on. We are using it a ton, and it's very helpful to the whole team πŸ˜„

I've just noticed that in the current version, markdown backticks are being rendered as display: block by highlight.js which is causing some layout problems.

image

image

When I fix my version of storybook-readme to 1.2.0 the problem seems to go away, along with the hljs classes.

image

Error when loading Readme that have image

Error when loading Readme that has gif (in my case).
When I remove ![](./static/screenplay.gif), it builds successfully.

yarn run v1.2.1
$ build-storybook --static-dir static --output-dir .storybook/dist
@storybook/vue v3.3.10

=> Loading custom addons config.
=> Loading custom webpack config (full-control mode).
=> Copying static files from: static
Building storybook ...
Failed to build the storybook
./static/screenplay.gif
Module parse failed: Unexpected character '' (1:7)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
 @ ./README.md 1:257-291
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/vue/dist/server/config/polyfills.js ./node_modules/@storybook/vue/dist/server/config/globals.js ./.storybook/config.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

my .storybook/webpack.config.js

const updateWebpackConfig = require('storybook-readme/env/vue/updateWebpackConfig')

module.exports = (storybookBaseConfig, configType, defaultConfig) => {
  // Return the altered config
  return updateWebpackConfig(storybookBaseConfig)
}

my .storybook/config.js

import { configure, addDecorator } from '@storybook/vue'
import { withReadme } from 'storybook-readme'

import Readme from '../README.md'

addDecorator(withReadme(Readme))

configure(() => require('../src/stories'), module)

Side note If I try to extend default storybook config by
module.exports = (storybookBaseConfig, configType, defaultConfig) => {
  return updateWebpackConfig(defaultConfig)
}

, I got this error

yarn run v1.2.1
$ build-storybook --static-dir static --output-dir .storybook/dist
@storybook/vue v3.3.10

=> Loading custom addons config.
=> Loading custom webpack config (full-control mode).
/home/wildan/Projects/Examples/myvu-component/node_modules/storybook-readme/env/vue/updateWebpackConfig.js:6
  storybookBaseConfig.module.rules = storybookBaseConfig.module.rules.map(function (rule) {
                      ^

TypeError: Cannot read property 'module' of undefined
    at module.exports (/home/wildan/Projects/Examples/myvu-component/node_modules/storybook-readme/env/vue/updateWebpackConfig.js:6:23)
    at module.exports (/home/wildan/Projects/Examples/myvu-component/.storybook/webpack.config.js:18:10)
    at exports.default (/home/wildan/Projects/Examples/myvu-component/node_modules/@storybook/vue/dist/server/config.js:62:12)
    at Object.<anonymous> (/home/wildan/Projects/Examples/myvu-component/node_modules/@storybook/vue/dist/server/build.js:77:35)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/wildan/Projects/Examples/myvu-component/node_modules/@storybook/vue/bin/build.js:3:1)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

opinionated styling of withDocs component wrapper

not a bug -- a point of discussion

Great new functionality, but I'm finding the opinionated styling (background and text-align in particular) to be a bit of a problem for me

https://github.com/tuchk4/storybook-readme/blob/master/src/with-docs.js#L18

Setting a background color here breaks the advantage of having something like addon-backgrounds running alongside it

(https://github.com/storybooks/addon-backgrounds)

With text-align set as center, I foresee myself having to additionally set text-align: left on all my components -- setting it on a component feels like it should be a solution based choice, and not due to a development tool quirk

(i.e. default browser alignment should be respected -- if a user wants everything center aligned, they should opt in to it themselves)

in-consistent margin for markdown texts before and after previewed component

Hi @tuchk4 ,
First of all, great work for build this plugin. It's very useful.
While I'm checking the online demo, I found there's a slight change of margin for the markdown texts before and after the previewed component as shown in blew:
2017-12-04 17_29_55-storybook

From my inspection, it seems the markdown block got a in-line style for margins and the second markdown block does not.
2017-12-04 17_36_03-storybook
Is this done on purpose?

Compile to ES2015

I'm using Jest for testing, which runs in a Node environment, and it fails on this add-on because the import statements are not compiled down to ES2015 (Node doesn't yet support ES6 modules):

[...]/node_modules/storybook-readme/with-readme.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';
                                                                                         ^^^^^^

SyntaxError: Unexpected token import

Jest has a transformer called babel-jest that can transform ES6 modules, but by default everything in node_modules is ignored for performance reasons. The workaround, which is far from idea, is to remove node_modules from the list of ignored transform patterns (in package.json):

"jest": {
  "transform": {
    "^.+\\.js$": "<rootDir>/node_modules/babel-jest"
  },
  "transformIgnorePatterns": []
}

Can't read .md files

Hi,

I'm conscious that this is something I'm doing wrong in my Webpack config, but I can't seem to load .md files.

This issue is the same as a previous one someone had which was closed in which your answer was that they had webpack.config.js set up incorrectly, but you didn't then detail the correct way.

Please help, I'm a complete beginner with Webpack and this has been driving me mad today.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.