Skip to content
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
23 changes: 23 additions & 0 deletions hw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
38,233 changes: 38,233 additions & 0 deletions hw/package-lock.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions hw/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "hw",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
10 changes: 10 additions & 0 deletions hw/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Drag and Drop</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
25 changes: 25 additions & 0 deletions hw/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
39 changes: 39 additions & 0 deletions hw/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: #f3f3f3;
}

.flexbox {
display : flex;
justify-content: space-between;
width: 100%;
max-width: 768px;
height: 100vh;

overflow: hidden;
margin: 0 auto;
padding: 15px;
}

.flexbox .board {
display: flex;
flex-direction: column;

width: 100%;
max-width: 300px;
background-color: #313131;
padding: 15px;
}

.flexbox .board .card{
padding: 15px 25px;
background-color: #f3f3f3;
cursor: pointer;
margin-bottom: 15px;
}

30 changes: 30 additions & 0 deletions hw/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import Board from "./Components/Board";
import Card from "./Components/Card";

function App() {
return (
<div className="App">
<main className="flexbox">
<Board id="board-1" className="board">
<Card id="card-1" className="card" draggable="true">
<p>Card One</p>
</Card>
</Board>

<Board id="board-2" className="board">
Copy link
Contributor

Choose a reason for hiding this comment

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

React의 defaultProps와 같은 부분을 사용해서 하드코딩한 부분을 목데이터를 통해서 생성하는 게 좋을 것 같습니다.

<Card id="card-2" className="card" draggable="true">
<p>Card Two</p>
</Card>
<Card id="card-3" className="card" draggable="true">
<p>Card Three</p>
</Card>
<Card id="card-4" className="card" draggable="true">
<p>Card Four</p>
</Card>
</Board>
</main>
</div>
);
}
export default App;
28 changes: 28 additions & 0 deletions hw/src/Components/Board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";

function Board(props) {
const drop = (e) => {
e.preventDefault();
const card_id = e.dataTransfer.getData("card_id");
const card = document.getElementById(card_id);
card.style.display = "block";
e.target.appendChild(card);
};

const dragOver = (e) => {
e.preventDefault();
};

return (
<div
id={props.id}
onDrop={drop}
onDragOver={dragOver}
className={props.className}
>
{props.children}
</div>
);
}

export default Board;
28 changes: 28 additions & 0 deletions hw/src/Components/Card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";

function Card(props) {
const dragStart = (e) => {
const target = e.target;
e.dataTransfer.setData("card_id", target.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

이벤트에 데이터를 전달하는 것보다 state로 현재 드래그 중인 카드를 관리하는 게 더 좋을 것 같습니다.

setTimeout(() => {
target.style.display = "none";
Copy link
Contributor

Choose a reason for hiding this comment

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

직접 돔을 수정하는 것보다 조건부 렌더링이 좋을 것 같아요.

}, 0);
};

const dragOver = (e) => {
e.stopPropagation();
Copy link
Contributor

Choose a reason for hiding this comment

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

이벤트 전파를 막는 이유는 무엇인가요?

};

return (
<div
id={props.id}
className={props.className}
draggable={props.draggable}
onDragStart={dragStart}
onDragOver={dragOver}
>
{props.children}
</div>
);
}
export default Card;
13 changes: 13 additions & 0 deletions hw/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import "./App.css";
import reportWebVitals from "./reportWebVitals";

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
reportWebVitals();
13 changes: 13 additions & 0 deletions hw/src/reportWebVitals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};

export default reportWebVitals;