-
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 fe3f253
Showing
8 changed files
with
180 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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, | ||
loadingHoverElement = children, | ||
dts, | ||
} = props; | ||
|
||
return ( | ||
<Button | ||
disabled={isLoading || props.disabled} | ||
{..._.pick(props, _.keys(Button.propTypes))} | ||
className={classNames('spinner-button-component', props.className)} | ||
{...expandDts(dts)} | ||
> | ||
<div className={`spinner-container ${isLoading ? '' : 'spinner-button-hidden'}`}> | ||
<div className="spinner-button-spinner"> | ||
<Spinner size={_.includes(['lg', 'large'], props.bsSize) ? 'medium' : 'small'} /> | ||
</div> | ||
<div className="spinner-button-hidden">{loadingHoverElement}</div> | ||
</div> | ||
<div className={isLoading ? 'spinner-button-hidden' : null}>{children}</div> | ||
</Button> | ||
); | ||
}; | ||
|
||
SpinnerButton.propTypes = _.assign({ | ||
isLoading: PropTypes.bool, | ||
loadingHoverElement: PropTypes.node, | ||
dts: PropTypes.string, | ||
}, Button.propTypes); | ||
|
||
SpinnerButton.defaultProps = { | ||
isLoading: false, | ||
}; | ||
|
||
// SpinnerButton.Spinner = Spinner; | ||
|
||
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,48 @@ | ||
.spinner-button { | ||
@mixin fill-area { | ||
position: absolute; | ||
right: 0; | ||
left: 0; | ||
margin-right: auto; | ||
margin-left: auto; | ||
} | ||
|
||
&-hidden { | ||
visibility: hidden; | ||
} | ||
|
||
&-spinner { | ||
@include fill-area; | ||
} | ||
|
||
&-component { | ||
|
||
.spinner-container { | ||
@include fill-area; | ||
|
||
&:hover { | ||
|
||
.spinner-button-spinner { | ||
visibility: hidden; | ||
} | ||
|
||
.spinner-button-hidden { | ||
visibility: initial; | ||
} | ||
} | ||
|
||
// 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,51 @@ | ||
import React from 'react'; | ||
import SpinnerButton from 'components/adslotUi/SpinnerButtonComponent'; | ||
import { shallow } from 'enzyme'; | ||
import assert from 'assert'; | ||
|
||
describe('SpinnerButtonComponent', () => { | ||
it('should render with defaults', () => { | ||
const element = shallow(<SpinnerButton>Test</SpinnerButton>); | ||
assert(element.find('Spinner')); | ||
const buttonElement = element.find('Button'); | ||
assert(!buttonElement.prop('disabled')); | ||
assert(!buttonElement.prop('isLoading')); | ||
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> | ||
); | ||
|
||
const buttonElement = element.find('Button[data-test-selector="test"]'); | ||
expect(buttonElement.prop('bsStyle')).to.equal('primary'); | ||
expect(buttonElement.prop('bsSize')).to.equal('lg'); | ||
assert(!buttonElement.prop('isLoading')); | ||
}); | ||
|
||
it('should accept custom loading hover element', () => { | ||
const element = shallow( | ||
<SpinnerButton loadingHoverElement="loading…">Test</SpinnerButton> | ||
); | ||
expect(element.children().first().text()).to.contains('loading…'); | ||
}); | ||
|
||
it('should be disabled in loading mode', () => { | ||
const element = shallow( | ||
<SpinnerButton>Test</SpinnerButton> | ||
); | ||
element.setProps({ isLoading: true }); | ||
const buttonElement = element.find('Button'); | ||
assert(buttonElement.prop('disabled')); | ||
}); | ||
|
||
it('should have disabled state controled by disabled prop if present regardless of isLoading prop', () => { | ||
const element = shallow( | ||
<SpinnerButton isLoading="false" disabled>Test</SpinnerButton> | ||
); | ||
|
||
const buttonElement = element.find('Button'); | ||
assert(buttonElement.prop('disabled')); | ||
}); | ||
}); |