@cjsaylor
goo.gl/Y33QR9
Ugh, another sketch/photoshop slice job. Maybe, if I had been involved...
Bad UX designs makes us susceptible to disruption.
Image source: @nicolesaidy
Image source: @nicolesaidy
export default class ListComponent extends React.Component {
state = { items: [] }
async componentDidMount() {
this.setState({
items: await fetch('/items')
});
}
renderItems() {
return this.state.items.map(item => <li>{item}</li>)
}
render = () => (
<ul>{ this.renderItems() }</ul>
)
}
export default class ListComponent extends React.Component {
renderItems = () => {
return (this.props.items || [])
.map(item => <li>{item}</li>)
}
render = () => <ul>{ this.renderItems() }</ul>
}
import List from './list-component';
export default class ListContainer extends React.Component {
state = { items: [] }
async componentDidMount() {
this.setState({
items: await fetch('/items')
});
}
render = () => <List items={this.state.items}/>
}
import { storiesOf } from '@storybook/react';
import List from './list-component';
storiesOf('List', module)
.add('No items', () => <List />)
.add('One item', () => <List items={['item 1']} />)
.add('Multiple items', () => (
<List items={['item 1', 'item 2', 'item 3']} />
));
export default class ListComponent extends React.Component {
onClick = (e) => {
this.props.onItemClicked(e.target.innerText);
}
renderItems = () => {
return (this.props.items || [])
.map(item => (
<li onClick={this.onClick}>{item}</li>
));
}
render = () => <ul>{ this.renderItems() }</ul>
}
$ npm install @storybook/addon-actions
// addons.js
import '@storybook/addon-actions/register';
This is what is responsible for showing the action panel
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import List from './list-component';
storiesOf('List', module)
.add('Multiple items', () => {
return (
<List
onItemClicked={action('Item clicked!')}
items={['item 1', 'item 2', 'item 3']}
/>
);
});
$ npm install @storybook/addon-knobs
// addons.js
import '@storybook/addon-knobs/register';
This is what is responsible for showing the panel
import { storiesOf } from '@storybook/react';
import List from './list-component';
import { action } from '@storybook/addon-actions';
import {withKnobs, array} from '@storybook/addon-knobs';
storiesOf('List', module)
.addDecorator(withKnobs)
.add('Multiple items', () => (
<List
onItemClicked={action('Item clicked!')}
items={
array('Items', [
'item 1',
'item 2',
'item 3'
])
}
/>
));
link
addon to demo a product.