From e06aeb378405c62af3f9692a0f8a78af6f9e5c0c Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Mon, 9 Oct 2023 17:03:16 +0200 Subject: [PATCH] fix sticky header attempt 1 --- .../src/ui/project/app_menu.tsx | 59 ++++++++++++------- src/core/public/_css_variables.scss | 4 ++ src/core/public/styles/rendering/_base.scss | 12 +++- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/packages/core/chrome/core-chrome-browser-internal/src/ui/project/app_menu.tsx b/packages/core/chrome/core-chrome-browser-internal/src/ui/project/app_menu.tsx index 22ff7c9415ba8..1ef7f072fe20d 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/ui/project/app_menu.tsx +++ b/packages/core/chrome/core-chrome-browser-internal/src/ui/project/app_menu.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { useEuiTheme } from '@elastic/eui'; +import { useEuiTheme, EuiResizeObserver } from '@elastic/eui'; import { css } from '@emotion/react'; import { MountPoint } from '@kbn/core-mount-utils-browser'; import React from 'react'; @@ -17,26 +17,43 @@ interface AppMenuBarProps { } export const AppMenuBar = ({ headerActionMenuMounter }: AppMenuBarProps) => { const { euiTheme } = useEuiTheme(); + const [height, setHeight] = React.useState(null); + + React.useLayoutEffect(() => { + if (height === null) return; + const kbnAppWrapper = document.querySelector('.kbnAppWrapper') as HTMLElement; + if (!kbnAppWrapper) return; // should never happen + + kbnAppWrapper.style.setProperty('--kbnProjectHeaderAppActionMenuHeight', `${height}px`); + return () => { + kbnAppWrapper.style.removeProperty('--kbnProjectHeaderAppActionMenuHeight'); + }; + }, [height]); + return ( -
- -
+ setHeight(d.height)}> + {(resizeRef) => ( +
+ +
+ )} +
); }; diff --git a/src/core/public/_css_variables.scss b/src/core/public/_css_variables.scss index cef1be40d1239..295ea67d8a5a8 100644 --- a/src/core/public/_css_variables.scss +++ b/src/core/public/_css_variables.scss @@ -5,6 +5,10 @@ --kbnHeaderOffset: var(--euiFixedHeadersOffset, 0); // total height of everything when the banner is present --kbnHeaderOffsetWithBanner: calc(var(--kbnHeaderBannerHeight) + var(--kbnHeaderOffset)); + + // height of the action menu in the header in serverless projects + // this variable is dynamically set when mounted + --kbnProjectHeaderAppActionMenuHeight: 0; } // Quick note: This shouldn't be mixed with Sass variable declarations, diff --git a/src/core/public/styles/rendering/_base.scss b/src/core/public/styles/rendering/_base.scss index 8a7b14242f8bf..f5268f281680c 100644 --- a/src/core/public/styles/rendering/_base.scss +++ b/src/core/public/styles/rendering/_base.scss @@ -33,6 +33,8 @@ flex-grow: 1; z-index: 0; // This effectively puts every high z-index inside the scope of this wrapper to it doesn't interfere with the header and/or overlay mask position: relative; // This is temporary for apps that relied on this being present on `.application` + + --euiFixedHeadersOffset: calc(var(--kbnHeaderOffset) + var(--kbnProjectHeaderAppActionMenuHeight)); } .kbnBody { @@ -41,9 +43,11 @@ // Conditionally override :root CSS fixed header variable. Updating `--euiFixedHeadersOffset` // on the body will cause all child EUI components to automatically update their offsets - .kbnBody--hasHeaderBanner { --euiFixedHeadersOffset: var(--kbnHeaderOffsetWithBanner); + .kbnAppWrapper { + --euiFixedHeadersOffset: calc(var(--kbnHeaderOffsetWithBanner) + var(--kbnProjectHeaderAppActionMenuHeight)); + } // Offset fixed EuiHeaders by the top banner .euiHeader[data-fixed-header] { @@ -58,7 +62,13 @@ } .kbnBody--chromeHidden { --euiFixedHeadersOffset: 0; + .kbnAppWrapper { + --euiFixedHeadersOffset: 0; + } } .kbnBody--chromeHidden.kbnBody--hasHeaderBanner { --euiFixedHeadersOffset: var(--kbnHeaderBannerHeight); + .kbnAppWrapper { + --euiFixedHeadersOffset: var(--kbnHeaderBannerHeight); + } }