Fixed #4384 - Add ptOptions property to all components

pull/4142/head
mertsincan 2023-09-04 22:23:35 +01:00
parent 334f986e15
commit a1a6d962b6
1 changed files with 13 additions and 17 deletions

View File

@ -366,6 +366,10 @@ export default {
type: Object, type: Object,
default: undefined default: undefined
}, },
ptOptions: {
type: Object,
default: undefined
},
unstyled: { unstyled: {
type: Boolean, type: Boolean,
default: undefined default: undefined
@ -464,23 +468,15 @@ export default {
_getPTValue(obj = {}, key = '', params = {}, searchInDefaultPT = true) { _getPTValue(obj = {}, key = '', params = {}, searchInDefaultPT = true) {
const datasetPrefix = 'data-pc-'; const datasetPrefix = 'data-pc-';
const searchOut = /./g.test(key) && !!params[key.split('.')[0]]; const searchOut = /./g.test(key) && !!params[key.split('.')[0]];
const self = searchOut ? undefined : this._usePT(this._getPT(obj, this.$name), this._getPTClassValue, key, params); const { mergeSections = true, mergeProps: useMergeProps = false } = this.ptOptions || {};
const globalPT = searchInDefaultPT ? (searchOut ? this._useGlobalPT(this._getPTClassValue, key, params) : this._useDefaultPT(this._getPTClassValue, key, params)) : undefined; const global = searchInDefaultPT ? (searchOut ? this._useGlobalPT(this._getPTClassValue, key, params) : this._useDefaultPT(this._getPTClassValue, key, params)) : undefined;
const merged = mergeProps( const self = searchOut ? undefined : this._usePT(this._getPT(obj, this.$name), this._getPTClassValue, key, { ...params, global });
self, const datasets = key !== 'transition' && {
globalPT,
key !== 'transition' && {
...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.toFlatCase(this.$.type.name) }), ...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.toFlatCase(this.$.type.name) }),
[`${datasetPrefix}section`]: ObjectUtils.toFlatCase(key) [`${datasetPrefix}section`]: ObjectUtils.toFlatCase(key)
} };
);
return merged; return mergeSections || (!mergeSections && self) ? (useMergeProps ? mergeProps(global, self, datasets) : { ...global, ...self, ...datasets }) : { ...self, ...datasets };
/*
* @todo: The 'class' option in self can always be more powerful to style the component easily.
*
* return self && self['class'] ? { ...merged, ...{ class: self['class'] } } : merged;
*/
}, },
_getPTClassValue(...args) { _getPTClassValue(...args) {
const value = this._getOptionValue(...args); const value = this._getOptionValue(...args);
@ -510,7 +506,7 @@ export default {
const fn = (value) => callback(value, key, params); const fn = (value) => callback(value, key, params);
if (pt?.hasOwnProperty('_usept')) { if (pt?.hasOwnProperty('_usept')) {
const { mergeSections, mergeProps: useMergeProps } = pt['_usept']; const { mergeSections = true, mergeProps: useMergeProps = false } = pt['_usept'] || {};
const originalValue = fn(pt.originalValue); const originalValue = fn(pt.originalValue);
const value = fn(pt.value); const value = fn(pt.value);