@iamsabbir/nanotoast v1.0.3
š¢ NanoToast
A lightweight and customizable toast notification library for JavaScript with support for success, error, info, warning, message descriptions, async promise handling, and positioning.
š Features
ā
Simple and easy-to-use API
ā
Supports success, error, warning, info toasts
ā
Custom duration, position, and closable toasts
ā
Promise-based toasts (toast.promise())
ā
Lightweight (~3KB) with no dependencies
ā
CSS scoped styles to prevent conflicts
ā
Works in Vanilla JS, React, Vue, Alpine.js, etc.
š¦ Installation
Using NPM
npm install @iamsabbir/nanotoastUsing Yarn
yarn add @iamsabbir/nanotoastUsing a CDN (No installation required)
<!-- Add the javascript -->
<script src="https://unpkg.com/@iamsabbir/nanotoast/dist/nanotoast.js"></script>
<!-- Or if you want esm module -->
<script src="https://unpkg.com/@iamsabbir/nanotoast/dist/nanotoast.esm.js"></script>
<!-- Add the css -->
<link rel="stylesheet" href="https://unpkg.com/@iamsabbir/nanotoast/dist/nanotoast.css">š Basic Usage
Import @iamsabbir/nanotoast
import toast from "@iamsabbir/nanotoast";
import "@iamsabbir/nanotoast/src/styles.css"; // Ensure you import stylesš„ Show a Basic Toast
toast("This is a simple toast!");šØ Success, Error, Warning, and Info Toasts
toast.success("Action was successful!");
toast.error("Something went wrong!");
toast.warning("Warning: Low disk space!");
toast.info("This is an info message.");š Message with Description
toast.message("Event has been created", {
description: "Monday, January 3rd at 6:00pm",
closeable: true,
position: "bottom-right",
});ā³ Promise-based Toasts
Show a loading toast while a promise is in progress, then update it on success/error.
const fetchData = () =>
new Promise((resolve) => setTimeout(() => resolve({ name: "NanoToast" }), 2000));
toast.promise(fetchData(), {
loading: "Fetching data...",
success: (data) => `${data.name} has been loaded!`,
error: "Failed to fetch data",
});šÆ Customization Options
š Set default options
All subsequent calls to toast.* will use these new defaults unless overridden locally.
toast.configure({
position: "bottom-center",
duration: 5000,
closeable: false,
});ā± Custom Duration
toast.success("Short message", { duration: 1500 }); // 1.5s
toast.error("Longer message", { duration: 5000 }); // 5sā Closable Toast
toast.info("Click to close this toast", { closeable: true });š Toast Positions
Toasts can be positioned in six locations:
top-lefttop-right(default)top-centerbottom-leftbottom-rightbottom-center
toast.success("Top Center", { position: "top-center" });
toast.error("Bottom Center", { position: "bottom-center" });šØ Styling & Customization
Modify Styles via CSS
You can customize styles by overriding the default CSS.
.nanotoast.success {
background: #28a745; /* Change success color */
}
.nanotoast {
font-size: 16px;
border-radius: 8px;
}š» Works With Frameworks
š Vanilla JS
import toast from "nanotoast";
toast.success("Hello, Vanilla JS!");or if you use regular build from cdn
// Basic Toast
NanoToast.toast("This is a simple toast!");
// Success, Error, Warning, and Info Toasts
NanoToast.toast.success("Action was successful!");
NanoToast.toast.error("Something went wrong!");
NanoToast.toast.warning("Warning: Low disk space!");
NanoToast.toast.info("This is an info message.");
// Promise
const fetchData = () =>
new Promise((resolve) => setTimeout(() => resolve({ name: "NanoToast" }), 2000));
NanoToast.toast.promise(fetchData(), {
loading: "Fetching data...",
success: (data) => `${data.name} has been loaded!`,
error: "Failed to fetch data",
});āļø React
import toast from "nanotoast";
const App = () => {
return <button onClick={() => toast.success("React is awesome!")}>Show Toast</button>;
};šŗ Vue
<script setup>
import toast from "nanotoast";
const showToast = () => {
toast.success("Hello from Vue!");
};
</script>
<template>
<button @click="showToast">Show Toast</button>
</template>š Alpine.js
<button x-data @click="toast.success('Alpine.js toast!')">Show Toast</button>š License
MIT License Ā© 2025 [Sabbir Hasan] šš Support & Contribution
- Found a bug? Open an issue.
- Want to contribute? Fork and submit a pull request!
- Star ā the repo if you find it useful!
š That's it!
Now you have a fully documented and ready-to-publish toast notification package! ššÆ