Skip to content

Commit

Permalink
Refactor #3965 - Update BaseComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jun 8, 2023
1 parent 6c29642 commit 57b6f2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
22 changes: 9 additions & 13 deletions components/lib/basecomponent/BaseComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default {
}
},
methods: {
_getHostInstance(instance) {
return instance ? (this.$options.hostName ? (instance.$.type.name === this.$options.hostName ? instance : this._getHostInstance(instance.$parentInstance)) : instance.$parentInstance) : undefined;
},
_getOptionValue(options, key = '', params = {}) {
const fKeys = ObjectUtils.convertToFlatCase(key).split('.');
const fKey = fKeys.shift();
Expand All @@ -51,10 +54,10 @@ export default {
: undefined
: ObjectUtils.getItemValue(options, params);
},
_getPTValue(obj = {}, key = '', params = {}) {
_getPTValue(obj = {}, key = '', params = {}, searchInDefaultPT = true) {
const datasetPrefix = 'data-pc-';
const self = this._getOptionValue(obj, key, params);
const globalPT = this._getOptionValue(this.defaultPT, key, params);
const globalPT = searchInDefaultPT ? this._getOptionValue(this.defaultPT, key, params) : undefined;
const merged = mergeProps(self, globalPT, {
...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.convertToFlatCase(this.$.type.name) }),
[`${datasetPrefix}section`]: ObjectUtils.convertToFlatCase(key)
Expand All @@ -71,13 +74,13 @@ export default {
return this._getPTValue(this.pt, key, { props: this.$props, state: this.$data, ...params });
},
ptmo(obj = {}, key = '', params = {}) {
return this._getPTValue(obj, key, params);
return this._getPTValue(obj, key, params, false);
},
cx(key = '', params = {}) {
return !this.isUnstyled ? this._getOptionValue(this.$css.classes, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params }) : undefined;
},
cxo(key = '', params = {}) {
return !this.isUnstyled ? this._getOptionValue(this.$parentInstance.$parentInstance.$css.classes, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params }) : undefined;
return this.cx(key, params);
},
sx(key = '', when = true, params = {}) {
if (when) {
Expand All @@ -90,14 +93,7 @@ export default {
return undefined;
},
sxo(key = '', when = true, params = {}) {
if (when) {
const self = this._getOptionValue(this.$parentInstance.$parentInstance.$css.inlineStyles, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params });
const base = this._getOptionValue(inlineStyles, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params });
return [base, self];
}
return undefined;
return this.sx(key, when, params);
}
},
computed: {
Expand All @@ -108,7 +104,7 @@ export default {
return this.unstyled !== undefined ? this.unstyled : this.$primevue.config.unstyled;
},
$css() {
return { classes: undefined, inlineStyles: undefined, loadStyle: () => {}, ...(this.$parentInstance || {}).$css, ...this.$options.css };
return { classes: undefined, inlineStyles: undefined, loadStyle: () => {}, ...(this._getHostInstance(this) || {}).$css, ...this.$options.css };
}
}
};
Expand Down
1 change: 1 addition & 0 deletions components/lib/datatable/TableBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import BodyCell from './BodyCell.vue';
export default {
name: 'TableBody',
hostName: 'DataTable',
extends: BaseComponent,
emits: [
'rowgroup-toggle',
Expand Down
1 change: 1 addition & 0 deletions components/lib/datatable/TableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ import HeaderCheckbox from './HeaderCheckbox.vue';
export default {
name: 'TableHeader',
hostName: 'DataTable',
extends: BaseComponent,
emits: [
'column-click',
Expand Down

0 comments on commit 57b6f2c

Please sign in to comment.