|
1 | | - |
2 | 1 | .animated-switch-container { |
3 | | - display: flex; |
4 | | - align-items: center; |
5 | | - justify-content: center; |
6 | | - } |
7 | | - |
8 | | - .animated-switch { |
9 | | - --switch-width: 60px; |
10 | | - --switch-height: calc(var(--switch-width) * 0.4); |
11 | | - --switch-thumb-size: calc(var(--switch-height) * 0.8); |
12 | | - |
13 | | - position: relative; |
14 | | - display: inline-flex; |
15 | | - align-items: center; |
16 | | - justify-content: space-between; |
17 | | - width: var(--switch-width); |
18 | | - height: var(--switch-height); |
19 | | - border-radius: calc(var(--switch-height) / 1.5); |
20 | | - padding: 2px; |
21 | | - background-color: #ccc; |
22 | | - transition: background-color 0.1s ease-out; |
23 | | - cursor: pointer; |
24 | | - overflow: hidden; |
25 | | - } |
26 | | - |
27 | | - .animated-switch[data-selected] { |
28 | | - background-color: #4CAF50; |
29 | | - } |
30 | | - |
31 | | - .animated-switch::before { |
32 | | - content: ""; |
33 | | - position: absolute; |
34 | | - left: 4px; |
35 | | - width: var(--switch-thumb-size); |
36 | | - height: var(--switch-thumb-size); |
37 | | - border-radius: 50%; |
38 | | - background-color: white; |
39 | | - transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.3); |
40 | | - z-index: 2; |
41 | | - } |
42 | | - |
43 | | - .animated-switch[data-selected]::before { |
44 | | - transform: translateX(calc(var(--switch-width) - var(--switch-height))); |
45 | | - } |
46 | | - |
47 | | - .switch-text { |
48 | | - font-size: 10px; |
49 | | - font-weight: bold; |
50 | | - position: absolute; |
51 | | - right: 4px; |
52 | | - top: 50%; |
53 | | - transform: translateY(-50%); |
54 | | - transition: opacity 0.3s ease-out; |
55 | | - z-index: 1; |
56 | | - user-select: none; |
57 | | - } |
58 | | - |
59 | | - .switch-text-false { |
60 | | - right: 10px; |
61 | | - color: #333; |
62 | | - } |
63 | | - |
64 | | - .switch-text-true { |
65 | | - left: 10px; |
66 | | - color: white; |
67 | | - } |
68 | | - |
69 | | - .animated-switch[data-selected] .switch-text-false, |
70 | | - .animated-switch:not([data-selected]) .switch-text-true { |
71 | | - opacity: 0; |
72 | | - } |
73 | | - |
74 | | - .animated-switch[data-selected] .switch-text-true, |
75 | | - .animated-switch:not([data-selected]) .switch-text-false { |
76 | | - opacity: 1; |
77 | | - } |
| 2 | + display: flex; |
| 3 | + align-items: center; |
| 4 | + justify-content: center; |
| 5 | +} |
| 6 | + |
| 7 | +.animated-switch { |
| 8 | + --switch-width: 60px; |
| 9 | + --switch-height: calc(var(--switch-width) * 0.4); |
| 10 | + --switch-thumb-size: calc(var(--switch-height) * 0.8); |
| 11 | + |
| 12 | + position: relative; |
| 13 | + display: inline-flex; |
| 14 | + align-items: center; |
| 15 | + justify-content: space-between; |
| 16 | + width: var(--switch-width); |
| 17 | + height: var(--switch-height); |
| 18 | + border-radius: calc(var(--switch-height) / 1.5); |
| 19 | + padding: 2px; |
| 20 | + background-color: #ccc; |
| 21 | + transition: background-color 0.1s ease-out; |
| 22 | + cursor: pointer; |
| 23 | + overflow: hidden; |
| 24 | +} |
| 25 | + |
| 26 | +.animated-switch[data-selected] { |
| 27 | + background-color: #4caf50; |
| 28 | +} |
| 29 | + |
| 30 | +.animated-switch::before { |
| 31 | + content: ''; |
| 32 | + position: absolute; |
| 33 | + left: 4px; |
| 34 | + width: var(--switch-thumb-size); |
| 35 | + height: var(--switch-thumb-size); |
| 36 | + border-radius: 50%; |
| 37 | + background-color: white; |
| 38 | + transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.3); |
| 39 | + z-index: 2; |
| 40 | +} |
| 41 | + |
| 42 | +.animated-switch[data-selected]::before { |
| 43 | + transform: translateX(calc(var(--switch-width) - var(--switch-height))); |
| 44 | +} |
| 45 | + |
| 46 | +.switch-text { |
| 47 | + font-size: 10px; |
| 48 | + font-weight: bold; |
| 49 | + position: absolute; |
| 50 | + right: 4px; |
| 51 | + top: 50%; |
| 52 | + transform: translateY(-50%); |
| 53 | + transition: opacity 0.3s ease-out; |
| 54 | + z-index: 1; |
| 55 | + user-select: none; |
| 56 | +} |
| 57 | + |
| 58 | +.switch-text-false { |
| 59 | + right: 10px; |
| 60 | + color: #333; |
| 61 | +} |
| 62 | + |
| 63 | +.switch-text-true { |
| 64 | + left: 10px; |
| 65 | + color: white; |
| 66 | +} |
| 67 | + |
| 68 | +.animated-switch[data-selected] .switch-text-false, |
| 69 | +.animated-switch:not([data-selected]) .switch-text-true { |
| 70 | + opacity: 0; |
| 71 | +} |
| 72 | + |
| 73 | +.animated-switch[data-selected] .switch-text-true, |
| 74 | +.animated-switch:not([data-selected]) .switch-text-false { |
| 75 | + opacity: 1; |
| 76 | +} |
0 commit comments