soapbox/app/soapbox/components/ui/layout/layout.tsx

65 wiersze
1.5 KiB
TypeScript
Czysty Zwykły widok Historia

2023-02-06 18:01:03 +00:00
import clsx from 'clsx';
2022-03-21 18:09:01 +00:00
import React from 'react';
import StickyBox from 'react-sticky-box';
2022-03-21 18:09:01 +00:00
2023-01-10 23:03:15 +00:00
interface ISidebar {
children: React.ReactNode
}
interface IAside {
children?: React.ReactNode
}
interface ILayout {
children: React.ReactNode
}
interface LayoutComponent extends React.FC<ILayout> {
Sidebar: React.FC<ISidebar>
Main: React.FC<React.HTMLAttributes<HTMLDivElement>>
Aside: React.FC<IAside>
2022-04-26 17:01:57 +00:00
}
/** Layout container, to hold Sidebar, Main, and Aside. */
const Layout: LayoutComponent = ({ children }) => (
2023-02-01 22:13:42 +00:00
<div className='relative sm:pt-4'>
<div className='mx-auto max-w-3xl sm:px-6 md:grid md:max-w-7xl md:grid-cols-12 md:gap-8 md:px-8'>
2022-03-21 18:09:01 +00:00
{children}
</div>
</div>
);
/** Left sidebar container in the UI. */
2023-01-10 23:03:15 +00:00
const Sidebar: React.FC<ISidebar> = ({ children }) => (
2023-02-01 22:13:42 +00:00
<div className='hidden lg:col-span-3 lg:block'>
<StickyBox offsetTop={80} className='pb-4'>
2022-03-21 18:09:01 +00:00
{children}
</StickyBox>
2022-03-21 18:09:01 +00:00
</div>
);
/** Center column container in the UI. */
const Main: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({ children, className }) => (
2022-03-21 18:09:01 +00:00
<main
2023-02-06 18:01:03 +00:00
className={clsx({
2022-06-04 20:58:41 +00:00
'md:col-span-12 lg:col-span-9 xl:col-span-6 pb-36': true,
}, className)}
2022-03-21 18:09:01 +00:00
>
{children}
</main>
);
/** Right sidebar container in the UI. */
2023-01-10 23:03:15 +00:00
const Aside: React.FC<IAside> = ({ children }) => (
2023-02-01 22:13:42 +00:00
<aside className='hidden xl:col-span-3 xl:block'>
<StickyBox offsetTop={80} className='space-y-6 pb-12'>
2022-03-21 18:09:01 +00:00
{children}
</StickyBox>
2022-03-21 18:09:01 +00:00
</aside>
);
Layout.Sidebar = Sidebar;
Layout.Main = Main;
Layout.Aside = Aside;
export default Layout;