pydantic/FastUI

add `FormattedText` component

Open

#29 ouverte le 1 déc. 2023

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)Python (341 forks)github user discovery
New Componentgood first issue

Métriques du dépôt

Stars
 (8 970 stars)
Métriques de merge PR
 (Métriques PR en attente)

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

Guide contributeur