2018-06-20 11:50:31 +08:00
|
|
|
import Component from '../Component';
|
|
|
|
import { Spinner } from 'spin.js';
|
2015-07-15 12:30:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The `LoadingIndicator` component displays a loading spinner with spin.js. It
|
|
|
|
* may have the following special props:
|
|
|
|
*
|
|
|
|
* - `size` The spin.js size preset to use. Defaults to 'small'.
|
|
|
|
*
|
|
|
|
* All other props will be assigned as attributes on the element.
|
|
|
|
*/
|
|
|
|
export default class LoadingIndicator extends Component {
|
|
|
|
view() {
|
|
|
|
const attrs = Object.assign({}, this.props);
|
|
|
|
|
2015-07-17 13:17:49 +08:00
|
|
|
attrs.className = 'LoadingIndicator ' + (attrs.className || '');
|
2015-07-15 12:30:11 +08:00
|
|
|
delete attrs.size;
|
|
|
|
|
|
|
|
return <div {...attrs}>{m.trust(' ')}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
config() {
|
2018-06-20 11:50:31 +08:00
|
|
|
const options = { zIndex: 'auto', color: this.$().css('color') };
|
2015-07-15 12:30:11 +08:00
|
|
|
|
2018-06-20 11:50:31 +08:00
|
|
|
switch (this.props.size) {
|
|
|
|
case 'large':
|
|
|
|
Object.assign(options, { lines: 10, length: 8, width: 4, radius: 8 });
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Object.assign(options, { lines: 8, length: 4, width: 3, radius: 5 });
|
|
|
|
}
|
|
|
|
|
|
|
|
new Spinner(options).spin(this.element);
|
2015-07-15 12:30:11 +08:00
|
|
|
}
|
|
|
|
}
|