Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
9 changes: 9 additions & 0 deletions resources/js/components/TwoFactorSetupModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,6 +27,8 @@ interface Props {
twoFactorEnabled: boolean;
}

const { resolvedAppearance } = useAppearance();

const props = defineProps<Props>();
const isOpen = defineModel<boolean>('isOpen');

Expand Down Expand Up @@ -172,6 +175,12 @@ watch(
<div
v-html="qrCodeSvg"
class="flex aspect-square size-full items-center justify-center"
:style="{
filter:
resolvedAppearance === 'dark'
? 'invert(1) brightness(1.5)'
: undefined,
}"
/>
</div>
</div>
Expand Down
18 changes: 16 additions & 2 deletions resources/js/composables/useAppearance.ts
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -80,6 +86,13 @@ export function useAppearance() {
}
});

const resolvedAppearance = computed<ResolvedAppearance>(() => {
if (appearance.value === 'system') {
return prefersDark() ? 'dark' : 'light';
}
return appearance.value;
});

function updateAppearance(value: Appearance) {
appearance.value = value;

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

return {
appearance,
resolvedAppearance,
updateAppearance,
};
}