2023-05-25 21:53:07 +00:00
|
|
|
<script>
|
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
|
|
|
import { useStyle } from 'primevue/usestyle';
|
|
|
|
|
|
|
|
const styles = `
|
2023-09-26 09:14:27 +00:00
|
|
|
@layer primevue {
|
2023-09-25 19:11:55 +00:00
|
|
|
.p-toast {
|
|
|
|
width: 25rem;
|
|
|
|
white-space: pre-line;
|
|
|
|
word-break: break-word;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-message-icon {
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-message-content {
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-message-text {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-top-center {
|
|
|
|
transform: translateX(-50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-bottom-center {
|
|
|
|
transform: translateX(-50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-center {
|
|
|
|
min-width: 20vw;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-icon-close {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
overflow: hidden;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-icon-close.p-link {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Animations */
|
|
|
|
.p-toast-message-enter-from {
|
|
|
|
opacity: 0;
|
|
|
|
-webkit-transform: translateY(50%);
|
|
|
|
-ms-transform: translateY(50%);
|
|
|
|
transform: translateY(50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-message-leave-from {
|
|
|
|
max-height: 1000px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast .p-toast-message.p-toast-message-leave-to {
|
|
|
|
max-height: 0;
|
|
|
|
opacity: 0;
|
|
|
|
margin-bottom: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-message-enter-active {
|
|
|
|
-webkit-transition: transform 0.3s, opacity 0.3s;
|
|
|
|
transition: transform 0.3s, opacity 0.3s;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toast-message-leave-active {
|
|
|
|
-webkit-transition: max-height 0.45s cubic-bezier(0, 1, 0, 1), opacity 0.3s, margin-bottom 0.3s;
|
|
|
|
transition: max-height 0.45s cubic-bezier(0, 1, 0, 1), opacity 0.3s, margin-bottom 0.3s;
|
|
|
|
}
|
2023-05-25 21:53:07 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2023-07-07 12:06:58 +00:00
|
|
|
// Position
|
|
|
|
const inlineStyles = {
|
|
|
|
root: ({ position }) => ({
|
|
|
|
position: 'fixed',
|
|
|
|
top: position === 'top-right' || position === 'top-left' || position === 'top-center' ? '20px' : position === 'center' ? '50%' : null,
|
|
|
|
right: (position === 'top-right' || position === 'bottom-right') && '20px',
|
|
|
|
bottom: (position === 'bottom-left' || position === 'bottom-right' || position === 'bottom-center') && '20px',
|
|
|
|
left: position === 'top-left' || position === 'bottom-left' ? '20px' : position === 'center' || position === 'top-center' || position === 'bottom-center' ? '50%' : null
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2023-05-25 21:53:07 +00:00
|
|
|
const classes = {
|
|
|
|
root: ({ props, instance }) => [
|
|
|
|
'p-toast p-component p-toast-' + props.position,
|
|
|
|
{
|
|
|
|
'p-input-filled': instance.$primevue.config.inputStyle === 'filled',
|
|
|
|
'p-ripple-disabled': instance.$primevue.config.ripple === false
|
|
|
|
}
|
2023-05-29 11:35:09 +00:00
|
|
|
],
|
|
|
|
container: ({ props }) => [
|
|
|
|
'p-toast-message',
|
|
|
|
{
|
2023-06-20 08:39:17 +00:00
|
|
|
'p-toast-message-info': props.message.severity === 'info' || props.message.severity === undefined,
|
2023-05-29 11:35:09 +00:00
|
|
|
'p-toast-message-warn': props.message.severity === 'warn',
|
|
|
|
'p-toast-message-error': props.message.severity === 'error',
|
|
|
|
'p-toast-message-success': props.message.severity === 'success'
|
|
|
|
}
|
|
|
|
],
|
2023-07-06 12:13:28 +00:00
|
|
|
content: 'p-toast-message-content',
|
2023-05-29 11:35:09 +00:00
|
|
|
icon: ({ props }) => [
|
|
|
|
'p-toast-message-icon',
|
|
|
|
{
|
|
|
|
[props.infoIcon]: props.message.severity === 'info',
|
|
|
|
[props.warnIcon]: props.message.severity === 'warn',
|
|
|
|
[props.errorIcon]: props.message.severity === 'error',
|
|
|
|
[props.successIcon]: props.message.severity === 'success'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
text: 'p-toast-message-text',
|
|
|
|
summary: 'p-toast-summary',
|
|
|
|
detail: 'p-toast-detail',
|
2023-07-19 11:34:12 +00:00
|
|
|
closeButton: 'p-toast-icon-close p-link',
|
|
|
|
closeIcon: 'p-toast-icon-close-icon'
|
2023-05-25 21:53:07 +00:00
|
|
|
};
|
|
|
|
|
2023-07-03 22:20:35 +00:00
|
|
|
const { load: loadStyle } = useStyle(styles, { name: 'toast', manual: true });
|
2023-05-25 21:53:07 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'BaseToast',
|
|
|
|
extends: BaseComponent,
|
|
|
|
props: {
|
|
|
|
group: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
position: {
|
|
|
|
type: String,
|
|
|
|
default: 'top-right'
|
|
|
|
},
|
|
|
|
autoZIndex: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
baseZIndex: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
breakpoints: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
closeIcon: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
infoIcon: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
warnIcon: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
errorIcon: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
successIcon: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
closeButtonProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
css: {
|
2023-05-30 12:28:04 +00:00
|
|
|
classes,
|
2023-07-07 12:06:58 +00:00
|
|
|
inlineStyles,
|
2023-05-30 12:28:04 +00:00
|
|
|
loadStyle
|
2023-05-25 21:53:07 +00:00
|
|
|
},
|
2023-05-30 12:28:04 +00:00
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
$parentInstance: this
|
|
|
|
};
|
2023-05-25 21:53:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|