Skip to content

Commit

Permalink
[Embedded Console] Introduce kbnSolutionNavOffset CSS variable (#175348)
Browse files Browse the repository at this point in the history
## Summary

This PR updates the Kibana `SolutionNav` component to set a global CSS
variable `--kbnSolutionNavOffset` with it's current width. This is
modeled off of the EUI CSS variable `--euiCollapsibleNavOffset` that can
be used in Serverless to get the current width of the side nav.

This will be used by the embedded dev console to ensure it is not
rendered over the page side navigation, at least for pages that use the
`KibanaPageTemplate` & `SolutionNav`.

### Testing

The easiest way to verify this change is to check the values of
`--kbnSolutionNavOffset` in the browser console, which can be done with
the following command:

`getComputedStyle(document.documentElement).getPropertyValue('--kbnSolutionNavOffset')`

You can check this with the solution nav open and closed or on pages
without a solution nav at all (`/app/home` for example)
  • Loading branch information
TattdCodeMonkey authored Jan 24, 2024
1 parent df855ba commit 98cb0c2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pageLoadAssetSize:
datasetQuality: 50624
dataViewEditor: 28082
dataViewFieldEditor: 27000
dataViewManagement: 5136
dataViewManagement: 5176
dataViews: 51000
dataVisualizer: 27530
devTools: 38637
Expand Down
4 changes: 4 additions & 0 deletions packages/shared-ux/page/solution_nav/src/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This size is also tracked with a variable in solution_nav.tsx, if updated
// update there as well
$solutionNavWidth: 248px;
$solutionNavCollapsedWidth: $euiSizeXXL;
8 changes: 5 additions & 3 deletions packages/shared-ux/page/solution_nav/src/collapse_button.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@import 'variables';

.kbnSolutionNavCollapseButton {
position: absolute;
opacity: 0;
left: 248px - $euiSize;
left: $solutionNavWidth - $euiSize;
top: $euiSizeL;
z-index: 2;

Expand All @@ -18,7 +20,7 @@
&:hover,
&:focus {
opacity: 1;
left: 248px - $euiSizeL;
left: $solutionNavWidth - $euiSizeL;
}

.kbnSolutionNav__sidebar:hover & {
Expand All @@ -39,7 +41,7 @@
top: 0;
bottom: 0;
height: 100%;
width: $euiSizeXXL;
width: $solutionNavCollapsedWidth;
border-radius: 0;
// Keep the icon at the top instead of it getting shifted to the center of the page
padding-top: $euiSizeL + $euiSizeS;
Expand Down
3 changes: 2 additions & 1 deletion packages/shared-ux/page/solution_nav/src/solution_nav.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$euiSideNavEmphasizedBackgroundColor: transparentize($euiColorLightShade, .7);
@import '@elastic/eui/src/components/side_nav/mixins';
@import 'variables';

// Put the page background color in the flyout version too
.kbnSolutionNav__flyout {
Expand All @@ -14,7 +15,7 @@ $euiSideNavEmphasizedBackgroundColor: transparentize($euiColorLightShade, .7);
flex-direction: column;

@include euiBreakpoint('m', 'l', 'xl') {
width: 248px;
width: $solutionNavWidth;
padding: $euiSizeL;
}

Expand Down
31 changes: 30 additions & 1 deletion packages/shared-ux/page/solution_nav/src/solution_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import './solution_nav.scss';

import React, { FC, useState, useMemo } from 'react';
import React, { FC, useState, useMemo, useEffect } from 'react';
import classNames from 'classnames';
import {
EuiAvatarProps,
Expand All @@ -23,6 +23,8 @@ import {
htmlIdGenerator,
useIsWithinBreakpoints,
useIsWithinMinBreakpoint,
useEuiTheme,
useEuiThemeCSSVariables,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -71,6 +73,7 @@ export type SolutionNavProps = Omit<EuiSideNavProps<{}>, 'children' | 'items' |
};

const FLYOUT_SIZE = 248;
const FLYOUT_SIZE_CSS = `${FLYOUT_SIZE}px`;

const setTabIndex = (items: Array<EuiSideNavItemType<{}>>, isHidden: boolean) => {
return items.map((item) => {
Expand Down Expand Up @@ -174,6 +177,32 @@ export const SolutionNav: FC<SolutionNavProps> = ({
);
}, [children, headingID, isCustomSideNav, isHidden, items, rest]);

const { euiTheme } = useEuiTheme();
const navWidth = useMemo(() => {
if (isLargerBreakpoint) {
return isOpenOnDesktop ? FLYOUT_SIZE_CSS : euiTheme.size.xxl;
}
if (isMediumBreakpoint) {
return isSideNavOpenOnMobile || !canBeCollapsed ? FLYOUT_SIZE_CSS : euiTheme.size.xxl;
}
return '0';
}, [
euiTheme,
isOpenOnDesktop,
isSideNavOpenOnMobile,
canBeCollapsed,
isMediumBreakpoint,
isLargerBreakpoint,
]);
const { setGlobalCSSVariables } = useEuiThemeCSSVariables();
// Setting a global CSS variable with the nav width
// so that other pages have it available when needed.
useEffect(() => {
setGlobalCSSVariables({
'--kbnSolutionNavOffset': navWidth,
});
}, [navWidth, setGlobalCSSVariables]);

return (
<>
{isSmallerBreakpoint && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
box-shadow: inset 0 $embeddableConsoleInitialHeight 0 $embeddableConsoleBackground, inset 0 600rem 0 $euiPageBackgroundColor;
bottom: 0;
right: 0;
left: var(--euiCollapsibleNavOffset, 0);
transform: translateY(0);
height: $embeddableConsoleInitialHeight;
max-height: $embeddableConsoleMaxHeight;
Expand All @@ -18,6 +17,18 @@
z-index: $euiZLevel1;
}

&--projectChrome {
left: var(--euiCollapsibleNavOffset, 0);
}

&--classicChrome {
left: var(--kbnSolutionNavOffset, 0);
}

&--unknownChrome {
left: 0;
}

&-isOpen {
animation-duration: $euiAnimSpeedNormal;
animation-timing-function: $euiAnimSlightResistance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React, { useState } from 'react';
import classNames from 'classnames';
import useObservable from 'react-use/lib/useObservable';
import {
EuiButton,
EuiFocusTrap,
Expand Down Expand Up @@ -38,6 +39,7 @@ export const EmbeddableConsole = ({
}: EmbeddableConsoleProps & EmbeddableConsoleDependencies) => {
const [isConsoleOpen, setIsConsoleOpen] = useState<boolean>(false);
const toggleConsole = () => setIsConsoleOpen(!isConsoleOpen);
const chromeStyle = useObservable(core.chrome.getChromeStyle$());

const onKeyDown = (event: any) => {
if (event.key === keys.ESCAPE) {
Expand All @@ -52,6 +54,9 @@ export const EmbeddableConsole = ({
'embeddableConsole--large': size === 'l',
'embeddableConsole--medium': size === 'm',
'embeddableConsole--small': size === 's',
'embeddableConsole--classicChrome': chromeStyle === 'classic',
'embeddableConsole--projectChrome': chromeStyle === 'project',
'embeddableConsole--unknownChrome': chromeStyle === undefined,
'embeddableConsole--fixed': true,
'embeddableConsole--showOnMobile': false,
});
Expand Down

0 comments on commit 98cb0c2

Please sign in to comment.