diff --git a/src/App.js b/src/App.js index 556b5fbc..8cdc275c 100644 --- a/src/App.js +++ b/src/App.js @@ -1,13 +1,73 @@ import React from 'react'; +import ReactDOM from 'react-dom'; +import TodoList from './components/TodoList'; +import TodoForm from './components/TodoForm'; + +import './Todo.css'; + +const todolist = [ +{ + task: 'Organize Garage', + id: 1528817077286, + completed: false +}, +{ + task: 'Bake Cookies', + id: 1528817084358, + completed: false +} +]; class App extends React.Component { // you will need a place to store your state in this component. // design `App` to be the parent component of your application. // this component is going to take care of state, and any change handlers you need to work with your state + constructor() { + super(); + this.state = { + todolist: todolist + } + } + + toggleCompleted = (todoId) => { + const updatedTodolist = this.state.todolist.map(todo => { + if (todo.id === todoId) { + return { + ...todo, + completed: !todo.completed + } + } + return todo; + }); + this.setState({ + ...this.state, + todolist: updatedTodolist + }); + } + + addTodo = (todoName) => { + const newTodo = { + task: todoName, + id: Date.now(), + completed: false + }; + this.setState({ + ...this.state, + todolist: [ + ...this.state.todolist, + newTodo + ] + }) + } + render() { return ( -
-

Welcome to your Todo App!

+
+
+

Todo List

+ +
+
); } diff --git a/src/Todo.css b/src/Todo.css new file mode 100644 index 00000000..91f09d10 --- /dev/null +++ b/src/Todo.css @@ -0,0 +1,96 @@ +@import url('https://fonts.googleapis.com/css?family=Roboto'); +html, +body { + width: 100%; + height: 100%; + margin: 0; + padding: 1em; +} + +body { + background-color: #2d2d37; +} + +h1, +h2, +h3, +h4, +h5, +h6, +div, +p, +span { + color: white; + font-family: 'Roboto', sans-serif; +} + +.App { + font-family: sans-serif; + text-align: center; + padding: 0 36px; + max-width: 665px; + margin: 0 auto; +} + +.header { + display: flex; + justify-content: space-between; + align-items: center; +} +h1 { + text-align: left; +} + +.todolist { + display: flex; + flex-flow: row wrap; + justify-content: space-between; + width: 100%; + margin: 0 auto; +} +.todo { + background-color: #e64944; + width: 45%; + text-align: left; + margin: 4px 0; + padding-left: 8px; + cursor: pointer; +} + +.todo.completed { + background-color: #d17d7c; + text-decoration: line-through; +} +form { + width: 50%; + display: flex; + justify-content: flex-end; +} +form > input { + background-color: #2d2d37; + border: 0; + padding: 6px 0; + font-size: 1rem; + width: 240px; + outline: 0; + color: white; + border-bottom: 1px solid #e64944; + margin-right: 8px; +} + +button { + background-color: #e64944; + border: 1px solid #e64944; + color: white; + font-size: 16px; + padding: 6px 14px; +} + +input::placeholder { + color: #e64944; + opacity: 1; +} + +.clear-btn { + margin-top: 16px; +} diff --git a/src/components/Todo.css b/src/components/Todo.css deleted file mode 100644 index e69de29b..00000000 diff --git a/src/components/Todo.js b/src/components/Todo.js index e69de29b..1f4a3049 100644 --- a/src/components/Todo.js +++ b/src/components/Todo.js @@ -0,0 +1,14 @@ +import React from 'react'; + +const Todo = props => { + return( +
props.toggleCompleted(props.todo.id)} + > +

{props.todo.task}

+
+ ); +}; + +export default Todo; \ No newline at end of file diff --git a/src/components/TodoForm.js b/src/components/TodoForm.js index e69de29b..ba4f25bc 100644 --- a/src/components/TodoForm.js +++ b/src/components/TodoForm.js @@ -0,0 +1,33 @@ +import React from 'react'; + +class TodoForm extends React.Component { + constructor(){ + super(); + this.state = { + newTodo: '' + } + } + + handleChanges = e => { + this.setState({ + ...this.state, + newTodo: e.target.value + }) + }; + + handleSubmit = e => { + e.preventDefault(); + this.props.addTodo(this.state.newTodo); + } + + render(){ + return( +
+ + +
+ ) + } +} + +export default TodoForm; \ No newline at end of file diff --git a/src/components/TodoList.js b/src/components/TodoList.js index dfd3d8f1..a9738ee9 100644 --- a/src/components/TodoList.js +++ b/src/components/TodoList.js @@ -1,2 +1,23 @@ // your components will all go in this `component` directory. // feel free to change this component.js into TodoList.js +import React from "react"; +import Todo from "./Todo"; + + + +const TodoList = props => { + + + return ( +
+ {props.todolist.map(todo => ( + + ))} + +
+ ); +}; + +export default TodoList; \ No newline at end of file