1- import { customElement , bindable , ViewResources , View , processAttributes } from 'aurelia-templating' ;
2- import { inject } from 'aurelia-dependency-injection' ;
3- import { StyleEngine } from '../styles/style-engine' ;
4- import { Themable } from '../styles/themable' ;
5- import { processDesignAttributes } from '../designs/design-attributes' ;
1+ import { customElement , bindable , ViewResources , View , processAttributes } from 'aurelia-templating' ;
2+ import { bindingMode } from 'aurelia-binding' ;
3+ import { inject } from 'aurelia-dependency-injection' ;
4+ import { StyleEngine } from '../styles/style-engine' ;
5+ import { Themable } from '../styles/themable' ;
6+ import { processDesignAttributes } from '../designs/design-attributes' ;
67
78@inject ( Element , ViewResources , StyleEngine )
89@customElement ( 'ux-checkbox' )
910@processAttributes ( processDesignAttributes )
10- export class UxButton implements Themable {
11- @bindable public type = null ;
12- @bindable public size = null ;
11+ export class UxCheckbox implements Themable {
1312 @bindable public effect = null ;
1413 @bindable public disabled = false ;
1514 @bindable public theme = null ;
1615
16+ @bindable ( { defaultBindingMode : bindingMode . twoWay } )
17+ @bindable public checked = false ;
18+
19+ @bindable ( { defaultBindingMode : bindingMode . twoWay } )
20+ @bindable public value : any = false ;
21+
1722 public view : View ;
1823
19- constructor ( public element : Element , public resources : ViewResources , private styleEngine : StyleEngine ) { }
24+ constructor ( public element : Element , public resources : ViewResources , private styleEngine : StyleEngine ) { }
2025
2126 public created ( _ : any , myView : View ) {
2227 this . view = myView ;
@@ -26,9 +31,25 @@ export class UxButton implements Themable {
2631 if ( this . theme ) {
2732 this . styleEngine . applyTheme ( this , this . theme ) ;
2833 }
34+
35+ if ( this . checked ) {
36+ this . element . classList . add ( 'checked' ) ;
37+ }
2938 }
3039
3140 public themeChanged ( newValue : any ) {
3241 this . styleEngine . applyTheme ( this , newValue ) ;
3342 }
34- }
43+
44+ public checkedChanged ( newValue : any ) {
45+ if ( newValue ) {
46+ this . element . classList . add ( 'checked' ) ;
47+ } else {
48+ this . element . classList . remove ( 'checked' ) ;
49+ }
50+ }
51+
52+ public toggle ( ) {
53+ this . checked = ! this . checked ;
54+ }
55+ }
0 commit comments