|
1 | | -import { component$, useComputed$, useSignal, useStyles$ } from '@builder.io/qwik'; |
| 1 | +import { $, component$, useComputed$, useSignal, useStyles$ } from '@builder.io/qwik'; |
2 | 2 | // eslint-disable-next-line @nx/enforce-module-boundaries |
3 | 3 | import { version as headlessVersion } from '../../../../../packages/kit-headless/package.json'; |
4 | 4 | // eslint-disable-next-line @nx/enforce-module-boundaries |
@@ -129,6 +129,23 @@ export default component$(({ showVersion = false }: HeaderProps) => { |
129 | 129 |
|
130 | 130 | const { theme, setTheme } = useTheme(); |
131 | 131 |
|
| 132 | + const switchLightDark = $((input: string | string[]): string | string[] | undefined => { |
| 133 | + const switchWord = (word: string): string => { |
| 134 | + if (word.includes('light')) { |
| 135 | + return word.replace('light', 'dark'); |
| 136 | + } else if (word.includes('dark')) { |
| 137 | + return word.replace('dark', 'light'); |
| 138 | + } |
| 139 | + return word; |
| 140 | + }; |
| 141 | + |
| 142 | + if (typeof input === 'string') { |
| 143 | + return switchWord(input); |
| 144 | + } else if (Array.isArray(input)) { |
| 145 | + return input.map((item) => switchWord(item)); |
| 146 | + } |
| 147 | + }); |
| 148 | + |
132 | 149 | return ( |
133 | 150 | <div |
134 | 151 | class={cn( |
@@ -185,9 +202,7 @@ export default component$(({ showVersion = false }: HeaderProps) => { |
185 | 202 | <button |
186 | 203 | type="button" |
187 | 204 | aria-label="Toggle dark mode" |
188 | | - onClick$={() => { |
189 | | - theme?.includes('light') ? setTheme('dark') : setTheme('light'); |
190 | | - }} |
| 205 | + onClick$={async () => setTheme(await switchLightDark(theme || 'light'))} |
191 | 206 | > |
192 | 207 | <div class="hidden dark:block"> |
193 | 208 | <MoonIcon /> |
|
0 commit comments