Match TallStackUI's theme fallback before first paint
The inline theme script treated an unknown stored "dark-theme" value as light, while tallstackui_darkTheme() treats it as "system", so a dark OS could flash the light theme. Also move an inline comment in AppServiceProvider into the method's PHPDoc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -26,7 +26,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
/**
|
||||
* TallStackUI uses red-500 for error text, which is 3.8:1 on white and
|
||||
* below the 4.5:1 WCAG 2.2 AA requires. Darker red in light mode, lighter
|
||||
* red in dark mode.
|
||||
* red in dark mode. The typed value of a field in error is red-600, which is
|
||||
* 3.8:1 on the dark input background, so inputs and selects change too.
|
||||
*/
|
||||
private function meetContrastRequirements(): void
|
||||
{
|
||||
@@ -45,7 +46,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
->block('asterisk')
|
||||
->replace('text-red-500', 'text-red-700 dark:text-red-400');
|
||||
|
||||
// The typed value of a field in error is red-600: 3.8:1 on the dark input background.
|
||||
TallStackUi::customize()
|
||||
->form('input')
|
||||
->block('error')
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
Apply the stored theme before the first paint. TallStackUI's
|
||||
tallstackui_darkTheme() keeps it in localStorage ("dark-theme"),
|
||||
but only runs once Alpine starts, which would flash the light theme.
|
||||
Like the package, any value other than dark/light (true/false) means "system".
|
||||
--}}
|
||||
<script>
|
||||
(() => {
|
||||
const stored = localStorage.getItem('dark-theme');
|
||||
const dark = stored === 'dark' || stored === 'true'
|
||||
|| ((stored === null || stored === 'system') && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
|| (stored !== 'light' && stored !== 'false' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
document.documentElement.classList.toggle('dark', dark);
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user