Skip to content

Commit

Permalink
Merge pull request #5514 from pgoforth/defect/addon-notes_onload
Browse files Browse the repository at this point in the history
[bug] `addon-notes` and `addon-cssresources` unavailable on initial load
  • Loading branch information
ndelangen authored Feb 8, 2019
2 parents b5b0784 + e914c98 commit ee81ab7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
33 changes: 16 additions & 17 deletions addons/cssresources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,27 @@ You need add the all the css resources at compile time using the `withCssResourc

```js
// Import from @storybook/X where X is your framework
import { configure, addDecorator, storiesOf } from '@storybook/react';
import { configure, addDecorator, addParameters, storiesOf } from '@storybook/react';
import { withCssResources } from '@storybook/addon-cssresources';

// global
addDecorator(
withCssResources({
cssresources: [{
id: `bluetheme`,
code: `<style>body { background-color: lightblue; }</style>`,
picked: false,
},
],
})
);
addDecorator(withCssResources)
addParameters({
cssresources: [{
id: `bluetheme`,
code: `<style>body { background-color: lightblue; }</style>`,
picked: false,
},
],
});

You can use the `cssresources` parameter to override resources on each story individually:

// per story
storiesOf('Addons|Cssresources', module)
.addDecorator(
withCssResources({
cssresources: [{
.add('Camera Icon', () => <i className="fa fa-camera-retro"> Camera Icon</i>, {
cssresources: [
{
id: `fontawesome`,
code: `<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"></link>`,
picked: true,
Expand All @@ -57,7 +58,5 @@ storiesOf('Addons|Cssresources', module)
picked: true,
},
],
})
)
.add('Camera Icon', () => <i className="fa fa-camera-retro"> Camera Icon</i>);
});
```
6 changes: 3 additions & 3 deletions addons/cssresources/src/css-resource-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, Fragment } from 'react';
import { SyntaxHighlighter } from '@storybook/components';
import Eventtypes, { STORY_CHANGED } from '@storybook/core-events';
import Eventtypes, { STORY_RENDERED } from '@storybook/core-events';

import { EVENTS, PARAM_KEY } from './constants';
import { CssResource } from './CssResource';
Expand Down Expand Up @@ -32,12 +32,12 @@ export class CssResourcePanel extends Component<CssResourcePanelProps, CssResour

componentDidMount() {
const { api } = this.props;
api.on(STORY_CHANGED, this.onStoryChange);
api.on(STORY_RENDERED, this.onStoryChange);
}

componentWillUnmount() {
const { api } = this.props;
api.off(STORY_CHANGED, this.onStoryChange);
api.off(STORY_RENDERED, this.onStoryChange);
}

onStoryChange = (id: string) => {
Expand Down
6 changes: 3 additions & 3 deletions addons/notes/src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import * as PropTypes from 'prop-types';
import { types } from '@storybook/addons';
import { styled } from '@storybook/theming';
import { STORY_CHANGED } from '@storybook/core-events';
import { STORY_RENDERED } from '@storybook/core-events';

import { SyntaxHighlighter as SyntaxHighlighterBase, Placeholder } from '@storybook/components';
import Giphy from './giphy';
Expand Down Expand Up @@ -73,12 +73,12 @@ export default class NotesPanel extends React.Component<Props, NotesPanelState>

componentDidMount() {
const { api } = this.props;
api.on(STORY_CHANGED, this.onStoryChange);
api.on(STORY_RENDERED, this.onStoryChange);
}

componentWillUnmount() {
const { api } = this.props;
api.off(STORY_CHANGED, this.onStoryChange);
api.off(STORY_RENDERED, this.onStoryChange);
}

onStoryChange = (id: string) => {
Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/addons/writing-addons/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ class MyPanel extends React.Component {
componentDidMount() {
const { api } = this.props;

api.on(STORY_CHANGED, this.onStoryChange);
api.on(STORY_RENDERED, this.onStoryChange);
}

componentWillUnmount() {
const { api } = this.props;

api.off(STORY_CHANGED, this.onStoryChange);
api.off(STORY_RENDERED, this.onStoryChange);
}

onStoryChange = id => {
Expand Down Expand Up @@ -184,12 +184,12 @@ class MyPanel extends React.Component {
componentDidMount() {
const { api } = this.props;
api.on('foo/doSomeAction', this.onSomeAction);
api.on(STORY_CHANGED, this.onStoryChange);
api.on(STORY_RENDERED this.onStoryChange);
}
componentWillUnmount() {
const { api } = this.props;
api.off('foo/doSomeAction', this.onSomeAction);
api.off(STORY_CHANGED, this.onStoryChange);
api.off(STORY_RENDERED, this.onStoryChange);
}

render() {
Expand Down

0 comments on commit ee81ab7

Please sign in to comment.