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

[사전 미션 - 워밍업] - 리버(최재희) 미션 제출합니다. #16

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
26 changes: 12 additions & 14 deletions a11y/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Accessibility</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Accessibility</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions a11y/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import "./Typography.css";
import "./App.css";

import FlightBooking from "./components/FlightBooking";
import { FlightBooking } from "./components/index";

function App() {
return (
<div className="app">
<div className="app-main">
<main className="app-main">
<div className="flight-booking-container">
<FlightBooking />
</div>
</div>
</main>
</div>
);
}
Expand Down
38 changes: 0 additions & 38 deletions a11y/src/components/FlightBooking.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.flight-booking {
position: relative;
background-color: white;
border-radius: 8px;
padding: 20px;
Expand Down Expand Up @@ -34,7 +35,7 @@
width: 30px;
height: 30px;
border-radius: 16px;
border: 1px solid #C0C0C0;
border: 1px solid #c0c0c0;
background-color: #fff;
cursor: pointer;
display: flex;
Expand All @@ -61,3 +62,13 @@
border-radius: 4px;
cursor: pointer;
}

.visually-hidden {
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px);
clip: rect(1px, 1px, 1px, 1px);
white-space: nowrap;
}
84 changes: 84 additions & 0 deletions a11y/src/components/FlightBooking/FlightBooking.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useState, useEffect } from "react";

import "./FlightBooking.css";
import Toast from "../Toast/Toast";

const MAX_PASSENGERS = 3;
const MIN_PASSENGERS = 1;

const STATUS_MESSAGE = {
increase: "성인 승객 증가 ",
decrease: "성인 승객 감소 ",
};

const ALERT_MESSAGE = {
min: "최소 승객 수에 도달했습니다.",
max: "최대 승객 수에 도달했습니다.",
};

const FlightBooking = () => {
const [adultCount, setAdultCount] = useState(MIN_PASSENGERS);
const [statusMessage, setStatusMessage] = useState<string | null>(null);
const [toastMessage, setToastMessage] = useState<string | null>(null);

useEffect(() => {
if (toastMessage) {
const timer = setTimeout(() => {
setToastMessage(null);
}, 1000 * 3);

return () => clearTimeout(timer);
}
}, [toastMessage]);

const incrementCount = () => {
setStatusMessage(STATUS_MESSAGE.increase);
setAdultCount((prev) => Math.min(MAX_PASSENGERS, prev + 1));

if (adultCount === MAX_PASSENGERS) {
setToastMessage(ALERT_MESSAGE.max);
}
};

const decrementCount = () => {
setStatusMessage(STATUS_MESSAGE.decrease);
setAdultCount((prev) => Math.max(MIN_PASSENGERS, prev - 1));

if (adultCount === MIN_PASSENGERS) {
setToastMessage(ALERT_MESSAGE.min);
}
};

return (
<div className="flight-booking">
<h2 className="heading-2-text">항공권 예매</h2>
<div className="passenger-count">
<span className="body-text">성인</span>
<div className="counter">
<button
className="button-text"
onClick={decrementCount}
aria-label={STATUS_MESSAGE.decrease}
>
-
</button>
<span aria-live="polite">
<span className="visually-hidden">{statusMessage}</span>
{adultCount}
</span>
<button
className="button-text"
onClick={incrementCount}
aria-label={STATUS_MESSAGE.increase}
>
+
</button>
</div>
</div>
<button className="search-button">항공편 검색</button>
{toastMessage && <Toast>{toastMessage}</Toast>}
</div>
);
};

export default FlightBooking;
11 changes: 11 additions & 0 deletions a11y/src/components/Toast/Toast.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.toast {
background-color: black;
border-radius: 8px;
padding: 15px 20px;
color: white;

position: absolute;
bottom: -4rem;
left: 0;
right: 0;
}
11 changes: 11 additions & 0 deletions a11y/src/components/Toast/Toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./Toast.css";

const Toast = ({ children }: React.PropsWithChildren) => {
return (
<span className="toast" aria-live="polite">
{children}
</span>
);
};

export default Toast;
2 changes: 2 additions & 0 deletions a11y/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as FlightBooking } from "./FlightBooking/FlightBooking";
export { default as Toast } from "./Toast/Toast";
3 changes: 3 additions & 0 deletions a11y/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host: "0.0.0.0",
},
});