fleshed out up to step 6

This commit is contained in:
Micah Godbolt
2019-02-12 15:44:59 -08:00
parent df6f302623
commit 5a87f131b5
26 changed files with 516 additions and 4 deletions

9
step05/index.html Normal file
View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="./src/style.css" />
<body>
<div id="app"></div>
</body>
</html>

18
step05/src/App.tsx Normal file
View File

@@ -0,0 +1,18 @@
import React from 'react';
import { TodoFooter } from './components/TodoFooter';
import { TodoHeader } from './components/TodoHeader';
import { TodoList } from './components/TodoList';
export class TodoApp extends React.Component {
render() {
return (
<div>
<TodoHeader />
<TodoList />
<TodoFooter />
</div>
);
}
}

View File

@@ -0,0 +1,13 @@
import React from "react";
export const TodoFooter = (props: any) => {
return (
<footer>
<span>
<span className="remaining">4</span> items left
</span>
<button className="button">Clear Completed</button>
</footer>
);
};

View File

@@ -0,0 +1,23 @@
import React from 'react';
export class TodoHeader extends React.Component {
render() {
return (
<div>
<h1>todos</h1>
<input className="textfield" />
<button className="button add">
Add
</button>
<div className="filter">
<button className="active">
all
</button>
<button >active</button>
<button>completed</button>
</div>
</div>
);
}
}

View File

@@ -0,0 +1,40 @@
import React from 'react';
import { TodoListItem } from './TodoListItem';
export class TodoList extends React.Component<any, any> {
render() {
const { filter, todos } = this.props;
let filteredTodos: typeof todos = {};
switch (filter) {
case 'completed':
Object.keys(todos).forEach(id => {
if (todos[id].completed) {
filteredTodos[id] = todos[id];
}
});
break;
case 'active':
Object.keys(todos).forEach(id => {
if (!todos[id].completed) {
filteredTodos[id] = todos[id];
}
});
break;
default:
filteredTodos = todos;
break;
}
return (
<ul className="todos">
<TodoListItem/>
<TodoListItem/>
<TodoListItem/>
<TodoListItem/>
</ul>
);
}
}

View File

@@ -0,0 +1,13 @@
import React from "react";
export class TodoListItem extends React.Component {
render() {
return (
<li className="todo">
<label>
<input type="checkbox" /> Todo 1
</label>
</li>
);
}
}

4
step05/src/index.tsx Normal file
View File

@@ -0,0 +1,4 @@
import React from "react";
import ReactDOM from "react-dom";
import { TodoApp } from "./App";
ReactDOM.render(<TodoApp />, document.getElementById("app"));

50
step05/src/style.css Normal file
View File

@@ -0,0 +1,50 @@
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
width: 400px;
margin: 20px auto;
}
h1 {
text-align: center;
}
.textfield {
width: 80%;
}
.add {
margin-left: 5%;
}
.button {
border: none;
padding: 5px 10px;
}
.filter {
margin: 10px 0 0;
}
.filter button {
background: transparent;
border: none;
}
.filter .active {
border-bottom: 2px solid blue;
}
.todos {
list-style: none;
padding: 0;
}
footer {
display: flex;
}
footer span {
flex-grow: 1;
}
.hidden {
display: none;
}