-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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 a storybook for the ui package #2504
Merged
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e77a198
Added first story as POC
tmeasday e625eb8
Added stories for @storybook/components
tmeasday 2ed0698
Added stories for stories tree
tmeasday 51361a8
Added remaining stories for stories_panel
tmeasday e50ceaa
Added stories for remaining components
tmeasday c4bc58b
Merge branch 'release/3.3' into tmeasday/add-stories
ndelangen 04dc8e0
Merge branch 'release/3.3' into tmeasday/add-stories
ndelangen 1de6949
Use linked package for ui storybook dev dependencies
tmeasday f3d72ad
Use correct storybook version in components
tmeasday fda8975
Created `examples/official-storybook` with ui/components/addon stories
tmeasday ae60bb8
Move more complex component stories over
tmeasday 92760d3
Use all addons in official storybook
tmeasday 32acde3
This is required
tmeasday d093bfd
This wasn't still supposed to be here
tmeasday f2dbe6d
Merge branch 'release/3.3' into tmeasday/add-stories
ndelangen 3b1d353
Working on moving most storyshots tests over to official-example
tmeasday 432e2db
Merge branch 'release/3.3' into tmeasday/add-stories
ndelangen 3b8be68
Disable ui/SearchBox story in storyshots
tmeasday 913324e
Add snapshots for new stories.
tmeasday 579cde7
Move --copy-files *before* --ignore for babel
tmeasday e4be9f5
Ignore __snapshots__ when building
tmeasday 8823299
Merge branch 'release/3.3' into tmeasday/add-stories
1a0e285
Merge branch 'release/3.3' into tmeasday/add-stories
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ | ||
|
||
import '@storybook/addon-actions/register'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ | ||
import React from 'react'; | ||
import { configure } from '@storybook/react'; | ||
|
||
function loadStories() { | ||
let req; | ||
req = require.context('../lib/ui/src', true, /\.stories\.js$/); | ||
req.keys().forEach(filename => req(filename)); | ||
|
||
req = require.context('../lib/components/src', true, /\.stories\.js$/); | ||
req.keys().forEach(filename => req(filename)); | ||
} | ||
|
||
configure(loadStories, module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import MenuLink from './menu_link'; | ||
|
||
storiesOf('components/MenuLink', module) | ||
.add('default', () => <MenuLink href="http://google.com">Link</MenuLink>) | ||
.add('active', () => ( | ||
<MenuLink active href="http://google.com"> | ||
Link | ||
</MenuLink> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import RoutedLink from './routed_link'; | ||
|
||
const onClick = action('onClick'); | ||
storiesOf('components/RoutedLink', module) | ||
.add('w/ onClick', () => <RoutedLink onClick={onClick}>Link</RoutedLink>) | ||
.add('w/ href', () => <RoutedLink href="http://google.com">Link</RoutedLink>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
// A small utility to add before/afterEach to stories. | ||
class WithLifecyle extends Component { | ||
componentWillMount() { | ||
this.props.beforeEach(); | ||
} | ||
componentWillUnmount() { | ||
this.props.afterEach(); | ||
} | ||
render() { | ||
return this.props.storyFn(); | ||
} | ||
} | ||
|
||
WithLifecyle.propTypes = { | ||
storyFn: PropTypes.func.isRequired, | ||
beforeEach: PropTypes.func, | ||
afterEach: PropTypes.func, | ||
}; | ||
WithLifecyle.defaultProps = { | ||
beforeEach: () => {}, | ||
afterEach: () => {}, | ||
}; | ||
|
||
export default ({ beforeEach, afterEach }) => storyFn => ( | ||
<WithLifecyle beforeEach={beforeEach} afterEach={afterEach} storyFn={storyFn} /> | ||
); |
28 changes: 28 additions & 0 deletions
28
lib/ui/src/modules/ui/components/addon_panel/index.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import AddonPanel from './index'; | ||
|
||
const panels = { | ||
test1: { | ||
title: 'Test 1', | ||
render() { | ||
return <div id="test1">TEST 1</div>; | ||
}, | ||
}, | ||
test2: { | ||
title: 'Test 2', | ||
render() { | ||
return <div id="test2">TEST 2</div>; | ||
}, | ||
}, | ||
}; | ||
|
||
const onPanelSelect = action('onPanelSelect'); | ||
storiesOf('ui/AddonPanel', module) | ||
.addDecorator(s => <div style={{ height: '100px', display: 'flex' }}>{s()}</div>) | ||
.add('default', () => ( | ||
<AddonPanel panels={panels} onPanelSelect={onPanelSelect} selectedPanel="test2" /> | ||
)) | ||
.add('no panels', () => <AddonPanel panels={{}} onPanelSelect={onPanelSelect} />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import Layout from './index'; | ||
|
||
const panelStyle = { | ||
position: 'absolute', | ||
height: '100%', | ||
width: '100%', | ||
color: 'white', | ||
}; | ||
|
||
const mockStoriesPanel = () => <div style={{ ...panelStyle, background: '#4abdac' }}>Stories</div>; | ||
const mockAddonPanel = () => <div style={{ ...panelStyle, background: '#fc4a1a' }}>Addon</div>; | ||
const mockPreviewPanel = () => <div style={{ ...panelStyle, background: '#f7b733' }}>Preview</div>; | ||
|
||
storiesOf('ui/Layout', module) | ||
.add('default', () => ( | ||
<Layout | ||
showStoriesPanel | ||
showAddonPanel | ||
goFullScreen={false} | ||
addonPanelInRight={false} | ||
storiesPanel={mockStoriesPanel} | ||
addonPanel={mockAddonPanel} | ||
preview={mockPreviewPanel} | ||
/> | ||
)) | ||
.add('full screen', () => ( | ||
<Layout | ||
showStoriesPanel={false} | ||
showAddonPanel={false} | ||
goFullScreen | ||
addonPanelInRight={false} | ||
storiesPanel={mockStoriesPanel} | ||
addonPanel={mockAddonPanel} | ||
preview={mockPreviewPanel} | ||
/> | ||
)) | ||
.add('no stories panel', () => ( | ||
<Layout | ||
showStoriesPanel={false} | ||
showAddonPanel | ||
goFullScreen={false} | ||
addonPanelInRight={false} | ||
storiesPanel={mockStoriesPanel} | ||
addonPanel={mockAddonPanel} | ||
preview={mockPreviewPanel} | ||
/> | ||
)) | ||
.add('no addon panel', () => ( | ||
<Layout | ||
showStoriesPanel | ||
showAddonPanel={false} | ||
goFullScreen={false} | ||
addonPanelInRight={false} | ||
storiesPanel={mockStoriesPanel} | ||
addonPanel={mockAddonPanel} | ||
preview={mockPreviewPanel} | ||
/> | ||
)) | ||
.add('addon panel in right', () => ( | ||
<Layout | ||
showStoriesPanel | ||
showAddonPanel | ||
goFullScreen={false} | ||
addonPanelInRight | ||
storiesPanel={mockStoriesPanel} | ||
addonPanel={mockAddonPanel} | ||
preview={mockPreviewPanel} | ||
/> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import MenuItem from './menu_item'; | ||
|
||
storiesOf('ui/MenuItem', module).add('default', () => ( | ||
<MenuItem title="title" onClick={action('onClick')}> | ||
Content | ||
</MenuItem> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import SearchBox from './search_box'; | ||
|
||
const stories = [ | ||
{ | ||
kind: 'a', | ||
stories: ['b', 'c'], | ||
}, | ||
]; | ||
const onSelectStory = action('onSelectStory'); | ||
const onClose = action('onClose'); | ||
storiesOf('ui/SearchBox', module) | ||
.add('default', () => <SearchBox showSearchBox onSelectStory={onSelectStory} onClose={onClose} />) | ||
.add('with stories', () => ( | ||
<SearchBox showSearchBox onSelectStory={onSelectStory} onClose={onClose} stories={stories} /> | ||
)); |
10 changes: 10 additions & 0 deletions
10
lib/ui/src/modules/ui/components/stories_panel/header.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import Header from './header'; | ||
|
||
const openShortcutsHelp = action('openShortcutsHelp'); | ||
storiesOf('ui/stories/Header', module).add('simple', () => ( | ||
<Header name="name" url="http://google.com" openShortcutsHelp={openShortcutsHelp} /> | ||
)); |
54 changes: 54 additions & 0 deletions
54
lib/ui/src/modules/ui/components/stories_panel/index.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import StoriesPanel from './index'; | ||
import { createHierarchy } from '../../libs/hierarchy'; | ||
import withLifecyle from '../../../../libs/withLifecycleDecorator'; | ||
import { setContext } from '../../../../compose'; | ||
|
||
const decorator = withLifecyle({ | ||
beforeEach() { | ||
setContext({ | ||
clientStore: { | ||
getAll() { | ||
return { shortcutOptions: {} }; | ||
}, | ||
subscribe() {}, | ||
}, | ||
}); | ||
}, | ||
afterEach() { | ||
setContext(null); | ||
}, | ||
}); | ||
|
||
const storiesHierarchy = createHierarchy([{ kind: 'kk', namespaces: ['kk'], stories: ['bb'] }]); | ||
const openShortcutsHelp = action('openShortcutsHelp'); | ||
const onStoryFilter = action('onStoryFilter'); | ||
storiesOf('ui/stories/StoriesPanel', module) | ||
.addDecorator(decorator) | ||
.add('default', () => ( | ||
<StoriesPanel | ||
filter="xxxxx" | ||
openShortcutsHelp={openShortcutsHelp} | ||
onStoryFilter={onStoryFilter} | ||
/> | ||
)) | ||
.add('with storiesHierarchy prop', () => ( | ||
<StoriesPanel | ||
storiesHierarchy={storiesHierarchy} | ||
selectedKind="kk" | ||
selectedStory="bb" | ||
selectedHierarchy={['kk']} | ||
openShortcutsHelp={openShortcutsHelp} | ||
onStoryFilter={onStoryFilter} | ||
/> | ||
)) | ||
.add('storiesHierarchy exists but is empty', () => ( | ||
<StoriesPanel | ||
storiesHierarchy={createHierarchy([])} | ||
openShortcutsHelp={openShortcutsHelp} | ||
onStoryFilter={onStoryFilter} | ||
/> | ||
)); |
97 changes: 97 additions & 0 deletions
97
lib/ui/src/modules/ui/components/stories_panel/stories_tree/index.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import Stories from './index'; | ||
import { setContext } from '../../../../../compose'; | ||
import { createHierarchy, prepareStoriesForHierarchy } from '../../../libs/hierarchy'; | ||
import { storyFilter } from '../../../libs/filters'; | ||
import withLifecyle from '../../../../../libs/withLifecycleDecorator'; | ||
|
||
const data = createHierarchy([ | ||
{ kind: 'a', name: 'a', namespaces: ['a'], stories: ['a1', 'a2'] }, | ||
{ kind: 'b', name: 'b', namespaces: ['b'], stories: ['b1', 'b2'] }, | ||
]); | ||
|
||
const initialData = [ | ||
{ | ||
kind: 'some.name.item1', | ||
stories: ['a1', 'a2'], | ||
}, | ||
{ | ||
kind: 'another.space.20', | ||
stories: ['b1', 'b2'], | ||
}, | ||
]; | ||
const dataWithoutSeparator = createHierarchy(prepareStoriesForHierarchy(initialData)); | ||
const dataWithSeparator = createHierarchy(prepareStoriesForHierarchy(initialData, '\\.')); | ||
|
||
const filter = 'th'; | ||
const selectedKind = 'another.space.20'; | ||
|
||
const filteredData = storyFilter( | ||
prepareStoriesForHierarchy(initialData, '\\.'), | ||
filter, | ||
selectedKind | ||
); | ||
|
||
const filteredDataHierarchy = createHierarchy(filteredData); | ||
|
||
const decorator = withLifecyle({ | ||
beforeEach() { | ||
setContext({ | ||
clientStore: { | ||
getAll() { | ||
return { shortcutOptions: {} }; | ||
}, | ||
subscribe() {}, | ||
}, | ||
}); | ||
}, | ||
afterEach() { | ||
setContext(null); | ||
}, | ||
}); | ||
|
||
storiesOf('ui/stories/Stories', module) | ||
.addDecorator(decorator) | ||
.add('empty', () => ( | ||
<Stories | ||
storiesHierarchy={createHierarchy([])} | ||
selectedKind="" | ||
selectedStory="" | ||
selectedHierarchy={[]} | ||
/> | ||
)) | ||
.add('simple', () => ( | ||
<Stories | ||
storiesHierarchy={data} | ||
selectedKind="b" | ||
selectedStory="b2" | ||
selectedHierarchy={['b']} | ||
/> | ||
)) | ||
.add('with hierarchy - hierarchySeparator is defined', () => ( | ||
<Stories | ||
storiesHierarchy={dataWithSeparator} | ||
selectedKind="another.space.20" | ||
selectedStory="b2" | ||
selectedHierarchy={['another', 'space', '20']} | ||
/> | ||
)) | ||
.add('without hierarchy - hierarchySeparator is defined', () => ( | ||
<Stories | ||
storiesHierarchy={dataWithoutSeparator} | ||
selectedKind="another.space.20" | ||
selectedStory="b2" | ||
selectedHierarchy={['another.space.20']} | ||
/> | ||
)) | ||
.add('with highlighting when storiesFilter is provided', () => ( | ||
<Stories | ||
storiesHierarchy={filteredDataHierarchy} | ||
selectedKind={selectedKind} | ||
selectedStory="b2" | ||
selectedHierarchy={['another', 'space', '20']} | ||
storyFilter={filter} | ||
/> | ||
)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use a
/examples/<any>
here? Do we really have to add something to the root of the project?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be happy with an
examples/official
or something, where we have a storybook to demo storybook's UI components.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any problem with that. The only thing is potentially wanting to combine all react-based storybooks in a single storybook (components, ui, cra-vanilla).
[This works better for chromatic for instance. I'm not sure it helps much else -- maybe storyshots?]
Maybe
examples/offical-storybook
or something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or
examples/meta[-storybook]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples/offical-storybook
would get my vote