From 87a09b8455387bd4a1c1abb45058638fa4fe10c8 Mon Sep 17 00:00:00 2001 From: Adam Bull Date: Mon, 11 Aug 2025 10:35:57 +0100 Subject: [PATCH 1/2] fix: app layout sidebar --- src/components/AppLayout/index.stories.tsx | 55 ++++++++++++++++++++++ src/components/AppLayout/index.tsx | 54 ++++++++++++++------- src/components/ThemeSwitcher/index.tsx | 35 ++++++++++++-- 3 files changed, 123 insertions(+), 21 deletions(-) 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..6381d4cc 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' @@ -126,24 +127,45 @@ const AppLayoutSidebar = ({ children, className }: AppLayoutSidebarProps) => { - {/* 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 +345,7 @@ interface AppLayoutNavProps extends HTMLAttributes { const AppLayoutNav = ({ children, className, ...props }: AppLayoutNavProps) => { return ( -