-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add Header component * chore: add preview code * fix: remove Flex component and change HeaderWrapper to have flex property * feat: dynamically change CenterElement tag based on content type * fix: narrow HeaderProps types to ReactElement or string * fix: convert styled components to object syntax * fix: manage z-index values using constants * fix: set height to 100% for child elements * fix: change interface naming
- Loading branch information
1 parent
0c37f4e
commit 251eda0
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { ReactElement } from "react"; | ||
import styled from "@emotion/styled"; | ||
import { Z_INDEX } from "../constants/zIndex"; | ||
|
||
interface HeaderProps { | ||
left?: ReactElement | string; | ||
center: ReactElement | string; | ||
right?: ReactElement | string; | ||
} | ||
|
||
function Header({ left, center, right }: HeaderProps) { | ||
return ( | ||
<HeaderWrapper aria-label="페이지 헤더"> | ||
<LeftElement>{left}</LeftElement> | ||
<CenterElement as={typeof center === "string" ? "h1" : "div"}> | ||
{center} | ||
</CenterElement> | ||
<RightElement>{right}</RightElement> | ||
</HeaderWrapper> | ||
); | ||
} | ||
|
||
export default Header; | ||
|
||
const HeaderWrapper = styled.header({ | ||
position: "sticky", | ||
zIndex: Z_INDEX.HEADER, | ||
top: 0, | ||
|
||
display: "flex", | ||
|
||
width: "100%", | ||
height: "4.8rem", | ||
|
||
backgroundColor: "white", | ||
}); | ||
|
||
const LeftElement = styled.div({ | ||
display: "flex", | ||
alignItems: "center", | ||
|
||
position: "absolute", | ||
left: "1.5rem", | ||
|
||
height: "100%", | ||
}); | ||
|
||
const CenterElement = styled.div({ | ||
display: "flex", | ||
alignItems: "center", | ||
|
||
margin: "0 auto", | ||
height: "100%", | ||
}); | ||
|
||
const RightElement = styled.div({ | ||
display: "flex", | ||
alignItems: "center", | ||
|
||
position: "absolute", | ||
right: "1.5rem", | ||
|
||
height: "100%", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const Z_INDEX = { | ||
MODAL: 1000, | ||
DROPDOWN: 100, | ||
HEADER: 10, | ||
} as const; |