Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion components/Board.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
import React from 'react';
import List from './list';

const Button = ({onClick, children}) => (
<button onClick={onClick}>{children}</button>
);

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 (
<div>Board!</div>
<div>
<form onSubmit={this.preventDefault}>
<input onChange={this.onTitleChange} value={this.state.newListName}/>
<Button onClick={this.onAddList}>add list</Button>
</form>
<div className="board">
{content}
</div>
</div>
);
}
}
22 changes: 22 additions & 0 deletions components/item.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

const Button = ({onClick, children}) => (
<button onClick={onClick}>{children}</button>
);

export default class Item extends React.Component {
onDeleteItem = () => {
this.props.onDelete();
};

render() {
return (
<div>
<div className="item">
{this.props.itemContent}
</div>
<Button onClick={this.onDeleteItem}>del list</Button>
</div>
);
}
}
58 changes: 58 additions & 0 deletions components/list.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import Item from './item';

const Button = ({onClick, children}) => (
<button onClick={onClick}>{children}</button>
);

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 (
<div>
<h4>{this.props.title}</h4>
<div className="list">
{ content }
</div>
<form onSubmit={this.preventDefault}>
<input onChange={this.onContentChange} value={this.state.newContent}/>
<Button onClick={this.onAddItem}>add item</Button>
</form>
<Button onClick={this.onDeleteList}>del list</Button>
</div>
);
}
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./styles.scss">
<title>Task Board</title>
</head>

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,6 +24,9 @@
"react",
"stage-1",
"es2015"
],
"plugins": [
"transform-class-properties"
]
},
"dependencies": {
Expand Down
28 changes: 28 additions & 0 deletions styles.scss
Original file line number Diff line number Diff line change
@@ -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;
}