Skip to content

Commit ea396bf

Browse files
committed
Add resolvedAppearance & Fix Two Factor QR Code for dark mode
1 parent cb93da5 commit ea396bf

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfigWithVueTs(
77
vue.configs['flat/essential'],
88
vueTsConfigs.recommended,
99
{
10-
ignores: ['vendor', 'node_modules', 'public', 'bootstrap/ssr', 'tailwind.config.js', 'resources/js/components/ui/*'],
10+
ignores: ['vendor', 'node_modules', 'public', 'bootstrap/ssr', 'resources/js/components/ui/*'],
1111
},
1212
{
1313
rules: {

resources/js/components/TwoFactorSetupModal.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
PinInputGroup,
1515
PinInputSlot,
1616
} from '@/components/ui/pin-input';
17+
import { useAppearance } from '@/composables/useAppearance';
1718
import { useTwoFactorAuth } from '@/composables/useTwoFactorAuth';
1819
import { confirm } from '@/routes/two-factor';
1920
import { Form } from '@inertiajs/vue3';
@@ -26,6 +27,8 @@ interface Props {
2627
twoFactorEnabled: boolean;
2728
}
2829
30+
const { resolvedAppearance } = useAppearance();
31+
2932
const props = defineProps<Props>();
3033
const isOpen = defineModel<boolean>('isOpen');
3134
@@ -172,6 +175,12 @@ watch(
172175
<div
173176
v-html="qrCodeSvg"
174177
class="flex aspect-square size-full items-center justify-center"
178+
:style="{
179+
filter:
180+
resolvedAppearance === 'dark'
181+
? 'invert(1) brightness(1.5)'
182+
: undefined,
183+
}"
175184
/>
176185
</div>
177186
</div>

resources/js/composables/useAppearance.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { onMounted, ref } from 'vue';
1+
import { computed, onMounted, ref } from 'vue';
22

3-
type Appearance = 'light' | 'dark' | 'system';
3+
export type ResolvedAppearance = 'light' | 'dark';
4+
type Appearance = ResolvedAppearance | 'system';
45

56
export function updateTheme(value: Appearance) {
67
if (typeof window === 'undefined') {
@@ -48,6 +49,11 @@ const getStoredAppearance = () => {
4849
return localStorage.getItem('appearance') as Appearance | null;
4950
};
5051

52+
const prefersDark = (): boolean => {
53+
if (typeof window === 'undefined') return false;
54+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
55+
};
56+
5157
const handleSystemThemeChange = () => {
5258
const currentAppearance = getStoredAppearance();
5359

@@ -80,6 +86,13 @@ export function useAppearance() {
8086
}
8187
});
8288

89+
const resolvedAppearance = computed<ResolvedAppearance>(() => {
90+
if (appearance.value === 'system') {
91+
return prefersDark() ? 'dark' : 'light';
92+
}
93+
return appearance.value;
94+
});
95+
8396
function updateAppearance(value: Appearance) {
8497
appearance.value = value;
8598

@@ -94,6 +107,7 @@ export function useAppearance() {
94107

95108
return {
96109
appearance,
110+
resolvedAppearance,
97111
updateAppearance,
98112
};
99113
}

0 commit comments

Comments
 (0)