Cosmetics

pull/5507/head
mertsincan 2024-03-15 10:22:40 +00:00
parent 9b0f1ac98a
commit 9a07a0b42c
2 changed files with 9 additions and 19 deletions

View File

@ -141,13 +141,7 @@ export const defaultOptions = {
preset: Aura, preset: Aura,
options: { options: {
prefix: 'p', prefix: 'p',
colorScheme: { colorScheme: 'auto',
dark: {
class: 'p-dark',
rule: `.p-dark { [CSS] }`
//default: false
}
},
layer: false layer: false
/*colorScheme: { /*colorScheme: {
// mode: 'light' | 'dark' | 'auto' | object // default: auto // mode: 'light' | 'dark' | 'auto' | object // default: auto

View File

@ -84,21 +84,17 @@ export default {
return options; return options;
}, },
applyColorScheme(options = {}, currentColorScheme, defaults) { applyColorScheme(options = {}, currentColorScheme, defaults) {
if (options.colorScheme) { const colorSchemeOption = this.getColorSchemeOption(options.colorScheme, defaults);
const colorSchemeOption = this.getColorSchemeOption(options.colorScheme, defaults); const isClient = SharedUtils.dom.isClient();
const isClient = SharedUtils.dom.isClient(); const isAuto = !colorSchemeOption.light?.default && !colorSchemeOption.dark?.default;
const isAuto = !colorSchemeOption.light?.default && !colorSchemeOption.dark?.default; const isDark = isAuto && isClient ? window.matchMedia('(prefers-color-scheme: dark)').matches : colorSchemeOption.dark?.default;
const isDark = isAuto && isClient ? window.matchMedia('(prefers-color-scheme: dark)').matches : colorSchemeOption.dark?.default; const defaultDocument = isClient ? window.document : undefined;
const defaultDocument = isClient ? window.document : undefined;
if (isDark && defaultDocument) { if (isDark && defaultDocument) {
SharedUtils.dom.addClass(defaultDocument.documentElement, colorSchemeOption.dark?.class); SharedUtils.dom.addClass(defaultDocument.documentElement, colorSchemeOption.dark?.class);
}
return isDark ? 'dark' : 'light';
} }
return currentColorScheme; return isDark ? 'dark' : 'light';
}, },
toggleColorScheme(options = {}, currentColorScheme, defaults) { toggleColorScheme(options = {}, currentColorScheme, defaults) {
const newColorScheme = currentColorScheme === 'dark' ? 'light' : 'dark'; const newColorScheme = currentColorScheme === 'dark' ? 'light' : 'dark';