Skip to content

Commit 4696abb

Browse files
committed
feat: emitting event to recognize a key hit
1 parent cfa8ca7 commit 4696abb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

scripts/ColorSchemeSwitchThreeStates/view/hero-icons-tailwind-alpine.blade.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
$iconClasses = $iconClasses ?? 'size-4';
55
@endphp
66

7-
<button
8-
x-data="{
9-
refresh() {
10-
this.isSystem = localStorage.getItem('colorScheme') === '{{ SchemeTypeEnum::SYSTEM }}';
11-
this.isDark = localStorage.getItem('colorScheme') === '{{ SchemeTypeEnum::DARK }}';
12-
this.isLight = localStorage.getItem('colorScheme') === '{{ SchemeTypeEnum::LIGHT }}';
13-
}
14-
}"
15-
x-init="refresh()"
7+
<button x-data="{
8+
refresh() {
9+
this.isSystem = localStorage.getItem('colorScheme') === '{{ SchemeTypeEnum::SYSTEM }}';
10+
this.isDark = localStorage.getItem('colorScheme') === '{{ SchemeTypeEnum::DARK }}';
11+
this.isLight = localStorage.getItem('colorScheme') === '{{ SchemeTypeEnum::LIGHT }}';
12+
},
13+
}"
14+
x-init="refresh(); (function () {
15+
document.addEventListener('colorSchemeChanged', function() {
16+
refresh();
17+
});
18+
})()"
1619
{{--
1720
.switchColorScheme() is defined in switch-script.js
1821
--}}
1922
@click="window.inlineScripts.switchColorScheme(); refresh()"
20-
@keydown.window="refresh()"
23+
@color-scheme-changed.document="refresh()"
2124
title="Color scheme switcher"
2225
>
2326
<span class="hidden"

0 commit comments

Comments
 (0)