From 751295c7551291d964ba27911e5e8cf4b7cb7344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 30 May 2023 14:06:57 +0300 Subject: [PATCH] Refactor #3965 - Update Base components --- .../lib/contextmenu/BaseContextMenu.vue | 28 +++++----- components/lib/contextmenu/ContextMenuSub.vue | 38 ++++++------- components/lib/editor/BaseEditor.vue | 16 +++--- .../lib/inputnumber/BaseInputNumber.vue | 16 +++--- .../lib/inputswitch/BaseInputSwitch.vue | 16 +++--- components/lib/inputtext/BaseInputText.vue | 16 +++--- components/lib/knob/BaseKnob.vue | 16 +++--- components/lib/listbox/BaseListbox.vue | 16 +++--- components/lib/megamenu/BaseMegaMenu.vue | 38 +++++++------ components/lib/megamenu/MegaMenuSub.vue | 54 ++++++++----------- components/lib/menu/BaseMenu.vue | 26 +++++---- components/lib/menu/Menuitem.vue | 30 +++++------ components/lib/menubar/BaseMenubar.vue | 30 +++++------ components/lib/menubar/MenubarSub.vue | 46 ++++++---------- .../lib/multiselect/BaseMultiSelect.vue | 16 +++--- components/lib/panelmenu/BasePanelMenu.vue | 26 +++++---- components/lib/panelmenu/PanelMenuList.vue | 12 ++--- components/lib/panelmenu/PanelMenuSub.vue | 40 ++++++-------- components/lib/password/BasePassword.vue | 16 +++--- components/lib/splitter/BaseSplitter.vue | 16 +++--- .../lib/splitterpanel/BaseSplitterPanel.vue | 16 +++--- components/lib/tabview/BaseTabView.vue | 16 +++--- components/lib/tieredmenu/BaseTieredMenu.vue | 30 +++++------ components/lib/tieredmenu/TieredMenuSub.vue | 46 ++++++---------- components/lib/tree/BaseTree.vue | 16 +++--- components/lib/tree/TreeNode.vue | 4 +- components/lib/treeselect/BaseTreeSelect.vue | 16 +++--- 27 files changed, 279 insertions(+), 377 deletions(-) diff --git a/components/lib/contextmenu/BaseContextMenu.vue b/components/lib/contextmenu/BaseContextMenu.vue index e62cfe3ce..616be7cd8 100644 --- a/components/lib/contextmenu/BaseContextMenu.vue +++ b/components/lib/contextmenu/BaseContextMenu.vue @@ -54,20 +54,20 @@ const classes = { } ], menu: 'p-contextmenu-root-list', - menuitem: ({ context, processedItem }) => [ + menuitem: ({ instance, processedItem }) => [ 'p-menuitem', { - 'p-menuitem-active p-highlight': context.isItemActive(processedItem), - 'p-focus': context.isItemFocused(processedItem), - 'p-disabled': context.isItemDisabled(processedItem) + 'p-menuitem-active p-highlight': instance.isItemActive(processedItem), + 'p-focus': instance.isItemFocused(processedItem), + 'p-disabled': instance.isItemDisabled(processedItem) } ], content: 'p-menuitem-content', - action: ({ context, isActive, isExactActive }) => [ + 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', @@ -77,7 +77,7 @@ const classes = { separator: 'p-menuitem-separator' }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_contextmenu_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_contextmenu_style', manual: true }); export default { name: 'BaseContextMenu', @@ -121,15 +121,13 @@ export default { } }, css: { - classes + classes, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/contextmenu/ContextMenuSub.vue b/components/lib/contextmenu/ContextMenuSub.vue index 5d3d41fa5..58f1600b3 100755 --- a/components/lib/contextmenu/ContextMenuSub.vue +++ b/components/lib/contextmenu/ContextMenuSub.vue @@ -6,7 +6,7 @@ v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')" :id="getItemId(processedItem)" :style="getItemProp(processedItem, 'style')" - :class="[getCXOptions('menuitem', { processedItem }), getItemProp(processedItem, 'class')]" + :class="[cx('menuitem', { processedItem }), getItemProp(processedItem, 'class')]" role="menuitem" :aria-label="getItemLabel(processedItem)" :aria-disabled="isItemDisabled(processedItem) || undefined" @@ -20,22 +20,22 @@ :data-p-focused="isItemFocused(processedItem)" :data-p-disabled="isItemDisabled(processedItem)" > -
+
@@ -45,7 +45,7 @@ v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" :id="getItemId(processedItem) + '_list'" role="menu" - :class="getCXOptions('submenu')" + :class="cx('submenu')" :menuId="menuId" :focusedItemId="focusedItemId" :items="processedItem.items" @@ -64,7 +64,7 @@ v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')" :id="getItemId(processedItem)" :style="getItemProp(processedItem, 'style')" - :class="[getCXOptions('separator'), getItemProp(processedItem, 'class')]" + :class="[cx('separator'), getItemProp(processedItem, 'class')]" role="separator" v-bind="ptm('separator')" > @@ -74,14 +74,14 @@ diff --git a/components/lib/inputnumber/BaseInputNumber.vue b/components/lib/inputnumber/BaseInputNumber.vue index f16bbb392..2ea01ddf0 100644 --- a/components/lib/inputnumber/BaseInputNumber.vue +++ b/components/lib/inputnumber/BaseInputNumber.vue @@ -132,7 +132,7 @@ const classes = { ] }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_inputnumber_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_inputnumber_style', manual: true }); export default { name: 'BaseInputNumber', @@ -276,15 +276,13 @@ export default { } }, css: { - classes + classes, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/inputswitch/BaseInputSwitch.vue b/components/lib/inputswitch/BaseInputSwitch.vue index ca7ee7e64..a78a88906 100644 --- a/components/lib/inputswitch/BaseInputSwitch.vue +++ b/components/lib/inputswitch/BaseInputSwitch.vue @@ -41,7 +41,7 @@ const classes = { slider: 'p-inputswitch-slider' }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_inputswitch_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_inputswitch_style', manual: true }); export default { name: 'BaseInputSwitch', @@ -90,15 +90,13 @@ export default { }, css: { classes, - inlineStyles + inlineStyles, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/inputtext/BaseInputText.vue b/components/lib/inputtext/BaseInputText.vue index edce7469d..b23b1f2be 100644 --- a/components/lib/inputtext/BaseInputText.vue +++ b/components/lib/inputtext/BaseInputText.vue @@ -116,7 +116,7 @@ const classes = { root: ({ instance }) => ['p-inputtext p-component', { 'p-filled': instance.filled }] }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_inputtext_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_inputtext_style', manual: true }); export default { name: 'BaseInputText', @@ -125,15 +125,13 @@ export default { modelValue: null }, css: { - classes + classes, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/knob/BaseKnob.vue b/components/lib/knob/BaseKnob.vue index 7c0ab9b33..2a70e2e0c 100644 --- a/components/lib/knob/BaseKnob.vue +++ b/components/lib/knob/BaseKnob.vue @@ -30,7 +30,7 @@ const classes = { label: 'p-knob-text' }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_knob_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_knob_style', manual: true }); export default { name: 'BaseKnob', @@ -102,15 +102,13 @@ export default { } }, css: { - classes + classes, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/listbox/BaseListbox.vue b/components/lib/listbox/BaseListbox.vue index f9f0524e2..e033c6657 100644 --- a/components/lib/listbox/BaseListbox.vue +++ b/components/lib/listbox/BaseListbox.vue @@ -69,7 +69,7 @@ const classes = { hiddenLastFocusableEl: 'p-hidden-accessible p-hidden-focusable' }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_listbox_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_listbox_style', manual: true }); export default { name: 'BaseListbox', @@ -149,15 +149,13 @@ export default { } }, css: { - classes + classes, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/megamenu/BaseMegaMenu.vue b/components/lib/megamenu/BaseMegaMenu.vue index ffcaf69db..fc956baba 100644 --- a/components/lib/megamenu/BaseMegaMenu.vue +++ b/components/lib/megamenu/BaseMegaMenu.vue @@ -116,7 +116,7 @@ const styles = ` `; const inlineStyles = { - submenu: ({ context, processedItem }) => ({ display: context.isItemActive(processedItem) ? 'block' : 'none' }) + submenu: ({ instance, processedItem }) => ({ display: instance.isItemActive(processedItem) ? 'block' : 'none' }) }; const classes = { @@ -129,26 +129,26 @@ const classes = { ], start: 'p-megamenu-start', menu: 'p-megamenu-root-list', - submenuHeader: ({ context, processedItem }) => [ + submenuHeader: ({ instance, processedItem }) => [ 'p-megamenu-submenu-header p-submenu-header', { - 'p-disabled': context.isItemDisabled(processedItem) + 'p-disabled': instance.isItemDisabled(processedItem) } ], - menuitem: ({ context, processedItem }) => [ + menuitem: ({ instance, processedItem }) => [ 'p-menuitem', { - 'p-menuitem-active p-highlight': context.isItemActive(processedItem), - 'p-focus': context.isItemFocused(processedItem), - 'p-disabled': context.isItemDisabled(processedItem) + 'p-menuitem-active p-highlight': instance.isItemActive(processedItem), + 'p-focus': instance.isItemFocused(processedItem), + 'p-disabled': instance.isItemDisabled(processedItem) } ], content: 'p-menuitem-content', - action: ({ context, isActive, isExactActive }) => [ + 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', @@ -156,8 +156,8 @@ const classes = { submenuIcon: 'p-submenu-icon', panel: 'p-megamenu-panel', grid: 'p-megamenu-grid', - column: ({ context, processedItem }) => { - let length = context.isItemGroup(processedItem) ? processedItem.items.length : 0; + column: ({ instance, processedItem }) => { + let length = instance.isItemGroup(processedItem) ? processedItem.items.length : 0; let columnClass; switch (length) { @@ -189,7 +189,7 @@ const classes = { end: 'p-megamenu-end' }; -const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_megamenu_style', manual: true }); +const { load: loadStyle } = useStyle(styles, { id: 'primevue_megamenu_style', manual: true }); export default { name: 'BaseMegaMenu', @@ -226,15 +226,13 @@ export default { }, css: { classes, - inlineStyles + inlineStyles, + loadStyle }, - watch: { - isUnstyled: { - immediate: true, - handler(newValue) { - !newValue && loadStyle(); - } - } + provide() { + return { + $parentInstance: this + }; } }; diff --git a/components/lib/megamenu/MegaMenuSub.vue b/components/lib/megamenu/MegaMenuSub.vue index 21868e3e2..6e2898457 100644 --- a/components/lib/megamenu/MegaMenuSub.vue +++ b/components/lib/megamenu/MegaMenuSub.vue @@ -1,12 +1,12 @@