1.0.3 โ€ข Published 7 months ago

@aicadev/toast-message v1.0.3

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

@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

AttributeTypeDefaultDescription
typestringinfoDefines the toast style: info, success, error, warning
durationnumber3000Time in milliseconds before toast disappears
positionstringtop-rightPosition of the toast on the screen
closeablebooleanfalseShows 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 /dist

Built 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.

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago