Skip to content

Commit 27dbca1

Browse files
authored
pref: Switch style (#150)
* pref: Switch style * pref: Switch style and ARIA
1 parent c8e7411 commit 27dbca1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

thaw/src/switch/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub fn Switch(
3737

3838
style=move || css_vars.get()
3939
on:click=move |_| value.set(!value.get_untracked())
40+
role="switch"
41+
aria-checked=move || if value.get() { "true" } else { "false" }
4042
>
4143
<div class="thaw-switch__button"></div>
4244
</div>

thaw/src/switch/switch.css

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
.thaw-switch {
22
position: relative;
33
display: inline-block;
4-
width: 35px;
5-
height: 19px;
6-
padding: 2px 5px 3px;
4+
width: 40px;
5+
height: 22px;
76
background-color: var(--thaw-background-color);
8-
border-radius: 25px;
7+
border-radius: 11px;
98
cursor: pointer;
109
box-shadow: inset 0 0 1px 0 rgba(0, 0, 0, 0.05);
1110
transition: all 0.4s ease;
12-
box-sizing: content-box;
11+
user-select: none;
1312
}
1413

1514
.thaw-switch__button {
1615
position: absolute;
17-
left: 4px;
16+
top: 2px;
17+
left: 2px;
1818
display: inline-block;
19-
width: 19px;
20-
height: 19px;
21-
border-radius: 50%;
19+
width: 18px;
20+
height: 18px;
21+
border-radius: 9px;
2222
background-color: #fff;
2323
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.3),
2424
inset 0 0 1px 0 rgba(0, 0, 0, 0.05);
@@ -30,5 +30,13 @@
3030
}
3131

3232
.thaw-switch--active .thaw-switch__button {
33-
left: 22px;
33+
left: 20px;
34+
}
35+
36+
.thaw-switch--active:active .thaw-switch__button {
37+
left: 14px;
38+
}
39+
40+
.thaw-switch:active .thaw-switch__button {
41+
width: 24px;
3442
}

0 commit comments

Comments
 (0)