aboutsummaryrefslogtreecommitdiff
path: root/pages/lib/useNotify.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-14 00:07:02 +0700
committerFactiven <[email protected]>2023-04-14 00:07:02 +0700
commit482b1c8db5cfeaa20d75ce92fcb10f3ca8433633 (patch)
treef0c12d3acb6bd8ce43e63e01527c97a62dba7e9c /pages/lib/useNotify.js
parentUpdate index.js (diff)
downloadmoopa-482b1c8db5cfeaa20d75ce92fcb10f3ca8433633.tar.xz
moopa-482b1c8db5cfeaa20d75ce92fcb10f3ca8433633.zip
Update 5th
Diffstat (limited to 'pages/lib/useNotify.js')
-rw-r--r--pages/lib/useNotify.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/pages/lib/useNotify.js b/pages/lib/useNotify.js
new file mode 100644
index 0000000..e6ba7e6
--- /dev/null
+++ b/pages/lib/useNotify.js
@@ -0,0 +1,41 @@
+import { useState, useCallback } from "react";
+import { motion as m, AnimatePresence } from "framer-motion";
+
+export const useNotification = () => {
+ const [showNotification, setShowNotification] = useState(false);
+ const [notificationMessage, setNotificationMessage] = useState("");
+
+ const show = useCallback(
+ (message) => {
+ setNotificationMessage(message);
+ setShowNotification(true);
+ setTimeout(() => {
+ setShowNotification(false);
+ }, 5000);
+ },
+ [setNotificationMessage, setShowNotification]
+ );
+
+ const NotificationComponent = () => {
+ return (
+ <AnimatePresence>
+ {showNotification && (
+ <m.div
+ key="teasa"
+ transition={{ duration: 0.5 }}
+ initial={{ opacity: 0, y: 100 }}
+ animate={{ opacity: 1, y: 0 }}
+ exit={{ opacity: 0, y: 100 }}
+ className="z-50 fixed bottom-10 w-screen flex justify-center text-center"
+ >
+ <div className="bg-green-600 text-white px-2 py-2 font-bold rounded-[30px]">
+ {notificationMessage}
+ </div>
+ </m.div>
+ )}
+ </AnimatePresence>
+ );
+ };
+
+ return { Notification: NotificationComponent, show };
+};