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] Converted EuiLoadingChart #5821

Merged
merged 15 commits into from
Apr 25, 2022
Merged
2 changes: 1 addition & 1 deletion src-docs/src/views/loading/loading_chart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { EuiLoadingChart } from '../../../../src/components/loading';
import { EuiLoadingChart } from '../../../../src';

export default () => (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/loading/loading_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const LoadingExample = {
),
props: { EuiLoadingChart },
demo: <LoadingChart />,
snippet: '<EuiLoadingChart size="m" />',
snippet: ['<EuiLoadingChart size="m" />', '<EuiLoadingChart mono />'],
playground: loadingChartConfig,
},
{
Expand Down
59 changes: 34 additions & 25 deletions src/components/loading/__snapshots__/loading_chart.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,105 @@
exports[`EuiLoadingChart is rendered 1`] = `
<span
aria-label="aria-label"
class="euiLoadingChart testClass1 testClass2 euiLoadingChart--medium"
class="euiLoadingChart testClass1 testClass2 euiLoadingChart--medium css-1ho1qj7-euiLoadingChart-m"
data-test-subj="test subject string"
role="progressbar"
>
<span
class="euiLoadingChart__bar"
class="css-1th8mu7-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-1h0t0ot-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-uodvp1-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-tt9vi3-euiLoadingChart__bar-m-euiCanAnimate"
/>
</span>
`;

exports[`EuiLoadingChart mono is rendered 1`] = `
<span
class="euiLoadingChart euiLoadingChart--mono euiLoadingChart--medium"
aria-label="Loading"
class="euiLoadingChart euiLoadingChart--mono euiLoadingChart--medium css-1ho1qj7-euiLoadingChart-m"
role="progressbar"
>
<span
class="euiLoadingChart__bar"
class="css-1rjdlrm-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-1psa3pr-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-ii216z-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-eldpjp-euiLoadingChart__bar-m-euiCanAnimate"
/>
</span>
`;

exports[`EuiLoadingChart size l is rendered 1`] = `
<span
class="euiLoadingChart euiLoadingChart--large"
aria-label="Loading"
class="euiLoadingChart euiLoadingChart--large css-1xdgh7e-euiLoadingChart-l"
role="progressbar"
>
<span
class="euiLoadingChart__bar"
class="css-17mln21-euiLoadingChart__bar-l-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-owe0jo-euiLoadingChart__bar-l-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-15sf8ua-euiLoadingChart__bar-l-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-10zon6n-euiLoadingChart__bar-l-euiCanAnimate"
/>
</span>
`;

exports[`EuiLoadingChart size m is rendered 1`] = `
<span
class="euiLoadingChart euiLoadingChart--medium"
aria-label="Loading"
class="euiLoadingChart euiLoadingChart--medium css-1ho1qj7-euiLoadingChart-m"
role="progressbar"
>
<span
class="euiLoadingChart__bar"
class="css-1th8mu7-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-1h0t0ot-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-uodvp1-euiLoadingChart__bar-m-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-tt9vi3-euiLoadingChart__bar-m-euiCanAnimate"
/>
</span>
`;

exports[`EuiLoadingChart size xl is rendered 1`] = `
<span
class="euiLoadingChart euiLoadingChart--xLarge"
aria-label="Loading"
class="euiLoadingChart euiLoadingChart--xLarge css-wh2pju-euiLoadingChart-xl"
role="progressbar"
>
<span
class="euiLoadingChart__bar"
class="css-10nwhuu-euiLoadingChart__bar-xl-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-191l3dt-euiLoadingChart__bar-xl-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-riztfw-euiLoadingChart__bar-xl-euiCanAnimate"
/>
<span
class="euiLoadingChart__bar"
class="css-fvdwz7-euiLoadingChart__bar-xl-euiCanAnimate"
/>
</span>
`;
1 change: 0 additions & 1 deletion src/components/loading/_index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import 'variables';
@import 'loading_elastic';
@import 'loading_chart';
@import 'loading_content';
@import 'loading_logo';
@import 'loading_spinner';
118 changes: 0 additions & 118 deletions src/components/loading/_loading_chart.scss

This file was deleted.

86 changes: 86 additions & 0 deletions src/components/loading/loading_chart.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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, keyframes } from '@emotion/react';
import { euiPaletteColorBlind, shadeOrTint, UseEuiTheme } from '../../services';
import { euiCanAnimate } from '../../global_styling/variables/_animations';

export const euiLoadingChartStyles = ({ euiTheme }: UseEuiTheme) => ({
euiLoadingChart: css`
overflow: hidden;
display: inline-flex;
`,
m: css`
height: ${euiTheme.size.base};
gap: ${euiTheme.size.xxs};
`,
l: css`
height: ${euiTheme.size.l};
gap: ${euiTheme.size.xxs};
`,
xl: css`
height: ${euiTheme.size.xl};
gap: ${euiTheme.size.xs};
`,
});

export const euiLoadingChartBarStyles = ({ euiTheme }: UseEuiTheme) => ({
euiLoadingChart__bar: css`
height: 100%;
display: inline-block;
`,
m: css`
width: ${euiTheme.size.xxs};
margin-block-end: ${euiTheme.size.s};
`,
l: css`
width: ${euiTheme.size.xs};
margin-block-end: ${euiTheme.size.m};
`,
xl: css`
width: ${euiTheme.size.s};
margin-block-end: ${euiTheme.size.base};
`,
});

const barAnimation = keyframes`
0% {
transform: translateY(0);
}

50% {
transform: translateY(66%);
}

100% {
transform: translateY(0);
}
`;

export const _barIndex = (
index: number,
mono: boolean,
{ euiTheme, colorMode }: UseEuiTheme
) => {
const backgroundColor = mono
? shadeOrTint(euiTheme.colors.lightShade, index * 0.04, colorMode)
: euiPaletteColorBlind()[index];

return css`
background-color: ${backgroundColor};
// Without the animation, the bars are all the same height,
// so we apply transforms which are overridden by the animation if animations are allowed
transform: translateY(${22 * index}%);

${euiCanAnimate(
css`
animation: ${barAnimation} 1s ${`.${index}s`} infinite;
`
)}
`;
};
4 changes: 4 additions & 0 deletions src/components/loading/loading_chart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
// import { renderWithStyles } from '../../test/internal';

import { EuiLoadingChart, SIZES } from './loading_chart';

describe('EuiLoadingChart', () => {
// renderWithStyles(<EuiLoadingChart />);

cchaos marked this conversation as resolved.
Show resolved Hide resolved
test('is rendered', () => {
const component = render(<EuiLoadingChart {...requiredProps} />);

Expand All @@ -24,6 +27,7 @@ describe('EuiLoadingChart', () => {

expect(component).toMatchSnapshot();
});

describe('size', () => {
SIZES.forEach((size) => {
test(`${size} is rendered`, () => {
Expand Down
Loading