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

[2주차] 이지인 미션 제출합니다. #6

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
124 changes: 124 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"styled-components": "^6.1.8",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
10 changes: 0 additions & 10 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,5 @@
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
56 changes: 53 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
import React, { useState } from 'react';
import styled from 'styled-components';
import Section from './Section';

const AppContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
width: 80%;
margin: 30px auto;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

px단위도 좋지만 반응형을 위해 rem단위를 사용했어도 좋았을 거 같아요!

`;

const Input = styled.input`
margin: 10px;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
`;

const Button = styled.button`
padding: 10px 20px;
margin: 5px;
border-radius: 5px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;

&:hover {
background-color: #0056b3;
}
`;

function App() {
const [sections, setSections] = useState([]);
const [sectionName, setSectionName] = useState('');

const addSection = () => {
setSections([...sections, { id: sections.length + 1, name: sectionName, todos: [] }]);
setSectionName('');
};

return (
<div className="App">
<h1>CEOS 19기 프론트엔드 파이팅!( ¨̮ )و✧🔥</h1>
</div>
<AppContainer>
<Input
type="text"
placeholder="New Section Name"
value={sectionName}
onChange={(e) => setSectionName(e.target.value)}
/>
<Button onClick={addSection}>Add Section</Button>
{sections.map((section) => (
<Section key={section.id} section={section} />
))}
</AppContainer>
);
}

Expand Down
59 changes: 59 additions & 0 deletions src/Section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState } from 'react';
import styled from 'styled-components';
import TodoItem from './TodoItem';

const SectionContainer = styled.div`
margin: 20px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
`;

const Input = styled.input`
margin: 10px;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
`;

const Button = styled.button`
padding: 10px 20px;
margin: 5px;
border-radius: 5px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;

&:hover {
background-color: #0056b3;
}
`;

function Section({ section }) {
const [todos, setTodos] = useState(section.todos);
const [todoText, setTodoText] = useState('');

const addTodo = () => {
setTodos([...todos, { id: todos.length + 1, text: todoText }]);
setTodoText('');
};

return (
<SectionContainer>
<h2>{section.name}</h2>
<Input
type="text"
placeholder="New Todo"
value={todoText}
onChange={(e) => setTodoText(e.target.value)}
/>
<Button onClick={addTodo}>Add Todo</Button>
{todos.map((todo) => (
<TodoItem key={todo.id} todo={todo} />
))}
</SectionContainer>
);
}

export default Section;
20 changes: 20 additions & 0 deletions src/TodoItem.js
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리액트는 통용화되는 폴더 구조가 있더라구요...! 리액트 폴더구조 확인해 보시면 좋을거 같아요~

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import styled from 'styled-components';

const ItemContainer = styled.div`
display: flex;
justify-content: space-between;
margin: 10px;
padding: 10px;
border-bottom: 1px solid #eee;
`;

function TodoItem({ todo }) {
return (
<ItemContainer>
<span>{todo.text}</span>
</ItemContainer>
);
}

export default TodoItem;
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById("root"));
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
<React.StrictMode>
<App />
</React.StrictMode>
);