Skip to content

Commit

Permalink
feat: add toast delay property
Browse files Browse the repository at this point in the history
  • Loading branch information
elio2t committed Oct 15, 2024
1 parent 5d9d604 commit e4c31b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/components_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class Delivery(BaseModel):
body=[c.Paragraph(text='This is a toast.')],
open_trigger=PageEvent(name='show-toast'),
position='bottom-end',
delay=5000,
),
],
class_name='border-top mt-3 pt-1',
Expand Down
10 changes: 8 additions & 2 deletions src/npm-fastui-bootstrap/src/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import BootstrapToast from 'react-bootstrap/Toast'
import BootstrapToastContainer from 'react-bootstrap/ToastContainer'

export const Toast: FC<models.Toast> = (props) => {
const { className, title, body, position, openTrigger, openContext } = props
const { className, title, body, position, delay, openTrigger, openContext } = props

const { eventContext, fireId, clear } = events.usePageEventListen(openTrigger, openContext)

return (
<EventContextProvider context={eventContext}>
<BootstrapToastContainer position={position} className="position-fixed bottom-0 end-0 p-3">
<BootstrapToast className={renderClassName(className)} show={!!fireId} onClose={clear}>
<BootstrapToast
className={renderClassName(className)}
show={!!fireId}
onClose={clear}
delay={delay}
autohide={!!delay}
>
<BootstrapToast.Header>
<strong className="me-auto">{title}</strong>
</BootstrapToast.Header>
Expand Down
1 change: 1 addition & 0 deletions src/npm-fastui/src/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ export interface Toast {
| 'bottom-start'
| 'bottom-center'
| 'bottom-end'
delay?: number
openTrigger?: PageEvent
openContext?: ContextType
className?: ClassName
Expand Down
3 changes: 3 additions & 0 deletions src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ class Toast(BaseModel, extra='forbid'):
] = None
"""Optional position of the toast."""

delay: _t.Union[int, None] = None
"""Optional delay of the toast."""

open_trigger: _t.Union[events.PageEvent, None] = None
"""Optional event to trigger when the toast is opened."""

Expand Down

0 comments on commit e4c31b6

Please sign in to comment.