Skip to content

Commit f896f6b

Browse files
committed
fix default theme computation
1 parent 2a86f98 commit f896f6b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/example/src/plugins/vuetify.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { aliases as appFaAliases } from '../icons/fa';
1818
import { aliases as appMdiAliases } from '../icons/mdi';
1919
import { useAppStore } from '../store';
2020
import { themes } from './themes';
21+
import { getLightDarkTheme } from '@chobantonov/jsonforms-vuetify-renderers';
22+
import { useMediaQuery } from '@vueuse/core';
2123

2224
function toIconSetAliases(iconset: string) {
2325
// we can add vue-vuetify icons setoverrides here if needed or use the default provided base on the iconset
@@ -94,9 +96,19 @@ function createVuetifyInstance(appStore: ReturnType<typeof useAppStore>) {
9496
if (!themeNames.includes(defaultTheme)) {
9597
defaultTheme =
9698
appStore.dark === undefined ? 'system' : appStore.dark ? 'dark' : 'light';
97-
}
9899

99-
appStore.theme = defaultTheme;
100+
if (defaultTheme === 'system') {
101+
const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)');
102+
103+
appStore.theme = getLightDarkTheme(
104+
appStore.dark ?? isPreferredDark.value,
105+
appStore.theme,
106+
(theme) => themeNames.includes(theme),
107+
);
108+
} else {
109+
appStore.theme = defaultTheme;
110+
}
111+
}
100112

101113
return createVuetify({
102114
components,

0 commit comments

Comments
 (0)