Skip to content

Commit

Permalink
Merge pull request #10542 from marmelab/bw-menu-closed
Browse files Browse the repository at this point in the history
Fix collapsed menu in B&W theme
  • Loading branch information
slax57 authored Feb 25, 2025
2 parents 23366b5 + 75cf474 commit c3d60d4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
6 changes: 5 additions & 1 deletion examples/demo/src/layout/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as React from 'react';
import { useState } from 'react';
import { Box } from '@mui/material';
import LabelIcon from '@mui/icons-material/Label';

import {
useTranslate,
DashboardMenuItem,
MenuItemLink,
MenuProps,
useSidebarState,
} from 'react-admin';
import clsx from 'clsx';

import visitors from '../visitors';
import orders from '../orders';
Expand Down Expand Up @@ -46,6 +46,10 @@ const Menu = ({ dense = false }: MenuProps) => {
duration: theme.transitions.duration.leavingScreen,
}),
}}
className={clsx({
'RaMenu-open': open,
'RaMenu-closed': !open,
})}
>
<DashboardMenuItem />
<SubMenu
Expand Down
1 change: 1 addition & 0 deletions examples/demo/src/layout/SubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const SubMenu = (props: Props) => {
dense={dense}
component="div"
disablePadding
className="SubMenu"
sx={{
'& .MuiMenuItem-root': {
transition:
Expand Down
31 changes: 30 additions & 1 deletion examples/demo/src/themes/themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,39 @@ export interface Theme {
dark?: RaThemeOptions;
}

const BW_SIDEBAR_OVERRIDE = {
styleOverrides: {
root: {
'& .SubMenu .MuiMenuItem-root': {
paddingLeft: 24,
},
'& .RaMenu-closed .SubMenu .MuiMenuItem-root': {
paddingLeft: 8,
},
},
},
};

export const themes: Theme[] = [
{ name: 'soft', light: softLightTheme, dark: softDarkTheme },
{ name: 'default', light: defaultLightTheme, dark: defaultDarkTheme },
{ name: 'B&W', light: bwLightTheme, dark: bwDarkTheme },
{
name: 'B&W',
light: {
...bwLightTheme,
components: {
...bwLightTheme.components,
RaSidebar: BW_SIDEBAR_OVERRIDE,
},
},
dark: {
...bwDarkTheme,
components: {
...bwDarkTheme.components,
RaSidebar: BW_SIDEBAR_OVERRIDE,
},
},
},
{ name: 'nano', light: nanoLightTheme, dark: nanoDarkTheme },
{ name: 'radiant', light: radiantLightTheme, dark: radiantDarkTheme },
{ name: 'house', light: houseLightTheme, dark: houseDarkTheme },
Expand Down
13 changes: 10 additions & 3 deletions packages/ra-ui-materialui/src/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import clsx from 'clsx';
import { ReactElement } from 'react';
import {
Drawer,
Expand Down Expand Up @@ -40,9 +41,12 @@ export const Sidebar = (props: SidebarProps) => {
open={open}
onClose={toggleSidebar}
classes={SidebarClasses}
className={
trigger && !appBarAlwaysOn ? SidebarClasses.appBarCollapsed : ''
}
className={clsx(
trigger && !appBarAlwaysOn
? SidebarClasses.appBarCollapsed
: '',
open ? OPEN_CLASS : CLOSED_CLASS
)}
{...rest}
>
<div className={SidebarClasses.fixed}>{children}</div>
Expand Down Expand Up @@ -75,6 +79,9 @@ export const SidebarClasses = {
appBarCollapsed: `${PREFIX}-appBarCollapsed`,
};

const OPEN_CLASS = `${PREFIX}-open`;
const CLOSED_CLASS = `${PREFIX}-closed`;

const StyledDrawer = styled(Drawer, {
name: PREFIX,
slot: 'Root',
Expand Down
6 changes: 5 additions & 1 deletion packages/ra-ui-materialui/src/theme/bwTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ const createBWTheme = (mode: 'light' | 'dark'): RaThemeOptions => {
root: {
margin: `0 ${SPACING}px`,
paddingRight: 0,
paddingLeft: SPACING,
borderRadius: 5,
color: isDarkMode ? grey['200'] : common['black'],
'&.RaMenuItemLink-active': {
Expand All @@ -351,13 +352,16 @@ const createBWTheme = (mode: 'light' | 'dark'): RaThemeOptions => {
'& .RaMenuItemLink-icon': {
minWidth: 30,
},
'.RaMenu-closed &': {
margin: `0 0 0 ${SPACING}px`,
},
},
},
},
},
sidebar: {
width: 195,
closedWidth: 50,
closedWidth: 45,
},
};
};
Expand Down

0 comments on commit c3d60d4

Please sign in to comment.