Skip to content

Commit 4e786ce

Browse files
committed
Updated toggle
1 parent ea07c48 commit 4e786ce

File tree

2 files changed

+72
-65
lines changed

2 files changed

+72
-65
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@impvis/components",
3-
"version": "1.1.8",
3+
"version": "1.1.9",
44
"license": "BSD-3-Clause",
55
"main": "./dist/impvis-components.js",
66
"unpkg": "./dist/impvis-components.umd.js",
Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,92 @@
11
<template>
2-
<label>
3-
<input type="checkbox" id="unchecked" class="toggleBasicInput hidden" @click="changeMode" :disabled="toggleDisabled">
4-
<label for="unchecked" class="toggleBasicLabel"></label>
5-
</label>
2+
<div>
3+
<span
4+
class="toggle-wrapper"
5+
role="checkbox"
6+
:aria-checked="value.toString()"
7+
tabindex="0"
8+
@click="toggle"
9+
@keydown.space.prevent="toggle"
10+
>
11+
<span
12+
class="toggle-background"
13+
:class="backgroundStyles"
14+
/>
15+
<span
16+
class="toggle-indicator"
17+
:style="indicatorStyles"
18+
/>
19+
</span>
20+
</div>
621
</template>
722
<script>
823
export default {
9-
name:"iv-toggle-basic",
10-
props:{
11-
initialMode:{
12-
type: Boolean,
13-
default: true
14-
},
15-
toggleDisabled: {
16-
type: Boolean,
17-
required: false,
18-
default: false
19-
}
20-
},
21-
data(){
24+
name:"iv-toggle-basic",
25+
props: {
26+
value:{
27+
type: Boolean,
28+
required: true
29+
}
30+
},
31+
computed: {
32+
backgroundStyles() {
2233
return {
23-
toggleMode: this.initialMode
24-
}
34+
'switchedOn': this.value,
35+
'switchedOff': !this.value
36+
};
2537
},
26-
methods:{
27-
changeMode(){
28-
this.toggleMode = !this.toggleMode;
29-
this.$emit("toggleswitched", this.toggleMode);
30-
}
38+
indicatorStyles() {
39+
return { transform: this.value ? 'translateX(14px)' : 'translateX(0)' };
3140
}
32-
}
41+
},
42+
methods: {
43+
toggle() {
44+
this.value =! this.value
45+
this.$emit('input', !this.value);
46+
}
47+
}
48+
};
3349
</script>
3450
<style>
35-
.toggleBasicLabel {
36-
position: relative;
37-
display: block;
38-
height: 20px;
39-
width: 44px;
51+
.switchedOn{
4052
background-color: #003E74;
41-
border-radius: 100px;
42-
cursor: pointer;
43-
transition: all 0.3s ease;
4453
}
4554
46-
.toggleBasicLabel:after {
47-
position: absolute;
48-
left: -2px;
49-
top: -3px;
50-
display: block;
51-
width: 26px;
52-
height: 26px;
53-
border-radius: 100px;
54-
background: #2980B9;
55-
box-shadow: 0 0 1px #ccc;
56-
content: '';
57-
transition: all 0.3s ease;
55+
.switchedOff{
56+
background-color: #2980B9;
5857
}
5958
60-
.toggleBasicLabel:active:after { transform: scale(1.15, 0.85); }
61-
62-
.toggleBasicInput:checked ~ label:after {
63-
left: 20px;
59+
.toggle-wrapper {
60+
display: inline-block;
61+
position: relative;
62+
cursor: pointer;
63+
width: 32px;
64+
height: 18px;
65+
border-radius: 9999px;
6466
}
6567
66-
.toggleBasicInput:disabled ~ label {
67-
background: #d5d5d5;
68-
pointer-events: none;
68+
.toggle-wrapper:focus {
69+
outline: 0;
6970
}
7071
71-
/* toggle on hover */
72-
.toggleBasicLabel:hover {
73-
cursor: pointer;
74-
background: #37538B;
75-
-webkit-transition: all 0.4s ease-in-out;
76-
-moz-transition: all 0.4s ease-in-out;
77-
-ms-transition: all 0.4s ease-in-out;
78-
-o-transition: all 0.4s ease-in-out;
79-
transition: all 0.4s ease-in-out;
72+
.toggle-background {
73+
display: inline-block;
74+
border-radius: 9999px;
75+
height: 100%;
76+
width: 100%;
77+
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
78+
transition: background-color .4s ease;
8079
}
8180
82-
.toggleBasicInput:disabled ~ label:after { background: #bcbdbc; }
83-
84-
.hidden { display: none; }
81+
.toggle-indicator {
82+
position: absolute;
83+
height: 14px;
84+
width: 14px;
85+
left: 2px;
86+
bottom: 2px;
87+
background-color: #ffffff;
88+
border-radius: 9999px;
89+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
90+
transition: transform .4s ease;
91+
}
8592
</style>

0 commit comments

Comments
 (0)