From cfd1f01299a13d8a27388388351c641a23e71aad Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Sat, 8 Aug 2020 16:11:43 -0400 Subject: [PATCH] update: common/components/Checkbox --- js/src/common/components/Checkbox.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/js/src/common/components/Checkbox.js b/js/src/common/components/Checkbox.js index 9ef46125e..293f77f6a 100644 --- a/js/src/common/components/Checkbox.js +++ b/js/src/common/components/Checkbox.js @@ -1,6 +1,8 @@ import Component from '../Component'; import LoadingIndicator from './LoadingIndicator'; import icon from '../helpers/icon'; +import classList from '../utils/classList'; +import withAttr from '../utils/withAttr'; /** * The `Checkbox` component defines a checkbox input. @@ -15,19 +17,24 @@ import icon from '../helpers/icon'; * - `children` A text label to display next to the checkbox. */ export default class Checkbox extends Component { - view() { + view(vnode) { // Sometimes, false is stored in the DB as '0'. This is a temporary // conversion layer until a more robust settings encoding is introduced - if (this.props.state === '0') this.props.state = false; - let className = 'Checkbox ' + (this.props.state ? 'on' : 'off') + ' ' + (this.props.className || ''); - if (this.props.loading) className += ' loading'; - if (this.props.disabled) className += ' disabled'; + if (this.attrs.state === '0') this.attrs.state = false; + + const className = classList([ + 'Checkbox', + this.attrs.state ? 'on' : 'off', + this.attrs.className, + this.attrs.loading && 'loading', + this.attrs.disabled && 'disabled', + ]); return ( ); } @@ -39,7 +46,7 @@ export default class Checkbox extends Component { * @protected */ getDisplay() { - return this.props.loading ? LoadingIndicator.component({ size: 'tiny' }) : icon(this.props.state ? 'fas fa-check' : 'fas fa-times'); + return this.attrs.loading ? : icon(this.attrs.state ? 'fas fa-check' : 'fas fa-times'); } /** @@ -49,6 +56,6 @@ export default class Checkbox extends Component { * @protected */ onchange(checked) { - if (this.props.onchange) this.props.onchange(checked, this); + if (this.attrs.onchange) this.attrs.onchange(checked, this); } }