Skip to content
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

Proposed minor CSS variable cleanup #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/core/public/_css_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
--kbnHeaderOffsetWithBanner: calc(var(--kbnHeaderBannerHeight) + var(--kbnHeaderOffset));
// height of the action menu in the header in serverless projects
--kbnProjectHeaderAppActionMenuHeight: #{$euiSize * 3};
// total height of all fixed headers for the app container in serverless projects, dynamically changes based on whether the banner or action menu is present
--kbnAppHeadersOffset: var(--euiFixedHeadersOffset, 0);
Comment on lines -10 to -11
Copy link
Author

@cee-chen cee-chen Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this from :root is a minor cleanup preference. IMO, this variable only needs to get set on the appropriate body modifier. Other CSS can conditionally use either this variable or --euiFixedHeadersOffset if present by simply nesting var() fallbacks:

top: var(--kbnAppHeadersOffset, var(--euiFixedHeadersOffset, 0));

}

// Quick note: This shouldn't be mixed with Sass variable declarations,
Expand Down
6 changes: 5 additions & 1 deletion src/core/public/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
// The `--kbnAppHeadersOffset` CSS variable is automatically updated by
// styles/rendering/_base.scss, based on whether the Kibana chrome has a
// header banner, app menu, and is visible or hidden
height: calc(100vh - var(--kbnAppHeadersOffset, 0) - #{$additionalOffset});
height: calc(
100vh
- var(--kbnAppHeadersOffset, var(--euiFixedHeadersOffset, 0))
- #{$additionalOffset}
);
}
32 changes: 17 additions & 15 deletions src/core/public/styles/rendering/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pointer-events: none;
visibility: hidden;
position: fixed;
top: var(--kbnAppHeadersOffset, 0);
top: var(--kbnAppHeadersOffset, var(--euiFixedHeadersOffset, 0));
right: 0;
bottom: 0;
left: 0;
Expand All @@ -38,18 +38,11 @@
.kbnBody {
padding-top: var(--euiFixedHeadersOffset, 0);
}

// Conditionally override :root CSS fixed header variable. Updating `--euiFixedHeadersOffset`
// on the body will cause all child EUI components to automatically update their offsets
.kbnBody--projectActionMenuVisible {
--kbnAppHeadersOffset: calc(var(--kbnHeaderOffset) + var(--kbnProjectHeaderAppActionMenuHeight));
}
.kbnBody--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderOffsetWithBanner);
--kbnAppHeadersOffset: var(--kbnHeaderOffsetWithBanner);

&.kbnBody--projectActionMenuVisible {
--kbnAppHeadersOffset: calc(var(--kbnHeaderOffsetWithBanner) + var(--kbnProjectHeaderAppActionMenuHeight));
}

// Offset fixed EuiHeaders by the top banner
.euiHeader[data-fixed-header] {
Expand All @@ -63,15 +56,24 @@
}
}

// Set a body CSS variable for the app container to use - calculates the total
// height of all fixed headers + the sticky action menu toolbar
.kbnBody--projectActionMenuVisible {
Comment on lines +59 to +61
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled this out to its own selector block instead of bogarting the other existing selectors because I thought it was easier to read and understand separately. If the toolbar goes away or changes its positioning logic someday, separating it also makes it easier to delete all at once

--kbnAppHeadersOffset: calc(var(--kbnHeaderOffset) + var(--kbnProjectHeaderAppActionMenuHeight));

&.kbnBody--hasHeaderBanner {
--kbnAppHeadersOffset: calc(var(--kbnHeaderOffsetWithBanner) + var(--kbnProjectHeaderAppActionMenuHeight));
}
}

.kbnBody--chromeHidden {
--euiFixedHeadersOffset: 0;
&.kbnBody--projectActionMenuVisible {
--kbnAppHeadersOffset: 0;

&.kbnBody--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderBannerHeight);
}
}
.kbnBody--chromeHidden.kbnBody--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderBannerHeight);

&.kbnBody--projectActionMenuVisible {
--kbnAppHeadersOffset: var(--kbnHeaderBannerHeight);
--kbnAppHeadersOffset: var(--euiFixedHeadersOffset, 0);
}
Comment on lines 76 to 78
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I kept in the .kbnBody--chromeHidden block because that is a pretty special state that needs to come after all other (in terms of CSS specificity). I also DRY'd it out to simply inherit straight from --euiFixedHeadersOffset, which should be set properly from the preceding 6 lines

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useGlobalHeaderPortal } from '../../../../common/hooks/use_global_heade
const StyledStickyWrapper = styled.div`
position: sticky;
z-index: ${(props) => props.theme.eui.euiZHeaderBelowDataGrid};
top: var(--kbnAppHeadersOffset, 0);
top: var(--kbnAppHeadersOffset, var(--euiFixedHeadersOffset, 0));
`;

export const GlobalKQLHeader = React.memo(() => {
Expand Down
Loading