Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emotion] Convert EuiHealth #5832

Merged
merged 7 commits into from
Apr 26, 2022
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
32 changes: 16 additions & 16 deletions src/components/health/__snapshots__/health.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiHealth is rendered 1`] = `
<div
aria-label="aria-label"
class="euiHealth euiHealth--textSizeS testClass1 testClass2"
class="euiHealth testClass1 testClass2 css-qn8ayk-euiHealth-s"
data-test-subj="test subject string"
>
<div
Expand All @@ -25,7 +25,7 @@ exports[`EuiHealth is rendered 1`] = `

exports[`EuiHealth props color #000000 is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -47,7 +47,7 @@ exports[`EuiHealth props color #000000 is rendered 1`] = `

exports[`EuiHealth props color accent is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -69,7 +69,7 @@ exports[`EuiHealth props color accent is rendered 1`] = `

exports[`EuiHealth props color danger is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -91,7 +91,7 @@ exports[`EuiHealth props color danger is rendered 1`] = `

exports[`EuiHealth props color default is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -113,7 +113,7 @@ exports[`EuiHealth props color default is rendered 1`] = `

exports[`EuiHealth props color ghost is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -135,7 +135,7 @@ exports[`EuiHealth props color ghost is rendered 1`] = `

exports[`EuiHealth props color inherit is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -157,7 +157,7 @@ exports[`EuiHealth props color inherit is rendered 1`] = `

exports[`EuiHealth props color primary is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -179,7 +179,7 @@ exports[`EuiHealth props color primary is rendered 1`] = `

exports[`EuiHealth props color subdued is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -201,7 +201,7 @@ exports[`EuiHealth props color subdued is rendered 1`] = `

exports[`EuiHealth props color success is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -223,7 +223,7 @@ exports[`EuiHealth props color success is rendered 1`] = `

exports[`EuiHealth props color text is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -245,7 +245,7 @@ exports[`EuiHealth props color text is rendered 1`] = `

exports[`EuiHealth props color warning is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -267,7 +267,7 @@ exports[`EuiHealth props color warning is rendered 1`] = `

exports[`EuiHealth props textSize inherit is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeInherit"
class="euiHealth css-1eqikqq-euiHealth-inherit"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -289,7 +289,7 @@ exports[`EuiHealth props textSize inherit is rendered 1`] = `

exports[`EuiHealth props textSize m is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeM"
class="euiHealth css-28ntf-euiHealth-m"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -311,7 +311,7 @@ exports[`EuiHealth props textSize m is rendered 1`] = `

exports[`EuiHealth props textSize s is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeS"
class="euiHealth css-qn8ayk-euiHealth-s"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand All @@ -333,7 +333,7 @@ exports[`EuiHealth props textSize s is rendered 1`] = `

exports[`EuiHealth props textSize xs is rendered 1`] = `
<div
class="euiHealth euiHealth--textSizeXS"
class="euiHealth css-ft4ki3-euiHealth-xs"
>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
Expand Down
19 changes: 0 additions & 19 deletions src/components/health/_health.scss

This file was deleted.

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

This file was deleted.

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

export const euiHealthStyles = ({ euiTheme }: UseEuiTheme) => ({
euiHealth: css`
display: inline-block;
`,
// Text sizes
xs: css`
${euiFontSize('xs', euiTheme)}
`,
s: css`
${euiFontSize('s', euiTheme)}
`,
m: css`
${euiFontSize('m', euiTheme)}
`,
inherit: css`
font-size: inherit;
`,
});
7 changes: 5 additions & 2 deletions src/components/health/health.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { TEXT_SIZES, EuiHealth } from './health';
import { shouldRenderCustomStyles } from '../../test/internal';
breehall marked this conversation as resolved.
Show resolved Hide resolved
import { COLORS } from '../icon/icon';
import { EuiHealth, TEXT_SIZES } from './health';

describe('EuiHealth', () => {
test('is rendered', () => {
Expand All @@ -19,9 +20,11 @@ describe('EuiHealth', () => {
expect(component).toMatchSnapshot();
});

shouldRenderCustomStyles(<EuiHealth />);

describe('props', () => {
describe('textSize', () => {
TEXT_SIZES.forEach((textSize) => {
TEXT_SIZES.forEach((textSize: any) => {
test(`${textSize} is rendered`, () => {
const component = render(
<EuiHealth textSize={textSize} color="success" />
Expand Down
25 changes: 9 additions & 16 deletions src/components/health/health.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@

import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';
import { useEuiTheme } from '../../services';
import { euiHealthStyles } from './health.styles';

import { CommonProps } from '../common';
import { EuiIcon, IconColor } from '../icon';

import { EuiFlexGroup, EuiFlexItem } from '../flex';

const sizeToClassNameMap = {
xs: 'euiHealth--textSizeXS',
s: 'euiHealth--textSizeS',
m: 'euiHealth--textSizeM',
inherit: 'euiHealth--textSizeInherit',
};

export const TEXT_SIZES = keysOf(sizeToClassNameMap);
export const TEXT_SIZES = ['xs', 's', 'm', 'inherit'] as const;

export type EuiHealthProps = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'color'> & {
Expand All @@ -45,14 +39,13 @@ export const EuiHealth: FunctionComponent<EuiHealthProps> = ({
textSize = 's',
...rest
}) => {
const classes = classNames(
'euiHealth',
textSize ? sizeToClassNameMap[textSize] : null,
className
);
const euiTheme = useEuiTheme();
const styles = euiHealthStyles(euiTheme);
const cssStyles = [styles.euiHealth, styles[textSize]];
const classes = classNames('euiHealth', className);

return (
<div className={classes} {...rest}>
<div css={cssStyles} className={classes} {...rest}>
<EuiFlexGroup gutterSize="xs" alignItems="center" responsive={false}>
<EuiFlexItem grow={false}>
<EuiIcon type="dot" color={color} />
Expand Down
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
@import 'flyout/index';
@import 'form/index';
@import 'header/index';
@import 'health/index';
@import 'icon/index';
@import 'image/index';
@import 'key_pad_menu/index';
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/5832.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**CSS-in-JS conversions**

- Converted `EuiHealth` to Emotion