Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 8177fbf

Browse files
committed
Material checkbox
1 parent 0441699 commit 8177fbf

File tree

5 files changed

+157
-7
lines changed

5 files changed

+157
-7
lines changed

dev/App.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ const data = () => ({
116116
inline: false,
117117
customClass: 'col-12',
118118
}),
119+
new FormField({
120+
type: 'checkbox',
121+
label: 'Disabled',
122+
name: 'disabled',
123+
inline: false,
124+
disabled: true,
125+
customClass: 'col-12',
126+
}),
119127
new FormField({
120128
type: 'radio',
121129
label: 'Prefered Animal',

src/components/input-checkbox/InputCheckbox.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<div class="form-check">
2+
<div class="input-checkbox">
33
<input
4-
class="form-check-input"
4+
class="input-checkbox__toggle"
55
type="checkbox"
66
:id="formControl.name"
77
v-model="formControl.value"
88
:disabled="formControl.disabled"
99
/>
10-
<label class="form-check-label" :for="formControl.name">
10+
<label class="input-checkbox__label" :for="formControl.name">
1111
{{ formControl.label }}
1212
</label>
1313
</div>

src/components/input-radio/InputRadio.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
<div class="input-radio">
33
<div
44
class="form-check"
5-
:class="{ 'form-check-inline': formControl.inline }"
5+
:class="{ 'form-check--inline': formControl.inline }"
66
v-for="opt in formControl.options"
77
:key="opt.name"
88
>
99
<input
10-
class="form-check-input"
10+
class="form-check__input"
1111
type="radio"
1212
:id="opt.value"
1313
v-model="formControl.value"
1414
:value="opt.value"
1515
:disabled="opt.disabled"
1616
/>
17-
<label class="form-check-label" :for="opt.value">
17+
<label class="form-check__label" :for="opt.value">
1818
{{ opt.text }}
1919
</label>
2020
</div>

src/core/utils/form-control.model.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function FormControl({
88
options = [],
99
placeholder = null,
1010
errors = {},
11+
disabled = false,
1112
valid = true,
1213
touched = false,
1314
dirty = false,
@@ -20,6 +21,7 @@ export function FormControl({
2021
this.customClass = customClass;
2122
this.options = options;
2223
this.placeholder = placeholder;
24+
this.disabled = disabled;
2325
this.errors = errors;
2426
this.valid = valid;
2527
this.touched = touched;

src/styles/themes/material.scss

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
$theme-color: #6200ee;
22
$base-color: #ced4da;
3+
$text-color: #202020;
4+
$light: #fefefe;
5+
36
$font-size: 1rem !default;
47

58
$font-family-sans-serif: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
@@ -109,7 +112,7 @@ select.form-control ~ .form-label,
109112
}
110113
}
111114

112-
.form-check ~ .form-bar,
115+
.input-checkbox ~ .form-bar,
113116
.input-radio ~ .form-bar {
114117
display: none;
115118
}
@@ -144,3 +147,140 @@ select.form-control ~ .form-label,
144147
.custom-control-input:not(:checked) ~ .custom-control-label::before {
145148
border-color: $theme-color;
146149
}
150+
151+
.input-checkbox {
152+
$checkbox: &;
153+
z-index: 0;
154+
position: relative;
155+
display: inline-block;
156+
color: $base-color;
157+
font-size: 16px;
158+
line-height: 1.5;
159+
160+
&:hover {
161+
#{$checkbox}__toggle {
162+
opacity: 0.04;
163+
164+
&:hover {
165+
opacity: 0.16;
166+
}
167+
}
168+
}
169+
170+
&__toggle {
171+
appearance: none;
172+
-moz-appearance: none;
173+
-webkit-appearance: none;
174+
z-index: -1;
175+
position: absolute;
176+
left: -10px;
177+
top: -8px;
178+
display: block;
179+
margin: 0;
180+
border-radius: 50%;
181+
width: 40px;
182+
height: 40px;
183+
background-color: $base-color;
184+
box-shadow: none;
185+
outline: none;
186+
opacity: 0;
187+
transform: scale(1);
188+
pointer-events: none;
189+
transition: opacity 0.3s, transform 0.2s;
190+
191+
&:focus {
192+
opacity: 0.12;
193+
}
194+
195+
&:active {
196+
opacity: 1;
197+
transform: scale(0);
198+
transition: transform 0s, opacity 0s;
199+
}
200+
201+
&:active + label::before {
202+
border-color: $light;
203+
}
204+
205+
&:checked:active + label::before {
206+
border-color: transparent;
207+
background-color: $base-color;
208+
}
209+
210+
/* Checked, Indeterminate */
211+
&:checked,
212+
&:indeterminate {
213+
background-color: $theme-color;
214+
}
215+
216+
&:checked + label::before,
217+
&:indeterminate + label::before {
218+
border-color: $theme-color;
219+
background-color: $theme-color;
220+
}
221+
222+
&:checked + label::after,
223+
&:indeterminate + label::after {
224+
border-color: $light;
225+
}
226+
227+
&:indeterminate + label::after {
228+
border-left: none;
229+
transform: translate(4px, 3px);
230+
}
231+
232+
&:disabled {
233+
opacity: 0;
234+
}
235+
236+
&:disabled + label {
237+
color: rgba($base-color, 0.38);
238+
cursor: initial;
239+
}
240+
241+
&:disabled + label::before {
242+
border-color: currentColor;
243+
}
244+
245+
&:checked:disabled + label::before,
246+
&:indeterminate:disabled + label::before {
247+
border-color: transparent;
248+
background-color: currentColor;
249+
}
250+
}
251+
252+
&__label {
253+
display: inline-block;
254+
width: 100%;
255+
cursor: pointer;
256+
color: $text-color;
257+
258+
&::before {
259+
content: '';
260+
display: inline-block;
261+
box-sizing: border-box;
262+
margin: 3px 11px 3px 1px;
263+
border: solid 2px; /* Safari */
264+
border-color: $base-color;
265+
border-radius: 2px;
266+
width: 18px;
267+
height: 18px;
268+
vertical-align: top;
269+
transition: border-color 0.2s, background-color 0.2s;
270+
}
271+
272+
&::after {
273+
content: '';
274+
display: block;
275+
position: absolute;
276+
top: 4px;
277+
left: 2px;
278+
width: 10px;
279+
height: 5px;
280+
border: solid 2px transparent;
281+
border-right: none;
282+
border-top: none;
283+
transform: translate(3px, 4px) rotate(-45deg);
284+
}
285+
}
286+
}

0 commit comments

Comments
 (0)