mirror of
https://github.com/anotherhadi/ilovetui.git
synced 2026-10-05 19:08:25 +02:00
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// @bun
|
||||
// src/context/notifications.ts
|
||||
import { createSignal } from "solid-js";
|
||||
var DEFAULT_DURATION = 3000;
|
||||
var [notifications, setNotifications] = createSignal([]);
|
||||
var nextId = 0;
|
||||
function notify(message, options = {}) {
|
||||
const id = options.id ?? `toast-${nextId++}`;
|
||||
const toast = { id, title: options.title, message, kind: options.kind ?? "info" };
|
||||
setNotifications((prev) => [...prev.filter((n) => n.id !== id), toast]);
|
||||
const duration = options.duration ?? DEFAULT_DURATION;
|
||||
if (duration > 0) {
|
||||
setTimeout(() => dismiss(id), duration);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
function dismiss(id) {
|
||||
setNotifications((prev) => prev.filter((n) => n.id !== id));
|
||||
}
|
||||
|
||||
export { notifications, notify, dismiss };
|
||||
Reference in New Issue
Block a user