primevue-mirror/components/lib/themes/config/index.js

111 lines
3.1 KiB
JavaScript
Raw Normal View History

2024-03-13 12:05:23 +00:00
import { ThemeUtils } from 'primevue/themes';
2024-03-05 09:22:33 +00:00
export default {
2024-03-13 12:05:23 +00:00
defaults: {
variable: {
prefix: '',
selector: ':root',
excludedKeyRegex: /^(primitive|semantic|variables|colorscheme|light|dark|common|colors|root|states)$/gi
},
colorScheme: {
light: {
class: '',
rule: `:root{[CSS]}`,
default: false
},
dark: {
class: 'p-dark',
rule: `.p-dark{[CSS]}`,
default: false
}
},
layer: {
2024-03-18 10:57:17 +00:00
name: 'primevue',
order: 'primevue'
2024-03-13 12:05:23 +00:00
}
},
2024-03-05 09:22:33 +00:00
_pConfig: undefined,
2024-03-13 12:05:23 +00:00
_theme: undefined,
_initialized: false,
_currentColorScheme: 'light',
init() {
if (!this._initialized) {
this.applyColorScheme();
}
this._initialized = true;
},
get theme() {
return this._theme || this._pConfig?.theme;
},
get base() {
return this.theme?.base || {};
},
get preset() {
return this.theme?.preset || {};
},
get options() {
return this.theme?.options || {};
},
get extend() {
return this.theme?.extend || {};
},
2024-03-05 09:22:33 +00:00
getPConfig() {
return this._pConfig;
},
setPConfig(newValue) {
this._pConfig = newValue;
},
2024-03-13 12:05:23 +00:00
setTheme(newValue) {
this._theme = newValue;
2024-03-05 09:22:33 +00:00
},
2024-03-13 12:05:23 +00:00
getCurrentColorScheme() {
return this._currentColorScheme;
2024-03-05 09:22:33 +00:00
},
2024-03-13 12:05:23 +00:00
setCurrentColorScheme(newValue) {
this._currentColorScheme = newValue;
2024-03-12 09:46:43 +00:00
},
2024-03-13 12:05:23 +00:00
applyColorScheme() {
const newColorScheme = ThemeUtils.applyColorScheme(this.options, this.getCurrentColorScheme(), this.defaults);
this.setCurrentColorScheme(newColorScheme);
return newColorScheme;
2024-03-12 09:46:43 +00:00
},
2024-03-06 10:38:51 +00:00
toggleColorScheme() {
2024-03-13 12:05:23 +00:00
const newColorScheme = ThemeUtils.toggleColorScheme(this.options, this.getCurrentColorScheme(), this.defaults);
2024-03-05 09:22:33 +00:00
2024-03-13 12:05:23 +00:00
this.setCurrentColorScheme(newColorScheme);
2024-03-06 10:38:51 +00:00
2024-03-13 12:05:23 +00:00
return newColorScheme;
},
getCommonCSS(name = '', theme, params) {
return ThemeUtils.getCommon({ name, theme: theme || this.theme, params, defaults: this.defaults });
},
getComponentCSS(name = '', theme, params) {
const options = { name, theme: theme || this.theme, params, defaults: this.defaults };
2024-03-05 09:22:33 +00:00
2024-03-13 12:05:23 +00:00
return {
style: ThemeUtils.getBaseC(options),
variables: ThemeUtils.getPresetC(options)
};
},
getDirectiveCSS(name = '', theme, params) {
const options = { name, theme: theme || this.theme, params, defaults: this.defaults };
2024-03-05 09:22:33 +00:00
2024-03-13 12:05:23 +00:00
return {
style: ThemeUtils.getBaseD(options),
variables: ThemeUtils.getPresetD(options)
};
},
2024-03-18 10:57:17 +00:00
getLayerOrderCSS(name = '') {
return ThemeUtils.getLayerOrder(name, this.options, this.defaults);
},
2024-03-13 12:05:23 +00:00
getCommonStyleSheet(name = '', theme, params, props = {}) {
return ThemeUtils.getCommonStyleSheet(name, theme, params, props);
},
getStyleSheet(name, theme = {}, params, props = {}) {
return ThemeUtils.getStyleSheet(name, theme, params, props);
2024-03-05 09:22:33 +00:00
}
};