1.0.3 • Published 7 months ago

@iamsabbir/nanotoast v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

šŸ“¢ 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/nanotoast

Using Yarn

yarn add @iamsabbir/nanotoast

Using 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-left
  • top-right (default)
  • top-center
  • bottom-left
  • bottom-right
  • bottom-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! šŸš€šŸŽÆ

1.0.3

7 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago