2021-10-15 16:48:38 +02:00
|
|
|
import '@material/mwc-circular-progress';
|
|
|
|
|
2021-11-09 12:15:15 +01:00
|
|
|
import {type Button} from '@material/mwc-button';
|
|
|
|
import {type ClassComponent} from 'mithril';
|
|
|
|
|
2021-10-15 16:48:38 +02:00
|
|
|
import Component from './Component.jsx';
|
|
|
|
import Mdi from './Mdi.jsx';
|
2021-12-07 16:34:00 +01:00
|
|
|
import type CSS from 'csstype';
|
2021-10-15 16:48:38 +02:00
|
|
|
|
2021-11-09 12:15:15 +01:00
|
|
|
export default class LoadingButton extends Component implements ClassComponent<Button> {
|
2021-10-15 16:48:38 +02:00
|
|
|
view(vnode) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<mwc-button {...this.attrs.all()}>
|
|
|
|
<span slot="icon" style="display: inline;">
|
|
|
|
<mwc-circular-progress
|
|
|
|
indeterminate
|
2021-12-07 16:34:00 +01:00
|
|
|
style={this.getCSSProperties()}/>
|
2021-10-15 16:48:38 +02:00
|
|
|
{this.attrs.has('icon') ? <Mdi icon={this.attrs.get('icon')}/> : ''}
|
|
|
|
</span>
|
|
|
|
</mwc-button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-07 16:34:00 +01:00
|
|
|
getCSSProperties() {
|
|
|
|
const css: CSS.Properties<> = {
|
|
|
|
display: 'none',
|
|
|
|
verticalAlign: 'bottom'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.attrs.has('raised')) {
|
|
|
|
css['--mdc-theme-primary'] = '#ffffff';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.attrs.has('icon')) {
|
|
|
|
css.marginRight = '8px';
|
|
|
|
}
|
|
|
|
|
|
|
|
return css;
|
|
|
|
}
|
|
|
|
|
2021-10-15 16:48:38 +02:00
|
|
|
oncreate(vnode) {
|
|
|
|
super.oncreate(vnode);
|
|
|
|
$(this.element)
|
|
|
|
.find('mwc-circular-progress')
|
|
|
|
.attr('density', -7);
|
|
|
|
}
|
|
|
|
}
|