Skip to content

Commit

Permalink
fix: propagate width props to drawer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jul 15, 2022
1 parent 6f16ea1 commit 8d36f1c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
36 changes: 33 additions & 3 deletions packages/widget/src/AppDrawer.style.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import { Button, Typography } from '@mui/material';
import { styled } from '@mui/material/styles';

const getButtonTransformWidth = (
drawerWidth?: number | string,
drawerMaxWidth?: number | string,
) => {
if (typeof drawerWidth === 'number') {
return `${drawerWidth}px`;
}
if (typeof drawerWidth === 'string' && !drawerWidth.includes('%')) {
return drawerWidth;
}
if (typeof drawerMaxWidth === 'number') {
return `${drawerMaxWidth}px`;
}
if (typeof drawerMaxWidth === 'string' && !drawerMaxWidth.includes('%')) {
return drawerMaxWidth;
}
return '392px';
};

export const DrawerButton = styled(Button, {
shouldForwardProp: (prop) => prop !== 'open',
})<{ open?: boolean }>(({ theme, open }) => ({
shouldForwardProp: (prop) =>
!['open', 'drawerProps'].includes(prop as string),
})<{
open?: boolean;
drawerProps?: {
width?: number | string;
maxWidth?: number | string;
};
}>(({ theme, open, drawerProps }) => ({
background:
theme.palette.mode === 'light'
? theme.palette.common.black
Expand All @@ -23,7 +49,11 @@ export const DrawerButton = styled(Button, {
position: 'absolute',
right: 0,
top: 'calc(50% - 74px)',
transform: `translate3d(calc(${open ? '392px' : '0px'} * -1), 0, 0)`,
transform: `translate3d(calc(${
open
? getButtonTransformWidth(drawerProps?.width, drawerProps?.maxWidth)
: '0px'
} * -1), 0, 0)`,
transition: theme.transitions.create(['transform'], {
duration: theme.transitions.duration.enteringScreen,
easing: theme.transitions.easing.easeOut,
Expand Down
8 changes: 8 additions & 0 deletions packages/widget/src/AppDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const AppDrawer = forwardRef<AppDrawerBase, AppDrawerProps>(
variant="contained"
onClick={toggleDrawer}
open={drawerOpen}
drawerProps={config?.containerStyle}
disableElevation
>
{drawerOpen ? <KeyboardArrowRightIcon /> : <KeyboardArrowLeftIcon />}
Expand All @@ -82,6 +83,13 @@ export const AppDrawer = forwardRef<AppDrawerBase, AppDrawerProps>(
backdropFilter: 'blur(3px)',
},
}}
PaperProps={{
sx: {
width: config?.containerStyle?.width ?? '100%',
minWidth: config?.containerStyle?.minWidth ?? 375,
maxWidth: config?.containerStyle?.maxWidth ?? 392,
},
}}
keepMounted
>
<AppDefault />
Expand Down

0 comments on commit 8d36f1c

Please sign in to comment.