File tree Expand file tree Collapse file tree 5 files changed +44
-115
lines changed Expand file tree Collapse file tree 5 files changed +44
-115
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
<template >
2
- <button >switch </button >
2
+ <button @click = " toggle " :class = " {checked} " > < span ></ span > </button >
3
3
</template >
4
+ <script lang="ts">
5
+ import { ref } from ' vue'
6
+ export default {
7
+ setup(){
8
+ const checked = ref (true )
9
+ const toggle = ()=> {
10
+ checked .value = ! checked .value
11
+ }
12
+ return { checked ,toggle }
13
+ }
14
+ }
15
+ </script >
16
+ <style lang="scss" scoped>
17
+ $h : 22px ;
18
+ $h2 : $h - 4px ;
19
+ button {
20
+ height : $h ;
21
+ width : $h * 2 ;
22
+ border : none ;
23
+ background : grey ;
24
+ border-radius : $h / 2 ;
25
+ position : relative ;
26
+ }
27
+ span {
28
+ position : absolute ;
29
+ top : 2px ;
30
+ left : 2px ;
31
+ height : $h2 ;
32
+ width : $h2 ;
33
+ background :white ;
34
+ border-radius : $h2 / 2 ;
35
+ transition : left 250ms ;
36
+ }
37
+ button .checked {
38
+ background : #1989fa ;
39
+ }
40
+ button .checked > span {
41
+ left : calc (100% - #{$h2 } - 2px );
42
+ }
43
+ button :focus {
44
+ outline : none ;
45
+ }
46
+ </style >
You can’t perform that action at this time.
0 commit comments