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

Lab 3 #58

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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "swppfront",
"homepage": ".",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.1.1"
},
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import logo from './logo.svg';
import { BrowserRouter, Route, Redirect, Switch } from 'react-router-dom';
// import logo from './logo.svg';
import './App.css';

function App() {
return (
<div className="App">
</div>
<BrowserRouter>
<div className="App">
<Route path='/todos' exact render={() => <TodoList title="My TODOs!" />} />
</div>
</BrowserRouter>
);
}

Expand Down
31 changes: 31 additions & 0 deletions src/components/Todo/Todo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.Todo {
border-top: 1px solid #f1f3f5;
padding: 1rem;
display: flex;
align-items: center;
transition: all 0.15s;
}

.Todo .text {
flex: 1;
text-align: left;
word-break: break-all;
cursor: pointer;
}

.Todo .text:hover {
color: orange;
}

.Todo .done {
text-decoration: line-through;
color: #adb5bd;
}

.Todo .done-mark {
font-size: 1.5rem;
line-height: 1rem;
margin-left: 1rem;
color: orange;
font-weight: 800;
}
13 changes: 13 additions & 0 deletions src/components/Todo/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import './Todo.css';
const Todo = props => {
return (
<div className='Todo'>
<div className={`text ${props.done && 'done'}`} onClick={props.clicked}>
{props.title}
</div>
{props.done && <div className='done-mark'>&#x2713;</div>}
</div>
);
}
export default Todo;
16 changes: 16 additions & 0 deletions src/components/TodoDetail/TodoDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import './TodoDetail.css';
const TodoDetail = (props) => {
return (<div className="TodoDetail">
<div className="row">
<div className="left"> Name: </div>
<div className="right"> {props.title} </div>
</div>
<div className="row">
<div className="left"> Content: </div>
<div className="right"> {props.content} </div>
</div>
</div>
);
};
export default TodoDetail;
41 changes: 41 additions & 0 deletions src/containers/TodoList/NewTodo/NewTodo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.NewTodo {
width: 80%;
margin: 20px auto;
border: 1px solid #eee;
box-shadow: 0 2px 3px #ccc;
text-align: center;
}

.NewTodo label {
display: block;
margin: 10px auto;
text-align: center;
font-weight: bold;
}

.NewTodo input,
.NewTodo textarea {
display: block;
width: 80%;
box-sizing: border-box;
border: 1px solid black;
outline: none;
font: inherit;
margin: auto;
}

.NewTodo button {
margin: 5px 0;
padding: 10px;
font: inherit;
border: 1px solid #fa923f;
background-color: transparent;
color: #fa923f;
cursor: pointer;
}

.NewTodo button:hover,
.NewTodo button:active {
color: white;
background-color: #fa923f;
}
24 changes: 24 additions & 0 deletions src/containers/TodoList/NewTodo/NewTodo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { Component } from 'react';
import '../NewTodo.css'
class NewTodo extends Component {
state = {
title: '',
content: '',
submitted: false,
}
render() {
return (
<div className="NewTodo">
<h1>Add a Todo</h1>
<label>Title</label>
<input type="text" value={this.state.title}
onChange={(event) => this.setState({ title: event.target.value })} />
<label>Content</label>
<textarea rows="4" type="text" value={this.state.content}
onChange={(event) => this.setState({ content: event.target.value })} />
<button onClick={() => alert('Submitted')}>Submit</button>
</div>
);
}
};
export default NewTodo;
16 changes: 16 additions & 0 deletions src/containers/TodoList/TodoList.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.TodoList {
background: white;
width: 512px;
box-shadow: 0 3px 9px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); /* 그림자 */
margin: auto;
margin-top: 4rem;
}

.TodoList .title {
padding: 2rem;
font-size: 2.5rem;
text-align: center;
font-weight: 500;
background: orange;
color: black;
}
42 changes: 42 additions & 0 deletions src/containers/TodoList/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { Component } from 'react';
import Todo from '../../components/Todo/Todo';
import TodoDetail from '../../components/TodoDetail/TodoDetail';
import './Todo.css';

class TodoList extends Component {
render() {
const todos = this.state.todos.map((td) => {
return ( <Todo key={td.id} title={td.title}
done={td.done} clicked={() => this.clickTodoHandler(td)}/> );
});
let todoDetail = null;
if (this.state.selectedTodo) {
todoDetail = <TodoDetail title={this.state.selectedTodo.title}
content={this.state.selectedTodo.content} />
}
return (
<div className="TodoList">
<div className="title">{this.props.title}</div>
<div className="todos">{todos}</div>
{todoDetail}
</div>
);
}
clickTodoHandler = td => {
if (this.state.selectedTodo == td) {
this.setState({selectedTodo: null});
} else {
this.setState({selectedTodo: td});
}
}
state = {
todos: [
{ id: 1, title: 'SWPP', content: 'take swpp class', done: true},
{ id: 2, title: 'Movie', content: 'watch movie', done: false },
{ id: 3, title: 'Dinner', content: 'eat dinner', done: false },
],
selectedTodo: null,
}
}

export default TodoList;
Loading