Skip to content

Feat: 헤더 컴포넌트 인터페이스 추가 구현 - #34

Merged
Yeonseo-Jo merged 6 commits into
mainfrom
feat/#33-refac-header
Aug 27, 2025
Merged

Feat: 헤더 컴포넌트 인터페이스 추가 구현#34
Yeonseo-Jo merged 6 commits into
mainfrom
feat/#33-refac-header

Conversation

@Yeonseo-Jo

@Yeonseo-Jo Yeonseo-Jo commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

close #33

☑️ 완료 태스크

  • Header 컴포넌트 default 동작 적용
  • 추가 커스터마이징을 위한 인터페이스 적용
  • Header Wrapper boxShadow 추가

🔎 PR 내용

Header 컴포넌트의 인터페이스를 완전히 리팩토링하여 더 유연하고 직관적인 사용이 가능하도록 개선했습니다.

기존 인터페이스:

<Header left="왼쪽" center="중앙" right="오른쪽" />

새로운 인터페이스:

// 우선순위: render* > backButton, title > 기본 뒤로가기 버튼

// 1. 기본 사용 (제목/  뒤로가기 버튼)
<Header title="홈" />
-> backButton / renderLeft prop이 없을시 default Icon(`ChevronLeftIcon`), default click event handler(`navigate -1`) 적용됩니다

// 2. 백 버튼 커스터마이징 - backButton에 들어갈 UI(ex. 아이콘)이나 event handler를 커스터마이징 할 때
<Header title="설정" backButton={{ onClick: () => navigate('/') }} />

// 3. 섹션별 완전 커스터마이징 - left, center, right 섹션을 각각 커스터마이징 할 때
<Header renderCenter={() => <SearchBar />} />

📷 스크린샷

@Yeonseo-Jo Yeonseo-Jo self-assigned this Jul 6, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the Header component to introduce a more flexible interface with customizable back button and section renderers, applies default styling updates, and updates dependent usage and dependencies.

  • Replaces left, center, right props with backButton, title, and renderLeft/renderCenter/renderRight callbacks
  • Implements default back-button behavior using React Router’s useNavigate and adds box-shadow style
  • Updates menu page to use new title prop and bumps @radix-ui/react-icons dependency

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/common/components/Header.tsx Refactored props, added back button logic, default styles
src/Menu/page.tsx Updated Header usage to the new interface
package.json Added @radix-ui/react-icons dependency and formatted lint-staged config
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

src/common/components/Header.tsx:70

  • Typo in function name renderCentnerElement; rename to renderCenterElement for consistency and clarity.
  const renderCentnerElement = () => renderCenter && <CenterElement as="div">{renderCenter()}</CenterElement>;

src/common/components/Header.tsx:47

  • [nitpick] Consider adding unit tests for renderBackButton to cover default navigation, custom onClick, and custom renderIcon scenarios.
  const renderBackButton = () => {

};

return (
<button type="button" onClick={onClickBackButton}>

Copilot AI Jul 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an accessible name (e.g., aria-label="뒤로가기") to the back button so screen readers can identify its purpose.

Suggested change
<button type="button" onClick={onClickBackButton}>
<button
type="button"
onClick={onClickBackButton}
aria-label={backButton?.ariaLabel || "뒤로가기"} // Default accessible name
>

Copilot uses AI. Check for mistakes.

const renderBackButton = () => {
const onClickBackButton = () => {
if (backButton && "onClick" in backButton && backButton.onClick) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"onClick" in backButton // backButton에 onClick prop이 있는지 확인
backButton.onClick // onClick에 nullish한 값이 들어오지는 않았는지 검증 용도

연서한테 구두로 설명받았습니다~!

Comment thread src/common/components/Header.tsx Outdated
<CenterElement as={typeof center === "string" ? "h1" : "div"}>{center}</CenterElement>
<RightElement>{right}</RightElement>
<LeftElement>{renderLeft?.() ?? renderBackButton()}</LeftElement>
{renderCenterElement() || renderTitleElement()}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요기는 ?? 대신 || 사용해준 이유가 있는지 궁금해요!!!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??가 더 적절하겠네유 수정했습니당!

@Yeonseo-Jo
Yeonseo-Jo requested a review from jungwoo3490 August 17, 2025 13:20

@jungwoo3490 jungwoo3490 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙌🏻

@Yeonseo-Jo
Yeonseo-Jo merged commit 10bbbc8 into main Aug 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Header 컴포넌트 인터페이스 수정

4 participants