Refactor #3965 - For ConfirmDialog
parent
6ce95dd393
commit
52e6aacc91
|
@ -0,0 +1,31 @@
|
||||||
|
<script>
|
||||||
|
import BaseComponent from 'primevue/basecomponent';
|
||||||
|
|
||||||
|
const classes = {
|
||||||
|
icon: ({ instance }) => ['p-confirm-dialog-icon', instance.confirmation ? instance.confirmation.icon : null],
|
||||||
|
message: 'p-confirm-dialog-message',
|
||||||
|
rejectButton: ({ instance }) => ['p-confirm-dialog-reject', instance.confirmation ? instance.confirmation.rejectClass || 'p-button-text' : null],
|
||||||
|
rejectButtonIcon: ({ context }) => [context && context.icon, context && context.iconClass],
|
||||||
|
acceptButton: ({ instance }) => ['p-confirm-dialog-accept', instance.confirmation ? instance.confirmation.acceptClass : null],
|
||||||
|
acceptButtonIcon: ({ context }) => [context && context.icon, context && context.iconClass]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'BaseConfirmDialog',
|
||||||
|
extends: BaseComponent,
|
||||||
|
props: {
|
||||||
|
group: String,
|
||||||
|
breakpoints: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
draggable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
classes
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -146,6 +146,11 @@ export interface ConfirmDialogProps {
|
||||||
* @type {ConfirmDialogPassThroughOptions}
|
* @type {ConfirmDialogPassThroughOptions}
|
||||||
*/
|
*/
|
||||||
pt?: ConfirmDialogPassThroughOptions;
|
pt?: ConfirmDialogPassThroughOptions;
|
||||||
|
/**
|
||||||
|
* When enabled, it removes component related styles in the core.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
unstyled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,27 +12,28 @@
|
||||||
:draggable="draggable"
|
:draggable="draggable"
|
||||||
@update:visible="onHide"
|
@update:visible="onHide"
|
||||||
:pt="pt"
|
:pt="pt"
|
||||||
|
:unstyled="unstyled"
|
||||||
>
|
>
|
||||||
<template v-if="!$slots.message">
|
<template v-if="!$slots.message">
|
||||||
<slot name="icon" class="p-confirm-dialog-icon">
|
<slot name="icon">
|
||||||
<component v-if="$slots.icon" :is="$slots.icon" class="p-confirm-dialog-icon" />
|
<component v-if="$slots.icon" :is="$slots.icon" class="p-confirm-dialog-icon" :class="cx('icon')" />
|
||||||
<span v-else-if="confirmation.icon" :class="iconClass" v-bind="ptm('icon')" />
|
<span v-else-if="confirmation.icon" :class="cx('icon')" v-bind="ptm('icon')" />
|
||||||
</slot>
|
</slot>
|
||||||
<span class="p-confirm-dialog-message" v-bind="ptm('message')">{{ message }}</span>
|
<span :class="cx('message')" v-bind="ptm('message')">{{ message }}</span>
|
||||||
</template>
|
</template>
|
||||||
<component v-else :is="$slots.message" :message="confirmation"></component>
|
<component v-else :is="$slots.message" :message="confirmation"></component>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<CDButton :label="rejectLabel" :class="rejectClass" iconPos="left" @click="reject()" :autofocus="autoFocusReject" :pt="ptm('rejectButton')">
|
<CDButton :label="rejectLabel" :class="cx('rejectButton')" iconPos="left" @click="reject()" :autofocus="autoFocusReject" :pt="ptm('rejectButton')">
|
||||||
<template #icon="iconProps">
|
<template #icon="iconProps">
|
||||||
<slot name="rejecticon">
|
<slot name="rejecticon">
|
||||||
<span :class="[rejectIcon, iconProps.class]" v-bind="ptm('rejectButton')['icon']" />
|
<span :class="cx('rejectButtonIcon', getCXOptions(rejectIcon, iconProps))" v-bind="ptm('rejectButton')['icon']" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
</CDButton>
|
</CDButton>
|
||||||
<CDButton :label="acceptLabel" :class="acceptClass" iconPos="left" @click="accept()" :autofocus="autoFocusAccept" :pt="ptm('acceptButton')">
|
<CDButton :label="acceptLabel" :class="cx('acceptButton')" iconPos="left" @click="accept()" :autofocus="autoFocusAccept" :pt="ptm('acceptButton')">
|
||||||
<template #icon="iconProps">
|
<template #icon="iconProps">
|
||||||
<slot name="accepticon">
|
<slot name="accepticon">
|
||||||
<span :class="[acceptIcon, iconProps.class]" v-bind="ptm('acceptButton')['icon']" />
|
<span :class="cx('acceptButtonIcon', getCXOptions(acceptIcon, iconProps))" v-bind="ptm('acceptButton')['icon']" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
</CDButton>
|
</CDButton>
|
||||||
|
@ -41,25 +42,15 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BaseComponent from 'primevue/basecomponent';
|
import BaseConfirmDialog from './BaseConfirmDialog';
|
||||||
import Button from 'primevue/button';
|
import Button from 'primevue/button';
|
||||||
import ConfirmationEventBus from 'primevue/confirmationeventbus';
|
import ConfirmationEventBus from 'primevue/confirmationeventbus';
|
||||||
import Dialog from 'primevue/dialog';
|
import Dialog from 'primevue/dialog';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ConfirmDialog',
|
name: 'ConfirmDialog',
|
||||||
extends: BaseComponent,
|
extends: BaseConfirmDialog,
|
||||||
props: {
|
|
||||||
group: String,
|
|
||||||
breakpoints: {
|
|
||||||
type: Object,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
draggable: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmListener: null,
|
confirmListener: null,
|
||||||
closeListener: null,
|
closeListener: null,
|
||||||
data() {
|
data() {
|
||||||
|
@ -118,6 +109,9 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
|
},
|
||||||
|
getCXOptions(icon, iconProps) {
|
||||||
|
return { contenxt: { icon, iconClass: iconProps.class } };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -133,9 +127,6 @@ export default {
|
||||||
position() {
|
position() {
|
||||||
return this.confirmation ? this.confirmation.position : null;
|
return this.confirmation ? this.confirmation.position : null;
|
||||||
},
|
},
|
||||||
iconClass() {
|
|
||||||
return ['p-confirm-dialog-icon', this.confirmation ? this.confirmation.icon : null];
|
|
||||||
},
|
|
||||||
acceptLabel() {
|
acceptLabel() {
|
||||||
return this.confirmation ? this.confirmation.acceptLabel || this.$primevue.config.locale.accept : null;
|
return this.confirmation ? this.confirmation.acceptLabel || this.$primevue.config.locale.accept : null;
|
||||||
},
|
},
|
||||||
|
@ -148,12 +139,6 @@ export default {
|
||||||
rejectIcon() {
|
rejectIcon() {
|
||||||
return this.confirmation ? this.confirmation.rejectIcon : null;
|
return this.confirmation ? this.confirmation.rejectIcon : null;
|
||||||
},
|
},
|
||||||
acceptClass() {
|
|
||||||
return ['p-confirm-dialog-accept', this.confirmation ? this.confirmation.acceptClass : null];
|
|
||||||
},
|
|
||||||
rejectClass() {
|
|
||||||
return ['p-confirm-dialog-reject', this.confirmation ? this.confirmation.rejectClass || 'p-button-text' : null];
|
|
||||||
},
|
|
||||||
autoFocusAccept() {
|
autoFocusAccept() {
|
||||||
return this.confirmation.defaultFocus === undefined || this.confirmation.defaultFocus === 'accept' ? true : false;
|
return this.confirmation.defaultFocus === undefined || this.confirmation.defaultFocus === 'accept' ? true : false;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue