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

[사전 미션 - 워밍업] - 소하(최소연) 미션 제출합니다. #34

Open
wants to merge 1 commit 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
86 changes: 49 additions & 37 deletions a11y/src/components/FlightBooking.css
Original file line number Diff line number Diff line change
@@ -1,63 +1,75 @@
.flight-booking {
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.flight-booking h2 {
margin-bottom: 16px;
margin-bottom: 16px;
}

.passenger-label {
display: flex;
align-items: center;
display: flex;
align-items: center;
}

.passenger-count {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}

.passenger-count span {
font-weight: 700;
font-weight: 700;
}

.counter {
display: flex;
align-items: center;
display: flex;
align-items: center;
}

.counter button {
width: 30px;
height: 30px;
border-radius: 16px;
border: 1px solid #C0C0C0;
background-color: #fff;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
width: 30px;
height: 30px;
border-radius: 16px;
border: 1px solid #c0c0c0;
background-color: #fff;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}

.counter span {
font-size: 18px;
text-align: center;
font-size: 18px;
font-style: normal;
font-weight: 500;
line-height: normal;
padding: 0 16px;
font-size: 18px;
text-align: center;
font-size: 18px;
font-style: normal;
font-weight: 500;
line-height: normal;
padding: 0 16px;
}

.search-button {
width: 100%;
padding: 10px;
background-color: #333;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
padding: 10px;
background-color: #333;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

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

import "./FlightBooking.css";
import './FlightBooking.css';

const MAX_PASSENGERS = 3;

const FlightBooking = () => {
const [adultCount, setAdultCount] = useState(1);

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

const decrementCount = () => {
setAdultCount((prev) => Math.max(1, prev - 1));
};

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}>
-
</button>
<span>{adultCount}</span>
<button className="button-text" onClick={incrementCount}>
+
</button>
</div>
</div>
<button className="search-button">항공편 검색</button>
</div>
);
const [adultCount, setAdultCount] = useState(1);
const [statusMessage, setStatusMessage] = useState('');

// const incrementCount = () => {
// setAdultCount((prev) => Math.min(MAX_PASSENGERS, prev + 1));
// };

// const decrementCount = () => {
// setAdultCount((prev) => Math.max(1, prev - 1));
// };

const incrementCount = () => {
if (adultCount === MAX_PASSENGERS) {
setStatusMessage('최대 승객 수에 도달했습니다');
return;
}

setAdultCount((prev) => Math.min(MAX_PASSENGERS, prev + 1));
};

const decrementCount = () => {
if (adultCount === 1) {
setStatusMessage('최소 1명의 승객이 필요합니다');
return;
}

setAdultCount((prev) => Math.max(1, prev - 1));
};

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="성인 승객 감소">
-
</button>
<span aria-live="polite">{adultCount}</span>
<button className="button-text" onClick={incrementCount} aria-label="성인 승객 증가">
+
</button>
</div>
</div>
{statusMessage && (
<div className="visually-hidden" role="alert">
{statusMessage}
</div>
)}
<button className="search-button">항공편 검색</button>
</div>
);
};

export default FlightBooking;