-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor headers to favour composition over configuration
- Loading branch information
1 parent
6a9363a
commit 54e2cb5
Showing
11 changed files
with
115 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { OnboardingSelectors } from '@tests/selectors/onboarding.selectors'; | ||
import { Box } from 'leather-styles/jsx'; | ||
import { Box, BoxProps } from 'leather-styles/jsx'; | ||
|
||
import { Logo } from '@leather.io/ui'; | ||
|
||
import { RouteUrls } from '@shared/route-urls'; | ||
|
||
interface LogoBoxProps { | ||
isHomePage?: boolean; | ||
isSessionLocked?: boolean; | ||
interface LogoBoxProps extends BoxProps { | ||
onClick?(): void; | ||
} | ||
|
||
export function LogoBox({ isHomePage = false, isSessionLocked = false }: LogoBoxProps) { | ||
const navigate = useNavigate(); | ||
|
||
export function LogoBox({ onClick, ...props }: LogoBoxProps) { | ||
return ( | ||
<Box | ||
height="headerContainerHeight" | ||
margin="auto" | ||
px="space.02" | ||
// Logo must always appear on Home but disappear on ROUTE_URLS.UNLOCK large view | ||
hideBelow={isHomePage || isSessionLocked ? undefined : 'sm'} | ||
hideFrom={!isHomePage && isSessionLocked ? 'sm' : undefined} | ||
> | ||
<Logo | ||
data-testid={OnboardingSelectors.LogoRouteToHome} | ||
onClick={() => navigate(RouteUrls.Home)} | ||
/> | ||
<Box height="headerContainerHeight" margin="auto" px="space.02" hideBelow="sm" {...props}> | ||
<Logo data-testid={OnboardingSelectors.LogoRouteToHome} onClick={onClick} /> | ||
</Box> | ||
); | ||
} |
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,33 @@ | ||
import { useOutletContext } from 'react-router-dom'; | ||
|
||
import { SettingsSelectors } from '@tests/selectors/settings.selectors'; | ||
|
||
import { HamburgerIcon } from '@leather.io/ui'; | ||
|
||
import { SwitchAccountOutletContext } from '@shared/switch-account'; | ||
|
||
import { Header } from '@app/components/layout/headers/header'; | ||
import { HeaderGrid, HeaderGridRightCol } from '@app/components/layout/headers/header-grid'; | ||
import { LogoBox } from '@app/components/layout/headers/logo-box'; | ||
import { Settings } from '@app/features/settings/settings'; | ||
|
||
export function HomeHeader() { | ||
const { isShowingSwitchAccount, setIsShowingSwitchAccount } = | ||
useOutletContext<SwitchAccountOutletContext>(); | ||
|
||
return ( | ||
<Header paddingLeft={{ base: undefined, sm: 0 }}> | ||
<HeaderGrid | ||
leftCol={<LogoBox />} | ||
rightCol={ | ||
<HeaderGridRightCol> | ||
<Settings | ||
triggerButton={<HamburgerIcon data-testid={SettingsSelectors.SettingsMenuBtn} />} | ||
toggleSwitchAccount={() => setIsShowingSwitchAccount(!isShowingSwitchAccount)} | ||
/> | ||
</HeaderGridRightCol> | ||
} | ||
/> | ||
</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
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,53 @@ | ||
import { useNavigate, useOutletContext } from 'react-router-dom'; | ||
|
||
import { SettingsSelectors } from '@tests/selectors/settings.selectors'; | ||
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors'; | ||
|
||
import { ArrowLeftIcon, HamburgerIcon } from '@leather.io/ui'; | ||
|
||
import { RouteUrls } from '@shared/route-urls'; | ||
import { SwitchAccountOutletContext } from '@shared/switch-account'; | ||
|
||
import { Header } from '@app/components/layout/headers/header'; | ||
import { HeaderActionButton } from '@app/components/layout/headers/header-action-button'; | ||
import { HeaderGrid, HeaderGridRightCol } from '@app/components/layout/headers/header-grid'; | ||
import { LogoBox } from '@app/components/layout/headers/logo-box'; | ||
import { Settings } from '@app/features/settings/settings'; | ||
|
||
export function UnlockHeader() { | ||
const { isShowingSwitchAccount, setIsShowingSwitchAccount } = | ||
useOutletContext<SwitchAccountOutletContext>(); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<> | ||
<Header paddingLeft={{ base: undefined, sm: 0 }}> | ||
<HeaderGrid | ||
leftCol={ | ||
<> | ||
<HeaderActionButton | ||
icon={<ArrowLeftIcon />} | ||
onAction={() => navigate(-1)} | ||
dataTestId={SharedComponentsSelectors.HeaderBackBtn} | ||
/> | ||
|
||
<LogoBox | ||
onClick={() => navigate(RouteUrls.Home)} | ||
hideBelow={undefined} | ||
hideFrom="sm" | ||
/> | ||
</> | ||
} | ||
rightCol={ | ||
<HeaderGridRightCol> | ||
<Settings | ||
triggerButton={<HamburgerIcon data-testid={SettingsSelectors.SettingsMenuBtn} />} | ||
toggleSwitchAccount={() => setIsShowingSwitchAccount(!isShowingSwitchAccount)} | ||
/> | ||
</HeaderGridRightCol> | ||
} | ||
/> | ||
</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
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
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