Skip to content

Commit 971c97d

Browse files
chore: Replace inline CSS with styled components in Panel component
Signed-off-by: Vidit-Kushwaha <[email protected]>
1 parent 7061c6e commit 971c97d

File tree

2 files changed

+56
-42
lines changed

2 files changed

+56
-42
lines changed

src/custom/Panel/Panel.tsx

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ import { CloseIcon, CollapseAllIcon, ExpandAllIcon } from '../../icons';
66
import { PanelDragHandleIcon } from '../../icons/PanelDragHandle';
77
import { useTheme } from '../../theme';
88
import { ErrorBoundary } from '../ErrorBoundary';
9-
import { DrawerHeader, PanelBody, ResizableContent } from './style';
9+
import {
10+
DragHandle,
11+
DrawerHeader,
12+
HeaderActionsContainer,
13+
HeaderContainer,
14+
PanelBody,
15+
PanelContainer,
16+
ResizableContent
17+
} from './style';
1018

11-
type PanelProps = {
19+
export type PanelProps = {
1220
isOpen: boolean;
1321
children: React.ReactNode;
1422
areAllExpanded?: boolean;
@@ -38,25 +46,7 @@ const Panel_: React.FC<PanelProps> = ({
3846
if (!isOpen) return null;
3947
return (
4048
<Draggable handle=".drag-handle">
41-
<Box
42-
sx={{
43-
borderRadius: '8px',
44-
overflow: 'hidden',
45-
flexShrink: 0,
46-
zIndex: 99999,
47-
position: 'absolute',
48-
backgroundColor: theme.palette.background.blur?.light,
49-
boxShadow: '0 4px 16px #05003812',
50-
maxHeight: '80%',
51-
display: 'flex',
52-
boxSizing: 'border-box',
53-
...(intitialPosition || {
54-
top: '6rem',
55-
right: '2rem'
56-
}),
57-
...(sx || {})
58-
}}
59-
>
49+
<PanelContainer theme={theme} intitialPosition={intitialPosition} sx={sx}>
6050
<Resizable
6151
defaultSize={{ width: '18rem', height: 'auto' }}
6252
onResize={() => {
@@ -86,37 +76,24 @@ const Panel_: React.FC<PanelProps> = ({
8676
</Tooltip>
8777
)}
8878
</Box>
89-
<PanelDragHandleIcon
90-
style={{ marginTop: '-3rem', position: 'absolute', left: '50%' }}
91-
/>
92-
<div
93-
style={{
94-
display: 'flex',
95-
justifyContent: 'end',
96-
alignItems: 'center',
97-
flex: 1
98-
}}
99-
>
100-
<div
79+
<DragHandle>
80+
<PanelDragHandleIcon />
81+
</DragHandle>
82+
<HeaderContainer>
83+
<HeaderActionsContainer
10184
id={`${id}-panel-header-actions-container`}
102-
style={{
103-
display: 'flex',
104-
gap: '1rem',
105-
justifyContent: 'flex-end',
106-
alignItems: 'center'
107-
}}
108-
></div>
85+
></HeaderActionsContainer>
10986
<IconButton onClick={handleClose}>
11087
<CloseIcon />
11188
</IconButton>
112-
</div>
89+
</HeaderContainer>
11390
</DrawerHeader>
11491
</div>
11592
<PanelBody className="panel-body">{children}</PanelBody>
11693
</ErrorBoundary>
11794
</ResizableContent>
11895
</Resizable>
119-
</Box>
96+
</PanelContainer>
12097
</Draggable>
12198
);
12299
};

src/custom/Panel/style.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ListItemProps } from '@mui/material';
22
import { Box, ListItem } from '../../base';
33
import { styled } from '../../theme';
4+
import { PanelProps } from './Panel';
45

56
export const ListHeader = styled(ListItem)(({ theme }) => ({
67
padding: theme.spacing(0.5, 0.5),
@@ -78,3 +79,39 @@ export const ResizableContent = styled('div')({
7879
flexDirection: 'column',
7980
minHeight: '3rem'
8081
});
82+
83+
export const PanelContainer = styled(Box)<{ intitialPosition: PanelProps['intitialPosition'] }>(
84+
({ theme, intitialPosition }) => ({
85+
borderRadius: '8px',
86+
overflow: 'hidden',
87+
flexShrink: 0,
88+
zIndex: 99999,
89+
position: 'absolute',
90+
backgroundColor: theme.palette.background.blur?.light,
91+
boxShadow: '0 4px 16px #05003812',
92+
maxHeight: '80%',
93+
display: 'flex',
94+
boxSizing: 'border-box',
95+
...intitialPosition
96+
})
97+
);
98+
99+
export const DragHandle = styled('div')({
100+
position: 'absolute',
101+
top: '-3rem',
102+
left: '50%'
103+
});
104+
105+
export const HeaderActionsContainer = styled('div')({
106+
display: 'flex',
107+
gap: '1rem',
108+
justifyContent: 'flex-end',
109+
alignItems: 'center'
110+
});
111+
112+
export const HeaderContainer = styled('div')({
113+
display: 'flex',
114+
justifyContent: 'end',
115+
alignItems: 'center',
116+
flex: '1'
117+
});

0 commit comments

Comments
 (0)