-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Embedded Console] Introduce kbnSolutionNavOffset CSS variable #175348
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
Changes from 2 commits
5312dbb
004ff2b
1e6fb1a
2fe79bf
412d25f
5a01641
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 |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -23,10 +23,12 @@ import { | |
| htmlIdGenerator, | ||
| useIsWithinBreakpoints, | ||
| useIsWithinMinBreakpoint, | ||
| useEuiThemeCSSVariables, | ||
| } from '@elastic/eui'; | ||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { KibanaSolutionAvatar } from '@kbn/shared-ux-avatar-solution'; | ||
| import { euiThemeVars } from '@kbn/ui-theme'; | ||
|
|
||
| import { SolutionNavCollapseButton } from './collapse_button'; | ||
|
|
||
|
|
@@ -174,6 +176,32 @@ export const SolutionNav: FC<SolutionNavProps> = ({ | |
| ); | ||
| }, [children, headingID, isCustomSideNav, isHidden, items, rest]); | ||
|
|
||
| const navWidth = useMemo(() => { | ||
| if (isLargerBreakpoint) { | ||
| return isOpenOnDesktop ? `${FLYOUT_SIZE}px` : euiThemeVars.euiSizeXXL; | ||
| } | ||
| if (isMediumBreakpoint) { | ||
| return isSideNavOpenOnMobile || !canBeCollapsed | ||
| ? `${FLYOUT_SIZE}px` | ||
| : euiThemeVars.euiSizeXXL; | ||
| } | ||
| return '0'; | ||
| }, [ | ||
| 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, | ||
| }); | ||
|
Contributor
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. I guess this should be cleaned in the destroy callback?
Contributor
Author
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. I had that initially, but it didn't seem to change anything so I removed it as superfluous. Also the eui code I modeled this off of does not have a destroy callback either.
Contributor
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. it could be a problem when this variable is used with a fallback for the case when solution nav is not rendered, e.g.: |
||
| }, [navWidth, setGlobalCSSVariables]); | ||
|
|
||
| return ( | ||
| <> | ||
| {isSmallerBreakpoint && ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,5 +20,6 @@ | |
| "@kbn/i18n", | ||
| "@kbn/i18n-react", | ||
| "@kbn/shared-ux-avatar-solution", | ||
| "@kbn/ui-theme", | ||
| ] | ||
| } | ||
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.
Looks like there is no way (or no straightforward way) to connect these widths with the widths that are actually set for the sidebar. Maybe it is worth at least adding a comment in the CSS where these widths are set, that this logic might also need an update in case the CSS is updated
like here
kibana/packages/shared-ux/page/solution_nav/src/with_solution_nav.tsx
Line 77 in 51569b4
or here
kibana/packages/shared-ux/page/solution_nav/src/solution_nav.scss
Line 17 in c39352f
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.
Or maybe it is worth at least connecting them with css variable
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.
@Dosant I added variables for the sizes and added a comment about it also being set in the tsx file.
I don't think there is way to read the variables from the scss file in the tsx file at compile time without configuration changes. But if I'm wrong about that let me know.