Skip to content

Commit fde48f4

Browse files
committed
feat(checkbox): simple checkbox features
animation and show checked bind to value with two way binding bind to checked with two way binding
1 parent a417b46 commit fde48f4

File tree

4 files changed

+85
-18
lines changed

4 files changed

+85
-18
lines changed

src/checkbox/ux-checkbox-theme.css

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
11
styles.checkbox {
22
display: inline-flex;
33
align-items: center;
4+
margin: auto;
5+
cursor: pointer;
46
}
57

68
styles.checkbox>.box {
7-
width: 20px;
8-
height: 20px;
9-
border: #5d5d5d solid 2px;
10-
border-radius: 3px;
9+
width: 20px;
10+
height: 20px;
11+
border: ${border || $swatches.grey.p700} solid 2px;
12+
border-radius: 3px;
13+
}
14+
15+
styles.checkbox>.box+label:not(:empty) {
16+
margin-left: 8px;
17+
}
18+
19+
styles.checkbox>.box:hover {
20+
width: 20px;
21+
height: 20px;
22+
border: ${background || $design.accent} solid 2px;
23+
border-radius: 3px;
24+
}
25+
26+
styles.checkbox.checked>.box {
27+
background-color: ${background || $design.accent};
28+
border: ${background || $design.accent} solid 2px;
29+
}
30+
31+
styles.checkbox>.box>.background-box {
32+
width: 100%;
33+
height: 100%;
34+
transform: scale3d(0, 0, 0);
35+
border-radius: 50%;
36+
transition: 100ms;
37+
}
38+
39+
styles.checkbox>.box>.background-box::after {
40+
margin: auto;
41+
display: block;
42+
width: 6px;
43+
height: 12px;
44+
border: ${foreground || $design.accentForeground} solid 2px;
45+
border-top: none;
46+
border-left: none;
47+
-webkit-transform-origin: 6px 6px;
48+
transform-origin: 6px 6px;
49+
transform: rotate(45deg);
50+
content: ' ';
51+
}
52+
53+
styles.checkbox.checked>.box>.background-box {
54+
transform: scale3d(1, 1, 1);
55+
border-radius: 0;
1156
}

src/checkbox/ux-checkbox-theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class UxCheckboxTheme {
66

77
public background: string;
88
public foreground: string;
9+
public border: string;
910

1011
public backgroundDisabled: string;
1112
public foregroundDisabled: string;

src/checkbox/ux-checkbox.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template styles.checkbox>
22
<require from="./ux-checkbox-theme"></require>
33

4-
<div class="box">
4+
<div class="box" click.trigger="toggle()">
5+
<div class="background-box"></div>
56
</div>
67

7-
<label>
8-
<slot></slot>
9-
</label>
8+
<!-- Leave Inline, uses :not(:empty) selector to determine margin -->
9+
<label ref="label"><slot></slot></label>
1010
</template>

src/checkbox/ux-checkbox.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
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

Comments
 (0)