Refactor #3832 Refactor #3833 - For Dialog

pull/3857/head
Bahadır Sofuoğlu 2023-04-12 00:00:21 +03:00
parent ff609bf403
commit 2efb8ad0d9
4 changed files with 60 additions and 32 deletions

View File

@ -189,6 +189,14 @@ const DialogSlots = [
{ {
name: 'footer', name: 'footer',
description: "Custom content for the component's footer" description: "Custom content for the component's footer"
},
{
name: 'closeicon',
description: 'Custom close icon template.'
},
{
name: 'maximizeicon',
description: 'Custom maximizeicon icon template of dialog.'
} }
]; ];

View File

@ -146,17 +146,14 @@ export interface DialogProps {
style?: any; style?: any;
/** /**
* Icon to display in the dialog close button. * Icon to display in the dialog close button.
* @defaultValue pi pi-times
*/ */
closeIcon?: string | undefined; closeIcon?: string | undefined;
/** /**
* Icon to display in the dialog maximize button when dialog is not maximized. * Icon to display in the dialog maximize button when dialog is not maximized.
* @defaultValue pi pi-window-maximize
*/ */
maximizeIcon?: string | undefined; maximizeIcon?: string | undefined;
/** /**
* Icon to display in the dialog maximize button when dialog is maximized. * Icon to display in the dialog maximize button when dialog is maximized.
* @defaultValue pi pi-window-minimize
*/ */
minimizeIcon?: string | undefined; minimizeIcon?: string | undefined;
} }
@ -177,6 +174,20 @@ export interface DialogSlots {
* Custom footer template. * Custom footer template.
*/ */
footer(): VNode[]; footer(): VNode[];
/**
* Custom close icon template.
*/
closeicon(): VNode[];
/**
* Custom maximizeicon icon template of dialog.
* @param {Object} scope - maximizeicon icon slot's params.
*/
maximizeicon(scope: {
/**
* Maximized state as a boolean
*/
maximized: boolean;
}): VNode[];
} }
/** /**

View File

@ -9,7 +9,9 @@
</slot> </slot>
<div class="p-dialog-header-icons"> <div class="p-dialog-header-icons">
<button v-if="maximizable" :ref="maximizableRef" v-ripple :autofocus="focusableMax" class="p-dialog-header-icon p-dialog-header-maximize p-link" @click="maximize" type="button" :tabindex="maximizable ? '0' : '-1'"> <button v-if="maximizable" :ref="maximizableRef" v-ripple :autofocus="focusableMax" class="p-dialog-header-icon p-dialog-header-maximize p-link" @click="maximize" type="button" :tabindex="maximizable ? '0' : '-1'">
<span :class="maximizeIconClass"></span> <slot name="maximizeicon" :maximized="maximized">
<component :is="maximizeIconComponent" :class="maximizeIconClass" />
</slot>
</button> </button>
<button <button
v-if="closable" v-if="closable"
@ -22,7 +24,9 @@
type="button" type="button"
v-bind="closeButtonProps" v-bind="closeButtonProps"
> >
<span :class="['p-dialog-header-close-icon', closeIcon]"></span> <slot name="closeicon">
<component :is="closeIcon ? 'span' : 'TimesIcon'" :class="['p-dialog-header-close-icon', closeIcon]"></component>
</slot>
</button> </button>
</div> </div>
</div> </div>
@ -44,6 +48,9 @@ import Portal from 'primevue/portal';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
import { DomHandler, UniqueComponentId, ZIndexUtils } from 'primevue/utils'; import { DomHandler, UniqueComponentId, ZIndexUtils } from 'primevue/utils';
import { computed } from 'vue'; import { computed } from 'vue';
import TimesIcon from 'primevue/icon/times';
import WindowMaximizeIcon from 'primevue/icon/windowmaximize';
import WindowMinimizeIcon from 'primevue/icon/windowminimize';
export default { export default {
name: 'Dialog', name: 'Dialog',
@ -140,15 +147,15 @@ export default {
}, },
closeIcon: { closeIcon: {
type: String, type: String,
default: 'pi pi-times' default: undefined
}, },
maximizeIcon: { maximizeIcon: {
type: String, type: String,
default: 'pi pi-window-maximize' default: undefined
}, },
minimizeIcon: { minimizeIcon: {
type: String, type: String,
default: 'pi pi-window-minimize' default: undefined
}, },
closeButtonProps: { closeButtonProps: {
type: null, type: null,
@ -169,20 +176,6 @@ export default {
focusableClose: null focusableClose: null
}; };
}, },
documentKeydownListener: null,
container: null,
mask: null,
content: null,
headerContainer: null,
footerContainer: null,
maximizableButton: null,
closeButton: null,
styleElement: null,
dragging: null,
documentDragListener: null,
documentDragEndListener: null,
lastPageX: null,
lastPageY: null,
updated() { updated() {
if (this.visible) { if (this.visible) {
this.containerVisible = this.visible; this.containerVisible = this.visible;
@ -475,14 +468,13 @@ export default {
} }
]; ];
}, },
maximizeIconComponent() {
return this.maximized ? (this.minimizeIcon ? 'span' : 'WindowMinimizeIcon') : this.maximizeIcon ? 'span' : 'WindowMaximizeIcon';
},
maximizeIconClass() { maximizeIconClass() {
return [ const maximizeClasses = this.maximized ? this.minimizeIcon : this.maximizeIcon;
'p-dialog-header-maximize-icon',
{ return `p-dialog-header-maximize-icon ${maximizeClasses}`;
[this.maximizeIcon]: !this.maximized,
[this.minimizeIcon]: this.maximized
}
];
}, },
ariaId() { ariaId() {
return UniqueComponentId(); return UniqueComponentId();
@ -500,12 +492,29 @@ export default {
return ['p-dialog-content', this.contentClass]; return ['p-dialog-content', this.contentClass];
} }
}, },
documentKeydownListener: null,
container: null,
mask: null,
content: null,
headerContainer: null,
footerContainer: null,
maximizableButton: null,
closeButton: null,
styleElement: null,
dragging: null,
documentDragListener: null,
documentDragEndListener: null,
lastPageX: null,
lastPageY: null,
directives: { directives: {
ripple: Ripple, ripple: Ripple,
focustrap: FocusTrap focustrap: FocusTrap
}, },
components: { components: {
Portal: Portal Portal: Portal,
WindowMinimizeIcon,
WindowMaximizeIcon,
TimesIcon
} }
}; };
</script> </script>

View File

@ -13,7 +13,7 @@
v-bind="{ ...previousButtonProps, ...ptm('prevbutton') }" v-bind="{ ...previousButtonProps, ...ptm('prevbutton') }"
> >
<slot name="previcon"> <slot name="previcon">
<component :is="prevIcon ? prevIcon : 'ChevronLeftIcon'" v-bind="ptm('previcon')" aria-hidden="true" /> <component :is="prevIcon ? 'span' : 'ChevronLeftIcon'" v-bind="ptm('previcon')" aria-hidden="true" :class="prevIcon" />
</slot> </slot>
</button> </button>
<div ref="content" class="p-tabview-nav-content" @scroll="onScroll" v-bind="ptm('navcontent')"> <div ref="content" class="p-tabview-nav-content" @scroll="onScroll" v-bind="ptm('navcontent')">
@ -59,7 +59,7 @@
v-bind="{ ...nextButtonProps, ...ptm('nextbutton') }" v-bind="{ ...nextButtonProps, ...ptm('nextbutton') }"
> >
<slot name="nexticon"> <slot name="nexticon">
<component :is="nextIcon ? nextIcon : 'ChevronRightIcon'" v-bind="ptm('nexticon')" aria-hidden="true" /> <component :is="nextIcon ? 'span' : 'ChevronRightIcon'" v-bind="ptm('nexticon')" aria-hidden="true" :class="nextIcon" />
</slot> </slot>
</button> </button>
</div> </div>