diff --git a/src/components/AppLayout/index.stories.tsx b/src/components/AppLayout/index.stories.tsx index bb522740..da0d06f0 100644 --- a/src/components/AppLayout/index.stories.tsx +++ b/src/components/AppLayout/index.stories.tsx @@ -6,6 +6,7 @@ import { Text } from '../Text' import { Icon } from '../Icon' import { Button } from '../Button' import React, { useState } from 'react' +import { MoonshineConfigProvider } from '@/context/ConfigContext' type Story = StoryObj @@ -436,3 +437,57 @@ export const WithFullScreenSurface: Story = { ), } + +export const CustomExtraSidebarChildren: Story = { + name: 'Custom Extra Sidebar Children', + args: { + children: [ + + + + alert('Home')} + title="Home" + icon="house" + /> + + + + + + + + + + + + + , + + + + + Home + Settings + Users + + , + + + , + ], + }, + render: (args, context) => ( + + { + console.log('theme', theme) + }} + > + + + + ), +} diff --git a/src/components/AppLayout/index.tsx b/src/components/AppLayout/index.tsx index 74a0f325..1bcb242a 100644 --- a/src/components/AppLayout/index.tsx +++ b/src/components/AppLayout/index.tsx @@ -1,4 +1,4 @@ -import { cn } from '@/lib/utils' +import { cn, partitionBy } from '@/lib/utils' import React, { Children, isValidElement, @@ -21,6 +21,7 @@ import { import { Key } from '../KeyHint' import { useAppLayoutKeys } from './useAppLayoutKeys' import { IconName } from '../Icon/names' +import { ThemeSwitcher } from '../ThemeSwitcher' interface AppLayoutProps extends PropsWithChildren { className?: string @@ -57,7 +58,7 @@ const AppLayoutBase = ({ children, className }: AppLayoutProps) => { return (
@@ -116,7 +117,7 @@ interface AppLayoutSidebarProps { const AppLayoutSidebar = ({ children, className }: AppLayoutSidebarProps) => { const { collapsed } = useAppLayout() - const nav = Children.toArray(children).find((child) => { + const [nav, rest] = partitionBy(Children.toArray(children), (child) => { if (!isValidElement(child)) return false const type = child.type as { displayName?: string } return type.displayName === 'AppLayout.Nav' @@ -127,23 +128,41 @@ const AppLayoutSidebar = ({ children, className }: AppLayoutSidebarProps) => { initial={false} layout="position" className={cn( - 'mt-4 mr-9 ml-2 flex w-fit flex-col gap-4', + 'mt-4 flex w-fit flex-col items-start', className, - collapsed && 'mr-6' + !collapsed && 'mr-5' )} transition={{ duration: 0.25, type: 'spring', bounce: 0 }} > - {/* TODO: Gram will use a different logo so we need a way of making this dynamic */} - -
{nav}
+
+ {/* TODO: Gram will use a different logo so we need a way of making this dynamic */} + + {nav} +
+ {rest} ) } AppLayoutSidebar.displayName = 'AppLayout.Sidebar' +interface AppLayoutThemeSwitcherProps { + className?: string +} + +const AppLayoutThemeSwitcher = ({ className }: AppLayoutThemeSwitcherProps) => { + const { collapsed } = useAppLayout() + return ( + + + + ) +} + +AppLayoutThemeSwitcher.displayName = 'AppLayout.ThemeSwitcher' + interface AppLayoutBreadcrumbProps extends PropsWithChildren { className?: string } @@ -323,7 +342,7 @@ interface AppLayoutNavProps extends HTMLAttributes { const AppLayoutNav = ({ children, className, ...props }: AppLayoutNavProps) => { return ( -