-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EuiCollapsibleNavBeta] Add global CSS variable for width offset #7248
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import type { Meta, StoryObj } from '@storybook/react'; | |
|
||
import { EuiHeader, EuiHeaderSection, EuiHeaderSectionItem } from '../header'; | ||
import { EuiPageTemplate } from '../page_template'; | ||
import { EuiBottomBar } from '../bottom_bar'; | ||
import { EuiFlyout } from '../flyout'; | ||
import { EuiButton } from '../button'; | ||
import { EuiTitle } from '../title'; | ||
|
@@ -469,6 +470,24 @@ export const FlyoutInFixedHeaders: Story = { | |
}, | ||
}; | ||
|
||
export const GlobalCSSVariable: Story = { | ||
render: ({ ...args }) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about hiding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @breehall Would you be cool with me making that change in #7245 as opposed to this PR? I'd like to do a release with this work so that I can get it into the currently open EUI upgrade and @nchaulet can update his Kibana PR sooner rather than later. There's a bunch of other stories under this file that need a closer inspection of their props pane in any case, and I'd rather have the new util I just set up while doing so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely! That's fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet! Will update that PR in a second here! |
||
<> | ||
<EuiHeader position="fixed"> | ||
<EuiHeaderSection> | ||
<EuiCollapsibleNavBeta {...args}> | ||
This story tests the global `--euiCollapsibleNavOffset` CSS variable | ||
</EuiCollapsibleNavBeta> | ||
</EuiHeaderSection> | ||
</EuiHeader> | ||
<EuiBottomBar left="var(--euiCollapsibleNavOffset, 0)"> | ||
This text should be visible at all times and the bar position should | ||
update dynamically based on the nav width (including on mobile) | ||
</EuiBottomBar> | ||
</> | ||
), | ||
}; | ||
|
||
export const CollapsedStateInLocalStorage: Story = { | ||
render: () => { | ||
const key = 'EuiCollapsibleNav__isCollapsed'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -88,6 +93,7 @@ const _EuiCollapsibleNavBeta: FunctionComponent<EuiCollapsibleNavBetaProps> = ({ | |
focusTrapProps: _focusTrapProps, | ||
...rest | ||
}) => { | ||
const { setGlobalCSSVariables } = useEuiThemeCSSVariables(); | ||
const euiTheme = useEuiTheme(); | ||
const headerHeight = euiHeaderVariables(euiTheme).height; | ||
|
||
|
@@ -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]); | ||
Comment on lines
+152
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very clever fix. I actually didn't know we had a styling function to globally set variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
/** | ||
* Prop setup | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
args
being set to anything here? Is it just the component defaults? If not, could we get away without passing anything to the render function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always need to pass
...args
(if there's a control panel), as that's where the control values come from