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

[사전 미션 - 워밍업] - 버건디(전태헌) 미션 제출합니다. #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions a11y/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v21.1.0
24 changes: 11 additions & 13 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>
<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>
4 changes: 2 additions & 2 deletions a11y/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import FlightBooking from "./components/FlightBooking";
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
14 changes: 13 additions & 1 deletion a11y/src/components/FlightBooking.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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 +61,15 @@
border-radius: 4px;
cursor: pointer;
}

.aria-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
58 changes: 47 additions & 11 deletions a11y/src/components/FlightBooking.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,73 @@
import { useState } from "react";
import { useEffect, useRef, useState } from "react";

import "./FlightBooking.css";

const MAX_PASSENGERS = 3;
const MIN_PASSENGERS = 1;

const getMessage = (count: number) => {
if (count === MAX_PASSENGERS) return "최대 승객 수에 도달했습니다.";
if (count === MIN_PASSENGERS) return "최소 승객 수는 1명입니다.";
return `성인 승객 ${count}명`;
};

const FlightBooking = () => {
const [adultCount, setAdultCount] = useState(1);
const [message, setMessage] = useState(getMessage(1));
const messageRef = useRef<HTMLDivElement | null>(null);

const incrementCount = () => {
setAdultCount((prev) => Math.min(MAX_PASSENGERS, prev + 1));
const adjustCount = (change: number) => {
setAdultCount((prevCount) => {
const newCount = prevCount + change;
setMessage(getMessage(newCount));
return newCount;
});
};

const decrementCount = () => {
setAdultCount((prev) => Math.max(1, prev - 1));
};
useEffect(() => {
if (messageRef.current) {
messageRef.current.focus();
}
}, [message]);

return (
<div className="flight-booking">
<section 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}>
<button
className="button-text"
onClick={() => adjustCount(-1)}
aria-label="성인 승객 감소"
disabled={adultCount === MIN_PASSENGERS}
>
-
</button>
<span>{adultCount}</span>
<button className="button-text" onClick={incrementCount}>
<span aria-live="polite" aria-atomic="true">
{adultCount}
</span>
<button
className="button-text"
onClick={() => adjustCount(1)}
aria-label="성인 승객 증가"
disabled={adultCount === MAX_PASSENGERS}
>
+
</button>
</div>
</div>
<div
aria-live="polite"
aria-atomic="true"
ref={messageRef}
tabIndex={-1}
className="aria-hidden"
>
{message}
</div>
<button className="search-button">항공편 검색</button>
</div>
</section>
);
};

Expand Down
4 changes: 2 additions & 2 deletions a11y/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"moduleResolution": "Node",
// "allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
Expand Down
6 changes: 3 additions & 3 deletions a11y/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"lib": ["ESNext"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"moduleResolution": "Node",
// "allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
Expand Down
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",
},
});