Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toast delay property #357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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