diff --git a/eslint.config.js b/eslint.config.js index ea86a495..601a6cc5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,7 +7,7 @@ export default defineConfigWithVueTs( vue.configs['flat/essential'], vueTsConfigs.recommended, { - ignores: ['vendor', 'node_modules', 'public', 'bootstrap/ssr', 'tailwind.config.js', 'resources/js/components/ui/*'], + ignores: ['vendor', 'node_modules', 'public', 'bootstrap/ssr', 'resources/js/components/ui/*'], }, { rules: { diff --git a/resources/js/components/TwoFactorSetupModal.vue b/resources/js/components/TwoFactorSetupModal.vue index 1f9ca86a..16083518 100644 --- a/resources/js/components/TwoFactorSetupModal.vue +++ b/resources/js/components/TwoFactorSetupModal.vue @@ -14,6 +14,7 @@ import { PinInputGroup, PinInputSlot, } from '@/components/ui/pin-input'; +import { useAppearance } from '@/composables/useAppearance'; import { useTwoFactorAuth } from '@/composables/useTwoFactorAuth'; import { confirm } from '@/routes/two-factor'; import { Form } from '@inertiajs/vue3'; @@ -26,6 +27,8 @@ interface Props { twoFactorEnabled: boolean; } +const { resolvedAppearance } = useAppearance(); + const props = defineProps(); const isOpen = defineModel('isOpen'); @@ -172,6 +175,12 @@ watch(
diff --git a/resources/js/composables/useAppearance.ts b/resources/js/composables/useAppearance.ts index 22bd855b..28f6c3e1 100644 --- a/resources/js/composables/useAppearance.ts +++ b/resources/js/composables/useAppearance.ts @@ -1,6 +1,7 @@ -import { onMounted, ref } from 'vue'; +import { computed, onMounted, ref } from 'vue'; -type Appearance = 'light' | 'dark' | 'system'; +export type ResolvedAppearance = 'light' | 'dark'; +type Appearance = ResolvedAppearance | 'system'; export function updateTheme(value: Appearance) { if (typeof window === 'undefined') { @@ -48,6 +49,11 @@ const getStoredAppearance = () => { return localStorage.getItem('appearance') as Appearance | null; }; +const prefersDark = (): boolean => { + if (typeof window === 'undefined') return false; + return window.matchMedia('(prefers-color-scheme: dark)').matches; +}; + const handleSystemThemeChange = () => { const currentAppearance = getStoredAppearance(); @@ -80,6 +86,13 @@ export function useAppearance() { } }); + const resolvedAppearance = computed(() => { + if (appearance.value === 'system') { + return prefersDark() ? 'dark' : 'light'; + } + return appearance.value; + }); + function updateAppearance(value: Appearance) { appearance.value = value; @@ -94,6 +107,7 @@ export function useAppearance() { return { appearance, + resolvedAppearance, updateAppearance, }; }