Skip to content

Commit

Permalink
fix(Drawer): mui styles refactor Closes #646
Browse files Browse the repository at this point in the history
  • Loading branch information
kaminderpal committed Oct 24, 2023
1 parent 30e73aa commit 98a59ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
37 changes: 37 additions & 0 deletions packages/geoview-core/src/ui/drawer/drawer-style.ts
Original file line number Diff line number Diff line change
@@ -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),
},
});
52 changes: 8 additions & 44 deletions packages/geoview-core/src/ui/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ 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';

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
Expand All @@ -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
*
Expand All @@ -70,7 +33,8 @@ export function Drawer(props: TypeDrawerProps): JSX.Element {

const { t } = useTranslation<string>();

const classes = useStyles();
const sxtheme = useTheme();
const classes = getSxClasses(sxtheme);

const mapConfig = useContext(MapContext);

Expand Down Expand Up @@ -109,13 +73,13 @@ export function Drawer(props: TypeDrawerProps): JSX.Element {
return (
<MaterialDrawer
variant={variant || 'permanent'}
className={open ? classes.drawerOpen : classes.drawerClose}
sx={open ? classes.drawerOpen : classes.drawerClose}
classes={{
paper: className || (open ? classes.drawerOpen : classes.drawerClose),
paper: className,
}}
style={style || undefined}
>
<div className={classes.toolbar}>
<Box sx={classes.toolbar}>
<IconButton
tooltip={open ? t('general.close')! : t('general.open')!}
tooltipPlacement="right"
Expand All @@ -126,7 +90,7 @@ export function Drawer(props: TypeDrawerProps): JSX.Element {
>
{!open ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
</div>
</Box>
{children !== undefined && children}
</MaterialDrawer>
);
Expand Down

0 comments on commit 98a59ed

Please sign in to comment.