This file contains hidden or 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
const UserList = ({ isLoading, results }) => ( | |
<div> | |
<div> | |
<h1>Users</h1> | |
<a href="/users/create">New User</a> | |
</div> | |
<div> | |
{isLoading && <span>Loading...</span>} | |
{!isLoading && !results.length && ( |
This file contains hidden or 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
const user = { | |
name: 'John', | |
surname: 'Doe', | |
address: null, | |
}; | |
const userName = user && user.name // John | |
const address = user && user.address // null | |
const zipCode = user && user.address && user.address.zipcode // null |
This file contains hidden or 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
const UserList = ({ isLoading, results }) => ( | |
<div> | |
<div> | |
<h1>Users</h1> | |
<a href="/users/create">New User</a> | |
</div> | |
<div> | |
{isLoading && <span>Loading...</span>} | |
{!isLoading && ( |
This file contains hidden or 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
const UserList = ({ isLoading, results }) => { | |
if (isLoading) { | |
return <span>Loading...</span> | |
} | |
return ( | |
<ul> | |
{result.map((user) => ( | |
<li>{user.name}</li> | |
))} |
This file contains hidden or 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
const handlers = { | |
number: value => <NumberDisplay>{value}</NumberDisplay> | |
currency: value => <CurrencyDisplay customProps value={value} /> | |
time: value => <TimeDisplay time={value} customProps /> | |
date: value => <DateDisplay date={value} showTime={false} /> | |
default: value => value, | |
}; | |
const displayData = (type, value) => { | |
const handler = handlers[type] || handlers.default; |
This file contains hidden or 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
// Helper to swap between localStorage and cookie storage due to stupid Safari | |
import Cookie from 'js-cookie'; | |
const storage = {}; | |
// Safari in incognito has local storage, but size 0 | |
// This system falls back to cookies in that situation | |
try { | |
if (!window.localStorage) { | |
throw Error('no local storage'); |
This file contains hidden or 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
const channelLabel = (channelKey) => { | |
switch(channelKey) { | |
case 'tv': | |
return 'TV/OTT'; | |
case 'youtube': | |
return 'Youtube'; | |
case 'instagram': | |
return 'Instagram'; | |
default: | |
return 'Default value' |
This file contains hidden or 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
import { configure } from '@storybook/react'; | |
const reqSrc = require.context('../src', true, /.stories.jsx$/); | |
function loadStories() { | |
reqSrc.keys().forEach(filename => reqSrc(filename)); | |
} | |
configure(loadStories, module); |
This file contains hidden or 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
import React from 'react'; | |
import { storiesOf } from '@storybook/react'; | |
import { action } from '@storybook/addon-actions'; | |
import Button from '../Button/Button'; | |
storiesOf('Button', module) | |
.add('default', () => ( | |
<Button onClick={action('clicked')}>Hello Button</Button> |