From 4cbfbafb387dfd96f4d6414e86bbb4ae501e189e Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Sun, 16 Aug 2015 16:16:53 -0300 Subject: [PATCH] [Ivan Diaz] - Add Button and widget --- app/js/App.js | 4 +- .../{components => components-app}/Footer.js | 3 - .../{components => components-app}/Header.js | 3 - .../components-core/__tests__/button-test.js | 35 ++ app/js/components-core/button.js | 44 ++ app/js/components-core/widget.js | 28 ++ app/js/components/.gitkeep | 0 app/js/components/__tests__/footer-test.js | 17 - app/js/pages/component-demo-page.js | 41 +- app/styles/_reset.scss | 427 ++++++++++++++++++ app/styles/_vars.scss | 2 + .../{elements => app-components}/_footer.scss | 0 .../{elements => app-components}/_header.scss | 0 app/styles/core-components/_button.scss | 16 + app/styles/core-components/_widget.scss | 6 + app/styles/elements/.gitkeep | 0 app/styles/main.scss | 7 +- package.json | 4 + 18 files changed, 597 insertions(+), 40 deletions(-) rename app/js/{components => components-app}/Footer.js (91%) rename app/js/{components => components-app}/Header.js (91%) create mode 100644 app/js/components-core/__tests__/button-test.js create mode 100644 app/js/components-core/button.js create mode 100644 app/js/components-core/widget.js delete mode 100644 app/js/components/.gitkeep delete mode 100644 app/js/components/__tests__/footer-test.js create mode 100644 app/styles/_reset.scss rename app/styles/{elements => app-components}/_footer.scss (100%) rename app/styles/{elements => app-components}/_header.scss (100%) create mode 100644 app/styles/core-components/_button.scss create mode 100644 app/styles/core-components/_widget.scss delete mode 100644 app/styles/elements/.gitkeep diff --git a/app/js/App.js b/app/js/App.js index 249d82d7..af81a6d5 100644 --- a/app/js/App.js +++ b/app/js/App.js @@ -6,8 +6,8 @@ import {RouteHandler} from 'react-router'; import CurrentUserActions from './actions/CurrentUserActions'; import CurrentUserStore from './stores/CurrentUserStore'; -import Header from './components/Header'; -import Footer from './components/Footer'; +import Header from './components-app/Header'; +import Footer from './components-app/Footer'; var App = React.createClass({ diff --git a/app/js/components/Footer.js b/app/js/components-app/Footer.js similarity index 91% rename from app/js/components/Footer.js rename to app/js/components-app/Footer.js index d2d769ad..3bc42db2 100644 --- a/app/js/components/Footer.js +++ b/app/js/components-app/Footer.js @@ -7,9 +7,6 @@ var Footer = React.createClass({ render() { return ( ); } diff --git a/app/js/components/Header.js b/app/js/components-app/Header.js similarity index 91% rename from app/js/components/Header.js rename to app/js/components-app/Header.js index 9f4a1fbd..e9c44faa 100644 --- a/app/js/components/Header.js +++ b/app/js/components-app/Header.js @@ -7,9 +7,6 @@ var Header = React.createClass({ render() { return (
- - Header -
); } diff --git a/app/js/components-core/__tests__/button-test.js b/app/js/components-core/__tests__/button-test.js new file mode 100644 index 00000000..1fd7a257 --- /dev/null +++ b/app/js/components-core/__tests__/button-test.js @@ -0,0 +1,35 @@ +/** + * Created by ivan on 16/08/15. + */ +jest.dontMock('../button.js'); + +import React from 'react/addons'; +import Button from '../button.js'; +var TestUtils = React.addons.TestUtils; + +describe('Button', () => { + it('should render children', () => { + var button = TestUtils.renderIntoDocument( + + ); + + expect(button.getDOMNode().textContent).toEqual('testcontent'); + }); + + it('should add passed types to class', () => { + var types = [ + 'primary' + ]; + + types.forEach((type) => { + var button = TestUtils.renderIntoDocument( + + ); + expect(button.getDOMNode().getAttribute('class')).toContain('button-' + type); + }); + }); +}); \ No newline at end of file diff --git a/app/js/components-core/button.js b/app/js/components-core/button.js new file mode 100644 index 00000000..6ae24dca --- /dev/null +++ b/app/js/components-core/button.js @@ -0,0 +1,44 @@ +/** + * Created by ivan on 16/08/15. + */ +'use strict'; + +import React from 'react/addons'; +import classNames from 'classnames'; + +var Button = React.createClass({ + + propTypes: { + children: React.PropTypes.node, + type: React.PropTypes.oneOf([ + 'primary' + ]) + }, + + getDefaultProps() { + return { + type: 'primary' + } + }, + + render() { + return ( + + ); + }, + + getClass() { + var classes = { + 'button': true + }; + + classes['button-' + this.props.type] = (this.props.type); + classes[this.props.className] = (this.props.className); + + return classNames(classes); + } +}); + +export default Button; \ No newline at end of file diff --git a/app/js/components-core/widget.js b/app/js/components-core/widget.js new file mode 100644 index 00000000..098bccf7 --- /dev/null +++ b/app/js/components-core/widget.js @@ -0,0 +1,28 @@ +import React from 'react/addons'; +import classNames from 'classnames'; + +var Widget = React.createClass({ + propTypes: { + children: React.PropTypes.node.isRequired + }, + + render() { + return ( +
+ {this.props.children} +
+ ); + }, + + getClass() { + var classes = { + 'widget': true + }; + + classes[this.props.className] = (this.props.className); + + return classNames(classes); + } +}); + +export default Widget; \ No newline at end of file diff --git a/app/js/components/.gitkeep b/app/js/components/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/js/components/__tests__/footer-test.js b/app/js/components/__tests__/footer-test.js deleted file mode 100644 index 818688be..00000000 --- a/app/js/components/__tests__/footer-test.js +++ /dev/null @@ -1,17 +0,0 @@ -jest.dontMock('../Footer.js'); - -import React from 'react/addons'; -import Footer from '../Footer.js'; -var TestUtils = React.addons.TestUtils; - -describe('Footer', () => { - it('should 2 equal 2', () => { - var footer = TestUtils.renderIntoDocument( -