File tree Expand file tree Collapse file tree 1 file changed +139
-0
lines changed Expand file tree Collapse file tree 1 file changed +139
-0
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <label
3
+ :class =" [
4
+ 'checkboxContainer',
5
+ isFocused ? 'focused' : '',
6
+ isChecked ? 'selected' : '',
7
+ ]"
8
+ >
9
+ <input
10
+ type =" checkbox"
11
+ class =" checkbox"
12
+ tabindex =" 0"
13
+ :name =" name"
14
+ :checked =" checked"
15
+ :value =" value"
16
+ @focus =" isFocus = true"
17
+ @blur =" isFocus = false"
18
+ @input =" onCheck"
19
+ />
20
+ <span class =" label" >{{ label }}</span >
21
+ </label >
22
+ </template >
23
+
24
+ <script lang="ts">
25
+ import Vue from ' vue'
26
+
27
+ export default Vue .extend ({
28
+ model: {
29
+ prop: ' checked' ,
30
+ event: ' input' ,
31
+ },
32
+ props: {
33
+ name: {
34
+ type: String ,
35
+ required: true ,
36
+ },
37
+ label: {
38
+ type: String ,
39
+ default: ' ' ,
40
+ },
41
+ checked: {
42
+ type: Boolean ,
43
+ default: false ,
44
+ },
45
+ value: {
46
+ type: String ,
47
+ default: ' ' ,
48
+ },
49
+ },
50
+ data(): {
51
+ isFocus: boolean
52
+ isChecked: boolean
53
+ } {
54
+ return {
55
+ isFocus: false ,
56
+ isChecked: false ,
57
+ }
58
+ },
59
+ computed: {
60
+ isFocused(): boolean {
61
+ return this .isFocus
62
+ },
63
+ handleIsChecked: {
64
+ get(): boolean {
65
+ return this .isChecked
66
+ },
67
+ set(newValue : boolean ) {
68
+ this .isChecked = newValue
69
+ },
70
+ },
71
+ },
72
+ methods: {
73
+ onCheck($event : { target: { checked: boolean ; value: string } }) {
74
+ this .$emit (' input' , $event .target .checked , $event .target .value )
75
+ this .isChecked = $event .target .checked
76
+ },
77
+ },
78
+ })
79
+ </script >
80
+
81
+ <style lang="scss" scoped>
82
+ .checkboxContainer {
83
+ position : relative ;
84
+ display : block ;
85
+ padding : 16px ;
86
+ border-radius : 6px ;
87
+ border : 1px solid $gray-2 ;
88
+ cursor : pointer ;
89
+ & .focused {
90
+ border : none ;
91
+ box-shadow : 0 0 0 2px #05a ;
92
+ }
93
+ & .selected {
94
+ background-color : rgba ($secondary , 0.25 );
95
+ border-color : $secondary ;
96
+ }
97
+ }
98
+
99
+ .label {
100
+ position : absolute ;
101
+ top : 16px ;
102
+ display : flex ;
103
+ align-items : center ;
104
+ cursor : pointer ;
105
+ & ::before {
106
+ display : block ;
107
+ border : 1px solid $gray-2 ;
108
+ border-radius : 50% ;
109
+ content : ' ' ;
110
+ height : 20px ;
111
+ width : 20px ;
112
+ margin-right : 8px ;
113
+ }
114
+ }
115
+
116
+ .checkbox :checked + .label {
117
+ & ::before {
118
+ border-color : $secondary ;
119
+ background-color : $secondary ;
120
+ }
121
+ & ::after {
122
+ position : absolute ;
123
+ top : 12px ;
124
+ left : 7px ;
125
+ border-right : 2px solid $white ;
126
+ border-bottom : 2px solid $white ;
127
+ content : ' ' ;
128
+ display : block ;
129
+ width : 6px ;
130
+ height : 12px ;
131
+ margin-top : -7px ;
132
+ transform : rotate (45deg );
133
+ }
134
+ }
135
+
136
+ .checkbox {
137
+ opacity : 0 ;
138
+ }
139
+ </style >
You can’t perform that action at this time.
0 commit comments