@aicadev/toast-message
v1.0.3
Published
π Lightweight and framework-agnostic Web Component for toast notifications
Maintainers
Readme
@aicadev/toast-message
π Lightweight and framework-agnostic Web Component for toast notifications.
This package provides a simple, customizable <toast-message> Web Component that works with any frontend stack (Vanilla JS, React, Vue, Astro, etc.).
Demo: https://aitorcachero.github.io/aicadev-toast-message/
β¨ Features
- β No dependencies
- β Highly customizable with multiple attributes
- β Works with any framework (or none)
- β Lightweight and fast
- β Easy to style or extend
- β Built with Web Standards
- β HTML support in messages
- β Flexible positioning
- β Accessible
- β Smooth animations
π Installation
npm install @aicadev/toast-messageπ§ͺ Basic Usage
Import the component in your project:
import '@aicadev/toast-message';Then use it like this:
// Create and show a toast
function showToast(
message,
type = 'info',
duration = 3000,
position = 'top-right',
closeable = false
) {
const toast = document.createElement('toast-message');
toast.innerHTML = message;
toast.setAttribute('type', type);
toast.setAttribute('duration', duration);
toast.setAttribute('position', position);
if (closeable) {
toast.setAttribute('closeable', '');
}
document.body.appendChild(toast);
}
// Usage examples
showToast('Operation successful!', 'success');
showToast(
'<strong>Error:</strong> Something went wrong',
'error',
5000,
'bottom-center',
true
);π Attributes
| Attribute | Type | Default | Description |
| ----------- | ------- | ----------- | -------------------------------------------------------------- |
| type | string | info | Defines the toast style: info, success, error, warning |
| duration | number | 3000 | Time in milliseconds before toast disappears |
| position | string | top-right | Position of the toast on the screen |
| closeable | boolean | false | Shows a button to manually close the toast |
Available Positions
- top-right
- top-left
- top-center
- bottom-right
- bottom-left
- bottom-center
π¦ Build & Development (for contributors)
git clone https://github.com/your-username/toast-message.git
cd toast-message
npm install
npm run dev # Start dev server
npm run build # Output build to /distBuilt using Vite. Output is bundled as an ES Module ready for direct use.
π€ Publishing
If you're the package maintainer:
npm login
npm run build
npm publish --access publicπ§ Example in React (or other frameworks)
import '@aicadev/toast-message';
function App() {
const handleClick = () => {
const toast = document.createElement('toast-message');
toast.innerHTML = '<strong>React</strong> triggered this!';
toast.setAttribute('type', 'success');
toast.setAttribute('duration', '4000');
toast.setAttribute('position', 'top-center');
toast.setAttribute('closeable', '');
document.body.appendChild(toast);
};
return <button onClick={handleClick}>Show Toast</button>;
}π¨ ## Customization
The component is encapsulated with Shadow DOM, but you can fork or extend the component easily to change:
- Animations
- Colors
- Icons
- Styles
- Positions
- Behavior
πͺͺ License
MIT License β Copyright Β© 2025 @aicadev
π¬ Support / Feedback
If you find any bugs or want improvements, feel free to open an issue or contribute via pull request.
