Browse Source

Make TopBar optional in some layouts

The existence of the TopBar widget depends on some props related to it.
master
TheoryOfNekomata 3 years ago
parent
commit
642192f4ac
6 changed files with 79 additions and 31 deletions
  1. +15
    -6
      src/layouts/Basic/index.tsx
  2. +16
    -6
      src/layouts/BasicNarrow/index.tsx
  3. +1
    -1
      src/layouts/LeftSidebar/index.tsx
  4. +18
    -8
      src/layouts/LeftSidebarWithMenu/index.tsx
  5. +16
    -7
      src/layouts/RightSidebarStatic/index.tsx
  6. +13
    -3
      src/widgets/TopBar/index.tsx

+ 15
- 6
src/layouts/Basic/index.tsx View File

@@ -34,12 +34,21 @@ export const Layout: React.FC<Props> = ({
return ( return (
<> <>
<Config /> <Config />
<TopBar
brand={brand}
userLink={userLink}
>
{topBarCenter}
</TopBar>
{
(
brand
|| userLink
|| topBarCenter
)
&& (
<TopBar
brand={brand}
userLink={userLink}
>
{topBarCenter}
</TopBar>
)
}
<ContentBase> <ContentBase>
{children} {children}
</ContentBase> </ContentBase>


+ 16
- 6
src/layouts/BasicNarrow/index.tsx View File

@@ -34,12 +34,22 @@ export const Layout: React.FC<Props> = ({
return ( return (
<> <>
<Config /> <Config />
<TopBar
brand={brand}
userLink={userLink}
>
{topBarCenter}
</TopBar>
{
(
brand
|| userLink
|| topBarCenter
)
&& (
<TopBar
span="narrow"
brand={brand}
userLink={userLink}
>
{topBarCenter}
</TopBar>
)
}
<ContentBase> <ContentBase>
{children} {children}
</ContentBase> </ContentBase>


+ 1
- 1
src/layouts/LeftSidebar/index.tsx View File

@@ -108,7 +108,7 @@ export const Layout: React.FC<Props> = ({
) )
} }
<TopBar <TopBar
wide
span="wide"
brand={brand} brand={brand}
menuLink={menuLink} menuLink={menuLink}
userLink={userLink} userLink={userLink}


+ 18
- 8
src/layouts/LeftSidebarWithMenu/index.tsx View File

@@ -350,14 +350,24 @@ export const Layout: React.FC<Props> = ({
) )
} }
<> <>
<TopBar
wide
brand={brand}
menuLink={sidebarMain ? menuLink : undefined}
userLink={userLink}
>
{topBarCenter}
</TopBar>
{
(
brand
|| userLink
|| topBarCenter
|| sidebarMain
)
&& (
<TopBar
span="wide"
brand={brand}
menuLink={sidebarMain ? menuLink : undefined}
userLink={userLink}
>
{topBarCenter}
</TopBar>
)
}
<SidebarBase> <SidebarBase>
<SidebarMenu> <SidebarMenu>
<SidebarMenuSize> <SidebarMenuSize>


+ 16
- 7
src/layouts/RightSidebarStatic/index.tsx View File

@@ -75,13 +75,22 @@ export const Layout: React.FC<Props> = ({
return ( return (
<> <>
<Config /> <Config />
<TopBar
wide
brand={brand}
userLink={userLink}
>
{topBarCenter}
</TopBar>
{
(
brand
|| userLink
|| topBarCenter
)
&& (
<TopBar
span="wide"
brand={brand}
userLink={userLink}
>
{topBarCenter}
</TopBar>
)
}
<ContentBase> <ContentBase>
{children} {children}
</ContentBase> </ContentBase>


+ 13
- 3
src/widgets/TopBar/index.tsx View File

@@ -35,6 +35,10 @@ const Container = styled('div')({
alignItems: 'center', alignItems: 'center',
}) })


const NarrowContainer = styled(Container)({
maxWidth: configVar('base-width'),
})

const WideContainer = styled(Container)({ const WideContainer = styled(Container)({
...minWidthFactor(3)({ ...minWidthFactor(3)({
maxWidth: `calc(${configVar('base-width')} * 3)`, maxWidth: `calc(${configVar('base-width')} * 3)`,
@@ -82,21 +86,27 @@ const MenuLinkContainer = styled(LinkContainer)({
}), }),
}) })


const CONTAINER_COMPONENTS = {
narrow: NarrowContainer,
normal: Container,
wide: WideContainer,
}

type Props = { type Props = {
wide?: boolean,
span?: keyof typeof CONTAINER_COMPONENTS,
brand?: React.ReactNode, brand?: React.ReactNode,
menuLink?: React.ReactNode, menuLink?: React.ReactNode,
userLink?: React.ReactNode, userLink?: React.ReactNode,
} }


const TopBar: React.FC<Props> = ({ const TopBar: React.FC<Props> = ({
wide,
span = 'normal',
brand, brand,
menuLink, menuLink,
userLink, userLink,
children, children,
}) => { }) => {
const ContainerComponent = wide ? WideContainer : Container
const { [span as keyof typeof CONTAINER_COMPONENTS]: ContainerComponent = Container } = CONTAINER_COMPONENTS
return ( return (
<Base> <Base>
<ContainerComponent> <ContainerComponent>


Loading…
Cancel
Save