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;
|
2023-03-20 12:06:33 +00:00
|
|
|
withoutBorder?: boolean;
|
2023-04-12 07:11:11 +00:00
|
|
|
isAlignToRight?: boolean;
|
2023-02-28 15:19:56 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 08:57:18 +00:00
|
|
|
export const Root: React.FC<PropsWithChildren<TopNavProps>> = ({
|
2023-02-28 15:19:56 +00:00
|
|
|
title,
|
|
|
|
href,
|
2023-03-20 12:06:33 +00:00
|
|
|
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 (
|
2023-03-20 12:06:33 +00:00
|
|
|
<TopNavWrapper withoutBorder={withoutBorder}>
|
2023-02-28 15:19:56 +00:00
|
|
|
{href && <TopNavLink to={href} />}
|
2023-07-04 07:27:17 +00:00
|
|
|
<Box __flex={isAlignToRight ? 1 : 0} __minWidth="max-content">
|
2023-04-12 07:11:11 +00:00
|
|
|
<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>
|
|
|
|
);
|
|
|
|
};
|