From 98a59edd98fe327bc7b3ee189c6a096f0dec196d Mon Sep 17 00:00:00 2001 From: kaminderpal Date: Tue, 24 Oct 2023 19:45:18 -0400 Subject: [PATCH] fix(Drawer): mui styles refactor Closes #646 --- .../src/ui/drawer/drawer-style.ts | 37 +++++++++++++ .../geoview-core/src/ui/drawer/drawer.tsx | 52 +++---------------- 2 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 packages/geoview-core/src/ui/drawer/drawer-style.ts diff --git a/packages/geoview-core/src/ui/drawer/drawer-style.ts b/packages/geoview-core/src/ui/drawer/drawer-style.ts new file mode 100644 index 00000000000..efb00ea4f9e --- /dev/null +++ b/packages/geoview-core/src/ui/drawer/drawer-style.ts @@ -0,0 +1,37 @@ +import { Theme } from '@mui/material/styles'; + +const drawerWidth = 200; +export const getSxClasses = (theme: Theme) => ({ + drawer: { + width: drawerWidth, + flexShrink: 0, + whiteSpace: 'nowrap', + }, + drawerOpen: { + width: drawerWidth, + transition: theme.transitions.create('width', { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen, + }), + '& $toolbar': { + justifyContent: 'flex-end', + }, + }, + drawerClose: { + transition: theme.transitions.create('width', { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen, + }), + overflowX: 'hidden', + width: '61px', + '& $toolbar': { + justifyContent: 'center', + }, + }, + toolbar: { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + padding: theme.spacing(0, 1), + }, +}); diff --git a/packages/geoview-core/src/ui/drawer/drawer.tsx b/packages/geoview-core/src/ui/drawer/drawer.tsx index 51c201cb580..cbd56e6d8f2 100644 --- a/packages/geoview-core/src/ui/drawer/drawer.tsx +++ b/packages/geoview-core/src/ui/drawer/drawer.tsx @@ -2,9 +2,7 @@ import { useContext, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Drawer as MaterialDrawer, DrawerProps } from '@mui/material'; - -import makeStyles from '@mui/styles/makeStyles'; +import { Drawer as MaterialDrawer, DrawerProps, useTheme, Box } from '@mui/material'; import { api } from '@/app'; import { EVENT_NAMES } from '@/api/events/event-types'; @@ -12,6 +10,7 @@ import { EVENT_NAMES } from '@/api/events/event-types'; import { IconButton, ChevronLeftIcon, ChevronRightIcon } from '..'; import { MapContext } from '@/core/app-start'; import { PayloadBaseClass, booleanPayload, payloadIsABoolean } from '@/api/events/payloads'; +import { getSxClasses } from './drawer-style'; /** * Drawer Properties @@ -21,42 +20,6 @@ export interface TypeDrawerProps extends DrawerProps { status?: boolean; } -const drawerWidth = 200; -const useStyles = makeStyles((theme) => ({ - drawer: { - width: drawerWidth, - flexShrink: 0, - whiteSpace: 'nowrap', - }, - drawerOpen: { - width: drawerWidth, - transition: theme.transitions.create('width', { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.enteringScreen, - }), - '& $toolbar': { - justifyContent: 'flex-end', - }, - }, - drawerClose: { - transition: theme.transitions.create('width', { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.leavingScreen, - }), - overflowX: 'hidden', - width: '61px', - '& $toolbar': { - justifyContent: 'center', - }, - }, - toolbar: { - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - padding: theme.spacing(0, 1), - }, -})); - /** * Create a customized Material UI Drawer * @@ -70,7 +33,8 @@ export function Drawer(props: TypeDrawerProps): JSX.Element { const { t } = useTranslation(); - const classes = useStyles(); + const sxtheme = useTheme(); + const classes = getSxClasses(sxtheme); const mapConfig = useContext(MapContext); @@ -109,13 +73,13 @@ export function Drawer(props: TypeDrawerProps): JSX.Element { return ( -
+ {!open ? : } -
+ {children !== undefined && children}
);