Skip to content

Commit 534c384

Browse files
committed
🆕 new: new field type: Switch
1 parent da4f766 commit 534c384

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

dev/schema.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
featured: true,
3636
required: true,
3737
placeholder: "User's first name",
38+
styleClasses: "half-width",
3839
validator: validators.string,
3940

4041
onChanged(model, newVal, oldVal, field) {
@@ -53,6 +54,7 @@ module.exports = {
5354
featured: true,
5455
required: true,
5556
placeholder: "User's last name",
57+
styleClasses: "half-width",
5658
validator: validators.string
5759
},
5860
{
@@ -382,11 +384,13 @@ module.exports = {
382384
get(model) { return model && model.created ? moment(model.created).format("LLL") : "-"; }
383385
},
384386
{
385-
type: "checkbox",
387+
type: "switch",
386388
label: "Status",
387389
model: "status",
388390
multi: true,
389-
default: true
391+
default: true,
392+
textOn: "Active",
393+
textOff: "Inactive"
390394
},
391395
{
392396
type: "textArea",

src/fields/fieldCheckbox.vue

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
mixins: [ abstractField ]
1010
};
1111
</script>
12+
13+
<style lang="sass" scoped>
14+
input[type=checkbox] {
15+
margin-left: 12px;
16+
}
17+
</style>

src/fields/fieldLabel.vue

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
span {
1515
display: block;
1616
width: 100%;
17+
margin-left: 12px;
1718
}
1819
</style>

src/fields/fieldSwitch.vue

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<template lang="jade">
2+
label
3+
input(type="checkbox", v-model="value", :disabled="disabled")
4+
span.label(:data-on="schema.textOn || 'On'", :data-off="schema.textOff || 'Off'")
5+
span.handle
6+
span {{ this | json}}
7+
</template>
8+
9+
<script>
10+
import abstractField from "./abstractField";
11+
12+
export default {
13+
mixins: [ abstractField ]
14+
};
15+
</script>
16+
17+
<style lang="sass" scoped>
18+
19+
label {
20+
position: relative;
21+
display: block;
22+
vertical-align: top;
23+
width: 100px;
24+
height: 30px;
25+
padding: 3px;
26+
margin: 0 10px 10px 0;
27+
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
28+
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
29+
border-radius: 18px;
30+
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
31+
cursor: pointer;
32+
}
33+
input {
34+
position: absolute;
35+
top: 0;
36+
left: 0;
37+
opacity: 0;
38+
}
39+
.label {
40+
position: relative;
41+
display: block;
42+
height: inherit;
43+
font-size: 10px;
44+
text-transform: uppercase;
45+
background: #eceeef;
46+
border-radius: inherit;
47+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
48+
}
49+
.label:before, .label:after {
50+
position: absolute;
51+
top: 50%;
52+
margin-top: -.5em;
53+
line-height: 1;
54+
-webkit-transition: inherit;
55+
-moz-transition: inherit;
56+
-o-transition: inherit;
57+
transition: inherit;
58+
}
59+
.label:before {
60+
content: attr(data-off);
61+
right: 11px;
62+
color: #aaaaaa;
63+
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
64+
}
65+
.label:after {
66+
content: attr(data-on);
67+
left: 11px;
68+
color: #FFFFFF;
69+
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
70+
opacity: 0;
71+
}
72+
input:checked ~ .label {
73+
background: #E1B42B;
74+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
75+
}
76+
input:checked ~ .label:before {
77+
opacity: 0;
78+
}
79+
input:checked ~ .label:after {
80+
opacity: 1;
81+
}
82+
83+
.handle {
84+
position: absolute;
85+
top: 4px;
86+
left: 4px;
87+
width: 28px;
88+
height: 28px;
89+
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
90+
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
91+
border-radius: 100%;
92+
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
93+
}
94+
.handle:before {
95+
content: "";
96+
position: absolute;
97+
top: 50%;
98+
left: 50%;
99+
margin: -6px 0 0 -6px;
100+
width: 12px;
101+
height: 12px;
102+
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
103+
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
104+
border-radius: 6px;
105+
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
106+
}
107+
input:checked ~ .handle {
108+
left: 74px;
109+
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
110+
}
111+
112+
/* Transition
113+
========================== */
114+
.label, .handle {
115+
transition: all 0.3s ease;
116+
}
117+
118+
</style>

0 commit comments

Comments
 (0)