@@ -30,7 +30,7 @@ import { Switch, Shadowed } from 'ember-primitives';
3030
3131</details >
3232
33- <details ><summary ><h3 >Dark/Light Theme Switch</h3 ></summary >
33+ <details open ><summary ><h3 >Dark/Light Theme Switch</h3 ></summary >
3434
3535CSS inspired/taken from [ this Codepen] ( https://codepen.io/Umer_Farooq/pen/eYJgKGN?editors=1100 )
3636
@@ -47,9 +47,13 @@ const toggleTheme = (e) =>
4747 <s.Control {{on 'change' toggleTheme}} />
4848 <s.Label>
4949 <span class="sr-only">Toggle between light and dark mode</span>
50- <Moon />
51- <Sun />
52- <span class="ball"></span>
50+ <span class="ball" data-state={{if s.isChecked "on" "off"}}>
51+ {{#if s.isChecked}}
52+ <Moon />
53+ {{else}}
54+ <Sun />
55+ {{/if}}
56+ </span>
5357 </s.Label>
5458 </Switch>
5559
@@ -69,6 +73,7 @@ const toggleTheme = (e) =>
6973 text-align: center;
7074 margin: 0;
7175 transition: background 0.2s linear;
76+ width: 100%;
7277 }
7378
7479 div.dark {background-color: #292c35;}
@@ -90,9 +95,10 @@ const toggleTheme = (e) =>
9095 }
9196
9297 label {
93- background-color: #111;
94- width: 50px;
95- height: 26px;
98+ background-color: #aaaaff;
99+ border: 1px solid;
100+ width: 60px;
101+ height: 32px;
96102 border-radius: 50px;
97103 position: relative;
98104 padding: 5px;
@@ -103,23 +109,30 @@ const toggleTheme = (e) =>
103109 gap: 0.5rem;
104110 }
105111
106- svg { fill: currentColor; }
112+ svg { fill: currentColor; position: absolute; top: 3px; left: 3px; }
107113 .fa-moon { color: #f1c40f; }
108- .fa- sun { color: #f39c12; }
114+ .sun { color: #f39c12; }
109115
110116 label .ball {
111- background-color: #fff ;
112- width: 22px ;
113- height: 22px ;
117+ background-color: #111 ;
118+ width: 26px ;
119+ height: 26px ;
114120 position: absolute;
115121 left: 2px;
116122 top: 2px;
117123 border-radius: 50%;
118- transition: transform 0.2s linear;
124+ transition-property: transform;
125+ transition-duration: 0.2s;
126+ transition-timing-function: linear(0, 0.1, 0.25, 0.5, 0.68, 0.8, 0.88, 0.94, 0.98, 0.995, 1);;
127+ border: 2px solid #f1c40f;
128+
129+ &[data-state="on"] {
130+ border: 2px solid purple;
131+ }
119132 }
120133
121134 input[type='checkbox'][role='switch']:checked + label .ball {
122- transform: translateX(24px );
135+ transform: translateX(28px );
123136 }
124137
125138 </style>
@@ -129,11 +142,50 @@ const toggleTheme = (e) =>
129142// 🎵 It's raining, it's pouring, ... 🎵
130143// https://www.youtube.com/watch?v=ll5ykbAumD4
131144const Sun = <template>
132- <svg class="fa-sun" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">{{!--! Font Awesome Pro 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --}}<path d="M361.5 1.2c5 2.1 8.6 6.6 9.6 11.9L391 121l107.9 19.8c5.3 1 9.8 4.6 11.9 9.6s1.5 10.7-1.6 15.2L446.9 256l62.3 90.3c3.1 4.5 3.7 10.2 1.6 15.2s-6.6 8.6-11.9 9.6L391 391 371.1 498.9c-1 5.3-4.6 9.8-9.6 11.9s-10.7 1.5-15.2-1.6L256 446.9l-90.3 62.3c-4.5 3.1-10.2 3.7-15.2 1.6s-8.6-6.6-9.6-11.9L121 391 13.1 371.1c-5.3-1-9.8-4.6-11.9-9.6s-1.5-10.7 1.6-15.2L65.1 256 2.8 165.7c-3.1-4.5-3.7-10.2-1.6-15.2s6.6-8.6 11.9-9.6L121 121 140.9 13.1c1-5.3 4.6-9.8 9.6-11.9s10.7-1.5 15.2 1.6L256 65.1 346.3 2.8c4.5-3.1 10.2-3.7 15.2-1.6zM160 256a96 96 0 1 1 192 0 96 96 0 1 1 -192 0zm224 0a128 128 0 1 0 -256 0 128 128 0 1 0 256 0z"/></svg>
145+ <svg
146+ class="sun"
147+ xmlns="http://www.w3.org/2000/svg"
148+ width="16"
149+ height="16"
150+ viewBox="0 0 16 16"
151+ fill="none"
152+ stroke="currentColor"
153+ stroke-width="1.5"
154+ stroke-linecap="round"
155+ stroke-linejoin="round"
156+ aria-hidden="true"
157+ >
158+ <circle cx="8" cy="8" r="3.25" />
159+ <line x1="8" y1="1" x2="8" y2="3" />
160+ <line x1="8" y1="13" x2="8" y2="15" />
161+ <line x1="1" y1="8" x2="3" y2="8" />
162+ <line x1="13" y1="8" x2="15" y2="8" />
163+ <line x1="3.05" y1="3.05" x2="4.47" y2="4.47" />
164+ <line x1="11.53" y1="11.53" x2="12.95" y2="12.95" />
165+ <line x1="11.53" y1="4.47" x2="12.95" y2="3.05" />
166+ <line x1="3.05" y1="12.95" x2="4.47" y2="11.53" />
167+ </svg>
133168</template>;
134169
135170const Moon = <template>
136- <svg class="fa-moon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512">{{!--! Font Awesome Pro 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --}}<path d="M223.5 32C100 32 0 132.3 0 256S100 480 223.5 480c60.6 0 115.5-24.2 155.8-63.4c5-4.9 6.3-12.5 3.1-18.7s-10.1-9.7-17-8.5c-9.8 1.7-19.8 2.6-30.1 2.6c-96.9 0-175.5-78.8-175.5-176c0-65.8 36-123.1 89.3-153.3c6.1-3.5 9.2-10.5 7.7-17.3s-7.3-11.9-14.3-12.5c-6.3-.5-12.6-.8-19-.8z"/></svg>
171+ <svg
172+ xmlns="http://www.w3.org/2000/svg"
173+ class="moon"
174+ width="16"
175+ height="16"
176+ viewBox="0 0 16 16"
177+ fill="none"
178+ stroke="currentColor"
179+ stroke-width="1.5"
180+ stroke-linecap="round"
181+ stroke-linejoin="round"
182+ aria-hidden="true"
183+ >
184+ <path
185+ transform="translate(-1 0)"
186+ d="M11.5 2a5.5 5.5 0 1 0 2 9.5 4.5 4.5 0 0 1 -2 -9.5z"
187+ />
188+ </svg>
137189</template>;
138190```
139191
0 commit comments