Skip to content

Commit

Permalink
add isLoading prop to EuiButtonEmpty (#768)
Browse files Browse the repository at this point in the history
* add isLoading prop to EuiButtonEmpty

* change log
  • Loading branch information
nreese authored May 3, 2018
1 parent c4735a1 commit bd21c3b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added `EuiDescribedFormGroup` component, a wrapper around `EuiFormRow`(s) ([#707](https://github.com/elastic/eui/pull/707))
- Added `describedByIds` prop to `EuiFormRow` to help with accessibility ([#707](https://github.com/elastic/eui/pull/707))
- Added `isLoading` prop to `EuiButtonEmpty` ([#768](https://github.com/elastic/eui/pull/768))

## [`0.0.45`](https://github.com/elastic/eui/tree/v0.0.45)

Expand Down
21 changes: 21 additions & 0 deletions src-docs/src/views/button/button_empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,27 @@ export default () => (
</EuiFlexItem>
</EuiFlexGroup>

<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={() => window.alert('Button clicked')}
isLoading
>
Loading
</EuiButtonEmpty>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={() => window.alert('Button clicked')}
isLoading
iconSide="right"
>
Loading
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>

<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
Expand Down
23 changes: 22 additions & 1 deletion src/components/button/button_empty/button_empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import {
EuiLoadingSpinner
} from '../../loading';

import { getSecureRelForTarget } from '../../../services';

import {
Expand Down Expand Up @@ -50,6 +54,7 @@ export const EuiButtonEmpty = ({
size,
flush,
isDisabled,
isLoading,
href,
target,
rel,
Expand All @@ -58,6 +63,9 @@ export const EuiButtonEmpty = ({
...rest
}) => {

// If in the loading state, force disabled to true
isDisabled = isLoading ? true : isDisabled;

const classes = classNames(
'euiButtonEmpty',
colorToClassNameMap[color],
Expand All @@ -70,7 +78,14 @@ export const EuiButtonEmpty = ({
// Add an icon to the button if one exists.
let buttonIcon;

if (iconType) {
if (isLoading) {
buttonIcon = (
<EuiLoadingSpinner
className="euiButton__spinner"
size="m"
/>
);
} else if (iconType) {
buttonIcon = (
<EuiIcon
className="euiButtonEmpty__icon"
Expand Down Expand Up @@ -130,6 +145,12 @@ EuiButtonEmpty.propTypes = {
target: PropTypes.string,
rel: PropTypes.string,
onClick: PropTypes.func,

/**
* Adds/swaps for loading spinner & disables
*/
isLoading: PropTypes.bool,

type: PropTypes.string,
buttonRef: PropTypes.func,
};
Expand Down

0 comments on commit bd21c3b

Please sign in to comment.