mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 08:52:34 +00:00
Update theme config with theme.base
, theme.preset
and theme.options
This commit is contained in:
parent
4053bbf4b9
commit
b5df82f247
308 changed files with 12926 additions and 97 deletions
35
components/lib/themes/utils/toVariables.js
Normal file
35
components/lib/themes/utils/toVariables.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import SharedUtils from './sharedUtils';
|
||||
|
||||
const VARIABLE = {
|
||||
PREFIX: 'p',
|
||||
SELECTOR: ':root',
|
||||
EXCLUDED_KEY_REGEX: /^(primitive|semantic|variables|colorscheme|light|dark|common|colors|root|states)$/gi
|
||||
};
|
||||
|
||||
export default function (theme, options = {}) {
|
||||
const { prefix = VARIABLE.PREFIX, selector = VARIABLE.SELECTOR, excludedKeyRegex = VARIABLE.EXCLUDED_KEY_REGEX } = options;
|
||||
|
||||
const _toVariables = (_theme, _prefix = '') => {
|
||||
return Object.entries(_theme).reduce((acc, [key, value]) => {
|
||||
const px = SharedUtils.object.toNormalizePrefix(SharedUtils.object.test(excludedKeyRegex, key) ? _prefix : `${_prefix}-${SharedUtils.object.toKebabCase(key)}`);
|
||||
const v = SharedUtils.object.toValue(value);
|
||||
|
||||
if (SharedUtils.object.isObject(v)) {
|
||||
const variables = _toVariables(v, px);
|
||||
|
||||
SharedUtils.object.merge(acc, variables);
|
||||
} else {
|
||||
SharedUtils.object.setProperty(acc, `--${px}`, SharedUtils.object.getVariableValue(v, px, prefix, [excludedKeyRegex]));
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
};
|
||||
|
||||
const value = _toVariables(theme, prefix);
|
||||
|
||||
return {
|
||||
value,
|
||||
css: SharedUtils.object.getRule(selector, value.join(''))
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue