Skip to content

Commit

Permalink
Add global CSS variable with collapsible nav width
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Oct 3, 2023
1 parent 10a50bb commit 390de42
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/collapsible_nav_beta/collapsible_nav_beta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import React, {
} from 'react';
import classNames from 'classnames';

import { useEuiTheme, useGeneratedHtmlId, throttle } from '../../services';
import {
useEuiTheme,
useEuiThemeCSSVariables,
useGeneratedHtmlId,
throttle,
} from '../../services';

import { CommonProps } from '../common';
import { EuiFlyout, EuiFlyoutProps } from '../flyout';
Expand Down Expand Up @@ -88,6 +93,7 @@ const _EuiCollapsibleNavBeta: FunctionComponent<EuiCollapsibleNavBetaProps> = ({
focusTrapProps: _focusTrapProps,
...rest
}) => {
const { setGlobalCSSVariables } = useEuiThemeCSSVariables();
const euiTheme = useEuiTheme();
const headerHeight = euiHeaderVariables(euiTheme).height;

Expand Down Expand Up @@ -138,9 +144,17 @@ const _EuiCollapsibleNavBeta: FunctionComponent<EuiCollapsibleNavBetaProps> = ({
const width = useMemo(() => {
if (isOverlayFullWidth) return '100%';
if (isPush && isCollapsed) return headerHeight;
return _width;
return `${_width}px`;
}, [_width, isOverlayFullWidth, isPush, isCollapsed, headerHeight]);

// Other UI elements may need to account for the nav width -
// set a global CSS variable that they can use
useEffect(() => {
setGlobalCSSVariables({
'--euiCollapsibleNavOffset': isOverlay ? '0' : width,
});
}, [width, isOverlay, setGlobalCSSVariables]);

/**
* Prop setup
*/
Expand Down

0 comments on commit 390de42

Please sign in to comment.