Skip to content

Commit

Permalink
Added global addOptions and chapter.addOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Feb 20, 2018
1 parent 66a7fe1 commit 9795fa6
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/angular/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { storiesOf, setAddon, addDecorator, configure, getStorybook } from './preview';
export { storiesOf, setAddon, addDecorator, addOptions, configure, getStorybook } from './preview';

export { moduleMetadata } from './preview/angular/decorators';
9 changes: 8 additions & 1 deletion app/angular/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ if (isBrowser) {
}

const clientApi = new ClientApi(context);
export const { storiesOf, setAddon, addDecorator, clearDecorators, getStorybook } = clientApi;
export const {
storiesOf,
setAddon,
addDecorator,
addOptions,
clearDecorators,
getStorybook,
} = clientApi;

const configApi = new ConfigApi({ ...context, clearDecorators });
export const { configure } = configApi;
Expand Down
2 changes: 1 addition & 1 deletion app/polymer/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { storiesOf, setAddon, addDecorator, configure, getStorybook } from './preview';
export { storiesOf, setAddon, addDecorator, addOptions, configure, getStorybook } from './preview';
9 changes: 8 additions & 1 deletion app/polymer/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ if (isBrowser) {
}

const clientApi = new ClientApi(context);
export const { storiesOf, setAddon, addDecorator, clearDecorators, getStorybook } = clientApi;
export const {
storiesOf,
setAddon,
addDecorator,
addOptions,
clearDecorators,
getStorybook,
} = clientApi;

const configApi = new ConfigApi({ clearDecorators, ...context });
export const { configure } = configApi;
Expand Down
1 change: 1 addition & 0 deletions app/react-native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const preview = new Preview();
export const storiesOf = preview.storiesOf.bind(preview);
export const setAddon = preview.setAddon.bind(preview);
export const addDecorator = preview.addDecorator.bind(preview);
export const addOptions = preview.addOptions.bind(preview);
export const clearDecorators = preview.clearDecorators.bind(preview);
export const configure = preview.configure.bind(preview);
export const getStorybook = preview.getStorybook.bind(preview);
Expand Down
9 changes: 8 additions & 1 deletion app/react-native/src/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ export default class Preview {
this._stories = new StoryStore();
this._clientApi = new ClientApi({ storyStore: this._stories });

['storiesOf', 'setAddon', 'addDecorator', 'clearDecorators', 'getStorybook'].forEach(method => {
[
'storiesOf',
'setAddon',
'addDecorator',
'addOptions',
'clearDecorators',
'getStorybook',
].forEach(method => {
this[method] = this._clientApi[method].bind(this._clientApi);
});
}
Expand Down
1 change: 1 addition & 0 deletions app/react/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
storiesOf,
setAddon,
addDecorator,
addOptions,
configure,
getStorybook,
forceReRender,
Expand Down
9 changes: 8 additions & 1 deletion app/react/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ if (isBrowser) {
}

const clientApi = new ClientApi(context);
export const { storiesOf, setAddon, addDecorator, clearDecorators, getStorybook } = clientApi;
export const {
storiesOf,
setAddon,
addDecorator,
addOptions,
clearDecorators,
getStorybook,
} = clientApi;

const configApi = new ConfigApi({ clearDecorators, ...context });
export const { configure } = configApi;
Expand Down
2 changes: 1 addition & 1 deletion app/vue/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { storiesOf, setAddon, addDecorator, configure, getStorybook } from './preview';
export { storiesOf, setAddon, addDecorator, addOptions, configure, getStorybook } from './preview';
9 changes: 8 additions & 1 deletion app/vue/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ if (isBrowser) {
}

const clientApi = new ClientApi(context);
export const { storiesOf, setAddon, addDecorator, clearDecorators, getStorybook } = clientApi;
export const {
storiesOf,
setAddon,
addDecorator,
addOptions,
clearDecorators,
getStorybook,
} = clientApi;

const configApi = new ConfigApi({ ...context, clearDecorators });
export const { configure } = configApi;
Expand Down
22 changes: 12 additions & 10 deletions examples/official-storybook/stories/core.stories.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { storiesOf, addOptions } from '@storybook/react';

storiesOf('core/options', module).add(
'passed to story',
({ options: { myOption } }) => (
<div>
Value of <code>myOption</code> is '<code>{myOption}</code>'
</div>
),
{ myOption: 'value' }
);
const globalOption = 'globalOption';
const chapterOption = 'chapterOption';
const storyOption = 'storyOption';

addOptions({ globalOption });

storiesOf('core/options', module)
.addOptions({ chapterOption })
.add('passed to story', ({ options }) => <div>Options are {JSON.stringify(options)}</div>, {
storyOption,
});
13 changes: 13 additions & 0 deletions lib/core/src/client/preview/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class ClientApi {
this._storyStore = storyStore;
this._addons = {};
this._globalDecorators = [];
this._globalOptions = {};
this._decorateStory = decorateStory;
}

Expand All @@ -29,6 +30,10 @@ export default class ClientApi {
this._globalDecorators.push(decorator);
};

addOptions = options => {
this._globalOptions = options;
};

clearDecorators = () => {
this._globalDecorators = [];
};
Expand All @@ -52,6 +57,7 @@ export default class ClientApi {
}

const localDecorators = [];
let localOptions = {};
const api = {
kind,
};
Expand Down Expand Up @@ -83,6 +89,8 @@ export default class ClientApi {

// Add the fully decorated getStory function.
this._storyStore.addStory(kind, storyName, this._decorateStory(getStory, decorators), {
...this._globalOptions,
...localOptions,
...options,
fileName,
});
Expand All @@ -94,6 +102,11 @@ export default class ClientApi {
return api;
};

api.addOptions = options => {
localOptions = { ...localOptions, ...options };
return api;
};

return api;
};

Expand Down

0 comments on commit 9795fa6

Please sign in to comment.