UNPKG

@bothub-chat/ui

Version:

Bothub UI Components

2 lines (1 loc) 1.94 kB
import{jsx as t,jsxs as o}from"react/jsx-runtime";import{useState as r,useCallback as i,useEffect as e}from"react";import{useTransition as n}from"@react-spring/web";import{NotificationStyled as s,NotificationContent as a,NotificationLeft as l,NotificationIcon as c,NotificationInfo as m,NotificationTitle as d,NotificationText as p,NotificationRight as f,NotificationCloseButton as u}from"./styled.js";import{ErrorBigIcon as x}from"../../icons/error-big/index.js";import{InfoBigIcon as b}from"../../icons/info-big/index.js";import{SuccessBigIcon as j}from"../../icons/success-big/index.js";import{WarningBigIcon as y}from"../../icons/warning-big/index.js";import{Loader as g}from"../loader/index.js";import"./list/styled.js";import{useNotifications as h}from"./list/context.js";export{NotificationsContext,NotificationsProvider}from"./list/context.js";import"tslib";import"react-dom";import"../portal/styled.js";const w=({className:w,variant:k="info",autoClose:N=5e3,notificationId:v="unknown",title:C,children:X,onClose:$})=>{const[D,I]=r(!0),{isInNotificationList:T}=h(),L=!!X&&!!C;let P;switch(k){case"info":P=b;break;case"warn":P=y;break;case"error":P=x;break;case"success":P=j;break;case"loading":P=g}const q=i((()=>{D||null==$||$(v)}),[D,$,v]);e((()=>{let t;return t=D&&N?window.setTimeout((()=>{I(!1)}),N):null,()=>{null!==t&&window.clearTimeout(t)}}),[N]);return n(D,T?{from:{opacity:0,transform:"translateX(412px)"},enter:{opacity:1,transform:"translateX(0px)"},leave:{opacity:0,transform:"translateX(412px)"},config:{duration:250},onDestroyed:q}:{onDestroyed:q})(((r,i)=>i&&t(s,{style:r,$variant:k,className:w,children:o(a,{$text:L,children:[o(l,{$text:L,children:[t(c,{as:P}),o(m,{children:[t(d,{children:null!=C?C:X}),L&&"string"==typeof X?t(p,{children:X}):null,L&&"string"!=typeof X?X:null]})]}),t(f,{children:t(u,{onClick:I.bind(null,!1)})})]})})))};export{w as Notification,p as NotificationText,h as useNotifications};