pydantic/FastUI

add `FormattedText` component

Open

#29 opened on Dec 1, 2023

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Python (341 forks)github user discovery
New Componentgood first issue

Repository metrics

Stars
 (8,970 stars)
PR merge metrics
 (PR metrics pending)

Description

Defined as something like

class FormattedText(pydantic.BaseModel, extra='forbid'):
    text: str
    text_format: typing.Literal['bold', 'italic', 'underline', 'strikethrough'] | None = pydantic.Field(None, serialization_alias='textFormat')
    # TODO, use pydantic-extra-types Color?
    text_color: str | None = pydantic.Field(None, serialization_alias='textColor')
    background_color: str | None = pydantic.Field(None, serialization_alias='backgroundColor')
    type: typing.Literal['FormattedText'] = 'FormattedText'

The items in components like Button and Link become list[str | FormattedText | Link]. We might want too provide a few more components specifically for typography, like Bullets and Numbers

Two reasons to do this over relying on Markdown:

  1. Markdown is a relatively heave lazy module, that it would be nice not to have to load
  2. Markdown by it's definition is terrible for templating or user defined values - it's virtually impossible to escape. Providing these types would allow text to be defined which included uses values safely

Contributor guide