Skip to content

Commit

Permalink
[CSS-in-JS] Convert EuiErrorBoundary (#6053)
Browse files Browse the repository at this point in the history
* convert euierrorboundary to styling via emotion

* CL

* use classNames

* WIP: background-image

* safari 15.4 repeating-linear-gradient fix
  • Loading branch information
thompsongl authored Jul 20, 2022
1 parent 5916088 commit 74edbd0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
13 changes: 0 additions & 13 deletions src/components/error_boundary/_error_boundary.scss

This file was deleted.

1 change: 0 additions & 1 deletion src/components/error_boundary/_index.scss

This file was deleted.

31 changes: 31 additions & 0 deletions src/components/error_boundary/error_boundary.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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';
import { logicalCSS } from '../../global_styling';
import { transparentize, UseEuiTheme } from '../../services';

export const euiErrorBoundaryStyles = ({ euiTheme }: UseEuiTheme) => {
const color1 = transparentize(euiTheme.colors.danger, 0.25);
const color2 = transparentize(euiTheme.colors.danger, 0.05);

return {
euiErrorBoundary: css`
background-image: repeating-linear-gradient(
45deg,
${color1},
${color1} 1px,
${color2} 1px,
${color2} 19px
);
background-size: 54px 54px; // Fix for Safari 15.4+
${logicalCSS('padding-horizontal', euiTheme.size.base)};
${logicalCSS('padding-vertical', euiTheme.size.base)};
`,
};
};
29 changes: 23 additions & 6 deletions src/components/error_boundary/error_boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
*/

import React, { Component, HTMLAttributes, ReactNode } from 'react';
import { CommonProps } from '../common';
import classNames from 'classnames';
import { CommonProps } from '../common';

import { EuiTitle } from '../title';
import { EuiCodeBlock } from '../code';
import { EuiI18n } from '../i18n';
import { withEuiTheme, WithEuiThemeProps } from '../../services';

import { euiErrorBoundaryStyles } from './error_boundary.styles';

interface EuiErrorBoundaryState {
hasError: boolean;
Expand All @@ -27,11 +30,13 @@ export type EuiErrorBoundaryProps = CommonProps &
children: ReactNode;
};

export class EuiErrorBoundary extends Component<
EuiErrorBoundaryProps,
type EuiErrorBoundaryExtendedProps = EuiErrorBoundaryProps & WithEuiThemeProps;

export class _EuiErrorBoundary extends Component<
EuiErrorBoundaryExtendedProps,
EuiErrorBoundaryState
> {
constructor(props: EuiErrorBoundaryProps) {
constructor(props: EuiErrorBoundaryExtendedProps) {
super(props);

const errorState: EuiErrorBoundaryState = {
Expand All @@ -57,14 +62,22 @@ ${stackStr}`;
}

render() {
const { children, 'data-test-subj': _dataTestSubj, ...rest } = this.props;
const {
className,
children,
'data-test-subj': _dataTestSubj,
theme,
...rest
} = this.props;
const dataTestSubj = classNames('euiErrorBoundary', _dataTestSubj);
const styles = euiErrorBoundaryStyles(theme);

if (this.state.hasError) {
// You can render any custom fallback UI
return (
<div
className="euiErrorBoundary"
css={styles.euiErrorBoundary}
className={classNames('euiErrorBoundary', className)}
data-test-subj={dataTestSubj}
{...rest}
>
Expand All @@ -83,3 +96,7 @@ ${stackStr}`;
return children;
}
}

export const EuiErrorBoundary = withEuiTheme<EuiErrorBoundaryProps>(
_EuiErrorBoundary
);
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@import 'description_list/index';
@import 'drag_and_drop/index';
@import 'empty_prompt/index';
@import 'error_boundary/index';
@import 'filter_group/index';
@import 'flex/index';
@import 'flyout/index';
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6053.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**CSS-in-JS conversions**

- Converted `EuiErrorBoundary` to Emotion

0 comments on commit 74edbd0

Please sign in to comment.