saleor-dashboard/src/components/AppLayout/TopNav/Root.tsx

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-02-28 15:19:56 +00:00
import { Box, Text } from "@saleor/macaw-ui/next";
import React, { PropsWithChildren } from "react";
import useAppChannel from "../AppChannelContext";
import AppChannelSelect from "../AppChannelSelect";
import { TopNavLink } from "./TopNavLink";
import { TopNavWrapper } from "./TopNavWrapper";
interface TopNavProps {
title: string | React.ReactNode;
href?: string;
withoutBorder?: boolean;
2023-04-12 07:11:11 +00:00
isAlignToRight?: boolean;
2023-02-28 15:19:56 +00:00
}
export const Root: React.FC<PropsWithChildren<TopNavProps>> = ({
2023-02-28 15:19:56 +00:00
title,
href,
withoutBorder = false,
2023-04-12 07:11:11 +00:00
isAlignToRight = true,
2023-02-28 15:19:56 +00:00
children,
}) => {
const { availableChannels, channel, isPickerActive, setChannel } =
useAppChannel(false);
return (
<TopNavWrapper withoutBorder={withoutBorder}>
2023-02-28 15:19:56 +00:00
{href && <TopNavLink to={href} />}
2023-04-12 07:11:11 +00:00
<Box __flex={isAlignToRight ? 1 : 0}>
<Text variant="title" size="small">
{title}
</Text>
2023-02-28 15:19:56 +00:00
</Box>
2023-04-12 07:11:11 +00:00
<Box
display="flex"
flexWrap="nowrap"
__flex={isAlignToRight ? "initial" : 1}
>
2023-02-28 15:19:56 +00:00
{isPickerActive && (
<AppChannelSelect
channels={availableChannels}
selectedChannelId={channel?.id}
onChannelSelect={setChannel}
/>
)}
{children}
</Box>
</TopNavWrapper>
);
};