import * as React from 'react'; import { cn } from '../lib/utils'; import { Separator } from '../shadcn/separator'; import { SidebarTrigger } from '../shadcn/sidebar'; import { If } from './if'; export type PageLayoutStyle = 'sidebar' | 'header' | 'custom'; type PageProps = React.PropsWithChildren<{ style?: PageLayoutStyle; contentContainerClassName?: string; className?: string; sticky?: boolean; }>; export function Page(props: PageProps) { switch (props.style) { case 'header': return ; case 'custom': return props.children; default: return ; } } function PageWithSidebar(props: PageProps) { const { Navigation, Children, MobileNavigation } = getSlotsFromPage(props); return (
{Navigation}
{MobileNavigation}
{Children}
); } export function PageMobileNavigation( props: React.PropsWithChildren<{ className?: string; }>, ) { return (
{props.children}
); } function PageWithHeader(props: PageProps) { const { Navigation, Children, MobileNavigation } = getSlotsFromPage(props); return (
{Navigation}
{MobileNavigation}
{Children}
); } export function PageBody( props: React.PropsWithChildren<{ className?: string; }>, ) { const className = cn( 'flex w-full flex-1 flex-col space-y-6', props.className, ); return
{props.children}
; } export function PageNavigation(props: React.PropsWithChildren) { return
{props.children}
; } export function PageDescription(props: React.PropsWithChildren) { return (
{props.children}
); } export function PageTitle(props: React.PropsWithChildren) { return (

{props.children}

); } export function PageHeaderActions(props: React.PropsWithChildren) { return
{props.children}
; } export function PageHeader({ children, title, description, className, displaySidebarTrigger = false, }: React.PropsWithChildren<{ className?: string; title?: string | React.ReactNode; description?: string | React.ReactNode; displaySidebarTrigger?: boolean; }>) { return (
{title}
{displaySidebarTrigger ? ( ) : null} {description}
{children}
); } function getSlotsFromPage(props: React.PropsWithChildren) { return React.Children.toArray(props.children).reduce<{ Children: React.ReactElement | null; Navigation: React.ReactElement | null; MobileNavigation: React.ReactElement | null; }>( (acc, child) => { if (!React.isValidElement(child)) { return acc; } if (child.type === PageNavigation) { return { ...acc, Navigation: child, }; } if (child.type === PageMobileNavigation) { return { ...acc, MobileNavigation: child, }; } return { ...acc, Children: child, }; }, { Children: null, Navigation: null, MobileNavigation: null, }, ); }