mirror of
https://github.com/flarum/core.git
synced 2025-08-09 01:46:35 +02:00
cleanup: common/components/Button
This commit is contained in:
committed by
Franz Liedke
parent
652d961907
commit
f72d118bec
@@ -1,5 +1,6 @@
|
|||||||
import Component from '../Component';
|
import Component from '../Component';
|
||||||
import icon from '../helpers/icon';
|
import icon from '../helpers/icon';
|
||||||
|
import classList from '../utils/classList';
|
||||||
import extract from '../utils/extract';
|
import extract from '../utils/extract';
|
||||||
import extractText from '../utils/extractText';
|
import extractText from '../utils/extractText';
|
||||||
import LoadingIndicator from './LoadingIndicator';
|
import LoadingIndicator from './LoadingIndicator';
|
||||||
@@ -24,7 +25,6 @@ export default class Button extends Component {
|
|||||||
view(vnode) {
|
view(vnode) {
|
||||||
const attrs = Object.assign({}, this.attrs);
|
const attrs = Object.assign({}, this.attrs);
|
||||||
|
|
||||||
attrs.className = attrs.className || '';
|
|
||||||
attrs.type = attrs.type || 'button';
|
attrs.type = attrs.type || 'button';
|
||||||
|
|
||||||
// If a tooltip was provided for buttons without additional content, we also
|
// If a tooltip was provided for buttons without additional content, we also
|
||||||
@@ -39,14 +39,14 @@ export default class Button extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const iconName = extract(attrs, 'icon');
|
const iconName = extract(attrs, 'icon');
|
||||||
if (iconName) attrs.className += ' hasIcon';
|
|
||||||
|
|
||||||
const loading = extract(attrs, 'loading');
|
const loading = extract(attrs, 'loading');
|
||||||
if (attrs.disabled || loading) {
|
if (attrs.disabled || loading) {
|
||||||
attrs.className += ' disabled' + (loading ? ' loading' : '');
|
|
||||||
delete attrs.onclick;
|
delete attrs.onclick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attrs.className = classList([attrs.className, iconName && 'hasIcon', attrs.disabled && 'disabled', loading && 'loading']);
|
||||||
|
|
||||||
return <button {...attrs}>{this.getButtonContent(vnode.children)}</button>;
|
return <button {...attrs}>{this.getButtonContent(vnode.children)}</button>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user