1+ import { create } from "zustand" ;
2+ import React from "react" ;
3+ import { IconAlertCircle , IconCircleCheck , IconCircleX , IconInfoCircle } from "@tabler/icons-react" ;
4+ import { Text } from "../text/Text" ;
5+
6+ export interface IslandNotificationProps {
7+ id ?: number
8+ icon : React . ReactNode
9+ message : React . ReactNode
10+ content ?: React . ReactNode
11+ duration ?: number
12+ index ?: number
13+ }
14+
15+ export const useIsland = create < {
16+ toasts : IslandNotificationProps [ ] ,
17+ addToast : ( toast : IslandNotificationProps ) => void ,
18+ removeToast : ( id : number ) => void
19+ } > ( ( set ) => ( {
20+ toasts : [ ] ,
21+ addToast : ( toast : IslandNotificationProps ) => {
22+ const id = Date . now ( )
23+ set ( state => ( { toasts : [ ...state . toasts , { id, ...toast } ] } ) )
24+ } ,
25+ removeToast : ( id : number ) => {
26+ set ( state => ( { toasts : state . toasts . filter ( t => t . id !== id ) } ) )
27+ }
28+ } ) )
29+
30+ export const addIslandNotification = ( toast : IslandNotificationProps ) => {
31+ useIsland . getState ( ) . addToast ( toast )
32+ }
33+
34+ export const addIslandInfoNotification = ( toast : Partial < IslandNotificationProps > ) => {
35+ useIsland . getState ( ) . addToast ( {
36+ icon : < IconInfoCircle color = { "#70ffb2" } size = { 16 } /> ,
37+ message : < Text c = { "#70ffb2" } > { toast . message } </ Text > ,
38+ ...toast
39+ } )
40+ }
41+
42+ export const addIslandSuccessNotification = ( toast : Partial < IslandNotificationProps > ) => {
43+ useIsland . getState ( ) . addToast ( {
44+ icon : < IconCircleCheck color = { "#29BF12" } size = { 16 } /> ,
45+ message : < Text c = { "#29BF12" } > { toast . message } </ Text > ,
46+ index : 1 ,
47+ ...toast
48+ } )
49+ }
50+
51+ export const addIslandWarningNotification = ( toast : Partial < IslandNotificationProps > ) => {
52+ useIsland . getState ( ) . addToast ( {
53+ icon : < IconAlertCircle color = { "#FFBE0B" } size = { 16 } /> ,
54+ message : < Text c = { "#FFBE0B" } > { toast . message } </ Text > ,
55+ index : 2 ,
56+ ...toast
57+ } )
58+ }
59+
60+ export const addIslandErrorNotification = ( toast : Partial < IslandNotificationProps > ) => {
61+ useIsland . getState ( ) . addToast ( {
62+ icon : < IconCircleX color = { "#D90429" } size = { 16 } /> ,
63+ message : < Text c = { "#D90429" } > { toast . message } </ Text > ,
64+ index : 3 ,
65+ ...toast
66+ } )
67+ }
0 commit comments