Skip to content

Commit

Permalink
migrate style overrides from scss to leverage emotion (elastic#204463)
Browse files Browse the repository at this point in the history
## 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](elastic#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>
  • Loading branch information
2 people authored and CAWilson94 committed Jan 10, 2025
1 parent 96b97b5 commit 3229a92
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 141 deletions.
1 change: 1 addition & 0 deletions packages/core/application/core-application-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -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)}
`}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 0 additions & 2 deletions src/core/public/styles/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@import './base';
@import './chrome/index';
@import './rendering/index';
13 changes: 0 additions & 13 deletions src/core/public/styles/chrome/_banner.scss

This file was deleted.

45 changes: 0 additions & 45 deletions src/core/public/styles/chrome/_index.scss

This file was deleted.

80 changes: 0 additions & 80 deletions src/core/public/styles/rendering/_base.scss

This file was deleted.

1 change: 0 additions & 1 deletion src/core/public/styles/rendering/_index.scss

This file was deleted.

0 comments on commit 3229a92

Please sign in to comment.