Skip to content

Commit

Permalink
using higher level base model
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed May 1, 2024
1 parent 10e8173 commit dfc532b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
34 changes: 17 additions & 17 deletions src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Heading(BaseModel, extra='forbid'):
level: _t.Literal[1, 2, 3, 4, 5, 6] = 1
"""The level of the heading. 1 is the largest, 6 is the smallest."""

html_id: _t.Union[str, None] = _p.Field(default=None)
html_id: _t.Union[str, None] = None
"""Optional HTML ID to apply to the heading's HTML component."""

class_name: _class_name.ClassNameField = None
Expand Down Expand Up @@ -224,10 +224,10 @@ class Button(BaseModel, extra='forbid'):
text: str
"""The text to display on the button."""

on_click: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
on_click: _t.Union[events.AnyEvent, None] = None
"""Optional event to trigger when the button is clicked."""

html_type: _t.Union[_t.Literal['button', 'reset', 'submit'], None] = _p.Field(default=None)
html_type: _t.Union[_t.Literal['button', 'reset', 'submit'], None] = None
"""Optional HTML type of the button. If None, defaults to 'button'."""

named_style: _class_name.NamedStyleField = None
Expand All @@ -246,7 +246,7 @@ class Link(BaseModel, extra='forbid'):
components: '_t.List[AnyComponent]'
"""List of components to render attached to the link."""

on_click: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
on_click: _t.Union[events.AnyEvent, None] = None
"""Optional event to trigger when the link is clicked."""

mode: _t.Union[_t.Literal['navbar', 'footer', 'tabs', 'vertical', 'pagination'], None] = None
Expand Down Expand Up @@ -287,13 +287,13 @@ class Navbar(BaseModel, extra='forbid'):
title: _t.Union[str, None] = None
"""Optional title to display in the navbar."""

title_event: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
title_event: _t.Union[events.AnyEvent, None] = None
"""Optional event to trigger when the title is clicked. Often used to navigate to the home page."""

start_links: _t.List[Link] = _p.Field(default=[])
start_links: _t.List[Link] = []
"""List of links to render at the start of the navbar."""

end_links: _t.List[Link] = _p.Field(default=[])
end_links: _t.List[Link] = []
"""List of links to render at the end of the navbar."""

class_name: _class_name.ClassNameField = None
Expand All @@ -318,7 +318,7 @@ class Footer(BaseModel, extra='forbid'):
links: _t.List[Link]
"""List of links to render in the footer."""

extra_text: _t.Union[str, None] = _p.Field(default=None)
extra_text: _t.Union[str, None] = None
"""Optional extra text to display in the footer."""

class_name: _class_name.ClassNameField = None
Expand All @@ -340,10 +340,10 @@ class Modal(BaseModel, extra='forbid'):
footer: '_t.Union[_t.List[AnyComponent], None]' = None
"""Optional list of components to render in the modal footer."""

open_trigger: _t.Union[events.PageEvent, None] = _p.Field(default=None)
open_trigger: _t.Union[events.PageEvent, None] = None
"""Optional event to trigger when the modal is opened."""

open_context: _t.Union[events.ContextType, None] = _p.Field(default=None)
open_context: _t.Union[events.ContextType, None] = None
"""Optional context to pass to the open trigger event."""

class_name: _class_name.ClassNameField = None
Expand All @@ -359,7 +359,7 @@ class ServerLoad(BaseModel, extra='forbid'):
path: str
"""The URL to load the component from."""

load_trigger: _t.Union[events.PageEvent, None] = _p.Field(default=None)
load_trigger: _t.Union[events.PageEvent, None] = None
"""Optional event to trigger when the component is loaded."""

components: '_t.Union[_t.List[AnyComponent], None]' = None
Expand All @@ -368,7 +368,7 @@ class ServerLoad(BaseModel, extra='forbid'):
sse: _t.Union[bool, None] = None
"""Optional flag to enable server-sent events (SSE) for the server load."""

sse_retry: _t.Union[int, None] = _p.Field(default=None)
sse_retry: _t.Union[int, None] = None
"""Optional time in milliseconds to retry the SSE connection."""

method: _t.Union[_t.Literal['GET', 'POST', 'PATCH', 'PUT', 'DELETE'], None] = None
Expand Down Expand Up @@ -405,15 +405,15 @@ class Image(BaseModel, extra='forbid'):
'unsafe-url',
],
None,
] = _p.Field(None)
] = None
"""Optional referrer policy for the image. Specifies what information to send when fetching the image.
For more info, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy."""

loading: _t.Union[_t.Literal['eager', 'lazy'], None] = None
"""Optional loading strategy for the image."""

on_click: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
on_click: _t.Union[events.AnyEvent, None] = None
"""Optional event to trigger when the image is clicked."""

class_name: _class_name.ClassNameField = None
Expand Down Expand Up @@ -507,7 +507,7 @@ class Error(BaseModel, extra='forbid'):
description: str
"""The description of the error."""

status_code: _t.Union[int, None] = _p.Field(None)
status_code: _t.Union[int, None] = None
"""Optional status code of the error."""

class_name: _class_name.ClassNameField = None
Expand Down Expand Up @@ -565,10 +565,10 @@ class Toast(BaseModel, extra='forbid'):
] = None
"""Optional position of the toast."""

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

open_context: _t.Union[events.ContextType, None] = _p.Field(default=None)
open_context: _t.Union[events.ContextType, None] = None
"""Optional context to pass to the open trigger event."""

class_name: _class_name.ClassNameField = None
Expand Down
4 changes: 2 additions & 2 deletions src/python-fastui/fastui/components/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DisplayBase(BaseModel, ABC, defer_build=True):
title: _t.Union[str, None] = None
"""Title to display for the value."""

on_click: _t.Union[events.AnyEvent, None] = pydantic.Field(default=None)
on_click: _t.Union[events.AnyEvent, None] = None
"""Event to trigger when the value is clicked."""


Expand All @@ -48,7 +48,7 @@ class DisplayLookup(DisplayBase, extra='forbid'):
field: str
"""Field to display."""

table_width_percent: _t.Union[_te.Annotated[int, _at.Interval(ge=0, le=100)], None] = pydantic.Field(default=None)
table_width_percent: _t.Union[_te.Annotated[int, _at.Interval(ge=0, le=100)], None] = None
"""Percentage width - 0 to 100, specific to tables."""


Expand Down
10 changes: 5 additions & 5 deletions src/python-fastui/fastui/components/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BaseFormField(BaseModel, ABC, defer_build=True):
description: _t.Union[str, None] = None
"""Description of the field."""

display_mode: _t.Union[_t.Literal['default', 'inline'], None] = pydantic.Field(default=None)
display_mode: _t.Union[_t.Literal['default', 'inline'], None] = None
"""Display mode for the field."""

class_name: _class_name.ClassNameField = None
Expand All @@ -46,7 +46,7 @@ class BaseFormField(BaseModel, ABC, defer_build=True):
class FormFieldInput(BaseFormField):
"""Form field for basic input."""

html_type: InputHtmlType = pydantic.Field(default='text')
html_type: InputHtmlType = 'text'
"""HTML input type for the field."""

initial: _t.Union[str, float, None] = None
Expand Down Expand Up @@ -175,13 +175,13 @@ class BaseForm(BaseModel, ABC, defer_build=True, extra='forbid'):
method: _t.Literal['POST', 'GOTO', 'GET'] = 'POST'
"""HTTP method to use for the form submission."""

display_mode: _t.Union[_t.Literal['default', 'page', 'inline'], None] = pydantic.Field(default=None)
display_mode: _t.Union[_t.Literal['default', 'page', 'inline'], None] = None
"""Display mode for the form."""

submit_on_change: _t.Union[bool, None] = pydantic.Field(default=None)
submit_on_change: _t.Union[bool, None] = None
"""Whether to submit the form on change."""

submit_trigger: _t.Union[events.PageEvent, None] = pydantic.Field(default=None)
submit_trigger: _t.Union[events.PageEvent, None] = None
"""Event to trigger form submission."""

loading: '_t.Union[_t.List[AnyComponent], None]' = None
Expand Down
8 changes: 5 additions & 3 deletions src/python-fastui/fastui/events.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from typing import Dict, Literal, Union

from pydantic import BaseModel, Field
from pydantic import Field
from typing_extensions import Annotated, TypeAliasType

from .base import BaseModel

ContextType = TypeAliasType('ContextType', Dict[str, Union[str, int]])


class PageEvent(BaseModel):
name: str
push_path: Union[str, None] = Field(default=None, serialization_alias='pushPath')
push_path: Union[str, None] = None
context: Union[ContextType, None] = None
clear: Union[bool, None] = None
next_event: 'Union[AnyEvent, None]' = Field(default=None, serialization_alias='nextEvent')
next_event: 'Union[AnyEvent, None]' = None
type: Literal['page'] = 'page'


Expand Down

0 comments on commit dfc532b

Please sign in to comment.