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

Addon Viewport - fix "defaultViewport" configuration #4683

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions addons/viewport/src/manager/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const Container = styled.div({
});
Container.displayName = 'Container';

const getDefaultViewport = (viewports, candidateViewport) =>
candidateViewport in viewports ? candidateViewport : Object.keys(viewports)[0];
function getDefaultViewport(viewports, candidateViewport) {
return candidateViewport in viewports ? candidateViewport : Object.keys(viewports)[0];
}

const getViewports = viewports =>
Object.keys(viewports).length > 0 ? viewports : INITIAL_VIEWPORTS;
Expand Down Expand Up @@ -62,7 +63,6 @@ export class Panel extends Component {

componentDidMount() {
const { channel, api } = this.props;
const { defaultViewport } = this.state;

this.iframe = document.getElementById(storybookIframe);

Expand All @@ -71,6 +71,7 @@ export class Panel extends Component {
channel.on(SET_STORY_DEFAULT_VIEWPORT_EVENT_ID, this.setStoryDefaultViewport);

this.unsubscribeFromOnStory = api.onStory(() => {
const { defaultViewport } = this.state;
this.setStoryDefaultViewport(defaultViewport);
});
}
Expand Down Expand Up @@ -98,7 +99,7 @@ export class Panel extends Component {
};

configure = (options = Panel.defaultOptions) => {
const viewports = getViewports(options.viewports);
const viewports = getViewports(options.viewports || {});
const defaultViewport = getDefaultViewport(viewports, options.defaultViewport);

this.setState(
Expand Down
12 changes: 7 additions & 5 deletions examples/html-kitchen-sink/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { configure } from '@storybook/html';
import { setOptions } from '@storybook/addon-options';
import { configure, addDecorator } from '@storybook/html';
import { withOptions } from '@storybook/addon-options';

setOptions({
hierarchyRootSeparator: /\|/,
});
addDecorator(
withOptions({
hierarchyRootSeparator: /\|/,
})
);

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
Expand Down
7 changes: 1 addition & 6 deletions examples/html-kitchen-sink/stories/addon-a11y.stories.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { document, setTimeout } from 'global';
import { storiesOf } from '@storybook/html';
import { setOptions } from '@storybook/addon-options';

import { checkA11y } from '@storybook/addon-a11y';

const text = 'Testing the a11y addon';

storiesOf('Addons|a11y', module)
.addDecorator(checkA11y)
.addDecorator(fn => {
setOptions({ selectedAddonPanel: '@storybook/addon-a11y/panel' });
return fn();
})
.addParameters({ options: { selectedAddonPanel: '@storybook/addon-a11y/panel' } })
.add('Default', () => `<button></button>`)
.add('Label', () => `<button>${text}</button>`)
.add('Disabled', () => `<button disabled>${text}</button>`)
Expand Down