lovely-alert
v0.1.1
Published
A beautiful, modern, accessible, themeable alert / modal / toast library with a fresh, ergonomic API.
Maintainers
Readme
lovely-alert
A beautiful, modern, accessible, themeable alert / modal / toast library with a fresh, ergonomic API.
Vanilla TypeScript, zero runtime dependencies. Styles auto-inject on first use, so CDN/UMD consumers and AI-generated snippets render correctly with no extra CSS import.
Install
npm install lovely-alert<!-- or via CDN (UMD) -->
<script src="https://unpkg.com/lovely-alert"></script>Usage
import { la } from 'lovely-alert'
await la.success('Saved!', 'Your changes have been stored.')
const ok = await la.confirm('Delete this item?', { confirmText: 'Delete', danger: true })
const email = await la.prompt('Your email?', {
input: 'email',
validate: (v) => (v.includes('@') ? null : 'Enter a valid email'),
})
la.toast.success('Copied to clipboard')
const result = await la.open({ title: 'Terms', html: 'Read our <a href="#">terms</a>.' })
// result = { confirmed, denied, dismissed, value, dismissReason }Features
- Themes:
light/dark/auto(+minimal,borderless) via CSS design tokens; runtimela.theme.set()and a token-based theme builder (la.theme.define/la.theme.export). - Accessibility:
dialog/alertdialogroles, focus trap,returnFocus, keyboard ESC/Enter/Tab, scroll lock, screen-reader live announce, RTL. - 18 input types with sync/async validation,
preConfirm/preDenyloaders, OTP / rating / tags. - Toasts that stack per position, with timers,
timerProgressBarand progress steps. - Builder (
la.build()), mixin presets (la.mixin()), and lifecycle hooks (willOpen→didOpen…didDestroy). - i18n (
la.locale, shipsen+vi) and effects (confetti, sounds) that respectprefers-reduced-motion.
API surface
- Convenience:
la.success / error / warning / info / question,la.confirm,la.prompt - Toasts:
la.toast.show / success / error / warning / info / question - Low-level:
la.open(options)→Promise<Result>;la.chain(steps) - Control:
la.update,la.close,la.current,la.isVisible - Theme/locale:
la.theme.{set,get,define,export},la.locale.{set,get,define}
See the docs & live playground for the full option reference.
License
MIT © Nguyễn Sơn Khánh
