Skip to content

Commit

Permalink
fix: make headers more composable, prevent logo hover, closes leather…
Browse files Browse the repository at this point in the history
…-io/issues#4597
  • Loading branch information
pete-watters committed Aug 21, 2024
1 parent 63dffd4 commit 053bc83
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 52 deletions.
32 changes: 7 additions & 25 deletions src/app/components/layout/headers/logo-box.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import { useLocation, 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';

export function LogoBox({ isSessionLocked }: { isSessionLocked?: boolean | undefined }) {
const navigate = useNavigate();
const location = useLocation();

const shouldShowLogo =
location.pathname === RouteUrls.Home || location.pathname === RouteUrls.Activity;

const hideBelow = shouldShowLogo ? undefined : isSessionLocked ? undefined : 'sm';
const hideFrom = shouldShowLogo ? undefined : isSessionLocked ? 'sm' : undefined;
interface LogoBoxProps extends BoxProps {
onClick?(): void;
}

export function LogoBox({ onClick, ...props }: LogoBoxProps) {
return (
<Box
height="headerContainerHeight"
margin="auto"
px="space.02"
hideBelow={hideBelow}
hideFrom={hideFrom}
>
<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>
);
}
33 changes: 33 additions & 0 deletions src/app/features/container/headers/home.header.tsx
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 hideBelow={undefined} />}
rightCol={
<HeaderGridRightCol>
<Settings
triggerButton={<HamburgerIcon data-testid={SettingsSelectors.SettingsMenuBtn} />}
toggleSwitchAccount={() => setIsShowingSwitchAccount(!isShowingSwitchAccount)}
/>
</HeaderGridRightCol>
}
/>
</Header>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SharedComponentsSelectors } from '@tests/selectors/shared-component.sel

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';
Expand All @@ -13,29 +14,27 @@ import { HeaderGrid, HeaderGridRightCol } from '@app/components/layout/headers/h
import { LogoBox } from '@app/components/layout/headers/logo-box';
import { Settings } from '@app/features/settings/settings';

interface MainHeaderProps {
hideBackButton?: boolean;
interface OnboardingHeaderProps {
hideLogo?: boolean;
}

export function MainHeader({ hideBackButton = false, hideLogo = false }: MainHeaderProps) {
export function OnboardingHeader({ hideLogo = false }: OnboardingHeaderProps) {
const { isShowingSwitchAccount, setIsShowingSwitchAccount } =
useOutletContext<SwitchAccountOutletContext>();
const navigate = useNavigate();

return (
<>
<Header paddingLeft={{ base: undefined, sm: 0 }}>
<HeaderGrid
leftCol={
<>
{!hideBackButton && (
<HeaderActionButton
icon={<ArrowLeftIcon />}
onAction={() => navigate(-1)}
dataTestId={SharedComponentsSelectors.HeaderBackBtn}
/>
)}
{!hideLogo && <LogoBox />}
<HeaderActionButton
icon={<ArrowLeftIcon />}
onAction={() => navigate(-1)}
dataTestId={SharedComponentsSelectors.HeaderBackBtn}
/>
{!hideLogo && <LogoBox onClick={() => navigate(RouteUrls.Home)} />}
</>
}
rightCol={
Expand Down
6 changes: 3 additions & 3 deletions src/app/features/container/headers/page.header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ interface PageHeaderProps {

export function PageHeader({
title,
isSummaryPage,
isSessionLocked,
isSummaryPage = false,
isSessionLocked = false,
isSettingsVisibleOnSm = true,
onBackLocation,
}: PageHeaderProps) {
Expand All @@ -52,7 +52,7 @@ export function PageHeader({
dataTestId={SharedComponentsSelectors.HeaderBackBtn}
/>
)}
<LogoBox isSessionLocked={isSessionLocked} />
<LogoBox onClick={() => navigate(RouteUrls.Home)} />
</>
}
centerCol={title && <styled.span textStyle="heading.05">{title}</styled.span>}
Expand Down
53 changes: 53 additions & 0 deletions src/app/features/container/headers/unlock.header.tsx
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>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EyeSlashIcon, KeyIcon, LockIcon } from '@leather.io/ui';
import { RouteUrls } from '@shared/route-urls';

import { Content, TwoColumnLayout } from '@app/components/layout';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { SecretKey } from '@app/features/secret-key-displayer/secret-key-displayer';
import { useDefaultWalletSecretKey } from '@app/store/in-memory-key/in-memory-key.selectors';

Expand All @@ -24,7 +24,7 @@ export const BackUpSecretKeyPage = memo(() => {

return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<TwoColumnLayout
title="Back up your Secret Key"
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/onboarding/set-password/set-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
validatePassword,
} from '@app/common/validation/validate-password';
import { Content, TwoColumnLayout } from '@app/components/layout';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { OnboardingGate } from '@app/routes/onboarding-gate';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

Expand Down Expand Up @@ -111,7 +111,7 @@ function SetPasswordPage() {
});
return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<Formik
initialValues={setPasswordFormValues}
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/onboarding/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from '@leather.io/ui';
import { createNullArrayOfLength } from '@leather.io/utils';

import { Content, TwoColumnLayout } from '@app/components/layout';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { MnemonicForm } from '@app/pages/onboarding/sign-in/mnemonic-form';

export function SignIn() {
Expand All @@ -20,7 +20,7 @@ export function SignIn() {

return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<TwoColumnLayout
title={
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/unlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Outlet, useNavigate } from 'react-router-dom';

import { Content } from '@app/components/layout';
import { RequestPassword } from '@app/components/request-password';
import { PageHeader } from '@app/features/container/headers/page.header';
import { UnlockHeader } from '@app/features/container/headers/unlock.header';

export function Unlock() {
const navigate = useNavigate();
Expand All @@ -12,7 +12,7 @@ export function Unlock() {

return (
<>
<PageHeader isSessionLocked />
<UnlockHeader />
<Content>
<RequestPassword onSuccess={returnToPreviousRoute} />
<Outlet />
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/view-secret-key/view-secret-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { analytics } from '@shared/utils/analytics';

import { Content, TwoColumnLayout } from '@app/components/layout';
import { RequestPassword } from '@app/components/request-password';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { SecretKey } from '@app/features/secret-key-displayer/secret-key-displayer';
import { useDefaultWalletSecretKey } from '@app/store/in-memory-key/in-memory-key.selectors';

Expand All @@ -20,7 +20,7 @@ export function ViewSecretKey() {
if (showSecretKey) {
return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<TwoColumnLayout
title={
Expand All @@ -46,7 +46,7 @@ export function ViewSecretKey() {

return (
<>
<MainHeader hideLogo />
<OnboardingHeader hideLogo />
<Content>
<RequestPassword onSuccess={() => setShowSecretKey(true)} />
<Outlet />
Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SwitchAccountLayout } from '@app/components/layout/layouts/switch-accou
import { LoadingSpinner } from '@app/components/loading-spinner';
import { AddNetwork } from '@app/features/add-network/add-network';
import { Container } from '@app/features/container/container';
import { MainHeader } from '@app/features/container/headers/main.header';
import { HomeHeader } from '@app/features/container/headers/home.header';
import { IncreaseBtcFeeDialog } from '@app/features/dialogs/increase-fee-dialog/increase-btc-fee-dialog';
import { IncreaseStxFeeDialog } from '@app/features/dialogs/increase-fee-dialog/increase-stx-fee-dialog';
import { leatherIntroDialogRoutes } from '@app/features/dialogs/leather-intro-dialog/leather-intro-dialog';
Expand Down Expand Up @@ -82,7 +82,7 @@ function useAppRoutes() {
<Route
element={
<>
<MainHeader hideBackButton />
<HomeHeader />
<Content>
<SwitchAccountLayout />
</Content>
Expand Down

0 comments on commit 053bc83

Please sign in to comment.