From e58fc576217408f89e0ad7ce6f9440aad9411ed0 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Wed, 24 May 2023 00:40:14 +0100 Subject: [PATCH] Refactor #3965 - For Accordion --- components/lib/accordion/Accordion.d.ts | 5 + components/lib/accordion/Accordion.vue | 111 ++++-------------- components/lib/accordion/BaseAccordion.vue | 95 +++++++++++++++ components/lib/accordiontab/AccordionTab.vue | 15 +-- .../lib/accordiontab/BaseAccordionTab.vue | 19 +++ .../lib/basecomponent/BaseComponent.vue | 22 ++-- components/lib/utils/ObjectUtils.js | 20 +++- 7 files changed, 175 insertions(+), 112 deletions(-) create mode 100644 components/lib/accordion/BaseAccordion.vue create mode 100644 components/lib/accordiontab/BaseAccordionTab.vue diff --git a/components/lib/accordion/Accordion.d.ts b/components/lib/accordion/Accordion.d.ts index deaa0e2a8..9d4c0ee16 100755 --- a/components/lib/accordion/Accordion.d.ts +++ b/components/lib/accordion/Accordion.d.ts @@ -128,6 +128,11 @@ export interface AccordionProps { * @type {AccordionPassThroughOptions} */ pt?: AccordionPassThroughOptions; + /** + * When enabled, it removes component related styles in the core. + * @defaultValue false + */ + unstyled?: boolean; } /** diff --git a/components/lib/accordion/Accordion.vue b/components/lib/accordion/Accordion.vue index fc9ff0ccc..d3c08ae91 100755 --- a/components/lib/accordion/Accordion.vue +++ b/components/lib/accordion/Accordion.vue @@ -1,10 +1,17 @@ - - diff --git a/components/lib/accordion/BaseAccordion.vue b/components/lib/accordion/BaseAccordion.vue new file mode 100644 index 000000000..7880a763a --- /dev/null +++ b/components/lib/accordion/BaseAccordion.vue @@ -0,0 +1,95 @@ + diff --git a/components/lib/accordiontab/AccordionTab.vue b/components/lib/accordiontab/AccordionTab.vue index 5e189784e..c5f577a91 100755 --- a/components/lib/accordiontab/AccordionTab.vue +++ b/components/lib/accordiontab/AccordionTab.vue @@ -3,21 +3,10 @@ diff --git a/components/lib/accordiontab/BaseAccordionTab.vue b/components/lib/accordiontab/BaseAccordionTab.vue new file mode 100644 index 000000000..298d02d7b --- /dev/null +++ b/components/lib/accordiontab/BaseAccordionTab.vue @@ -0,0 +1,19 @@ + diff --git a/components/lib/basecomponent/BaseComponent.vue b/components/lib/basecomponent/BaseComponent.vue index af71ea6d4..b4f075fd6 100644 --- a/components/lib/basecomponent/BaseComponent.vue +++ b/components/lib/basecomponent/BaseComponent.vue @@ -28,15 +28,19 @@ export default { } }, methods: { - getOption(options, key = '') { + getOptionValue(options, key = '', params = {}) { const fKeys = ObjectUtils.convertToFlatCase(key).split('.'); const fKey = fKeys.shift(); - return fKey ? (typeof options === 'object' ? this.getOption(options[Object.keys(options).find((k) => ObjectUtils.convertToFlatCase(k) === fKey) || ''], fKeys.join('.')) : undefined) : options; + return fKey + ? ObjectUtils.isObject(options) + ? this.getOptionValue(ObjectUtils.getItemValue(options[Object.keys(options).find((k) => ObjectUtils.convertToFlatCase(k) === fKey) || ''], params), fKeys.join('.'), params) + : undefined + : ObjectUtils.getItemValue(options, params); }, getPTValue(obj = {}, key = '', params = {}) { - const self = ObjectUtils.getItemValue(this.getOption(obj, key), params); - const globalPT = ObjectUtils.getItemValue(this.getOption(this.defaultPT, key), params); + const self = this.getOptionValue(obj, key, params); + const globalPT = this.getOptionValue(this.defaultPT, key, params); const merged = mergeProps(self, globalPT); return merged; @@ -53,16 +57,16 @@ export default { return this.getPTValue(obj, key, params); }, cx(key = '', params = {}) { - return !this.isUnstyled ? ObjectUtils.getItemValue(this.getOption(this.$options.css && this.$options.css.classes, key), { instance: this, props: this.$props, state: this.$data, ...params }) : undefined; + 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 ? ObjectUtils.getItemValue(this.getOption(obj.css && obj.css.classes, key), { instance: obj, props: obj && obj.props, state: obj && obj.data, ...params }) : undefined; + return !this.isUnstyled ? this.getOptionValue(obj.css && obj.css.classes, key, { instance: obj, props: obj && obj.props, state: obj && obj.data, ...params }) : undefined; }, sx(key = '', when = true, params = {}) { if (when) { - const self = ObjectUtils.getItemValue(this.getOption(this.$options.css && this.$options.css.inlineStyles, key), { instance: this, props: this.$props, state: this.$data, ...params }); - const base = ObjectUtils.getItemValue(this.getOption(inlineStyles, key), { instance: this, props: this.$props, state: this.$data, ...params }); + 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 }); return [base, self]; } @@ -72,7 +76,7 @@ export default { }, computed: { defaultPT() { - return ObjectUtils.getItemValue(this.getOption(this.$primevue.config.pt, this.$.type.name), this.defaultsParams); + return this.getOptionValue(this.$primevue.config.pt, this.$.type.name, this.defaultsParams); }, defaultsParams() { return { instance: this }; diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js index b72db6552..d8cff9054 100755 --- a/components/lib/utils/ObjectUtils.js +++ b/components/lib/utils/ObjectUtils.js @@ -80,10 +80,6 @@ export default { } }, - isFunction(obj) { - return !!(obj && obj.constructor && obj.call && obj.apply); - }, - getItemValue(obj, ...params) { return this.isFunction(obj) ? obj(...params) : obj; }, @@ -218,6 +214,22 @@ export default { return !this.isEmpty(value); }, + isFunction(value) { + return !!(value && value.constructor && value.call && value.apply); + }, + + isObject(value) { + return value !== null && value instanceof Object && value.constructor === Object; + }, + + isDate(value) { + return value !== null && value instanceof Date && value.constructor === Date; + }, + + isArray(value) { + return value !== null && Array.isArray(value); + }, + isPrintableCharacter(char = '') { return this.isNotEmpty(char) && char.length === 1 && char.match(/\S| /); },