mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
fleshed out up to step 6
This commit is contained in:
13
step05/src/components/TodoFooter.tsx
Normal file
13
step05/src/components/TodoFooter.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
23
step05/src/components/TodoHeader.tsx
Normal file
23
step05/src/components/TodoHeader.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
}
|
||||
40
step05/src/components/TodoList.tsx
Normal file
40
step05/src/components/TodoList.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
}
|
||||
13
step05/src/components/TodoListItem.tsx
Normal file
13
step05/src/components/TodoListItem.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user