From a556b46e481dcaf72c72d430ac9515191ac6fa38 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Tue, 30 May 2023 10:59:17 +0100 Subject: [PATCH] Refactor #3965 - Update CascadeSelect and Breadcrumb --- .../lib/basecomponent/BaseComponent.vue | 31 ++++++++++++------- components/lib/breadcrumb/BaseBreadcrumb.vue | 22 ++++++------- components/lib/breadcrumb/BreadcrumbItem.vue | 28 +++++++---------- .../lib/cascadeselect/BaseCascadeSelect.vue | 26 +++++++--------- .../lib/cascadeselect/CascadeSelectSub.vue | 12 ++----- components/lib/panel/BasePanel.vue | 16 +++++----- components/lib/toast/ToastMessage.vue | 2 +- components/lib/utils/DomHandler.js | 2 +- 8 files changed, 65 insertions(+), 74 deletions(-) diff --git a/components/lib/basecomponent/BaseComponent.vue b/components/lib/basecomponent/BaseComponent.vue index 627db1196..b7ec02fc5 100644 --- a/components/lib/basecomponent/BaseComponent.vue +++ b/components/lib/basecomponent/BaseComponent.vue @@ -27,6 +27,19 @@ export default { default: undefined } }, + inject: { + $parentInstance: { + default: undefined + } + }, + watch: { + isUnstyled: { + immediate: true, + handler(newValue) { + !newValue && this.$options.css && this.$css.loadStyle(); + } + } + }, methods: { _getOptionValue(options, key = '', params = {}) { const fKeys = ObjectUtils.convertToFlatCase(key).split('.'); @@ -61,16 +74,12 @@ export default { return this._getPTValue(obj, key, params); }, cx(key = '', params = {}) { - return !this.isUnstyled ? this._getOptionValue(this.$options.css && this.$options.css.classes, key, { instance: this, props: this.$props, state: this.$data, ...params }) : undefined; - }, - cxo(obj = {}, key = '', params = {}) { - // @todo - return !this.isUnstyled ? this._getOptionValue(obj.css && obj.css.classes, key, { instance: obj, props: obj && obj.props, state: obj && obj.data, ...params }) : undefined; + return !this.isUnstyled ? this._getOptionValue(this.$css.classes, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params }) : undefined; }, sx(key = '', when = true, params = {}) { if (when) { - const self = this._getOptionValue(this.$options.css && this.$options.css.inlineStyles, key, { instance: this, props: this.$props, state: this.$data, ...params }); - const base = this._getOptionValue(inlineStyles, key, { instance: this, props: this.$props, state: this.$data, ...params }); + const self = this._getOptionValue(this.$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]; } @@ -80,13 +89,13 @@ export default { }, computed: { defaultPT() { - return this._getOptionValue(this.$primevue.config.pt, this.$.type.name, this.defaultsParams); - }, - defaultsParams() { - return { instance: this }; + return this._getOptionValue(this.$primevue.config.pt, this.$.type.name, { instance: this }); }, isUnstyled() { return this.unstyled !== undefined ? this.unstyled : this.$primevue.config.unstyled; + }, + $css() { + return { classes: undefined, inlineStyles: undefined, loadStyle: () => {}, ...(this.$parentInstance || {}).$css, ...this.$options.css }; } } }; diff --git a/components/lib/breadcrumb/BaseBreadcrumb.vue b/components/lib/breadcrumb/BaseBreadcrumb.vue index 87cf9f38b..c9d72908f 100644 --- a/components/lib/breadcrumb/BaseBreadcrumb.vue +++ b/components/lib/breadcrumb/BaseBreadcrumb.vue @@ -41,19 +41,19 @@ const classes = { menu: 'p-breadcrumb-list', home: 'p-breadcrumb-home', separator: 'p-menuitem-separator', - menuitem: ({ context }) => ['p-menuitem', { 'p-disabled': context.disabled() }], - action: ({ context, isActive, isExactActive }) => [ + menuitem: ({ instance }) => ['p-menuitem', { 'p-disabled': instance.disabled() }], + action: ({ instance, isActive, isExactActive }) => [ 'p-menuitem-link', { 'router-link-active': isActive, - 'router-link-active-exact': context.exact && isExactActive + 'router-link-active-exact': instance.exact && isExactActive } ], icon: 'p-menuitem-icon', label: 'p-menuitem-text' }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_breadcrumb_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_breadcrumb_style', manual: true }); export default { name: 'BaseBreadcrumb', @@ -73,15 +73,13 @@ export default { } }, css: { - classes + classes, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/breadcrumb/BreadcrumbItem.vue b/components/lib/breadcrumb/BreadcrumbItem.vue index acdaf09eb..bae64ad74 100755 --- a/components/lib/breadcrumb/BreadcrumbItem.vue +++ b/components/lib/breadcrumb/BreadcrumbItem.vue @@ -1,17 +1,17 @@ diff --git a/components/lib/cascadeselect/CascadeSelectSub.vue b/components/lib/cascadeselect/CascadeSelectSub.vue index 969f22bf2..87fb71048 100644 --- a/components/lib/cascadeselect/CascadeSelectSub.vue +++ b/components/lib/cascadeselect/CascadeSelectSub.vue @@ -3,7 +3,7 @@