Skip to content

Commit

Permalink
fix: fix Notification component bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rCatMAN committed Jul 21, 2023
1 parent bd3d3a0 commit 03ebb5f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 61 deletions.
37 changes: 8 additions & 29 deletions packages/vuesax/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,39 @@
import { defineComponent } from "vue";
import { defineComponent, ref } from "vue";

import { VsButton, useNotification } from "./components";

export default defineComponent({
setup() {
const { open, close, clear } = useNotification();
let key: string;
const n = ref(true);
return () => (
<>
<VsButton
onClick={() => {
key = open({
success: true,
text: "These documents refer to the latest version of vuesax (4.0+), to see the documents of the previous versions you can do it here 👉 Vuesax 3.x",
title: "Documentation Vuesax 4.0+",
});
console.log(key);
}}
>
open
</VsButton>
<VsButton
onClick={() => {
open({
warn: true,
position: "bottom-left",
text: "These documents refer to the latest version of vuesax (4.0+), to see the documents of the previous versions you can do it here 👉 Vuesax 3.x",
title: "Documenasdasdtation Vuesax 4.0+",
sticky: true,
});
}}
>
bottom-left
open
</VsButton>
<VsButton
onClick={() => {
open({
warn: true,
position: "top-center",
text: "These documents refer to the latest version of vuesax (4.0+), to see the documents of the previous versions you can do it here 👉 Vuesax 3.x",
title: "Documenasdasdtation Vuesax 4.0+",
});
n.value = true;
}}
>
top-center
true
</VsButton>
<VsButton
onClick={() => {
open({
warn: true,
position: "bottom-center",
text: "These documents refer to the latest version of vuesax (4.0+), to see the documents of the previous versions you can do it here 👉 Vuesax 3.x",
title: "Documenasdasdtation Vuesax 4.0+",
});
n.value = false;
}}
>
bottom-center
false
</VsButton>
<VsButton
onClick={() => {
Expand Down
46 changes: 16 additions & 30 deletions packages/vuesax/src/components/notification/base/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
defineComponent,
onMounted,
onUnmounted,
PropType,
Ref,
ref,
Transition,
watch,
Expand All @@ -17,9 +19,6 @@ const Notification = defineComponent({
name: "VsNotification",
props: {
...BaseProps,
index: {
type: Number,
},
isVisible: {
type: Boolean,
default: true,
Expand All @@ -36,10 +35,6 @@ const Notification = defineComponent({
type: Boolean,
default: false,
},
// icon: {
// type: Boolean,
// default: false,
// },
clickClose: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -69,16 +64,11 @@ const Notification = defineComponent({
default: null,
},
loading: {
type: Boolean,
default: false,
type: Object as PropType<Ref<boolean>>,
},
progressAuto: {
type: Boolean,
default: true,
},
progress: {
type: Number,
default: null,
default: false,
},
duration: {
type: Number,
Expand All @@ -88,10 +78,6 @@ const Notification = defineComponent({
type: Boolean,
default: false,
},
classNotification: {
type: String,
default: null,
},
},
emits: ["onClick", "clickClose", "onDestroy"],
slots: ["default", "content"],
Expand All @@ -114,19 +100,19 @@ const Notification = defineComponent({

onMounted(() => {
innerIsVisible.value = props.isVisible;
innerProgress.value = props.progress;
if (elRef.value) {
setColor("color", props.color, elRef.value);
setColor("border", props.color, elRef.value);
}
if (props.progressAuto && props.progress) {
if (props.progressAuto) {
intervalProgress = setInterval(() => {
innerProgress.value += 1;
if (innerProgress.value >= 100) {
clearInterval(intervalProgress);
innerIsVisible.value = false;
emit("clickClose");
}
}, props.duration / 100);
} else if (props.progress && !props.progressAuto) {
setTimeout(() => {
innerIsVisible.value = false;
}, props.progress);
}
});
onUnmounted(() => {
Expand All @@ -135,7 +121,7 @@ const Notification = defineComponent({

const handleClickClose = () => {
innerIsVisible.value = false;
emit("clickClose", props.index);
emit("clickClose");
};

const beforeEnter = () => {
Expand Down Expand Up @@ -233,7 +219,7 @@ const Notification = defineComponent({
{ "vs-notification--square": props.square },
{ "vs-notification--width-all": props.width === "100%" },
{ "vs-notification--width-auto": props.width === "auto" },
{ "vs-notification--loading": props.loading },
{ "vs-notification--loading": props.loading?.value },
{ "vs-notification--notPadding": props.noPadding },
{ "vs-notification--primary": props.primary },
{ "vs-notification--success": props.success },
Expand All @@ -250,11 +236,11 @@ const Notification = defineComponent({
}}
ref={elRef}
>
{!props.loading && slots.icon && icon()}
{!props.loading && content()}
{!props.loading?.value && slots.icon && icon()}
{!props.loading?.value && content()}
{props.buttonClose && closeBtn()}
{props.loading && loading()}
{props.progress && progress()}
{props.loading?.value && loading()}
{props.progressAuto && progress()}
</div>
)}
</Transition>
Expand Down
15 changes: 14 additions & 1 deletion packages/vuesax/src/components/notification/base/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
&.vs-notification--border {
border: 3px solid transparent;
border-top: 3px solid -color('border');
--vs-text:var(--vs-dark);
background: rgb(var(--vs-background));
}
}
.notification-enter-from {
Expand Down Expand Up @@ -101,6 +103,8 @@
&.vs-notification--border {
border: 3px solid transparent;
border-bottom: 3px solid -color('border');
--vs-text:var(--vs-dark);
background: rgb(var(--vs-background));
}
}
.notification-enter-from {
Expand Down Expand Up @@ -130,6 +134,8 @@
&.vs-notification--border {
border: 3px solid transparent;
border-left: 3px solid -color('border');
--vs-text:var(--vs-dark);
background: rgb(var(--vs-background));
}
}
.notification-enter-from {
Expand All @@ -153,6 +159,8 @@
&.vs-notification--border {
border: 3px solid transparent;
border-left: 3px solid -color('border');
--vs-text:var(--vs-dark);
background: rgb(var(--vs-background));
}
}
.notification-enter-from {
Expand All @@ -167,7 +175,7 @@
}
.vs-notification {
--vs-color: var(--vs-background);
--vs-border: var(--vs-background);
--vs-border: var(--vs-color);
--vs-opacity: .6;
max-height: 112px;
padding: 20px;
Expand Down Expand Up @@ -244,6 +252,8 @@
&.vs-notification--border {
border: 0px solid transparent !important;
border-right: 3px solid -color('border') !important;
--vs-text:var(--vs-dark);
background: rgb(var(--vs-background));
}
&:after {
content: '';
Expand Down Expand Up @@ -287,6 +297,9 @@
&.vs-notification--border {
border: 3px solid transparent;
border-right: 3px solid -color('border');
--vs-text:var(--vs-dark);
background: rgb(var(--vs-background));

}
&__progress {
width: 0%;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from "nanoid/non-secure";
import { createApp, ref, TransitionGroup } from "vue";
import { createApp, ref, TransitionGroup, VNode } from "vue";

import Notification, { NotificationProps } from "./Notification";

Expand All @@ -13,6 +13,7 @@ type Position =

type NotificationHookProps = Omit<NotificationProps, "isVisible"> & {
position?: Position;
icon?: VNode;
};

const useNotification = () => {
Expand Down Expand Up @@ -104,6 +105,7 @@ const useNotification = () => {
close(key, props.position || "bottom-right");
}}
key={key}
v-slots={props.icon && { icon: () => props.icon }}
></Notification>,
]);

Expand Down

0 comments on commit 03ebb5f

Please sign in to comment.