diff --git a/my-app/src/chapter_08/ConfirmButton.jsx b/my-app/src/chapter_08/ConfirmButton.jsx new file mode 100644 index 000000000..b192bd658 --- /dev/null +++ b/my-app/src/chapter_08/ConfirmButton.jsx @@ -0,0 +1,20 @@ +import React from "react"; + +function ConfirmButton(props) { + const [isConfirmed, setIsConfirmed] = React.useState(false); + + const handleConfirm = () => { + setIsConfirmed(prevIsConfirmed => !prevIsConfirmed); + }; + + return ( + + ); +} + +export default ConfirmButton; \ No newline at end of file diff --git a/my-app/src/chapter_09/LandingPage.jsx b/my-app/src/chapter_09/LandingPage.jsx new file mode 100644 index 000000000..0bfb1cbfd --- /dev/null +++ b/my-app/src/chapter_09/LandingPage.jsx @@ -0,0 +1,27 @@ +import React, { useState } from "react"; +import Toolbar from "./Toolbar"; + +function LandingPage(props) { + const [isLoggedIn, setIsLoggedIn] = useState(false); + + const onClickLogin = () => { + setIsLoggedIn(true); + }; + + const onClickLogout = () => { + setIsLoggedIn(false); + }; + + return ( +
+ +
리액트 공부!
+
+ ); +} + +export default LandingPage; \ No newline at end of file diff --git a/my-app/src/chapter_09/Toolbar.jsx b/my-app/src/chapter_09/Toolbar.jsx new file mode 100644 index 000000000..01035b676 --- /dev/null +++ b/my-app/src/chapter_09/Toolbar.jsx @@ -0,0 +1,30 @@ +import React from "react"; + +const styles = { + wrapper: { + display: "flex", + padding: 16, + flexDirection: "row", + borderBottom: "1px solid grey", + }, + greeting: { + marginRight: 8, + }, +}; + +function Toolbar(props) { + const { isLoggedIn, onClickLogin, onClickLogout } = props; + + return ( +
+ {isLoggedIn && 환영합니다!} + {isLoggedIn ? ( + + ) : ( + + )} +
+ ); +} + +export default Toolbar; \ No newline at end of file diff --git a/my-app/src/chapter_10/AttendanceBook.jsx b/my-app/src/chapter_10/AttendanceBook.jsx new file mode 100644 index 000000000..ba3b17d7f --- /dev/null +++ b/my-app/src/chapter_10/AttendanceBook.jsx @@ -0,0 +1,34 @@ +import React from "react"; + +const students = [ + { + id: 1, + name: "Inje", + }, + { + id: 2, + name: "Jisoo", + }, + { + id: 3, + name: "Jiwon", + }, + { + id: 4, + name: "Soojin", + }, +]; + +function AttendanceBook(props) { + return ( + + + ) +} + +export default AttendanceBook; \ No newline at end of file diff --git a/my-app/src/chapter_11/SignUp.jsx b/my-app/src/chapter_11/SignUp.jsx new file mode 100644 index 000000000..8d4201b68 --- /dev/null +++ b/my-app/src/chapter_11/SignUp.jsx @@ -0,0 +1,37 @@ +import React, {useState} from "react"; + +function SignUp(props) { + const [name, setName] = useState(""); + const [gender, setGender] = useState("남자"); + + const handleChangeName = (e) => { + setName(e.target.value); + }; + const handleChangeGender = (e) => { + setGender(e.target.value); + }; + + const handleSubmit = (e) => { + alert(`이름: ${name}, 성별: ${gender}`); + e.preventDefault(); + }; + + return ( +
+ +
+ + +
+ ); +} +export default SignUp; diff --git a/my-app/src/chapter_12/Calculator.jsx b/my-app/src/chapter_12/Calculator.jsx new file mode 100644 index 000000000..a0862b9c4 --- /dev/null +++ b/my-app/src/chapter_12/Calculator.jsx @@ -0,0 +1,65 @@ +import React, { useState } from "react"; +import TemperatureInput from "./TemperatureInput"; + +function BoilingVerdict(props) { + if (props.celsius >= 100) { + return

물이 끓습니다.

; + } + return

물이 끓지 않습니다.

; +} + +function toCelsius(fahrenheit) { + return ((fahrenheit - 32) * 5) / 9; +} + +function toFahrenheit(celsius) { + return (celsius * 9) / 5 + 32; +} + +function tryConvert(temperature, convert) { + const input = parseFloat(temperature); + if (Number.isNaN(input)) { + return ""; + } + const output = convert(input); + const rounded = Math.round(output * 1000) / 1000; + return rounded.toString(); +} + +function Calculator(props) { + const [temperature, setTemperature] = useState(""); + const [scale, setScale] = useState("c"); + + const handleCelsiusChange = (temperature) => { + setTemperature(temperature); + setScale("c"); + }; + + const handleFahrenheitChange = (temperature) => { + setTemperature(temperature); + setScale("f"); + }; + + const celsius = + scale === "f" ? tryConvert(temperature, toCelsius) : temperature; + const fahrenheit = + scale === "c" ? tryConvert(temperature, toFahrenheit) : temperature; + + return ( +
+ + + +
+ ); +} + +export default Calculator; \ No newline at end of file diff --git a/my-app/src/chapter_12/TemperatureInput.jsx b/my-app/src/chapter_12/TemperatureInput.jsx new file mode 100644 index 000000000..6c606592f --- /dev/null +++ b/my-app/src/chapter_12/TemperatureInput.jsx @@ -0,0 +1,21 @@ +const scaleNames = { + c: "섭씨", + f: "화씨", +}; + +function TemperatureInput(props) { + const handleChange = (event) => { + props.onTemperatureChange(event.target.value); + }; + + return ( +
+ + 온도를 입력해주세요(단위:{scaleNames[props.scale]}): + + +
+ ); +} + +export default TemperatureInput; \ No newline at end of file diff --git a/my-app/src/chapter_13/Card.jsx b/my-app/src/chapter_13/Card.jsx new file mode 100644 index 000000000..d8d1d83d3 --- /dev/null +++ b/my-app/src/chapter_13/Card.jsx @@ -0,0 +1,20 @@ +function Card(props) { + const { title, backgroundColor, children } = props; + + return ( +
+ {title &&

{title}

} + {children} +
+ ); +} + +export default Card; \ No newline at end of file diff --git a/my-app/src/chapter_13/ProfileCard.jsx b/my-app/src/chapter_13/ProfileCard.jsx new file mode 100644 index 000000000..5051c3cd9 --- /dev/null +++ b/my-app/src/chapter_13/ProfileCard.jsx @@ -0,0 +1,12 @@ +import Card from "./Card"; + +function ProfileCard(props) { + return ( + +

안녕하세요, 김윤지입니다.

+

저는 리액트를 사용해서 개발하고 있습니다.

+
+ ); +} + +export default ProfileCard; \ No newline at end of file diff --git a/my-app/src/index.js b/my-app/src/index.js index 6ca54edd6..d5ebbed43 100644 --- a/my-app/src/index.js +++ b/my-app/src/index.js @@ -9,12 +9,18 @@ import Clock from './chapter_04/Clock'; import CommentList from './chapter_05/CommentList'; import NotificationList from './chapter_06/NotificationList'; import Accommodate from './chapter_07/Accommodate'; +import ConfirmButton from './chapter_08/ConfirmButton'; +import LandingPage from './chapter_09/LandingPage'; +import AttendanceBook from './chapter_10/AttendanceBook'; +import SignUp from './chapter_11/SignUp'; +import Calculator from './chapter_12/Calculator'; +import ProfileCard from './chapter_13/ProfileCard'; const root = ReactDOM.createRoot(document.getElementById('root')); // React 18 방식 root.render( - + );