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

Adding a content block loading animation. #1730

Merged
merged 11 commits into from
Mar 22, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## [`9.5.0`](https://github.com/elastic/eui/tree/v9.5.0)

- Changed `EuiSuperDatePicker` to call `onRefresh` instead of `onTimeChanged` when user clicks "Refresh" button ([#1745](https://github.com/elastic/eui/pull/1745))
- Added a new `EuiLoadingContent` component that displays blocks as placeholders for text. ([#1730](https://github.com/elastic/eui/pull/1730))
- Added documentation entry in `EuiPagination` for `activePage` prop. ([#1740](https://github.com/elastic/eui/pull/1740))
- Changed `EuiButton` to use "m" as it's default `size` prop ([#1742](https://github.com/elastic/eui/pull/1742))
- Adds type definitions for `EuiListGroup` and `EuiListGroupItem` ([#1737](https://github.com/elastic/eui/pull/1737))
Expand Down
9 changes: 9 additions & 0 deletions src-docs/src/views/loading/loading_content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

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

export default () => (
<div>
<EuiLoadingContent lines={3} />
</div>
);
24 changes: 24 additions & 0 deletions src-docs/src/views/loading/loading_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {
} from '../../components';

import {
EuiCode,
EuiLoadingKibana,
EuiLoadingSpinner,
EuiLoadingChart,
EuiLoadingContent,
} from '../../../../src/components';

import LoadingKibana from './loading_kibana';
Expand All @@ -24,6 +26,10 @@ import LoadingSpinner from './loading_spinner';
const loadingSpinnerSource = require('!!raw-loader!./loading_spinner');
const loadingSpinnerHtml = renderToHtml(LoadingSpinner);

import LoadingContent from './loading_content';
const loadingContentSource = require('!!raw-loader!./loading_content');
const loadingContentHtml = renderToHtml(LoadingContent);

export const LoadingExample = {
title: 'Loading',
sections: [{
Expand Down Expand Up @@ -80,5 +86,23 @@ export const LoadingExample = {
props: { EuiLoadingSpinner },
demo: <LoadingSpinner />,
snippet: `<EuiLoadingSpinner size="m" />`
}, {
title: 'Text Content',
source: [{
type: GuideSectionTypes.JS,
code: loadingContentSource,
}, {
type: GuideSectionTypes.HTML,
code: loadingContentHtml,
}],
text: (
<p>
A simple loading animation for displaying placeholder text content.
You can pass in a number of <EuiCode>lines</EuiCode> between 1 and 10.
</p>
),
props: { EuiLoadingContent },
demo: <LoadingContent />,
snippet: `<EuiLoadingContent lines={3} />`
}],
};
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export {
export {
EuiLoadingKibana,
EuiLoadingChart,
EuiLoadingContent,
EuiLoadingSpinner,
} from './loading';

Expand Down
2 changes: 2 additions & 0 deletions src/components/loading/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import 'variables';
@import 'mixins';
@import 'loading_kibana';
@import 'loading_chart';
@import 'loading_content';
@import 'loading_spinner';
38 changes: 38 additions & 0 deletions src/components/loading/_loading_content.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.euiLoadingContent__loader {
width: 100%;
}

.euiLoadingContent__singleLine {
width: 100%;
height: $euiSize;
margin-bottom: $euiSizeS;
border-radius: $euiBorderRadius;
overflow: hidden;

&:last-child:not(:only-child) {
width: 75%;
}
}

.euiLoadingContent__singleLineBackground {
width: 220%;
height: 100%;
background: linear-gradient(
to right,
$euiGradientStartStop 45%,
$euiGradientMiddle 50%,
$euiGradientStartStop 55%,
);
animation: euiLoadingContentGradientLoad 1.5s $euiAnimSlightResistance infinite;
}

@keyframes euiLoadingContentGradientLoad {
0% {
transform: translateX(-53%);
}

100% {
transform: translateX(0);
}
}

2 changes: 2 additions & 0 deletions src/components/loading/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$euiGradientStartStop: tintOrShade($euiColorLightShade, 5%, 12%);
$euiGradientMiddle: tintOrShade($euiColorLightShade, 50%, 24%);
1 change: 1 addition & 0 deletions src/components/loading/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { EuiLoadingKibana } from './loading_kibana';
export { EuiLoadingChart } from './loading_chart';
export { EuiLoadingContent } from './loading_content';
export { EuiLoadingSpinner } from './loading_spinner';
29 changes: 29 additions & 0 deletions src/components/loading/loading_content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';
import { CommonProps } from '../common';

type LineRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary now that each line is a block level element so you don't have to calculate the y position. You can leave lines as a number type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I limited this more as a design decision to prevent it being used for giant walls of text. That's just a philosophy thing though. I can remove the limit if the preference is to keep EUI less opinionated. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with being opinionated, I was just thinking about cleanliness. I'm fine if you'd like to keep it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool beans. I'll leave it here for the time being. We'll see what kind of feedback we get.


export const EuiLoadingContent: FunctionComponent<
CommonProps &
HTMLAttributes<HTMLDivElement> & {
lines?: LineRange;
}
> = ({ lines = 3, className, ...rest }) => {
const classes = classNames('euiLoadingContent', className);
const lineElements = [];

for (let i = 0; i < lines; i++) {
lineElements.push(
<div key={i} className="euiLoadingContent__singleLine">
<div className="euiLoadingContent__singleLineBackground" />
</div>
);
}

return (
<div className={classes} {...rest}>
{lineElements}
</div>
);
};