25
loading...
This website collects cookies to deliver better user experience
npm install classnames react-icons react-hot-toast
App.jsx
we will import our dependencies:// @src/App.jsx
import React from "react";
import classNames from "classnames";
import toast, { Toaster } from "react-hot-toast";
import { MdOutlineClose } from "react-icons/md";
import { HiLightningBolt } from "react-icons/hi";
// ...
App.jsx
:/* @src/App.module.css */
.notificationWrapper {
@apply flex flex-row items-center justify-between w-96 bg-gray-900 px-4 py-6 text-white shadow-2xl hover:shadow-none transform-gpu translate-y-0 hover:translate-y-1 rounded-xl relative transition-all duration-500 ease-in-out;
}
.iconWrapper {
@apply text-xl;
}
.contentWrapper {
@apply flex flex-col items-start justify-center ml-4 cursor-default;
}
.contentWrapper h1 {
@apply text-base text-gray-200 font-semibold leading-none tracking-wider;
}
.contentWrapper p {
@apply text-sm text-gray-400 mt-2 leading-relaxed tracking-wider;
}
.closeIcon {
@apply absolute top-2 right-2 cursor-pointer text-lg;
}
App.jsx
. First we'll import the styles we just created and then we'll start working on our notification component.// @src/App.jsx
import React from "react";
import classNames from "classnames";
import toast, { Toaster } from "react-hot-toast";
import { MdOutlineClose } from "react-icons/md";
import { HiLightningBolt } from "react-icons/hi";
import styles from "./App.module.css";
const notify = () =>
toast.custom(
(t) => (
<div
className={classNames([
styles.notificationWrapper,
t.visible ? "top-0" : "-top-96",
])}
>
<div className={styles.iconWrapper}>
<HiLightningBolt />
</div>
<div className={styles.contentWrapper}>
<h1>New version available</h1>
<p>
An improved version of VESSEL is now available, refresh to update.
</p>
</div>
<div className={styles.closeIcon} onClick={() => toast.dismiss(t.id)}>
<MdOutlineClose />
</div>
</div>
),
{ id: "unique-notification", position: "top-center" }
);
// ...
// @src/App.jsx
import React from "react";
import classNames from "classnames";
import toast, { Toaster } from "react-hot-toast";
import { MdOutlineClose } from "react-icons/md";
import { HiLightningBolt } from "react-icons/hi";
import styles from "./App.module.css";
const notify = () =>
toast.custom(
(t) => (
<div
className={classNames([
styles.notificationWrapper,
t.visible ? "top-0" : "-top-96",
])}
>
<div className={styles.iconWrapper}>
<HiLightningBolt />
</div>
<div className={styles.contentWrapper}>
<h1>New version available</h1>
<p>
An improved version of VESSEL is now available, refresh to update.
</p>
</div>
<div className={styles.closeIcon} onClick={() => toast.dismiss(t.id)}>
<MdOutlineClose />
</div>
</div>
),
{ id: "unique-notification", position: "top-center" }
);
const App = () => {
return (
<div>
<button onClick={notify}>Notify</button>
<Toaster />
</div>
);
};
export default App;