Skip to content

Commit cc2ba41

Browse files
committed
Added BEMIT and molecule design. Formatted fontSize so it works. Changed default fontWeight value. Reformatted SCSS
1 parent 3eeb104 commit cc2ba41

File tree

3 files changed

+55
-67
lines changed

3 files changed

+55
-67
lines changed

src/App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ export default {
1212
}
1313
}
1414
</script>
15+
<style>
16+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap');
17+
* {
18+
font-family: 'Roboto', sans-serif;
19+
}
20+
</style>

src/components/VueToggle.vue

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
<template>
22
<section
33
:class="{'dark': darkTheme, disabled}"
4-
:title="title"
4+
class="m-toggle"
55
>
66
<input
77
:id="id"
88
v-model="toggleState"
9-
:aria-checked="toggleState"
10-
:aria-readonly="disabled"
119
:disabled="disabled"
1210
:name="name"
13-
role="checkbox"
11+
class="m-toggle__input"
1412
type="checkbox"
1513
/>
16-
<label
17-
:for="id"
14+
<span
15+
:aria-checked="toggleState"
16+
:aria-disabled="disabled"
17+
:aria-readonly="disabled"
1818
:style="toggleState && {background: activeColor}"
19-
class="toggler"
19+
class="m-toggle__content"
20+
role="checkbox"
21+
@click="toggleState = !toggleState"
2022
/>
2123
<label
2224
:for="id"
23-
:style="[{fontSize, fontWeight}]"
24-
class="title"
25+
:style="[{fontSize: `${fontSize}px`, fontWeight}]"
26+
class="m-toggle__label"
2527
>
2628
{{title}}
2729
</label>
@@ -37,7 +39,7 @@ export default {
3739
darkTheme: {type: Boolean, default: false},
3840
disabled: {type: Boolean, default: false },
3941
fontSize: {type: Number, default: 16},
40-
fontWeight: {type: String, default: 'bold'},
42+
fontWeight: {type: String, default: 'normal'},
4143
name: {type: String, required: true},
4244
title: {type: String, required: true},
4345
toggled: {type: Boolean, default: false},
@@ -58,68 +60,57 @@ export default {
5860
</script>
5961

6062
<style lang="scss" scoped>
61-
62-
section {
63+
.m-toggle {
6364
display: flex;
64-
flex-wrap: wrap;
65-
padding: 5px;
65+
align-items: center;
66+
margin: 0 -5px;
6667
6768
> * {
6869
cursor: pointer;
6970
margin: 0 5px;
7071
}
71-
}
7272
73-
.title {
74-
display: inline-block;
75-
line-height: 2em;
76-
vertical-align: middle;
77-
-webkit-touch-callout: none;
78-
-webkit-user-select: none;
79-
-moz-user-select: none;
80-
-ms-user-select: none;
81-
user-select: none;
82-
83-
&::selection {
84-
background: none;
85-
}
73+
$self: &;
8674
87-
.disabled & {
88-
&:hover {
75+
&__label {
76+
user-select: none;
77+
78+
.disabled & {
8979
cursor: not-allowed;
9080
}
91-
}
9281
93-
.dark & {
94-
color: white;
82+
.dark & {
83+
color: white;
84+
}
9585
}
96-
}
9786
98-
input {
99-
display: none;
87+
&__input {
88+
display: none;
10089
101-
&:after,
102-
& + .toggler {
103-
box-sizing: border-box;
90+
&:checked {
91+
& + #{$self}__content {
92+
&:after {
93+
left: 50%;
94+
}
95+
}
96+
}
10497
}
10598
106-
+ .toggler {
99+
&__content {
100+
box-sizing: border-box;
107101
background: #F0F0F0;
108102
border-radius: 2em;
109-
display: block;
110103
height: 2em;
111104
outline: 0;
112105
padding: 2px;
113-
position: relative;
114106
transition: background .4s ease;
115-
user-select: none;
116107
width: 4em;
117108
will-change: background;
118109
119110
&:after {
120111
background: white;
121112
border-radius: 50%;
122-
content: "";
113+
content: '';
123114
display: block;
124115
height: 100%;
125116
left: 0;
@@ -141,14 +132,5 @@ input {
141132
background: #374151;
142133
}
143134
}
144-
145-
&:checked {
146-
& + .toggler {
147-
&:after {
148-
left: 50%;
149-
}
150-
}
151-
}
152135
}
153-
154136
</style>

vue-toggle-component/src/vue-toggle-component.vue

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
<label
1717
:for="id"
1818
:style="toggleState && {background: activeColor}"
19-
class="toggler"
19+
class="toggle__content"
2020
/>
2121
<label
2222
:for="id"
2323
:style="[{fontSize, fontWeight}]"
24-
class="title"
24+
class="toggle__label"
2525
>
2626
{{title}}
2727
</label>
@@ -67,30 +67,30 @@ section {
6767
cursor: pointer;
6868
margin: 0 5px;
6969
}
70-
.title {
70+
.toggle__label {
7171
display: inline-block;
7272
line-height: 2em;
7373
vertical-align: middle;
7474
}
75-
.title::selection {
75+
.toggle__label::selection {
7676
background: none;
7777
}
78-
.disabled .title:hover {
78+
.disabled .toggle__label:hover {
7979
cursor: not-allowed;
8080
}
81-
.dark .title {
81+
.dark .toggle__label {
8282
color: white;
8383
}
8484
input {
8585
display: none;
8686
}
87-
input:after, .toggle + .toggler {
87+
input:after, .toggle + .toggle__content {
8888
box-sizing: border-box;
8989
}
90-
input:after::selection, .toggle + .toggler::selection {
90+
input:after::selection, .toggle + .toggle__content::selection {
9191
background: none;
9292
}
93-
input + .toggler {
93+
input + .toggle__content {
9494
background: #f0f0f0;
9595
border-radius: 2em;
9696
display: block;
@@ -103,7 +103,7 @@ input + .toggler {
103103
width: 4em;
104104
will-change: background;
105105
}
106-
.toggle + .toggler:after {
106+
.toggle + .toggle__content:after {
107107
background: white;
108108
border-radius: 50%;
109109
content: "";
@@ -115,16 +115,16 @@ input + .toggler {
115115
width: 50%;
116116
will-change: left;
117117
}
118-
.disabled .toggle + .toggler {
118+
.disabled .toggle + .toggle__content {
119119
opacity: 50%;
120120
}
121-
.disabled .toggle + .toggler:hover {
121+
.disabled .toggle + .toggle__content:hover {
122122
cursor: not-allowed;
123123
}
124-
.dark .toggle + .toggler {
124+
.dark .toggle + .toggle__content {
125125
background: #374151;
126126
}
127-
.toggle:checked + .toggler:after {
127+
.toggle:checked + .toggle__content:after {
128128
left: 50%;
129129
}
130130

0 commit comments

Comments
 (0)