From 7b0362b2286f6c1613b948582d6e8d2cc6ccfb0f Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Wed, 26 Jun 2024 09:37:17 +0100 Subject: [PATCH] Drawer: Improve performance when resizing (#89691) apply dynamic styles as styles instead of emotion classes --- .../src/components/Drawer/Drawer.tsx | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/grafana-ui/src/components/Drawer/Drawer.tsx b/packages/grafana-ui/src/components/Drawer/Drawer.tsx index f3b17f2511f..9d5defacf03 100644 --- a/packages/grafana-ui/src/components/Drawer/Drawer.tsx +++ b/packages/grafana-ui/src/components/Drawer/Drawer.tsx @@ -54,6 +54,12 @@ export interface Props { onClose: () => void; } +const drawerSizes = { + sm: { width: '25vw', minWidth: 384 }, + md: { width: '50vw', minWidth: 568 }, + lg: { width: '75vw', minWidth: 744 }, +}; + export function Drawer({ children, onClose, @@ -68,7 +74,7 @@ export function Drawer({ const [drawerWidth, onMouseDown, onTouchStart] = useResizebleDrawer(); const styles = useStyles2(getStyles); - const sizeStyles = useStyles2(getSizeStyles, size, drawerWidth ?? width); + const wrapperStyles = useStyles2(getWrapperStyles, size); const dragStyles = useStyles2(getDragStyles); const overlayRef = React.useRef(null); @@ -85,8 +91,9 @@ export function Drawer({ // Adds body class while open so the toolbar nav can hide some actions while drawer is open useBodyClassWhileOpen(); - const rootClass = cx(styles.drawer, sizeStyles); const content =
{children}
; + const overrideWidth = drawerWidth ?? width ?? drawerSizes[size].width; + const minWidth = drawerSizes[size].minWidth; return ( { }; }; -const drawerSizes = { - sm: { width: '25vw', minWidth: 384 }, - md: { width: '50vw', minWidth: 568 }, - lg: { width: '75vw', minWidth: 744 }, -}; - -function getSizeStyles(theme: GrafanaTheme2, size: 'sm' | 'md' | 'lg', overrideWidth: number | string | undefined) { - let width = overrideWidth ?? drawerSizes[size].width; - let minWidth = drawerSizes[size].minWidth; - +function getWrapperStyles(theme: GrafanaTheme2, size: 'sm' | 'md' | 'lg') { return css({ - '.rc-drawer-content-wrapper': { - label: `drawer-content-wrapper-${size}`, - width: width, - minWidth: minWidth, - overflow: 'unset', + label: `drawer-content-wrapper-${size}`, + overflow: 'unset !important', - [theme.breakpoints.down('md')]: { - width: `calc(100% - ${theme.spacing(2)}) !important`, - minWidth: 0, - }, + [theme.breakpoints.down('md')]: { + width: `calc(100% - ${theme.spacing(2)}) !important`, + minWidth: 0, }, }); }