From 92bfbe726ec9521baba271029529bebe23eef9cf Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 22 Jul 2016 16:29:43 +0300 Subject: [PATCH] react --- components/Board.jsx | 45 +++++++++++++++++++++++++++++++++- components/item.jsx | 22 +++++++++++++++++ components/list.jsx | 58 ++++++++++++++++++++++++++++++++++++++++++++ index.html | 1 + package.json | 4 +++ styles.scss | 28 +++++++++++++++++++++ 6 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 components/item.jsx create mode 100644 components/list.jsx create mode 100644 styles.scss diff --git a/components/Board.jsx b/components/Board.jsx index e35ad4b..0a8df0d 100644 --- a/components/Board.jsx +++ b/components/Board.jsx @@ -1,9 +1,52 @@ import React from 'react'; +import List from './list'; + +const Button = ({onClick, children}) => ( + +); export default class Board extends React.Component { + state = { + newListName: '', + lists: [] + }; + + onTitleChange = e => { + this.setState({newListName: e.target.value}); + }; + + onAddList = () => { + this.setState({ + lists: this.state.lists.concat([this.state.newListName]), + newListName: '' + }); + }; + + preventDefault = e => { + e.preventDefault(); + } + + onListDelete = i => { + this.setState({ + lists: this.state.lists.filter((item, index) => index != i), + }); + } + render() { + let content = []; + for (let i = 0; i < this.state.lists.length; i++) { + content.push(< List key = { this.state.lists[i] } title = { this.state.lists[i] } onDelete = { () => this.onListDelete(i) } />); + } return ( -
Board!
+
+
+ + +
+
+ {content} +
+
); } } diff --git a/components/item.jsx b/components/item.jsx new file mode 100644 index 0000000..600f5aa --- /dev/null +++ b/components/item.jsx @@ -0,0 +1,22 @@ +import React from 'react'; + +const Button = ({onClick, children}) => ( + +); + +export default class Item extends React.Component { + onDeleteItem = () => { + this.props.onDelete(); + }; + + render() { + return ( +
+
+ {this.props.itemContent} +
+ +
+ ); + } +} diff --git a/components/list.jsx b/components/list.jsx new file mode 100644 index 0000000..18ddb46 --- /dev/null +++ b/components/list.jsx @@ -0,0 +1,58 @@ +import React from 'react'; +import Item from './item'; + +const Button = ({onClick, children}) => ( + +); + +export default class List extends React.Component { + state = { + newContent: '', + items: [] + }; + + onContentChange = e => { + this.setState({newContent: e.target.value}); + }; + + onAddItem = () => { + this.setState({ + items: this.state.items.concat([this.state.newContent]), + newContent: '' + }); + }; + + onDeleteList = () => { + this.props.onDelete(); + }; + + preventDefault = e => { + e.preventDefault(); + } + + onItemDelete = i => { + this.setState({ + items: this.state.items.filter((item, index) => index != i), + }); + } + + render() { + let content = []; + for (let i = 0; i < this.state.items.length; i++) { + content.push(< Item key = { this.state.items[i] } itemContent = { this.state.items[i] } onDelete = { () => this.onItemDelete(i) } />); + } + return ( +
+

{this.props.title}

+
+ { content } +
+
+ + +
+ +
+ ); + } +} diff --git a/index.html b/index.html index 95760da..b23be32 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ + Task Board diff --git a/package.json b/package.json index 6e887d9..42064a1 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "devDependencies": { "babel-core": "^6.11.4", "babel-loader": "^6.2.4", + "babel-plugin-transform-class-properties": "^6.10.2", "babel-preset-es2015": "^6.9.0", "babel-preset-react": "^6.11.1", "babel-preset-stage-1": "^6.5.0", @@ -23,6 +24,9 @@ "react", "stage-1", "es2015" + ], + "plugins": [ + "transform-class-properties" ] }, "dependencies": { diff --git a/styles.scss b/styles.scss new file mode 100644 index 0000000..1323482 --- /dev/null +++ b/styles.scss @@ -0,0 +1,28 @@ +.item { + height: 100px; + width: 100px; + background-color: gray; + margin: 5px; +} + +.list { + width: 110px; + background-color: black; + margin: 5px; +} + +.board { + display: flex; +} + +.add-item-btn { + height: 20px; + width: 20px; + background-color: red; +} + +.add-list-btn { + height: 40px; + width: 40px; + background-color: yellow; +}