Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,63 @@

import { css } from '@emotion/react';
import { layoutVar, layoutLevels } from '@kbn/core-chrome-layout-constants';
import { euiOverflowScroll, euiShadow } from '@elastic/eui';
import { euiOverflowScroll, euiShadow, type UseEuiTheme } from '@elastic/eui';
import { getHighContrastBorder } from '@kbn/core-chrome-layout-utils';
import type { ChromeStyle } from '@kbn/core-chrome-browser';
import type { EmotionFn } from '../types';

const root: EmotionFn = (useEuiTheme) =>
css`
grid-area: application;
const root = (chromeStyle: ChromeStyle = 'classic'): EmotionFn => {
const isProjectStyle = chromeStyle === 'project';

height: calc(100% - ${layoutVar('application.marginBottom')});
width: calc(100% - ${layoutVar('application.marginRight')});
margin-bottom: ${layoutVar('application.marginBottom')};
margin-right: ${layoutVar('application.marginRight')};
return (useEuiTheme: UseEuiTheme) => {
return css`
grid-area: application;

z-index: ${layoutLevels.content};
height: calc(100% - ${layoutVar('application.marginBottom')});
width: calc(100% - ${layoutVar('application.marginRight')});
margin-bottom: ${layoutVar('application.marginBottom')};
margin-right: ${layoutVar('application.marginRight')};

position: relative;
display: flex;
flex-direction: column;
z-index: ${layoutLevels.content};

background-color: ${useEuiTheme.euiTheme.colors.backgroundBasePlain};
border-radius: ${useEuiTheme.euiTheme.border.radius.medium};
border: ${getHighContrastBorder(useEuiTheme)};
${euiShadow(useEuiTheme, 'xs', { border: 'none' })};
position: relative;
display: flex;
flex-direction: column;

&:focus-visible {
border: 2px solid ${useEuiTheme.euiTheme.colors.textParagraph};
}
// Only apply distinguished background styling for "project" chrome style
${isProjectStyle &&
css`
background-color: ${useEuiTheme.euiTheme.colors.backgroundBasePlain};
border-radius: ${useEuiTheme.euiTheme.border.radius.medium};
border: ${getHighContrastBorder(useEuiTheme)};
${euiShadow(useEuiTheme, 'xs', { border: 'none' })};
`}
${!isProjectStyle &&
css`
background-color: transparent;
border-radius: 0;
border: none;
`}

// only restrict overflow scroll on screen (not print) to allow for full page printing
@media screen {
${euiOverflowScroll(useEuiTheme, { direction: 'y' })};
// reset the height back to respect the margin bottom
height: calc(100% - ${layoutVar('application.marginBottom')});
&:focus-visible {
border: 2px solid ${useEuiTheme.euiTheme.colors.textParagraph};
}

// Hide scrollbar
scrollbar-width: none; /* Firefox */
&::-webkit-scrollbar {
display: none; /* Chrome, Safari, Edge */
// only restrict overflow scroll on screen (not print) to allow for full page printing
@media screen {
${euiOverflowScroll(useEuiTheme, { direction: 'y' })};
// reset the height back to respect the margin bottom
height: calc(100% - ${layoutVar('application.marginBottom')});

// Hide scrollbar
scrollbar-width: none; /* Firefox */
&::-webkit-scrollbar {
display: none; /* Chrome, Safari, Edge */
}
}
}
`;
`;
};
};
Comment thread
ryankeairns marked this conversation as resolved.

const content: EmotionFn = () => css`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React from 'react';
import { APP_MAIN_SCROLL_CONTAINER_ID } from '@kbn/core-chrome-layout-constants';

import { styles } from './layout_application.styles';
import { useLayoutConfig } from '../layout_config_context';

/**
* The application slot wrapper
Expand All @@ -29,9 +30,11 @@ export const LayoutApplication = ({
topBar?: ReactNode;
bottomBar?: ReactNode;
}) => {
const { chromeStyle } = useLayoutConfig();

return (
<div
css={styles.root}
css={styles.root(chromeStyle)}
id={APP_MAIN_SCROLL_CONTAINER_ID}
className="kbnChromeLayoutApplication"
data-test-subj="kbnChromeLayoutApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export {
type LayoutConfigProviderProps as ChromeLayoutConfigProviderProps,
useLayoutUpdate,
} from './layout_config_context';
export type { ChromeStyle } from '@kbn/core-chrome-browser';
export { SimpleDebugOverlay } from './debug/simple_debug_overlay';
export { LayoutDebugOverlay } from './debug/layout_debug_overlay';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import type { ReactNode } from 'react';
import React, { createContext, useContext, useState, useCallback, useEffect } from 'react';
import type { ChromeStyle } from '@kbn/core-chrome-browser';
import type { LayoutDimensions } from './layout.types';

/**
Expand All @@ -26,7 +27,9 @@ export type LayoutConfig = Pick<
| 'applicationBottomBarHeight'
| 'applicationMarginBottom'
| 'applicationMarginRight'
>;
> & {
chromeStyle?: ChromeStyle;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc @Dosant


/**
* Context interface including both the config and an update function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ project:
dependsOn:
- '@kbn/core-chrome-layout-constants'
- '@kbn/core-chrome-layout-utils'
- '@kbn/core-chrome-browser'
tags:
- shared-browser
- package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"kbn_references": [
"@kbn/core-chrome-layout-constants",
"@kbn/core-chrome-layout-utils",
"@kbn/core-chrome-browser",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { APP_FIXED_VIEWPORT_ID } from '../../app_fixed_viewport';

const layoutConfigs: { classic: ChromeLayoutConfig; project: ChromeLayoutConfig } = {
classic: {
chromeStyle: 'classic',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without this change, each component that needed to know the chrome style would have to:

  1. Get access to the chrome service somehow
  2. Subscribe to chromeStyle$
  3. Handle the observable subscription lifecycle

Now it's just a one-liner hook call. So if other layout slots (header, navigation, sidebar, footer, etc.) or any nested components need style variations between classic and project mode in the future, the plumbing is already in place.

const { chromeStyle } = useLayoutConfig();

// Then use it for conditional styling
const isProjectStyle = chromeStyle === 'project';

headerHeight: 96,
bannerHeight: 32,

Expand All @@ -37,6 +38,7 @@ const layoutConfigs: { classic: ChromeLayoutConfig; project: ChromeLayoutConfig
navigationWidth: 48,
},
project: {
chromeStyle: 'project',
headerHeight: 48,
bannerHeight: 32,

Expand Down