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:
9
step05/index.html
Normal file
9
step05/index.html
Normal 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
18
step05/src/App.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
}
|
||||
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>
|
||||
);
|
||||
}
|
||||
}
|
||||
4
step05/src/index.tsx
Normal file
4
step05/src/index.tsx
Normal 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
50
step05/src/style.css
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user