-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(examples): refactor & add code examples (#12)
- Loading branch information
Showing
12 changed files
with
164 additions
and
124 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { configure } from '@kadira/storybook'; | ||
|
||
function loadStories() { | ||
require('../stories/api.js'); | ||
require('../stories/weather.js'); | ||
// require as many stories as you need. | ||
} | ||
|
||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,69 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
import { SimpleComponent } from './components/SimpleComponent'; | ||
import indie from '../src/index.js'; | ||
|
||
|
||
// helpers | ||
|
||
function mockAjaxRequest() { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve('Loaded title'); | ||
}, 1000); | ||
}); | ||
} | ||
|
||
function mockErrorAjaxRequest() { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
reject(new Error('Some server error')); | ||
}, 1000); | ||
}); | ||
} | ||
|
||
storiesOf('API', module) | ||
.add('Basic Example', () => { | ||
const propsConfig = { | ||
title: ['Loading...', mockAjaxRequest()], | ||
subtitle: ['Please wait', 'Loaded subtitle'], | ||
bgColor: ['#ccc', '#1bc98e'], | ||
}; | ||
const Widget = indie(SimpleComponent, propsConfig); | ||
return (<Widget />); | ||
}) | ||
.add('Handle Server error', () => { | ||
const propsConfig = { | ||
title: ['Loading...', mockErrorAjaxRequest(), 'Something went wrong...'], | ||
subtitle: ['Please wait', 'Loaded subtitle', 'Unknown error'], | ||
bgColor: ['#ccc', '#1bc98e', 'red'], | ||
}; | ||
const Widget = indie(SimpleComponent, propsConfig); | ||
return (<Widget />); | ||
}) | ||
.add('Handle Server error + show server error message', () => { | ||
const propsConfig = { | ||
title: ['Loading...', mockErrorAjaxRequest(), 'Something went wrong...'], | ||
subtitle: ['Please wait', 'Loaded subtitle', (err) => (err.message)], | ||
bgColor: ['#ccc', '#1bc98e', 'red'], | ||
}; | ||
const Widget = indie(SimpleComponent, propsConfig); | ||
return (<Widget />); | ||
}) | ||
.add('Handle onResolve', () => { | ||
function mockOnResolve() { | ||
return (props, component) => { | ||
let num = props.subtitle; | ||
setInterval(() => { | ||
component.setState({ subtitle: num++ }); | ||
}, 1000); | ||
}; | ||
} | ||
const propsConfig = { | ||
title: ['Loading...', mockAjaxRequest()], | ||
subtitle: ['Please wait', 1], | ||
bgColor: ['#ccc', '#1bc98e'], | ||
}; | ||
const Widget = indie(SimpleComponent, propsConfig, mockOnResolve); | ||
return (<Widget />); | ||
}); |
File renamed without changes.
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,30 @@ | ||
import React, { PropTypes } from 'react'; | ||
import Paper from 'material-ui/lib/paper'; | ||
|
||
export const Weather = (props) => { | ||
console.log(props); | ||
const style = { | ||
container: { | ||
width: 400, | ||
padding: 15, | ||
background: '#4A90E2', | ||
color: '#fff', | ||
fontWeight: 100, | ||
}, | ||
inner: { | ||
marginTop: '0.5em', | ||
}, | ||
heading: { | ||
fontSize: 40, | ||
}, | ||
}; | ||
return ( | ||
<Paper style={ style.container } zDepth={1}> | ||
<div style={ style.heading }>New York</div> | ||
<p style={ style.inner }>{ props.weatherDescription }</p> | ||
<div style={style.heading}> | ||
{ props.temp }<small>°C</small> | ||
</div> | ||
</Paper> | ||
); | ||
}; |
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,40 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
import axios from 'axios'; | ||
import { Weather } from './components/Weather'; | ||
import indie from '../src/index.js'; | ||
|
||
storiesOf('Weather', module) | ||
.add('Basic Example', () => { | ||
const APPID = 'f08136975f949dad9ee0192e087d5397'; | ||
const WEATHER_END_POINT = | ||
`http://api.openweathermap.org/data/2.5/weather?q=New%20York,us&units=metric&appid=${APPID}`; | ||
let weatherData = {}; | ||
function getNewYorkWeather() { | ||
if (weatherData.main) return weatherData; | ||
return axios.get(WEATHER_END_POINT) | ||
.then(({ data }) => { | ||
weatherData = data; | ||
return { | ||
weatherDescription: data.weather[0].main, | ||
temp: data.main.temp, | ||
}; | ||
}); | ||
} | ||
function getNewYorkWeatherDesc() { | ||
return getNewYorkWeather() | ||
.then(({ weatherDescription }) => (weatherDescription)); | ||
} | ||
function getNewYorkWeatherTemp() { | ||
return getNewYorkWeather() | ||
.then(({ temp }) => (Math.round(temp))); | ||
} | ||
|
||
const propsConfig = { | ||
City: ['New York'], | ||
weatherDescription: ['Loading...', getNewYorkWeatherDesc()], | ||
temp: ['--', getNewYorkWeatherTemp()], | ||
}; | ||
const Widget = indie(Weather, propsConfig); | ||
return (<Widget />); | ||
}); |
This file was deleted.
Oops, something went wrong.