Skip to content

Commit

Permalink
feat: add props to toast
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Jan 16, 2025
1 parent 08dbc03 commit bb10002
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/beacon-ui/src/ui/toast/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ let initDone: boolean = false
const config$ = new Subject<ToastConfig | undefined>()
const show$ = new Subject<boolean>()

const createToast = () => {
const createToast = (config: ToastConfig) => {
const el = document.createElement('beacon-toast')
document.body.prepend(el)
setTimeout(() => createRoot(el).render(<ToastRoot />), 50)
setTimeout(() => createRoot(el).render(<ToastRoot {...config}/>), 50)
initDone = true
}

const openToast = (config: ToastConfig) => {
!initDone && createToast()
!initDone && createToast(config)
config$.next(config)

if (config.state !== 'finished') {
Expand All @@ -31,8 +31,8 @@ const closeToast = () => {
show$.next(false)
}

const ToastRoot = () => {
const [config, setConfig] = useState<ToastConfig | undefined>(undefined)
const ToastRoot = (props: ToastConfig) => {
const [config, setConfig] = useState<ToastConfig | undefined>(props)
const [isOpen, setIsOpen] = useState(true)
const [mount, setMount] = useState(false)

Expand Down Expand Up @@ -78,16 +78,16 @@ const ToastRoot = () => {

return (
<>
{mount && (
{mount && config && (
<Toast
label={config?.body ?? ''}
label={config.body}
open={isOpen}
onClickClose={() => {
closeToast()
}}
actions={config?.actions}
walletInfo={config?.walletInfo}
openWalletAction={config?.openWalletAction}
actions={config.actions}
walletInfo={config.walletInfo}
openWalletAction={config.openWalletAction}
/>
)}
</>
Expand Down

0 comments on commit bb10002

Please sign in to comment.