Refactor #3885 - For ConfirmDialog

pull/3913/head
Tuğçe Küçükoğlu 2023-04-25 12:58:01 +03:00
parent b4cf56a714
commit 639d662ed0
3 changed files with 111 additions and 6 deletions

View File

@ -16,6 +16,12 @@ const ConfirmDialogProps = [
type: 'boolean',
default: 'true',
description: 'Whether the dialog can be relocated by dragging.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
}
];

View File

@ -11,6 +11,97 @@ import { VNode } from 'vue';
import { ConfirmationOptions } from '../confirmationoptions';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type ConfirmDialogPassThroughOptionType = ConfirmDialogPassThroughAttributes | ((options: ConfirmDialogPassThroughMethodOptions) => ConfirmDialogPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface ConfirmDialogPassThroughMethodOptions {
props: ConfirmDialogProps;
state: ConfirmDialogState;
}
/**
* Custom passthrough(pt) options.
* @see {@link ConfirmDialogProps.pt}
*/
export interface ConfirmDialogPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the header's DOM element.
*/
header?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the header title's DOM element.
*/
headerTitle?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the close button's DOM element.
*/
closeButton?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the close icon's DOM element.
*/
closeIcon?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the content's DOM element.
*/
content?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the footer's DOM element.
*/
footer?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the icon's DOM element.
*/
icon?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the message's DOM element.
*/
message?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the reject button's DOM element.
*/
rejectButton?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the reject icon's DOM element.
*/
rejectIcon?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the accept button's DOM element.
*/
acceptButton?: ConfirmDialogPassThroughOptionType;
/**
* Uses to pass attributes to the accept icon's DOM element.
*/
acceptIcon?: ConfirmDialogPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface ConfirmDialogPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in ConfirmDialog component.
*/
export interface ConfirmDialogState {
/**
* Current visible state as a boolean.
* @defaultValue false
*/
visible: boolean;
/**
* Current confirmation message.
*/
confirmation: any;
}
/**
* Breakpoint metadata.
*/
@ -51,6 +142,11 @@ export interface ConfirmDialogProps {
* @defaultValue true
*/
draggable?: boolean | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {ConfirmDialogPassThroughOptions}
*/
pt?: ConfirmDialogPassThroughOptions;
}
/**

View File

@ -11,27 +11,28 @@
:closeOnEscape="closeOnEscape"
:draggable="draggable"
@update:visible="onHide"
:pt="{ root: ptm('root'), header: ptm('header'), headerTitle: ptm('headerTitle'), closeButton: ptm('closeButton'), closeIcon: ptm('closeIcon'), content: ptm('content'), footer: ptm('footer') }"
>
<template v-if="!$slots.message">
<slot name="icon" class="p-confirm-dialog-icon">
<component v-if="$slots.icon" :is="$slots.icon" class="p-confirm-dialog-icon" />
<span v-else-if="confirmation.icon" :class="iconClass" />
<span v-else-if="confirmation.icon" :class="iconClass" v-bind="ptm('icon')" />
</slot>
<span class="p-confirm-dialog-message">{{ message }}</span>
<span class="p-confirm-dialog-message" v-bind="ptm('message')">{{ message }}</span>
</template>
<component v-else :is="$slots.message" :message="confirmation"></component>
<template #footer>
<CDButton :label="rejectLabel" :class="rejectClass" iconPos="left" @click="reject()" :autofocus="autoFocusReject">
<CDButton :label="rejectLabel" :class="rejectClass" iconPos="left" @click="reject()" :autofocus="autoFocusReject" v-bind="ptm('rejectButton')">
<template #icon="iconProps">
<slot name="rejecticon">
<span :class="[rejectIcon, iconProps.class]" />
<span :class="[rejectIcon, iconProps.class]" v-bind="ptm('rejectIcon')" />
</slot>
</template>
</CDButton>
<CDButton :label="acceptLabel" :class="acceptClass" iconPos="left" @click="accept()" :autofocus="autoFocusAccept">
<CDButton :label="acceptLabel" :class="acceptClass" iconPos="left" @click="accept()" :autofocus="autoFocusAccept" v-bind="ptm('acceptButton')">
<template #icon="iconProps">
<slot name="accepticon">
<span :class="[acceptIcon, iconProps.class]" />
<span :class="[acceptIcon, iconProps.class]" v-bind="ptm('acceptIcon')" />
</slot>
</template>
</CDButton>
@ -40,12 +41,14 @@
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
import Button from 'primevue/button';
import ConfirmationEventBus from 'primevue/confirmationeventbus';
import Dialog from 'primevue/dialog';
export default {
name: 'ConfirmDialog',
extends: BaseComponent,
props: {
group: String,
breakpoints: {