mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 14:20:47 +08:00
31 lines
813 B
JavaScript
31 lines
813 B
JavaScript
import Component from 'flarum/component';
|
|
import LoadingIndicator from 'flarum/components/loading-indicator';
|
|
|
|
export default class SwitchInput extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.loading = m.prop(false);
|
|
}
|
|
|
|
view() {
|
|
return m('div.checkbox.checkbox-switch', [
|
|
m('label', [
|
|
m('div.switch-control', [
|
|
m('input[type=checkbox]', {
|
|
checked: this.props.state,
|
|
onchange: m.withAttr('checked', this.onchange.bind(this))
|
|
}),
|
|
m('div.switch', {className: this.loading() && 'loading'})
|
|
]),
|
|
this.props.label, ' ',
|
|
this.loading() ? LoadingIndicator.component({size: 'tiny'}) : ''
|
|
])
|
|
])
|
|
}
|
|
|
|
onchange(checked) {
|
|
this.props.onchange && this.props.onchange(checked, this);
|
|
}
|
|
}
|