mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 00:42:36 +00:00
Theming API: Update themes folder structure and all exports
This commit is contained in:
parent
5403be3a70
commit
e23fd12ff4
27 changed files with 92 additions and 18 deletions
31
components/lib/themes/helpers/toVariables.js
Normal file
31
components/lib/themes/helpers/toVariables.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import Theme, { SharedUtils } from 'primevue/themes';
|
||||
|
||||
export default function (theme, options = {}) {
|
||||
const VARIABLE = Theme.defaults.variable;
|
||||
const { prefix = VARIABLE.prefix, selector = VARIABLE.selector, excludedKeyRegex = VARIABLE.excludedKeyRegex } = options;
|
||||
|
||||
const _toVariables = (_theme, _prefix = '') => {
|
||||
return Object.entries(_theme).reduce((acc, [key, value]) => {
|
||||
const px = SharedUtils.object.test(excludedKeyRegex, key) ? SharedUtils.object.toNormalizeVariable(_prefix) : SharedUtils.object.toNormalizeVariable(_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, SharedUtils.object.getVariableName(px), SharedUtils.object.getVariableValue(v, px, prefix, [excludedKeyRegex]));
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
};
|
||||
|
||||
const value = _toVariables(theme, prefix);
|
||||
|
||||
return {
|
||||
value,
|
||||
declarations: value.join(''),
|
||||
css: SharedUtils.object.getRule(selector, value.join(''))
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue