feat: improve mobile board experience
This commit is contained in:
1 parent
bc57f9579d
commit
7c0e98c55b
46 files changed
+1455
-130
No files matched your search
@@ -6,25 +6,49 @@ import { Link } from "@homarr/ui";
|
||||
|
||||
import { ClientBurger } from "./header/burger";
|
||||
import { DesktopSearchInput, MobileSearchButton } from "./header/search";
|
||||
import { ResponsiveUserButton } from "./header/responsive-user";
|
||||
import { TourTarget } from "./header/tour-target";
|
||||
import { UserButton } from "./header/user";
|
||||
import { HomarrLogoWithTitle } from "./logo/homarr-logo";
|
||||
|
||||
interface Props {
|
||||
logo?: ReactNode;
|
||||
logoHref?: string | null;
|
||||
actions?: ReactNode;
|
||||
hasNavigation?: boolean;
|
||||
withSafeArea?: boolean;
|
||||
hideUserOnMobileBoard?: boolean;
|
||||
}
|
||||
|
||||
export const MainHeader = ({ logo, actions, hasNavigation = true }: Props) => {
|
||||
export const MainHeader = ({
|
||||
logo,
|
||||
logoHref = "/",
|
||||
actions,
|
||||
hasNavigation = true,
|
||||
withSafeArea = false,
|
||||
hideUserOnMobileBoard = false,
|
||||
}: Props) => {
|
||||
return (
|
||||
<AppShellHeader maw="100vw" zIndex={201} style={{ overflowX: "hidden" }}>
|
||||
<Group h="100%" gap="xl" px="md" justify="apart" wrap="nowrap">
|
||||
<AppShellHeader
|
||||
maw="100vw"
|
||||
zIndex={201}
|
||||
style={{
|
||||
overflowX: "hidden",
|
||||
paddingTop: withSafeArea ? "env(safe-area-inset-top)" : undefined,
|
||||
paddingRight: withSafeArea ? "env(safe-area-inset-right)" : undefined,
|
||||
paddingLeft: withSafeArea ? "env(safe-area-inset-left)" : undefined,
|
||||
}}
|
||||
>
|
||||
<Group h="100%" gap="md" px="md" justify="apart" wrap="nowrap">
|
||||
<Group h="100%" align="center" style={{ flex: 1 }} wrap="nowrap">
|
||||
{hasNavigation && <ClientBurger />}
|
||||
<UnstyledButton component={Link} href="/">
|
||||
{logo ?? <HomarrLogoWithTitle size="md" />}
|
||||
</UnstyledButton>
|
||||
{logoHref === null ? (
|
||||
(logo ?? <HomarrLogoWithTitle size="md" />)
|
||||
) : (
|
||||
<UnstyledButton component={Link} href={logoHref}>
|
||||
{logo ?? <HomarrLogoWithTitle size="md" />}
|
||||
</UnstyledButton>
|
||||
)}
|
||||
</Group>
|
||||
<TourTarget id="board-search">
|
||||
<DesktopSearchInput />
|
||||
@@ -32,9 +56,11 @@ export const MainHeader = ({ logo, actions, hasNavigation = true }: Props) => {
|
||||
<Group h="100%" align="center" justify="end" style={{ flex: 1 }} wrap="nowrap">
|
||||
{actions}
|
||||
<MobileSearchButton />
|
||||
<TourTarget id="board-user-menu">
|
||||
<UserButton />
|
||||
</TourTarget>
|
||||
<ResponsiveUserButton hideOnMobileBoard={hideUserOnMobileBoard}>
|
||||
<TourTarget id="board-user-menu">
|
||||
<UserButton />
|
||||
</TourTarget>
|
||||
</ResponsiveUserButton>
|
||||
</Group>
|
||||
</Group>
|
||||
<Spotlight />
|
||||
|
||||
@@ -20,7 +20,7 @@ const headerButtonActionIconProps: ActionIconProps = {
|
||||
variant: "subtle",
|
||||
style: { border: "none" },
|
||||
color: "gray",
|
||||
size: "lg",
|
||||
size: 44,
|
||||
};
|
||||
|
||||
export const HeaderButton = forwardRef<HTMLButtonElement, HeaderButtonProps>((props, ref) => {
|
||||
@@ -29,15 +29,15 @@ export const HeaderButton = forwardRef<HTMLButtonElement, HeaderButtonProps>((pr
|
||||
<ActionIcon
|
||||
ref={ref as ForwardedRef<HTMLAnchorElement>}
|
||||
component={Link}
|
||||
{...props}
|
||||
{...headerButtonActionIconProps}
|
||||
{...props}
|
||||
>
|
||||
{props.children}
|
||||
</ActionIcon>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<ActionIcon ref={ref} {...props} {...headerButtonActionIconProps}>
|
||||
<ActionIcon ref={ref} {...headerButtonActionIconProps} {...props}>
|
||||
{props.children}
|
||||
</ActionIcon>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import type { PropsWithChildren } from "react";
|
||||
|
||||
import { useIsMobileBoard } from "../../board/use-mobile-board";
|
||||
|
||||
export const ResponsiveUserButton = ({
|
||||
hideOnMobileBoard,
|
||||
children,
|
||||
}: PropsWithChildren<{ hideOnMobileBoard: boolean }>) => {
|
||||
const isMobileBoard = useIsMobileBoard();
|
||||
return hideOnMobileBoard && isMobileBoard ? null : children;
|
||||
};
|
||||
@@ -28,8 +28,10 @@ export const DesktopSearchInput = () => {
|
||||
};
|
||||
|
||||
export const MobileSearchButton = () => {
|
||||
const t = useI18n();
|
||||
|
||||
return (
|
||||
<HeaderButton onClick={openSpotlight} className={classes.mobileSearch}>
|
||||
<HeaderButton onClick={openSpotlight} className={classes.mobileSearch} aria-label={t("search.placeholder")}>
|
||||
<IconSearch size={20} stroke={1.5} />
|
||||
</HeaderButton>
|
||||
);
|
||||
|
||||
@@ -4,19 +4,20 @@ import { UnstyledButton } from "@mantine/core";
|
||||
import { api } from "@homarr/api/server";
|
||||
import { auth } from "@homarr/auth/next";
|
||||
import { env } from "@homarr/docker/env";
|
||||
import { getI18n } from "@homarr/translation/server";
|
||||
|
||||
import { CurrentUserAvatar } from "~/components/user-avatar";
|
||||
import { UserAvatarMenu } from "~/components/user-avatar-menu";
|
||||
import { UpdateIndicator } from "./update";
|
||||
|
||||
export const UserButton = async () => {
|
||||
const session = await auth();
|
||||
const [session, t] = await Promise.all([auth(), getI18n()]);
|
||||
const isAdmin = session?.user.permissions.includes("admin");
|
||||
const isDockerEnabled = isAdmin && env.ENABLE_DOCKER;
|
||||
const availableUpdatesPromise = isAdmin ? api.updateChecker.getAvailableUpdates() : undefined;
|
||||
return (
|
||||
<UserAvatarMenu availableUpdatesPromise={availableUpdatesPromise} isDockerEnabled={isDockerEnabled}>
|
||||
<UnstyledButton>
|
||||
<UnstyledButton aria-label={t("board.mobile.profile")}>
|
||||
<Suspense fallback={<CurrentUserAvatar size="md" />}>
|
||||
<UpdateIndicator availableUpdatesPromise={availableUpdatesPromise} disabled={!isAdmin}>
|
||||
<CurrentUserAvatar size="md" />
|
||||
|
||||
@@ -10,11 +10,13 @@ import { navigationCollapsedAtom } from "./header/burger";
|
||||
interface ClientShellProps {
|
||||
hasHeader?: boolean;
|
||||
hasNavigation?: boolean;
|
||||
withSafeArea?: boolean;
|
||||
}
|
||||
|
||||
export const ClientShell = ({
|
||||
hasHeader = true,
|
||||
hasNavigation = true,
|
||||
withSafeArea = false,
|
||||
children,
|
||||
}: PropsWithChildren<ClientShellProps>) => {
|
||||
const collapsed = useAtomValue(navigationCollapsedAtom);
|
||||
@@ -23,7 +25,7 @@ export const ClientShell = ({
|
||||
return (
|
||||
<AppShell
|
||||
{...backgroundProps}
|
||||
header={hasHeader ? { height: 60 } : undefined}
|
||||
header={hasHeader ? { height: withSafeArea ? "calc(60px + env(safe-area-inset-top))" : 60 } : undefined}
|
||||
navbar={
|
||||
hasNavigation
|
||||
? {
|
||||
|
||||
Reference in new issue
Block a user