Fixed #4384 - Add ptOptions property to all components
parent
334f986e15
commit
a1a6d962b6
|
@ -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 === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.toFlatCase(this.$.type.name) }),
|
||||||
key !== 'transition' && {
|
[`${datasetPrefix}section`]: ObjectUtils.toFlatCase(key)
|
||||||
...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.toFlatCase(this.$.type.name) }),
|
};
|
||||||
[`${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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue