-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
591 additions
and
221 deletions.
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
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,21 @@ | ||
import { createThemeContract, style } from '@vanilla-extract/css'; | ||
|
||
import { HEADER_Z_INDEX } from '../constants'; | ||
|
||
export const styleVar = createThemeContract({ | ||
display: null, | ||
background: null, | ||
}); | ||
|
||
export const container = style({ | ||
position: 'fixed', | ||
top: 0, | ||
zIndex: HEADER_Z_INDEX, | ||
display: `${styleVar.display}`, | ||
width: '100%', | ||
background: `${styleVar.background}`, | ||
}); | ||
|
||
export const headerContainer = style({ | ||
padding: '0.8rem 2rem !important', | ||
}); |
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,46 @@ | ||
'use client'; | ||
|
||
import { useIsScrollOver } from '@linker/react'; | ||
import { colors } from '@linker/styles'; | ||
import { assignInlineVars } from '@vanilla-extract/dynamic'; | ||
import clsx from 'clsx'; | ||
import { ReactNode, forwardRef } from 'react'; | ||
|
||
import { container, styleVar, headerContainer } from './FixedHeader.css'; | ||
import Header from './Header'; | ||
import { HEADER_HEIGHT_NUMBER, TAB_HEIGHT_NUMBER } from '../constants'; | ||
|
||
interface HeaderProps { | ||
children: ReactNode; | ||
leftAddon?: ReactNode; | ||
rightAddon?: ReactNode; | ||
className?: string; | ||
bgColor?: string; | ||
scrollOver?: number; | ||
} | ||
|
||
const MINIMIZE_SCROLL = HEADER_HEIGHT_NUMBER + TAB_HEIGHT_NUMBER + 15; | ||
|
||
const FixedHeader = forwardRef<HTMLDivElement, HeaderProps>( | ||
({ children, leftAddon, rightAddon, className, bgColor, scrollOver = 0 }: HeaderProps, ref) => { | ||
const isScrollOver = useIsScrollOver(MINIMIZE_SCROLL + scrollOver ?? MINIMIZE_SCROLL); | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
aria-hidden | ||
className={clsx(container, className)} | ||
style={assignInlineVars(styleVar, { | ||
display: isScrollOver ? 'block' : 'none', | ||
background: bgColor ?? colors.gradationBlue, | ||
})} | ||
> | ||
<Header leftAddon={leftAddon} rightAddon={rightAddon} className={headerContainer} /> | ||
|
||
{children} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export default FixedHeader; |
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,18 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
import { HEADER_HEIGHT } from '../constants'; | ||
|
||
export const headerContainer = style({ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
maxWidth: '72rem', | ||
height: HEADER_HEIGHT, | ||
margin: '0 auto', | ||
padding: '1.4rem 2rem', | ||
}); | ||
|
||
export const rightItem = style({ | ||
display: 'flex', | ||
gap: '1rem', | ||
}); |
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,32 @@ | ||
'use client'; | ||
|
||
import clsx from 'clsx'; | ||
import Link from 'next/link'; | ||
|
||
import { Logo } from '@linker/lds'; | ||
|
||
import { headerContainer, rightItem } from './Header.css'; | ||
|
||
interface Props { | ||
leftAddon?: React.ReactNode; | ||
rightAddon?: React.ReactNode; | ||
className?: string; | ||
} | ||
|
||
const Header = ({ leftAddon, rightAddon, className }: Props) => { | ||
return ( | ||
<header className={clsx(headerContainer, className)}> | ||
{leftAddon ? ( | ||
<>{leftAddon}</> | ||
) : ( | ||
<Link href="/my/feed"> | ||
<Logo /> | ||
</Link> | ||
)} | ||
|
||
<div className={rightItem}>{rightAddon}</div> | ||
</header> | ||
); | ||
}; | ||
|
||
export default Header; |
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,2 @@ | ||
export { default as Header } from './Header'; | ||
export { default as HeaderFixed } from './FixedHeader'; |
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
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,17 @@ | ||
import Image from 'next/image'; | ||
|
||
const Logo = () => { | ||
return ( | ||
<Image | ||
src="https://static.im-linker.com/icons/logo.svg" | ||
blurDataURL="https://static.im-linker.com/icons/logo.svg" | ||
alt="Linker ogo" | ||
width={72} | ||
height={24} | ||
priority | ||
placeholder="blur" | ||
/> | ||
); | ||
}; | ||
|
||
export default Logo; |
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,31 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
import { recipe } from '@vanilla-extract/recipes'; | ||
|
||
export const profile = style({ | ||
objectFit: 'contain', | ||
borderRadius: '2.4rem', | ||
export const profile = recipe({ | ||
base: { | ||
objectFit: 'contain', | ||
}, | ||
|
||
variants: { | ||
size: { | ||
small: { | ||
borderRadius: '1.2rem', | ||
}, | ||
medium: { | ||
borderRadius: '1.2rem', | ||
}, | ||
large: { | ||
borderRadius: '2.4rem', | ||
}, | ||
xLarge: { | ||
borderRadius: '2.4rem', | ||
}, | ||
xxLarge: { | ||
borderRadius: '2.4rem', | ||
}, | ||
}, | ||
}, | ||
|
||
defaultVariants: { | ||
size: 'large', | ||
}, | ||
}); |
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
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 |
---|---|---|
@@ -1,2 +1,11 @@ | ||
/** z-index */ | ||
export const HEADER_Z_INDEX = 1; | ||
export const DIALOG_Z_INDEX = 10; | ||
export const MODAL_Z_INDEX = 1000; | ||
export const FAB_Z_INDEX = 100; | ||
|
||
/** height */ | ||
export const HEADER_HEIGHT = '5.2rem'; | ||
export const HEADER_HEIGHT_NUMBER = 52; | ||
export const TAB_HEIGHT = '3.6rem'; | ||
export const TAB_HEIGHT_NUMBER = 36; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { createContext } from './createContext'; | ||
export { useBodyScrollLock } from './useBodyScrollLock'; | ||
export { useIsClient } from './useIsClient'; | ||
export { useIsScrollOver } from './useIsScrollOver'; |
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 @@ | ||
export { default as useIsScrollOver } from './useIsScrollOver'; |
48 changes: 48 additions & 0 deletions
48
packages/react/src/useIsScrollOver/useIsScorllOver.test.ts
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,48 @@ | ||
import { fireEvent } from '@testing-library/dom'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import useIsScrollOver from './useIsScrollOver'; | ||
|
||
describe('useIsScrollOver', () => { | ||
test('스크롤을 하면 true를 반환한다.', () => { | ||
const { result } = renderHook(() => useIsScrollOver()); | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 100 } }); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
test('스크롤 위치가 인수값을 넘지 않으면 false를 반환한다.', () => { | ||
const { result } = renderHook(() => useIsScrollOver(50)); | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 37 } }); | ||
|
||
expect(result.current).toBe(false); | ||
}); | ||
|
||
test('스크롤 위치가 인수값을 넘으면 true를 반환한다.', () => { | ||
const { result } = renderHook(() => useIsScrollOver(50)); | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 328 } }); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
test('true를 반환한 이후에 인수값보다 스크롤 위치가 작아지지 않으면 호출하지 않는다.', () => { | ||
const { result, unmount } = renderHook(() => useIsScrollOver(50)); | ||
|
||
const spyAdd = jest.spyOn(window, 'addEventListener'); | ||
const spyRemove = jest.spyOn(window, 'removeEventListener'); | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 328 } }); | ||
|
||
unmount(); | ||
|
||
expect(result.current).toBe(true); | ||
expect(spyRemove).toHaveBeenCalledWith('scroll', expect.any(Function)); | ||
|
||
fireEvent.scroll(window, { target: { scrollY: 167 } }); | ||
|
||
expect(spyAdd).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.