Skip to content

Commit

Permalink
Add toast position option
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoyingz committed Dec 20, 2023
1 parent feb74b1 commit ac40c31
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion demo/components_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ class Delivery(BaseModel):
c.Button(text='Show Toast', on_click=PageEvent(name='show-toast')),
c.Toast(
title='Toast',
body=[c.Paragraph(text='This is some static content that was set when the modal was defined.')],
body=[c.Paragraph(text='This is a toast.')],
open_trigger=PageEvent(name='show-toast'),
position='bottom-end',
),
],
class_name='border-top mt-3 pt-1',
Expand Down
4 changes: 2 additions & 2 deletions src/npm-fastui-bootstrap/src/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import BootstrapToast from 'react-bootstrap/Toast'
import BootstrapToastContainer from 'react-bootstrap/ToastContainer'

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

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

return (
<EventContextProvider context={eventContext}>
<BootstrapToastContainer>
<BootstrapToastContainer position={position} className="position-fixed bottom-0 end-0 p-3">
<BootstrapToast className={renderClassName(className)} show={!!fireId} onClose={clear}>
<BootstrapToast.Header>
<strong className="me-auto">{title}</strong>
Expand Down
10 changes: 10 additions & 0 deletions src/npm-fastui/src/components/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ export interface ToastProps {
type: 'Toast'
title: string
body: FastProps[]
position?:
| 'top-start'
| 'top-center'
| 'top-end'
| 'middle-start'
| 'middle-center'
| 'middle-end'
| 'bottom-start'
| 'bottom-center'
| 'bottom-end'
openTrigger?: PageEvent
openContext?: ContextType
className?: ClassName
Expand Down
14 changes: 14 additions & 0 deletions src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ class Custom(_p.BaseModel, extra='forbid'):
class Toast(_p.BaseModel, extra='forbid'):
title: str
body: '_t.List[AnyComponent]'
position: _t.Union[
_t.Literal[
'top-start',
'top-center',
'top-end',
'middle-start',
'middle-center',
'middle-end',
'bottom-start',
'bottom-center',
'bottom-end',
],
None,
] = None
open_trigger: _t.Union[events.PageEvent, None] = _p.Field(default=None, serialization_alias='openTrigger')
open_context: _t.Union[events.ContextType, None] = _p.Field(default=None, serialization_alias='openContext')
class_name: _class_name.ClassNameField = None
Expand Down
14 changes: 14 additions & 0 deletions src/python-fastui/tests/react-fastui-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,20 @@
"openTrigger": {
"$ref": "#/definitions/PageEvent"
},
"position": {
"enum": [
"bottom-center",
"bottom-end",
"bottom-start",
"middle-center",
"middle-end",
"middle-start",
"top-center",
"top-end",
"top-start"
],
"type": "string"
},
"title": {
"type": "string"
},
Expand Down

0 comments on commit ac40c31

Please sign in to comment.