From a48b0ac68166d76780523b565a1e8b6d54a0d5ff Mon Sep 17 00:00:00 2001 From: EunKo Date: Fri, 10 Apr 2020 15:19:34 +0900 Subject: [PATCH 01/29] commit index.js --- pages/index.js | 76 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/pages/index.js b/pages/index.js index f494909..1f65697 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,30 +1,64 @@ -import React from "react"; +import React, { Component } from 'react'; +import styled from 'styled-components'; -import TodoInput from "../components/todo-input"; -import TodoList from "../components/todo-list"; +import TodoInput from '../components/todo-input'; +import TodoList from '../components/todo-list'; -import styled from "styled-components"; +export default class Home extends Component { + id = 0; + state = { + todos: [], + }; -export default function Home() { - return ( - - - - - - - ); + handleCreate = (data) => { + const { todos } = this.state; + this.setState({ + todos: todos.concat({ id: this.id++, ...data }), + }); + }; + handleRemove = (id) => { + const { todos } = this.state; + this.setState({ + todos: todos.filter((info) => info.id !== id), + }); + }; + + render() { + const { todos } = this.state; + + return ( + + 리액트-투두 + + + + + + + ); + } } +const Space = styled.div` + flex: 0.3; +`; const Wrapper = styled.div` - height: 100vh; + height: 100vh; + font-size: 20px; + background-color: rgb(155, 197, 195); + padding: 4rem 5rem; +`; +const Subject = styled.div` + font-size: 3rem; + font-weight: 600; + padding: 0px; + margin: 0px 0px 3rem; + color: white; `; - const Contents = styled.div` - border: solid 1px black; - display: flex; - flex-direction: row; - justify-content: space-between; - padding: 10px 20px; - margin: 20px 10px; + font-size: 0.1rem; + + display: flex; + flex-direction: row; + justify-content: space-between; `; From 78602bfa869fd2de83283303cf7ed335291104ac Mon Sep 17 00:00:00 2001 From: EunKo Date: Fri, 10 Apr 2020 15:21:30 +0900 Subject: [PATCH 02/29] commit todo-input.js --- components/todo-input.js | 136 ++++++++++++++++++++++++++++++++++----- 1 file changed, 120 insertions(+), 16 deletions(-) diff --git a/components/todo-input.js b/components/todo-input.js index 1844e25..32f90d0 100644 --- a/components/todo-input.js +++ b/components/todo-input.js @@ -1,20 +1,124 @@ -import React from "react"; -import styled from "styled-components"; +import React, { Component } from 'react'; +import styled from 'styled-components'; -export default function TodoInput() { - return ( - - 리액트-투두 -
- 시간을 입력하는 칸 -
- Todo를 입력하는 칸 -
- ); +export default class TodoInput extends Component { + state = { + date: '', + todo: '', + }; + handleChange = (e) => { + this.setState({ + [e.target.name]: e.target.value, + }); + }; + handleSubmit = (e) => { + e.preventDefault(); + // 페이지 리로딩 방지 + if (this.state.todo === '' || this.state.date === '') { + alert('모든 항목을 입력해주세요!'); + return false; + } else if (this.state.date.length != 8) { + alert('날짜를 올바른 형식으로 입력해주세요!'); + return false; + } else alert('입력되었습니다!'); + this.props.onCreate(this.state); + // 상태값을 onCreate 를 통하여 부모에게 전달 + this.setState({ date: '', todo: '' }); + // 상태 초기화 + }; + maxLengthCheck = (object) => { + if (object.value.length > object.maxLength) { + object.value = object.value.slice(0, object.maxLength); + } + }; + render() { + const { date, todo } = this.state; + return ( +
+ +

시간

+ +
+ + +

TODO

+