Skip to content

Commit

Permalink
chore: Replace inline CSS with styled components in Panel component
Browse files Browse the repository at this point in the history
Signed-off-by: Vidit-Kushwaha <[email protected]>
  • Loading branch information
Vidit-Kushwaha committed Dec 30, 2024
1 parent 7061c6e commit 971c97d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
61 changes: 19 additions & 42 deletions src/custom/Panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ import { CloseIcon, CollapseAllIcon, ExpandAllIcon } from '../../icons';
import { PanelDragHandleIcon } from '../../icons/PanelDragHandle';
import { useTheme } from '../../theme';
import { ErrorBoundary } from '../ErrorBoundary';
import { DrawerHeader, PanelBody, ResizableContent } from './style';
import {
DragHandle,
DrawerHeader,
HeaderActionsContainer,
HeaderContainer,
PanelBody,
PanelContainer,
ResizableContent
} from './style';

type PanelProps = {
export type PanelProps = {
isOpen: boolean;
children: React.ReactNode;
areAllExpanded?: boolean;
Expand Down Expand Up @@ -38,25 +46,7 @@ const Panel_: React.FC<PanelProps> = ({
if (!isOpen) return null;
return (
<Draggable handle=".drag-handle">
<Box
sx={{
borderRadius: '8px',
overflow: 'hidden',
flexShrink: 0,
zIndex: 99999,
position: 'absolute',
backgroundColor: theme.palette.background.blur?.light,
boxShadow: '0 4px 16px #05003812',
maxHeight: '80%',
display: 'flex',
boxSizing: 'border-box',
...(intitialPosition || {
top: '6rem',
right: '2rem'
}),
...(sx || {})
}}
>
<PanelContainer theme={theme} intitialPosition={intitialPosition} sx={sx}>
<Resizable
defaultSize={{ width: '18rem', height: 'auto' }}
onResize={() => {
Expand Down Expand Up @@ -86,37 +76,24 @@ const Panel_: React.FC<PanelProps> = ({
</Tooltip>
)}
</Box>
<PanelDragHandleIcon
style={{ marginTop: '-3rem', position: 'absolute', left: '50%' }}
/>
<div
style={{
display: 'flex',
justifyContent: 'end',
alignItems: 'center',
flex: 1
}}
>
<div
<DragHandle>
<PanelDragHandleIcon />
</DragHandle>
<HeaderContainer>
<HeaderActionsContainer
id={`${id}-panel-header-actions-container`}
style={{
display: 'flex',
gap: '1rem',
justifyContent: 'flex-end',
alignItems: 'center'
}}
></div>
></HeaderActionsContainer>
<IconButton onClick={handleClose}>
<CloseIcon />
</IconButton>
</div>
</HeaderContainer>
</DrawerHeader>
</div>
<PanelBody className="panel-body">{children}</PanelBody>
</ErrorBoundary>
</ResizableContent>
</Resizable>
</Box>
</PanelContainer>
</Draggable>
);
};
Expand Down
37 changes: 37 additions & 0 deletions src/custom/Panel/style.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ListItemProps } from '@mui/material';
import { Box, ListItem } from '../../base';
import { styled } from '../../theme';
import { PanelProps } from './Panel';

export const ListHeader = styled(ListItem)(({ theme }) => ({
padding: theme.spacing(0.5, 0.5),
Expand Down Expand Up @@ -78,3 +79,39 @@ export const ResizableContent = styled('div')({
flexDirection: 'column',
minHeight: '3rem'
});

export const PanelContainer = styled(Box)<{ intitialPosition: PanelProps['intitialPosition'] }>(
({ theme, intitialPosition }) => ({
borderRadius: '8px',
overflow: 'hidden',
flexShrink: 0,
zIndex: 99999,
position: 'absolute',
backgroundColor: theme.palette.background.blur?.light,
boxShadow: '0 4px 16px #05003812',
maxHeight: '80%',
display: 'flex',
boxSizing: 'border-box',
...intitialPosition
})
);

export const DragHandle = styled('div')({
position: 'absolute',
top: '-3rem',
left: '50%'
});

export const HeaderActionsContainer = styled('div')({
display: 'flex',
gap: '1rem',
justifyContent: 'flex-end',
alignItems: 'center'
});

export const HeaderContainer = styled('div')({
display: 'flex',
justifyContent: 'end',
alignItems: 'center',
flex: '1'
});

0 comments on commit 971c97d

Please sign in to comment.