Skip to content

Commit

Permalink
Convert EuiOverlayMask to @emotion/css
Browse files Browse the repository at this point in the history
- body overflow CSS still needs to be `@emotion/react`, and should be moved into a different file
  • Loading branch information
cee-chen committed Oct 4, 2022
1 parent d08a00b commit 04a81c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
44 changes: 16 additions & 28 deletions src/components/overlay_mask/overlay_mask.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,30 @@
* Side Public License, v 1.
*/

import { css } from '@emotion/react';
import { css } from '@emotion/css';
import { logicalCSS, euiAnimFadeIn } from '../../global_styling';
import { transparentize, UseEuiTheme } from '../../services';

export const euiOverlayMaskStyles = ({ euiTheme }: UseEuiTheme) => ({
euiOverlayMask: css`
.euiOverlayMask {
position: fixed;
${logicalCSS('top', 0)}
${logicalCSS('left', 0)}
${logicalCSS('right', 0)}
${logicalCSS('bottom', 0)}
display: flex;
align-items: center;
justify-content: center;
${logicalCSS('padding-bottom', '10vh')};
animation: ${euiAnimFadeIn} ${euiTheme.animation.fast} ease-in;
background: ${transparentize(euiTheme.colors.ink, 0.5)};
}
position: fixed;
${logicalCSS('top', 0)}
${logicalCSS('left', 0)}
${logicalCSS('right', 0)}
${logicalCSS('bottom', 0)}
display: flex;
align-items: center;
justify-content: center;
${logicalCSS('padding-bottom', '10vh')};
animation: ${euiAnimFadeIn} ${euiTheme.animation.fast} ease-in;
background: ${transparentize(euiTheme.colors.ink, 0.5)};
`,
aboveHeader: css`
.euiOverlayMask {
z-index: ${euiTheme.levels.mask};
}
z-index: ${euiTheme.levels.mask};
`,
belowHeader: css`
.euiOverlayMask {
z-index: ${euiTheme.levels.maskBelowHeader};
// TODO: use size variable when EuiHeader is converted
${logicalCSS('top', `${euiTheme.base * 3}px`)};
}
z-index: ${euiTheme.levels.maskBelowHeader};
// TODO: use size variable when EuiHeader is converted
${logicalCSS('top', `${euiTheme.base * 3}px`)};
`,
});

export const euiOverlayMaskBodyStyles = css`
body {
overflow: hidden;
}
`;
17 changes: 7 additions & 10 deletions src/components/overlay_mask/overlay_mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import React, {
useEffect,
useState,
} from 'react';
import classNames from 'classnames';
import { cx } from '@emotion/css';
import { Global } from '@emotion/react';
import { CommonProps, keysOf } from '../common';
import { useCombinedRefs, useEuiTheme } from '../../services';
import { EuiPortal } from '../portal';
import {
euiOverlayMaskStyles,
euiOverlayMaskBodyStyles,
} from './overlay_mask.styles';
import { euiOverlayMaskStyles } from './overlay_mask.styles';
import { euiOverlayMaskBodyStyles } from './overlay_mask_body.styles';

export interface EuiOverlayMaskInterface {
/**
Expand Down Expand Up @@ -69,10 +67,10 @@ export const EuiOverlayMask: FunctionComponent<EuiOverlayMaskProps> = ({
]);
const euiTheme = useEuiTheme();
const styles = euiOverlayMaskStyles(euiTheme);
const cssStyles = [
const cssStyles = cx([
styles.euiOverlayMask,
styles[`${headerZindexLocation}Header`],
];
]);

useEffect(() => {
if (!overlayMaskNode) return;
Expand All @@ -90,13 +88,12 @@ export const EuiOverlayMask: FunctionComponent<EuiOverlayMaskProps> = ({

useEffect(() => {
if (!overlayMaskNode) return;
overlayMaskNode.className = classNames('euiOverlayMask', className);
}, [overlayMaskNode, className]);
overlayMaskNode.className = cx('euiOverlayMask', cssStyles, className);
}, [overlayMaskNode, cssStyles, className]);

return (
<EuiPortal portalRef={combinedMaskRef}>
<Global styles={euiOverlayMaskBodyStyles} />
<Global styles={cssStyles} />
{children}
</EuiPortal>
);
Expand Down
15 changes: 15 additions & 0 deletions src/components/overlay_mask/overlay_mask_body.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';

export const euiOverlayMaskBodyStyles = css`
body {
overflow: hidden;
}
`;

0 comments on commit 04a81c6

Please sign in to comment.