migrate style overrides from scss to leverage emotion (#204463)

## Summary

This PR migrates style overrides within core from SCSS to leverage
emotion. Why is this necessary? Kibana builds it's stylesheets we get 4
stylesheets for all the supported themes, in which in turn impacts the
files built. Switching to leveraging emotion makes it such that we don't
need to build 4 files anymore for this particular cases in turn reducing
the page load bundle size.

This PR results in ~12% reduction in the page load bundle, that would
have come into effect from [the
PR](https://github.com/elastic/kibana/pull/203840) that introduces the
new Borealis theme as a default. The results can be seen in [this
build](https://buildkite.com/elastic/kibana-pull-request/builds/260881)

<!--

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

-->

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Eyo O. Eyo 2024-12-17 09:22:40 +00:00 committed by GitHub
parent dbf8818f88
commit 26fe24a0bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 169 additions and 141 deletions

View file

@ -10,3 +10,4 @@
export type { AppCategory } from './src/app_category';
export { APP_WRAPPER_CLASS } from './src/app_wrapper_class';
export { DEFAULT_APP_CATEGORIES } from './src/default_app_categories';
export { GlobalAppStyle } from './src/global_app_style';

View file

@ -0,0 +1,164 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import React from 'react';
import { css, Global } from '@emotion/react';
import { useEuiTheme, type UseEuiTheme } from '@elastic/eui';
export const renderingOverrides = (euiTheme: UseEuiTheme['euiTheme']) => css`
#kibana-body {
// DO NOT ADD ANY OVERFLOW BEHAVIORS HERE
// It will break the sticky navigation
min-height: 100%;
display: flex;
flex-direction: column;
}
// Affixes a div to restrict the position of charts tooltip to the visible viewport minus the header
#app-fixed-viewport {
pointer-events: none;
visibility: hidden;
position: fixed;
top: var(--kbnAppHeadersOffset, var(--euiFixedHeadersOffset, 0));
right: 0;
bottom: 0;
left: 0;
}
.kbnAppWrapper {
// DO NOT ADD ANY OTHER STYLES TO THIS SELECTOR
// This a very nested dependency happening in "all" apps
display: flex;
flex-flow: column nowrap;
flex-grow: 1;
z-index: 0; // This effectively puts every high z-index inside the scope of this wrapper to it doesn't interfere with the header and/or overlay mask
position: relative; // This is temporary for apps that relied on this being present on \`.application\`
}
.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--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderOffsetWithBanner);
// Offset fixed EuiHeaders by the top banner
.euiHeader[data-fixed-header] {
margin-top: var(--kbnHeaderBannerHeight);
}
// Prevent banners from covering full screen data grids
.euiDataGrid--fullScreen {
height: calc(100vh - var(--kbnHeaderBannerHeight));
top: var(--kbnHeaderBannerHeight);
}
}
// 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--hasProjectActionMenu {
--kbnAppHeadersOffset: calc(
var(--kbnHeaderOffset) + var(--kbnProjectHeaderAppActionMenuHeight)
);
&.kbnBody--hasHeaderBanner {
--kbnAppHeadersOffset: calc(
var(--kbnHeaderOffsetWithBanner) + var(--kbnProjectHeaderAppActionMenuHeight)
);
}
}
.kbnBody--chromeHidden {
// stylelint-disable-next-line length-zero-no-unit
--euiFixedHeadersOffset: 0px;
&.kbnBody--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderBannerHeight);
}
&.kbnBody--hasProjectActionMenu {
--kbnAppHeadersOffset: var(--euiFixedHeadersOffset, 0);
}
}
`;
export const bannerStyles = (euiTheme: UseEuiTheme['euiTheme']) => css`
.header__topBanner {
position: fixed;
top: 0;
left: 0;
height: var(--kbnHeaderBannerHeight);
width: 100%;
z-index: ${euiTheme.levels.header};
}
.header__topBannerContainer {
height: 100%;
width: 100%;
}
`;
export const chromeStyles = (euiTheme: UseEuiTheme['euiTheme']) => css`
.euiDataGrid__restrictBody {
.headerGlobalNav,
.kbnQueryBar {
display: none;
}
}
.euiDataGrid__restrictBody.euiBody--headerIsFixed {
.euiFlyout {
top: 0;
height: 100%;
}
}
.chrHeaderHelpMenu__version {
text-transform: none;
}
.chrHeaderBadge__wrapper {
align-self: center;
margin-right: ${euiTheme.size.base};
}
.header__toggleNavButtonSection {
.euiBody--collapsibleNavIsDocked & {
display: none;
}
}
.header__breadcrumbsWithExtensionContainer {
overflow: hidden; // enables text-ellipsis in the last breadcrumb
.euiHeaderBreadcrumbs {
// stop breadcrumbs from growing.
// this makes the extension appear right next to the last breadcrumb
flex-grow: 0;
margin-right: 0;
overflow: hidden; // enables text-ellipsis in the last breadcrumb
}
}
.header__breadcrumbsAppendExtension {
flex-grow: 1;
}
`;
export const GlobalAppStyle = () => {
const { euiTheme } = useEuiTheme();
return (
<Global
styles={css`
${bannerStyles(euiTheme)} ${chromeStyles(euiTheme)} ${renderingOverrides(euiTheme)}
`}
/>
);
};

View file

@ -20,6 +20,7 @@ import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import { KibanaRootContextProvider } from '@kbn/react-kibana-context-root';
import { APP_FIXED_VIEWPORT_ID } from '@kbn/core-rendering-browser';
import { GlobalAppStyle } from '@kbn/core-application-common';
import { AppWrapper } from './app_containers';
interface StartServices {
@ -62,6 +63,9 @@ export class RenderingService {
ReactDOM.render(
<KibanaRootContextProvider {...startServices} globalStyles={true}>
<>
{/* Global Styles that apply across the entire app */}
<GlobalAppStyle />
{/* Fixed headers */}
{chromeHeader}

View file

@ -1,3 +1 @@
@import './base';
@import './chrome/index';
@import './rendering/index';

View file

@ -1,13 +0,0 @@
.header__topBanner {
position: fixed;
top: 0;
left: 0;
height: var(--kbnHeaderBannerHeight);
width: 100%;
z-index: $euiZHeader;
}
.header__topBannerContainer {
height: 100%;
width: 100%;
}

View file

@ -1,45 +0,0 @@
@import './banner';
.euiDataGrid__restrictBody {
.headerGlobalNav,
.kbnQueryBar {
display: none;
}
}
.euiDataGrid__restrictBody.euiBody--headerIsFixed {
.euiFlyout {
top: 0;
height: 100%;
}
}
.chrHeaderHelpMenu__version {
text-transform: none;
}
.chrHeaderBadge__wrapper {
align-self: center;
margin-right: $euiSize;
}
.header__toggleNavButtonSection {
.euiBody--collapsibleNavIsDocked & {
display: none;
}
}
.header__breadcrumbsWithExtensionContainer {
overflow: hidden; // enables text-ellipsis in the last breadcrumb
.euiHeaderBreadcrumbs {
// stop breadcrumbs from growing.
// this makes the extension appear right next to the last breadcrumb
flex-grow: 0;
margin-right: 0;
overflow: hidden; // enables text-ellipsis in the last breadcrumb
}
}
.header__breadcrumbsAppendExtension {
flex-grow: 1;
}

View file

@ -1,80 +0,0 @@
@import '../../mixins';
/**
* Stretch the root element of the Kibana application to set the base-size that
* flexed children should keep. Only works when paired with root styles applied
* by core service from new platform
*/
#kibana-body {
// DO NOT ADD ANY OVERFLOW BEHAVIORS HERE
// It will break the sticky navigation
min-height: 100%;
display: flex;
flex-direction: column;
}
// Affixes a div to restrict the position of charts tooltip to the visible viewport minus the header
#app-fixed-viewport {
pointer-events: none;
visibility: hidden;
position: fixed;
top: var(--kbnAppHeadersOffset, var(--euiFixedHeadersOffset, 0));
right: 0;
bottom: 0;
left: 0;
}
.kbnAppWrapper {
// DO NOT ADD ANY OTHER STYLES TO THIS SELECTOR
// This a very nested dependency happnening in "all" apps
display: flex;
flex-flow: column nowrap;
flex-grow: 1;
z-index: 0; // This effectively puts every high z-index inside the scope of this wrapper to it doesn't interfere with the header and/or overlay mask
position: relative; // This is temporary for apps that relied on this being present on `.application`
}
.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--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderOffsetWithBanner);
// Offset fixed EuiHeaders by the top banner
.euiHeader[data-fixed-header] {
margin-top: var(--kbnHeaderBannerHeight);
}
// Prevent banners from covering full screen data grids
.euiDataGrid--fullScreen {
height: calc(100vh - var(--kbnHeaderBannerHeight));
top: var(--kbnHeaderBannerHeight);
}
}
// 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--hasProjectActionMenu {
--kbnAppHeadersOffset: calc(var(--kbnHeaderOffset) + var(--kbnProjectHeaderAppActionMenuHeight));
&.kbnBody--hasHeaderBanner {
--kbnAppHeadersOffset: calc(var(--kbnHeaderOffsetWithBanner) + var(--kbnProjectHeaderAppActionMenuHeight));
}
}
.kbnBody--chromeHidden {
// stylelint-disable-next-line length-zero-no-unit
--euiFixedHeadersOffset: 0px;
&.kbnBody--hasHeaderBanner {
--euiFixedHeadersOffset: var(--kbnHeaderBannerHeight);
}
&.kbnBody--hasProjectActionMenu {
--kbnAppHeadersOffset: var(--euiFixedHeadersOffset, 0);
}
}

View file

@ -1 +0,0 @@
@import './base';