UNPKG

pkg-components

Version:
2 lines (1 loc) 2.16 kB
import{j as s,a as g}from"./jsx-runtime-DI8_P1Ft.js";import{P as a}from"./index-B3IC6ylx.js";import{r}from"./index-DPzuYzxM.js";import{B as I,P as T}from"./index-BINBIgVg.js";import{e as x}from"./index-RGaBZlDs.js";const C="_notification_jm8hf_1",N="_toast_jm8hf_169",o={"notification-container":"_notification-container_jm8hf_1","top-right":"_top-right_jm8hf_11","toast-in-right":"_toast-in-right_jm8hf_1","bottom-right":"_bottom-right_jm8hf_23","top-left":"_top-left_jm8hf_39","toast-in-left":"_toast-in-left_jm8hf_1","bottom-left":"_bottom-left_jm8hf_51",notification:C,"notification-title":"_notification-title_jm8hf_109","notification-message":"_notification-message_jm8hf_131","notification-image":"_notification-image_jm8hf_151",toast:N,"notification-button":"_notification-button_jm8hf_181"},c=m=>{const{toastList:i,position:d,autoDelete:p,autoDeleteTime:h}=m,[n,u]=r.useState(i);r.useEffect(()=>{u([...i])},[i]),r.useEffect(()=>{const t=setInterval(()=>{p&&i.length&&n.length&&l(i[0].id)},h);return()=>{clearInterval(t)}},[i,p,h,n]);const l=t=>{const e=n.findIndex(_=>_.id===t),f=i.findIndex(_=>_.id===t);n.splice(e,1),i.splice(f,1),u([...n])},[b,j]=r.useState(0),v=t=>{j(t.clientX)},y=(t,e)=>{window.innerWidth-t.clientX>window.innerWidth/2&&l(e)},D={success:"#50a773",warning:"#ebbc26",error:`${T}69`};return s("div",{className:o[`notification-container ${d}`],children:n.map((t,e)=>g("div",{className:`${o.notification} ${o.toast} ${o[d]}`,draggable:!0,onDrag:v,onDragEnd:f=>y(f,t.id),style:{position:"relative",left:`${b}px`,transition:"left 0.5s ease-in-out",backgroundColor:D[t==null?void 0:t.backgroundColor]??"#50a773"},children:[s("button",{className:o["notification-button"],onClick:()=>l(t.id),children:s(x,{color:I,size:30})}),g("div",{children:[s("p",{className:o["notification-title"],children:t.title}),s("p",{className:o["notification-message"],children:t.description})]})]},e))})};c.propTypes={autoDelete:a.bool,autoDeleteTime:a.number,position:a.string,toastList:a.array.isRequired};c.defaultProps={position:"top-right"};try{c.displayName="Toast",c.__docgenInfo={description:"",displayName:"Toast",props:{}}}catch{}export{c as T};