App.js
import "./App.css";
import React, { useState } from 'react'
import Button1 from "./components/Button1";
import Button2 from "./components/Button2";
import CheckBox from "./components/CheckBox";
function App() {
// useState๋ก ์ฒดํฌ ์ฌ๋ถ ํ๋จ
const [check, setChecked] = useState(false);
const onChange = (event) => {
setChecked(event.target.checked); // ์ฒดํฌ๋์ด์์ผ๋ฉด check์์ ๋ฃ์
}
return (
<>
<Button1 />
<Button2 />
<hr />
<CheckBox checked={check} onChange={onChange}>
<span>์ฝ๊ด ๋ด์ฉ์ด ๋ค์ด๊ฐ ๋ถ๋ถ</span>
</CheckBox>
</>
);
}
export default App;
Button1.jsx
import React from 'react'
import style from "./Button1.module.css";
// ๊ณ ์ ์ด๋ฆ์ ๋ง๋ค์ด์ ๊ฐ์ ธ์ด
const Button1 = () => {
return (
<button className={style.button}>Button1</button>
)
}
export default Button1
Button1.module.css
.button {
background-color: skyblue;
padding: 20px 40px;
margin: 30px;
}
Button2.jsx
import React from "react";
import aa from "./Button2.module.css";
const Button2 = () => {
return (
<>
<button className={aa.button}>Button2</button>
<span className="text">๋ฒํผ2 ์ปดํฌ๋ํธ</span>
</>
);
};
export default Button2;
Button2.module.css
.button {
background-color: coral;
padding: 30px 60px;
margin: 30px;
font-size: 2rem;
}
CheckBox.jsx
// rafce
import React from "react";
// react-icons : ์ปดํฌ๋ํธ์ฒ๋ผ ์ฌ์ฉ
import { MdUpdate, MdUpdateDisabled } from "react-icons/md";
import cx from "./CheckBox.module.scss";
const CheckBox = ({ children, checked, ...rest }) => {
return (
<div className={cx.checkbox}>
<label>
<input type="checkbox" checked={checked} {...rest} />
{checked ? <MdUpdate className={cx.checked} /> : <MdUpdateDisabled />}
</label>
{/* App.js์์ ๋ฐ์์ด */}
<p>{children}</p>
</div>
);
};
export default CheckBox;
CheckBox.module.scss
.checkbox {
input {
width: 0;
height: 0;
position: absolute;
opacity: 0;
}
}
.checked { color: skyblue; }
// ์ ์ญ์ ์ผ๋ก ์ฌ์ฉํ ๋(๋ชจ๋ ์ปดํฌ๋ํธ์์ ์ฌ์ฉ ๊ฐ๋ฅ)
:global .text { color: cornflowerblue; }