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

Add left panel hierarchy support #1329

Merged
merged 16 commits into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions addons/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ npm i -D @storybook/addon-actions

Then, add following content to `.storybook/addons.js`

```
import '@storybook/addon-actions/register';
```
import '@storybook/addon-actions/register';

Import the `action` function and use it to create actions handlers. When creating action handlers, provide a **name** to make it easier to identify.

Expand Down
4 changes: 2 additions & 2 deletions docs/pages/basics/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ npm test -- --coverage --collectCoverageFrom='["src/**/*.{js,jsx}","!src/**/stor

Next automatically defines `React` for all of your files via a babel plugin. You must define `React` for JSX to work. You can solve this either by:

1. Adding `import React from 'react'` to your component files.
1. Adding a `.babelrc` that includes [`babel-plugin-react-require`](https://www.npmjs.com/package/babel-plugin-react-require)
1. Adding `import React from 'react'` to your component files.
2. Adding a `.babelrc` that includes [`babel-plugin-react-require`](https://www.npmjs.com/package/babel-plugin-react-require)
3 changes: 2 additions & 1 deletion examples/cra-kitchen-sink/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ setOptions({
showSearchBox: false,
downPanelInRight: true,
sortStoriesByKind: false,
})
leftPanelHierarchy: true
});

setAddon(infoAddon);

Expand Down
40 changes: 40 additions & 0 deletions examples/cra-kitchen-sink/src/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,43 @@ storiesOf('WithEvents', module)
</WithEvents>
)
.add('Logger', () => <Logger emiter={emiter} />);

storiesOf('component.base.Link')
.addDecorator(withKnobs)
.add('first', () => <a>{text('firstLink', 'first link')}</a>)
.add('second', () => <a>{text('secondLink', 'second link')}</a>);

storiesOf('component.base.Span')
.add('first', () => <span>first span</span>)
.add('second', () => <span>second span</span>);

storiesOf('component.common.Div')
.add('first', () => <div>first div</div>)
.add('second', () => <div>second div</div>);

storiesOf('component.common.Table')
.add('first', () => <table><tr><td>first table</td></tr></table>)
.add('second', () => <table><tr><td>first table</td></tr></table>);

storiesOf('component.Button')
.add('first', () => <button>first button</button>)
.add('second', () => <button>first second</button>);

// Atomic

storiesOf('Atoms.Molecules.Cells.simple', module)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the order is backwards: Cells.Molecules.Atoms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible we could get our existing kitchen-sink stuff and reorganize in a hierarchical way?

.addDecorator(withKnobs)
.add('with text', () => <Button>{text('buttonText', 'Hello Button')}</Button>)
.add('with some emoji', () => <Button>😀 😎 👍 💯</Button>);

storiesOf('Atoms.Molecules.Cells.more', module)
.add('with text2', () => <Button>Hello Button</Button>)
.add('with some emoji2', () => <Button>😀 😎 👍 💯</Button>);

storiesOf('Atoms.Molecules', module)
.add('with text', () => <Button>Hello Button</Button>)
.add('with some emoji', () => <Button>😀 😎 👍 💯</Button>);

storiesOf('Atoms.Molecules.Cells', module)
.add('with text2', () => <Button>Hello Button</Button>)
.add('with some emoji2', () => <Button>😀 😎 👍 💯</Button>);
57 changes: 47 additions & 10 deletions lib/ui/example/client/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,62 @@ export default class ReactProvider extends Provider {
this.api = api;
this.api.setOptions({
name: 'REACT-STORYBOOK',
sortStoriesByKind: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"breaking"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I checked - no. But maybe it's already has another meaning.. Anyway the hierarchy is built after the filtering:
image

leftPanelHierarchy: true
});

// set stories
this.api.setStories([
this.api.setStories(this.createStories());

// listen to the story change and update the preview.
this.api.onStory((kind, story) => {
this.globalState.emit('change', kind, story);
});
}

createStories() {
return [
{
kind: 'Component 1',
kind: 'some.name.Component 1',
stories: ['State 1', 'State 2'],
},

{
kind: 'Component 2',
kind: 'some.name.Component 2',
stories: ['State a', 'State b'],
},
]);

// listen to the story change and update the preview.
this.api.onStory((kind, story) => {
this.globalState.emit('change', kind, story);
});
{
kind: 'some.name2.Component 3',
stories: ['State a', 'State b'],
},
{
kind: 'some.name2',
stories: ['State a', 'State b'],
},
{
kind: 'some.name2.Component 4',
stories: ['State a', 'State b'],
},
{
kind: 'another.name3.Component 5',
stories: ['State a', 'State b'],
},
{
kind: 'another.name3.Component 6',
stories: ['State a', 'State b'],
},
{
kind: 'Bla 1',
stories: ['State 1', 'State 2'],
},
{
kind: 'Bla 2',
stories: ['State 1', 'State 2'],
},
{
kind: 'anotherComponent in the middle',
stories: ['State a', 'State b'],
},
]
}

_handlePreviewEvents() {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
{
test: /\.js$/,
loader: require.resolve('babel-loader'),
query: { presets: ['react', 'es2015', 'stage-0'] },
query: { presets: ['babel-preset-es2015', 'babel-preset-react', 'babel-preset-stage-0'].map(require.resolve) },
include: [path.join(__dirname, 'client'), path.resolve(__dirname, '../src')],
},
],
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/src/libs/key_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const features = {
PREV_STORY: 7,
SEARCH: 8,
DOWN_PANEL_IN_RIGHT: 9,
STORIES_HIERARCHY: 10,
};

export function isModifierPressed(e) {
Expand Down Expand Up @@ -58,6 +59,9 @@ export default function handle(e) {
case keycode('J'):
e.preventDefault();
return features.DOWN_PANEL_IN_RIGHT;
case keycode('H'):
e.preventDefault();
return features.STORIES_HIERARCHY;
default:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions lib/ui/src/modules/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
name: 'STORYBOOK',
url: 'https://github.com/storybooks/storybook',
sortStoriesByKind: false,
leftPanelHierarchy: false,
},
},
load({ clientStore, provider }, _actions) {
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/src/modules/shortcuts/actions/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ export function keyEventToOptions(currentOptions, event) {
export default {
handleEvent(context, event) {
const { clientStore } = context;
const uiOptions = clientStore.get('uiOptions');

switch (event) {
case features.NEXT_STORY:
apiActions.api.jumpToStory(context, 1);
break;
case features.PREV_STORY:
apiActions.api.jumpToStory(context, -1);
break;
case features.STORIES_HIERARCHY:
apiActions.api.setOptions(context, { leftPanelHierarchy: !uiOptions.leftPanelHierarchy });
break;
default:
clientStore.update(state => {
const newOptions = keyEventToOptions(state.shortcutOptions, event);
Expand Down
9 changes: 8 additions & 1 deletion lib/ui/src/modules/ui/components/left_panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ const mainStyle = {
padding: '10px 0 10px 10px',
};

const storyProps = ['stories', 'selectedKind', 'selectedStory', 'onSelectStory'];
const storyProps = [
'stories',
'storiesHierarchy',
'selectedKind',
'leftPanelHierarchy',
'selectedStory',
'onSelectStory',
];

const LeftPanel = props =>
<div style={mainStyle}>
Expand Down
Loading