From ac40c319bf0231b404e7feb0ea8bf8835702a6cf Mon Sep 17 00:00:00 2001 From: Chaoying Date: Wed, 20 Dec 2023 21:53:40 +0800 Subject: [PATCH] Add toast position option --- demo/components_list.py | 3 ++- src/npm-fastui-bootstrap/src/toast.tsx | 4 ++-- src/npm-fastui/src/components/toast.tsx | 10 ++++++++++ src/python-fastui/fastui/components/__init__.py | 14 ++++++++++++++ .../tests/react-fastui-json-schema.json | 14 ++++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/demo/components_list.py b/demo/components_list.py index 06987b18..cdf8558f 100644 --- a/demo/components_list.py +++ b/demo/components_list.py @@ -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', diff --git a/src/npm-fastui-bootstrap/src/toast.tsx b/src/npm-fastui-bootstrap/src/toast.tsx index 5a11867f..47c3e335 100644 --- a/src/npm-fastui-bootstrap/src/toast.tsx +++ b/src/npm-fastui-bootstrap/src/toast.tsx @@ -4,13 +4,13 @@ import BootstrapToast from 'react-bootstrap/Toast' import BootstrapToastContainer from 'react-bootstrap/ToastContainer' export const Toast: FC = (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 ( - + {title} diff --git a/src/npm-fastui/src/components/toast.tsx b/src/npm-fastui/src/components/toast.tsx index 9ce5c4a3..b0cd4bb8 100644 --- a/src/npm-fastui/src/components/toast.tsx +++ b/src/npm-fastui/src/components/toast.tsx @@ -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 diff --git a/src/python-fastui/fastui/components/__init__.py b/src/python-fastui/fastui/components/__init__.py index d2e0ab22..6b3f39b3 100644 --- a/src/python-fastui/fastui/components/__init__.py +++ b/src/python-fastui/fastui/components/__init__.py @@ -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 diff --git a/src/python-fastui/tests/react-fastui-json-schema.json b/src/python-fastui/tests/react-fastui-json-schema.json index a76621b5..d7ca8765 100644 --- a/src/python-fastui/tests/react-fastui-json-schema.json +++ b/src/python-fastui/tests/react-fastui-json-schema.json @@ -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" },