tempest_fastapi_sdk.ui.components¶
Componentes: as peças reutilizáveis de que as páginas são feitas.
Card
¶
Bases: Component
A titled block of content.
Renders a <section> with an optional heading, the body content
and an optional footer.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
The heading text. Empty renders no heading. |
children |
list[Widget]
|
The body content. |
footer |
Widget | None
|
Optional footer content. |
heading_tag |
str
|
Which heading element to use — pick the one
that fits the page outline ( |
classes |
ComponentClasses
|
Class names to apply. |
Example
render
¶
Compose the card.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
Widget
|
footer that were provided. |
Alert
¶
Bases: Component
A short message, coloured by severity.
warning and error render with role="alert" so assistive
technology announces them immediately; the quieter variants use
role="status".
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
The message text. |
variant |
AlertVariant
|
The severity. |
title |
str
|
Optional heading above the message. |
classes |
ComponentClasses
|
Class names to apply. |
Example
render
¶
Compose the alert.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
Widget
|
the ARIA role matching its severity. |
DataTable
¶
Bases: Component
A table rendered from a list of schemas.
Attributes:
| Name | Type | Description |
|---|---|---|
rows |
list[Any]
|
The records — Pydantic models or mappings. |
columns |
list[str | TableColumn]
|
Columns, in order — a field
name for a text cell, or a :class: |
row_schema |
Any | None
|
The Pydantic model class describing the
rows. Supplying it means the header still renders when the
list is empty, and column labels come from each field's
|
headers |
dict[str, str]
|
Header text overrides, per column. |
caption |
str
|
Optional |
empty_text |
str
|
Text of the single row shown when there is nothing to list. |
bool_labels |
tuple[str, str]
|
Text for |
none_text |
str
|
Text for |
classes |
ComponentClasses
|
Class names to apply. |
Example
column_specs
¶
column_specs() -> list[TableColumn]
Return the columns actually rendered, as :class:TableColumn.
Returns:
| Type | Description |
|---|---|
list[TableColumn]
|
list[TableColumn]: The explicit |
list[TableColumn]
|
becomes a default text column) when given, otherwise one text |
list[TableColumn]
|
column per schema field, otherwise per key of the first row. |
list[TableColumn]
|
Empty when none of the three is available. |
resolved_columns
¶
Return the names of the columns actually rendered.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The name of every entry of :meth: |
list[str]
|
in order. |
header_text
¶
Return the header label of a column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
The column name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The override when given, else the schema field's |
str
|
|
cell_text
¶
Format one cell value as text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
The raw value read from the row. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The rendered cell text. |
str
|
attr: |
|
str
|
render ISO, sequences join with |
|
str
|
renders its own field values. |
render
¶
Compose the table.
The <table> sits inside a <div> carrying
:attr:ComponentClasses.table_scroll, which scrolls it
horizontally: a table wider than a narrow viewport scrolls in
place instead of widening the whole page. The wrapper is
focusable (tabindex="0") so keyboard users can scroll it, and
becomes a labelled region when :attr:caption is set.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A scroll wrapper around a |
Widget
|
row and one body row per record, or a single spanning row |
|
carrying |
Widget
|
attr: |
TableColumn
dataclass
¶
TableColumn(
name: str,
header: str | None = None,
render: CellRenderer | None = None,
align: CellAlign | None = None,
class_name: str = "",
)
One column of a :class:DataTable, when a field name is not enough.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The column name — the field read from each row for a
text cell, and the key of :attr: |
header |
str | None
|
Header text. |
render |
CellRenderer | None
|
Builds the cell content from the
row. |
align |
CellAlign | None
|
Horizontal alignment of the header and
every cell, applied as the
:attr: |
class_name |
str
|
Extra class applied to the header and every cell of the column — for example one a media query hides on narrow screens. |
Example
from pydantic import BaseModel
from tempest_core import Text, Widget
from tempest_fastapi_sdk.ui.components import DataTable, TableColumn
class FileResponseSchema(BaseModel):
id: int
name: str
size: int
def name_link(row: FileResponseSchema) -> Widget:
return Text(content=row.name, tag="a", attrs={"href": f"/files/{row.id}"})
table = DataTable(
rows=[FileResponseSchema(id=1, name="a.txt", size=120)],
columns=[
TableColumn("name", render=name_link),
TableColumn("size", align="right", class_name="col-optional"),
],
)
Pagination
¶
Bases: Component
Numbered page links with previous / next controls.
Attributes:
| Name | Type | Description |
|---|---|---|
page |
int
|
The current page, 1-indexed. |
pages |
int
|
The total number of pages. |
url |
str
|
Path the links point at. The page number is appended as a query parameter. |
query_param |
str
|
Name of the page query parameter. |
extra_query |
dict[str, str]
|
Query parameters carried over on every link, so active filters survive a page change. |
window |
int
|
How many neighbours of the current page to list on each side. |
previous_label |
str
|
Text of the previous-page link. |
next_label |
str
|
Text of the next-page link. |
classes |
ComponentClasses
|
Class names to apply. |
Example
href
¶
Build the URL of one page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
The target page number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
|
str
|
parameters preserved in insertion order. |
visible_pages
¶
Return the page numbers rendered as links.
Returns:
| Type | Description |
|---|---|
list[int]
|
list[int]: The current page plus :attr: |
list[int]
|
on each side, clamped to the available range. |
render
¶
Compose the pagination control.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
Widget
|
when there is at most one page. |
PaginationEnvelopeLike
¶
Bases: Protocol
Any pagination envelope exposing page and pages.
Declared as read-only properties so
:class:~tempest_fastapi_sdk.schemas.BasePaginationSchema, frozen
dataclasses, and plain objects are all accepted.
pagination_for
¶
pagination_for(
envelope: PaginationEnvelopeLike,
*,
url: str,
query_param: str = "page",
extra_query: dict[str, str] | None = None,
window: int = 2,
classes: ComponentClasses | None = None,
) -> Pagination
Build a :class:Pagination from a pagination envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
PaginationEnvelopeLike
|
A
:class: |
required |
url
|
str
|
Path the links point at. |
required |
query_param
|
str
|
Name of the page query parameter. |
'page'
|
extra_query
|
dict[str, str] | None
|
Query parameters carried over on every link. |
None
|
window
|
int
|
Neighbour pages listed on each side. |
2
|
classes
|
ComponentClasses | None
|
Class name overrides. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Pagination |
Pagination
|
The control matching the envelope. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
When the envelope exposes no |
EmptyState
¶
Bases: Component
A titled placeholder for an empty collection.
Collections return [] rather than a 404 (the SDK's convention),
so "nothing here" is a normal, successful state and deserves a
normal, informative screen.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
The heading. |
description |
str
|
Supporting text under the heading. |
action |
Widget | None
|
Optional call to action — a link or a button leading to the screen that creates the first record. |
classes |
ComponentClasses
|
Class names to apply. |
Example
render
¶
Compose the empty state.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
Widget
|
was given, and the action when present. |
FlashMessages
¶
Bases: Component
The list of pending flash messages, one :class:Alert each.
Place it once in the base page's shell and feed it what
:func:tempest_fastapi_sdk.ssr.get_flashes returned for the request.
With no messages it renders an empty wrapper, which the bundled
stylesheet hides.
Attributes:
| Name | Type | Description |
|---|---|---|
messages |
list[FlashMessage]
|
The messages to show, in order. |
classes |
ComponentClasses
|
Class names to apply. |
Example
render
¶
Compose the messages.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
FlashMessage
¶
Bases: BaseModel
One notice queued for the next screen the user sees.
Written by :func:tempest_fastapi_sdk.ssr.flash and read back by
:func:tempest_fastapi_sdk.ssr.get_flashes, which travel it in a
signed cookie — the text is always the server's, never read from the
URL.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
The notice text, rendered escaped. |
variant |
AlertVariant
|
Its severity, which picks the colour and
the ARIA role of the rendered :class: |
NavBar
¶
Bases: Component
A list of links, with the current one marked.
The active link renders aria-current="page" so assistive
technology reports the location, not just the styling.
Attributes:
| Name | Type | Description |
|---|---|---|
items |
list[NavItem]
|
The entries, in order. |
active_href |
str
|
The |
label |
str
|
The |
classes |
ComponentClasses
|
Class names to apply. |
Example
render
¶
Compose the navigation bar.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
NavItem
dataclass
¶
One entry of a :class:NavBar.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The link text. |
href |
str
|
The link target. |
ComponentClasses
dataclass
¶
ComponentClasses(
card: str = "tui-card",
card_title: str = "tui-card__title",
card_body: str = "tui-card__body",
card_footer: str = "tui-card__footer",
alert: str = "tui-alert",
alert_variant: str = "tui-alert--",
flash: str = "tui-flash",
table: str = "tui-table",
table_empty: str = "tui-table__empty",
pagination: str = "tui-pagination",
pagination_link: str = "tui-pagination__link",
pagination_current: str = "tui-pagination__link--current",
pagination_disabled: str = "tui-pagination__link--disabled",
empty_state: str = "tui-empty",
empty_state_title: str = "tui-empty__title",
empty_state_text: str = "tui-empty__text",
nav: str = "tui-nav",
nav_link: str = "tui-nav__link",
nav_active: str = "tui-nav__link--active",
shell: str = "tui-shell",
shell_header: str = "tui-shell__header",
shell_main: str = "tui-shell__main",
shell_footer: str = "tui-shell__footer",
grid: str = "tui-grid",
table_align: str = "tui-table__cell--",
shell_main_full: str = "tui-shell__main--full",
table_scroll: str = "tui-table-scroll",
)
Class names applied by :mod:tempest_fastapi_sdk.ui.components.
The defaults match the rules built by
:func:~tempest_fastapi_sdk.ui.components.component_stylesheet.
Attributes:
| Name | Type | Description |
|---|---|---|
card |
str
|
The card wrapper. |
card_title |
str
|
The card heading. |
card_body |
str
|
The card content area. |
card_footer |
str
|
The card footer. |
alert |
str
|
The alert wrapper. |
alert_variant |
str
|
Prefix of the per-variant alert modifier;
|
flash |
str
|
The wrapper of the flash messages. |
table |
str
|
The data table. |
table_scroll |
str
|
The wrapper around the table that scrolls it horizontally, so a table wider than the viewport scrolls in place instead of widening the whole page. |
table_empty |
str
|
The row shown when a table has no rows. |
table_align |
str
|
Prefix of the per-column alignment modifier;
|
pagination |
str
|
The pagination wrapper. |
pagination_link |
str
|
A page link. |
pagination_current |
str
|
The current-page marker. |
pagination_disabled |
str
|
A disabled previous/next link. |
empty_state |
str
|
The empty-state wrapper. |
empty_state_title |
str
|
The empty-state heading. |
empty_state_text |
str
|
The empty-state description. |
nav |
str
|
The navigation bar. |
nav_link |
str
|
A navigation link. |
nav_active |
str
|
The active navigation link. |
shell |
str
|
The page shell wrapper. |
shell_header |
str
|
The shell header. |
shell_main |
str
|
The shell main region. |
shell_main_full |
str
|
Modifier of the main region when the
shell spans the full viewport width ( |
shell_footer |
str
|
The shell footer. |
grid |
str
|
The grid container. |
component_stylesheet
¶
component_stylesheet(
*, classes: ComponentClasses | None = None, theme: ThemeTokens | None = None
) -> StyleSheet
Build the stylesheet that styles the bundled components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
ComponentClasses | None
|
The class names to target. Defaults to the set the components apply. |
None
|
theme
|
ThemeTokens | None
|
The tokens whose custom properties the rules reference. Pass the same theme the application sheet emits so the prefixes line up. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
StyleSheet |
StyleSheet
|
The component rules, with no reset and no token |
StyleSheet
|
block of their own, ready to merge into the application sheet. |