Skip to content

Commit

Permalink
Merge pull request #7860 from storybookjs/hooks-context
Browse files Browse the repository at this point in the history
Core: Pass a separate hooks context per story
  • Loading branch information
shilman authored Aug 26, 2019
2 parents a45bc68 + ad67427 commit 7ac1cab
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 338 deletions.
4 changes: 1 addition & 3 deletions addons/docs/src/blocks/DocsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ export const DocsPage: React.FunctionComponent<DocsPageProps> = ({
const propsTableProps = propsSlot(context);

const { selectedKind, storyStore } = context;
const componentStories = (storyStore.raw() as StoryData[]).filter(
s => s.kind === selectedKind
);
const componentStories = storyStore.getStoriesForKind(selectedKind);
const primary = primarySlot(componentStories, context);
const stories = storiesSlot(componentStories, context);

Expand Down
21 changes: 21 additions & 0 deletions examples/official-storybook/stories/hooks.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { useState } from '@storybook/client-api';

export default {
title: 'Hooks',
};

export const Checkbox = () => {
const [on, setOn] = useState(false);
return (
<label>
<input type="checkbox" checked={on} onChange={e => setOn(e.target.checked)} />
On
</label>
);
};

export const Input = () => {
const [text, setText] = useState('foo');
return <input value={text} onChange={e => setText(e.target.value)} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const template = () => ({
template: '<my-button>MyButton with template</my-button>',
});

export const withData = ({ parameters, ...rest }) => ({
export const withData = ({ parameters, hooks, ...rest }) => ({
template: `<pre>${JSON.stringify({ ...rest, parameters }, null, 2)}</pre>`,
});

Expand Down
1 change: 1 addition & 0 deletions lib/addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@storybook/api": "5.2.0-beta.40",
"@storybook/channels": "5.2.0-beta.40",
"@storybook/client-logger": "5.2.0-beta.40",
"@storybook/core-events": "5.2.0-beta.40",
"core-js": "^3.0.1",
"global": "^4.3.2",
"util-deprecate": "^1.0.2"
Expand Down
Loading

0 comments on commit 7ac1cab

Please sign in to comment.