From d10a5c781dc210d563ea8577ff56d4e5501f79d4 Mon Sep 17 00:00:00 2001 From: Jon Q Date: Mon, 15 Apr 2019 11:54:44 -0400 Subject: [PATCH] Adjust Button + Loading UI. Add + fix tests --- src/components/Button/Button.css.js | 27 ++++++++++-- src/components/Button/ButtonV2.js | 9 +++- .../Button/__tests__/ButtonV2.test.js | 44 +++++++++++++++++++ src/components/Button/docs/ButtonV2.md | 1 + src/components/Spinner/Spinner.tsx | 3 +- .../Spinner/__tests__/Spinner.test.tsx | 33 ++++++++++++-- stories/ButtonV2.stories.js | 16 ++++--- 7 files changed, 116 insertions(+), 17 deletions(-) diff --git a/src/components/Button/Button.css.js b/src/components/Button/Button.css.js index 31fde89bd..3489efe8c 100644 --- a/src/components/Button/Button.css.js +++ b/src/components/Button/Button.css.js @@ -299,6 +299,18 @@ export const makeButtonUI = (selector = 'button') => { width: 100%; } + &.is-loading { + &.is-spinButtonOnLoading { + animation: SpinButtonOnLoadAnimation 700ms linear infinite; + will-change: transform; + @keyframes SpinButtonOnLoadAnimation { + 100% { + transform: rotate(360deg); + } + } + } + } + ${makeButtonSizeStyles()} ${props => makePrimaryStyles('primary', props)} @@ -472,6 +484,12 @@ export const ButtonContentUI = styled('span')` pointer-events: none; } `}; + + ${({ isLoading }) => + isLoading && + ` + opacity: 0.35; + `}; ` export const FocusUI = styled('span')` @@ -509,9 +527,12 @@ export const FocusUI = styled('span')` ` export const SpinnerUI = styled(Spinner)` - margin-left: 8px; - position: relative; - top: -0.5px; + color: ${getColor('charcoal.500')}; + margin: -6px 0 0 -6px; + position: absolute; + z-index: 1; + top: 50%; + left: 50%; ` SpinnerUI.defaultProps = { diff --git a/src/components/Button/ButtonV2.js b/src/components/Button/ButtonV2.js index 6585de0a6..47bf16a34 100644 --- a/src/components/Button/ButtonV2.js +++ b/src/components/Button/ButtonV2.js @@ -36,6 +36,7 @@ type Props = { isLoading: boolean, isSuffix: boolean, size: ButtonSize, + spinButtonOnLoading: boolean, state?: UIState, submit: boolean, theme?: string, @@ -57,6 +58,7 @@ class Button extends Component { isLast: false, isSuffix: false, size: 'md', + spinButtonOnLoading: false, submit: false, } @@ -152,6 +154,7 @@ class Button extends Component { isLoading, isSuffix, size, + spinButtonOnLoading, state, submit, theme, @@ -174,6 +177,7 @@ class Button extends Component { isSuffix && 'is-suffix', kind && `is-${kind}`, size && `is-${size}`, + spinButtonOnLoading && 'is-spinButtonOnLoading', state && `is-${state}`, theme && `is-${theme}`, className @@ -191,12 +195,13 @@ class Button extends Component { innerRef={this.setInnerRef} type={type} > + {isLoading ? : null} {this.getChildrenMarkup()} - {isLoading ? : null} {this.getFocusMarkup()} diff --git a/src/components/Button/__tests__/ButtonV2.test.js b/src/components/Button/__tests__/ButtonV2.test.js index 040617951..41510d865 100644 --- a/src/components/Button/__tests__/ButtonV2.test.js +++ b/src/components/Button/__tests__/ButtonV2.test.js @@ -323,3 +323,47 @@ describe('Link', () => { expect(wrapper.find('button').length).toBeTruthy() }) }) + +describe('Loading', () => { + test('Add loading className, if isLoading', () => { + const wrapper = mount( - ) + return