Skip to content

Commit

Permalink
Refactor #3965 - Refactor on Toast
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jul 7, 2023
1 parent 9b9444b commit 63b11df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
39 changes: 12 additions & 27 deletions components/lib/toast/BaseToast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useStyle } from 'primevue/usestyle';
const styles = `
.p-toast {
position: fixed;
width: 25rem;
}
Expand All @@ -17,41 +16,15 @@ const styles = `
flex: 1 1 auto;
}
.p-toast-top-right {
top: 20px;
right: 20px;
}
.p-toast-top-left {
top: 20px;
left: 20px;
}
.p-toast-bottom-left {
bottom: 20px;
left: 20px;
}
.p-toast-bottom-right {
bottom: 20px;
right: 20px;
}
.p-toast-top-center {
top: 20px;
left: 50%;
transform: translateX(-50%);
}
.p-toast-bottom-center {
bottom: 20px;
left: 50%;
transform: translateX(-50%);
}
.p-toast-center {
left: 50%;
top: 50%;
min-width: 20vw;
transform: translate(-50%, -50%);
}
Expand Down Expand Up @@ -98,6 +71,17 @@ const styles = `
}
`;
// 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
})
};
const classes = {
root: ({ props, instance }) => [
'p-toast p-component p-toast-' + props.position,
Expand Down Expand Up @@ -185,6 +169,7 @@ export default {
},
css: {
classes,
inlineStyles,
loadStyle
},
provide() {
Expand Down
2 changes: 1 addition & 1 deletion components/lib/toast/Toast.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Portal>
<div ref="container" :class="cx('root')" v-bind="{ ...$attrs, ...ptm('root') }">
<div ref="container" :class="cx('root')" :style="sx('root', true, { position })" v-bind="{ ...$attrs, ...ptm('root') }">
<transition-group name="p-toast-message" tag="div" @enter="onEnter" @leave="onLeave" v-bind="ptm('message')">
<ToastMessage
v-for="msg of messages"
Expand Down

0 comments on commit 63b11df

Please sign in to comment.