diff --git a/ui_framework/components/button/button.js b/ui_framework/components/button/button.js index 5093a0dcbc422..15afbb1bf602f 100644 --- a/ui_framework/components/button/button.js +++ b/ui_framework/components/button/button.js @@ -1,15 +1,16 @@ import React, { - Component, PropTypes, } from 'react'; import classNames from 'classnames'; import keyMirror from 'keymirror'; +import { KuiLoadingButtonIcon } from './button_icon'; + const KuiButton = props => { if (props.isSubmit) { // input is a void element tag and can't have children. - if (typeof props.children !== 'string' || props.icon || props.rightIcon) { + if (typeof props.children !== 'string' || props.icon) { throw new Error( `KuiButton with isSubmit prop set to true can only accept string children, and can't display icons. This is because input is a void element and can't contain children.` @@ -29,8 +30,13 @@ const KuiButton = props => { props.onClick(props.data); } + const icon = + props.isLoading + ? + : props.icon; + const className = classNames('kuiButton', props.className, { - 'kuiButton--iconText': props.icon || props.iconRight, + 'kuiButton--iconText': icon, }); let wrappedChildren; @@ -53,11 +59,16 @@ const KuiButton = props => { const children = props.isSubmit ? null - : ( + : props.isIconOnRight + ? ( + + {wrappedChildren} + {icon} + + ) : ( - {props.icon} + {icon} {wrappedChildren} - {props.iconRight} ); @@ -77,14 +88,14 @@ KuiButton.propTypes = { testSubject: PropTypes.string, data: PropTypes.any, icon: PropTypes.node, - iconRight: PropTypes.node, + isIconOnRight: PropTypes.bool, children: PropTypes.node, isSubmit: PropTypes.bool, href: PropTypes.string, target: PropTypes.string, onClick: PropTypes.func, isDisabled: PropTypes.bool, - hasIcon: PropTypes.bool, + isLoading: PropTypes.bool, className: PropTypes.oneOfType([ PropTypes.string, PropTypes.array, diff --git a/ui_framework/components/button/button_icon.js b/ui_framework/components/button/button_icon.js index c5650f907939b..377753b8aa2af 100644 --- a/ui_framework/components/button/button_icon.js +++ b/ui_framework/components/button/button_icon.js @@ -24,6 +24,7 @@ const KuiCreateButtonIcon = () => ; const KuiDeleteButtonIcon = () => ; const KuiPreviousButtonIcon = () => ; const KuiNextButtonIcon = () => ; +const KuiLoadingButtonIcon = () => ; export { KuiButtonIcon, @@ -31,4 +32,5 @@ export { KuiDeleteButtonIcon, KuiPreviousButtonIcon, KuiNextButtonIcon, + KuiLoadingButtonIcon, }; diff --git a/ui_framework/doc_site/src/views/button/button_example.jsx b/ui_framework/doc_site/src/views/button/button_example.jsx index 81107197cf33b..c7708602c4a62 100644 --- a/ui_framework/doc_site/src/views/button/button_example.jsx +++ b/ui_framework/doc_site/src/views/button/button_example.jsx @@ -24,6 +24,9 @@ const primarySource = require('!!raw!./button_primary'); import Danger from './button_danger'; const dangerSource = require('!!raw!./button_danger'); +import Loading from './button_loading'; +const loadingSource = require('!!raw!./button_loading'); + import WithIcon from './button_with_icon'; const withIconSource = require('!!raw!./button_with_icon'); @@ -106,6 +109,18 @@ export default props => ( + + + + + + ( }/> - }/> + }/> ); diff --git a/ui_framework/doc_site/src/views/button/button_loading.js b/ui_framework/doc_site/src/views/button/button_loading.js new file mode 100644 index 0000000000000..3f58084dc6a8b --- /dev/null +++ b/ui_framework/doc_site/src/views/button/button_loading.js @@ -0,0 +1,58 @@ +import React, { + Component, +} from 'react'; + +import { + KuiCreateButtonIcon, + KuiPrimaryButton, + KuiBasicButton, +} from '../../../../components'; + +export default class LoadingButton extends Component { + constructor() { + super(); + + this.state = { + isLoading: false, + }; + + this.onClick = this.onClick.bind(this); + } + + onClick() { + this.setState({ + isLoading: true, + }); + + setTimeout(() => { + this.setState({ + isLoading: false, + }); + }, 3000); + } + + render() { + return ( +
+ + {this.state.isLoading ? 'Loading...' : 'Load more'} + + +
+ + } + isLoading={this.state.isLoading} + isDisabled={this.state.isLoading} + > + {this.state.isLoading ? 'Creating...' : 'Create'} + +
+ ); + } +} diff --git a/ui_framework/doc_site/src/views/button/button_with_icon.js b/ui_framework/doc_site/src/views/button/button_with_icon.js index 218154a03dd09..bcaa3aa8fd511 100644 --- a/ui_framework/doc_site/src/views/button/button_with_icon.js +++ b/ui_framework/doc_site/src/views/button/button_with_icon.js @@ -8,6 +8,7 @@ import { KuiDeleteButtonIcon, KuiNextButtonIcon, KuiPreviousButtonIcon, + KuiLoadingButtonIcon, KuiPrimaryButton, } from '../../../../components'; @@ -31,12 +32,18 @@ export default () => (
- }> + } isIconOnRight> Next
+ }> + Loading + + +
+ }/> );