-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b17bc5
commit 2be5a1f
Showing
9 changed files
with
153 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import _ from 'lodash'; | ||
import React, { PropTypes } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import Button from 'react-bootstrap/lib/Button'; | ||
import { Spinner } from 'alexandria-adslot'; | ||
import 'styles/adslotUi/SpinnerButton.scss'; | ||
import expandDts from '../../helpers/expandDtsHelper'; | ||
|
||
const SpinnerButton = (props) => { | ||
const { | ||
isLoading, | ||
children, | ||
dts, | ||
} = props; | ||
|
||
return ( | ||
<Button | ||
disabled={isLoading || props.disabled} | ||
{..._.pick(props, _.keys(Button.propTypes))} | ||
className={classNames('spinner-button-component', props.className)} | ||
{...expandDts(dts)} | ||
> | ||
{isLoading ? | ||
<div className="spinner-container"> | ||
<Spinner size={_.includes(['lg', 'large'], props.bsSize) ? 'medium' : 'small'} /> | ||
</div> | ||
: null } | ||
<div className={isLoading ? 'spinner-button-component-children-container' : null}>{children}</div> | ||
</Button> | ||
); | ||
}; | ||
|
||
SpinnerButton.propTypes = _.assign({ | ||
isLoading: PropTypes.bool, | ||
dts: PropTypes.string, | ||
}, Button.propTypes); | ||
|
||
SpinnerButton.defaultProps = { | ||
isLoading: false, | ||
}; | ||
|
||
export default SpinnerButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import ExampleForm from './components/forms'; | ||
import ExampleSelect from './components/selects'; | ||
|
||
module.exports = { | ||
export { | ||
ExampleForm, | ||
ExampleSelect, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.spinner-button-component { | ||
&-children-container { | ||
visibility: hidden; // preserves width and height of button | ||
} | ||
|
||
.spinner-container { | ||
position: absolute; | ||
right: 0; | ||
left: 0; | ||
margin-right: auto; | ||
margin-left: auto; | ||
|
||
// workaround for vertical centering | ||
.spinner-component { | ||
.spinner { | ||
&-small { | ||
margin-top: 1px; | ||
} | ||
|
||
&-medium { | ||
margin-top: -3px; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import SpinnerButton from 'components/adslotUi/SpinnerButtonComponent'; | ||
import { Spinner } from 'alexandria-adslot'; | ||
import { shallow } from 'enzyme'; | ||
|
||
describe('SpinnerButtonComponent', () => { | ||
it('should render with defaults', () => { | ||
const element = shallow(<SpinnerButton>Test</SpinnerButton>); | ||
expect(element.find(Spinner)).to.have.length(0); | ||
const buttonElement = element.find('Button'); | ||
console.log(buttonElement.prop('disabled')); | ||
expect(buttonElement.prop('disabled')).to.equal(false); | ||
expect(buttonElement.prop('isLoading')).to.equal(undefined); | ||
expect(element.children().last().text()).to.equal('Test'); | ||
}); | ||
|
||
it('should pass props to button', () => { | ||
const element = shallow( | ||
<SpinnerButton dts="test" bsStyle="primary" bsSize="lg" isLoading>Test</SpinnerButton> | ||
); | ||
expect(element.find(Spinner)).to.have.length(1); | ||
|
||
const buttonElement = element.find('Button[data-test-selector="test"]'); | ||
expect(buttonElement.prop('bsStyle')).to.equal('primary'); | ||
expect(buttonElement.prop('bsSize')).to.equal('lg'); | ||
expect(buttonElement.prop('isLoading')).to.equal(undefined); | ||
}); | ||
|
||
it('should be disabled in loading mode', () => { | ||
const element = shallow( | ||
<SpinnerButton isLoading>Test</SpinnerButton> | ||
); | ||
const buttonElement = element.find('Button'); | ||
console.log(buttonElement.prop('disabled')); | ||
expect(buttonElement.prop('disabled')).to.equal(true); | ||
}); | ||
|
||
it('should preserve disabled state even when not loading', () => { | ||
const element = shallow( | ||
<SpinnerButton disabled>Test</SpinnerButton> | ||
); | ||
|
||
const buttonElement = element.find('Button'); | ||
expect(buttonElement.prop('isLoading')).to.equal(undefined); | ||
expect(buttonElement.prop('disabled')).to.equal(true); | ||
}); | ||
}); |