diff --git a/src/Radio/Radio.js b/src/Radio/Radio.js new file mode 100644 index 00000000..dcec4b99 --- /dev/null +++ b/src/Radio/Radio.js @@ -0,0 +1,26 @@ +import React, {Component, PropTypes} from 'react'; +import classNames from 'classnames/bind'; +import RadioButtonGroup from 'react-radio-button'; +import styles from './Radio.styles.css'; +import Select from 'react-select'; + +const cx = classNames.bind(styles); + +const className = cx({ base: true }); + +const Radio = ({ listOfItems, selectedItemCallback}) => { + return + +}; + +Radio.displayName = 'Radio'; + +Radio.propTypes = { + listOfItems: PropTypes.array.isRequired, + selectedItemCallback: PropTypes.func.isRequired, +} + +export default Radio; diff --git a/src/Radio/Radio.styles.css b/src/Radio/Radio.styles.css new file mode 100644 index 00000000..15a46931 --- /dev/null +++ b/src/Radio/Radio.styles.css @@ -0,0 +1,9 @@ +.base { + border: 1px solid #eee; + border-radius: 3px; + background-color: #FFFFFF; + cursor: pointer; + font-size: 15px; + padding: 3px 10px; + margin: 10px; +} diff --git a/src/Radio/Radio.test.js b/src/Radio/Radio.test.js new file mode 100644 index 00000000..e69de29b diff --git a/src/ViewData/ViewData.js b/src/ViewData/ViewData.js new file mode 100644 index 00000000..f22fa242 --- /dev/null +++ b/src/ViewData/ViewData.js @@ -0,0 +1,95 @@ +import React, { Component } from 'react'; +import fetch from 'isomorphic-fetch'; //eslint-disable-line +// import { whereBy } from 'ramda'; + +// function makeYearData(data) { +// const yearData = []; +// data.forEach((month) => { +// for (let i = 0; i < month.length; i++) { +// yearData.push(month[i]); +// } +// }); +// return yearData; +// } + +const splitForYear = date => date.split('-')[0]; + +const filterByYear = (transactions) => { + const dataByYear = {}; + transactions.forEach((t) => { + const year = splitForYear(t.tran_date); + const yearToUpdate = dataByYear[year]; + if (yearToUpdate) { + dataByYear[year].push(t); + } else { + dataByYear[year] = [t]; + } + }); + return dataByYear; +}; + + +function reduceData(year, data) { + return data[year] && data[year].reduce((acc, item) => acc + item.amount, 0); +} + +export default class ViewData extends Component { + + static defaultProps = {} + + static propTypes = {} + + constructor(props) { + super(props); + this.state = { + data: null, + display: null, + }; + } + + componentDidMount() { + fetch('http://54.213.83.132/hackoregon/http/current_candidate_transactions_in/5591/') + .then((response) => { + if (response.ok) { + return response.json(); + } + return response; + }) + .then(json => filterByYear(json)) + .then(data => this.setState({ data })); + } + + renderData = data => ( +
+
{data.filer}
+

+ {data.tran_date} | {data.contributor_payee} | {data.amount} +

+
+) + + renderYear = year => this.setState({ display: this.state.data[year] }); + getYears = () => Object.keys(this.state.data); + + render() { + let mappedData; + if (this.state.data) { + mappedData = this.getYears().map(year => reduceData(year, this.state.data)); + // console.log(mappedData); + } + + return ( +
+ +

Totals

+ + {this.state.display && (this.renderData(this.state.display) || 'Loading...')} +
+ ); + } + +} diff --git a/src/index.js b/src/index.js index 7d1986ca..3a1ded52 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ export StamenMap from './StamenMap/StamenMap'; export Dropdown from './Dropdown/Dropdown'; export Icon from './Icon/Icon'; export Scatterplot from './Scatterplot/Scatterplot'; +export Radio from './Radio/Radio'; // export utils as well for broader use export isClient from './utils/isClient'; diff --git a/stories/Radio.story.js b/stories/Radio.story.js new file mode 100644 index 00000000..3b767c03 --- /dev/null +++ b/stories/Radio.story.js @@ -0,0 +1,55 @@ +import React, {Component, PropTypes} from 'react'; +import { storiesOf, action } from '@kadira/storybook'; +import { Radio } from '../src'; +import RadioButtonGroup from 'react-radio-button'; + +const displayName = Radio.displayName || 'Radio'; +const title = 'Simple usage'; +const description = ` + This is some basic usage with the button with providing a label to show the text. + Clicking should trigger an action.`; + +const demoCode = () => { + class DemoRadio extends React.Component { + constructor() { + super(); + this.handleChange = this.handleChange.bind(this); + this.state = { + selectedValue: undefined, + radioOptions: [ + { value: 'Snoopy', text: 'Snoopy' }, + { value: 'Charlie Brown', text: 'Charlie Brown'}, + { value: 'Sally', text: 'Sally'}, + { value: 'Shroeder', text: 'Shroeder'}, + { value: 'Lucy', text: 'Lucy'}, + { value: 'Linus', text: 'Linus'} + ] + }; + } + + handleChange(value) { + this.setState({selectedValue: value,}); + } + + render() { + return ( + this.state.handleChange(value)} + listOfItems={this.state.radioOptions} + /> + ); + } + } + + return +}; + +const propDocs = { inline: true, propTables: [Radio] }; + +export default () => storiesOf(displayName, module) + .addWithInfo( + title, + description, + demoCode, + propDocs, + ); diff --git a/stories/ViewData.story.js b/stories/ViewData.story.js new file mode 100644 index 00000000..22973823 --- /dev/null +++ b/stories/ViewData.story.js @@ -0,0 +1,23 @@ +import React from 'react'; +import { storiesOf, action } from '@kadira/storybook'; +import { ViewData } from '../src'; + +const displayName = ViewData.displayName || 'ViewData'; +const title = 'Simple usage'; +const description = ` + This is some basic usage with the button with providing a label to show the text. + Clicking should trigger an action.`; + +const demoCode = () => ( + +); + +const propDocs = { inline: true, propTables: [ViewData] }; + +export default () => storiesOf(displayName, module) + .addWithInfo( + title, + description, + demoCode, + propDocs, + ); \ No newline at end of file diff --git a/stories/index.js b/stories/index.js index 9a25b50d..9749842b 100644 --- a/stories/index.js +++ b/stories/index.js @@ -20,6 +20,7 @@ import dropdownStory from './Dropdown.story'; import rechartsPie from './RechartsPie.story'; import heroStory from './Hero.story'; import scatterplotStory from './Scatterplot.story'; +import radioStory from './Radio.story'; import '../src/global.styles.css'; import '../assets/leaflet.css'; @@ -50,3 +51,4 @@ leafletMap(); heroStory(); StamenMap(); scatterplotStory(); +radioStory();