composeui.core.webstyle

The look of the web app: its colors, shapes and font, and stylesheets of its own.

Pass a WebStyle to composeui.core.application.run as web_style. The other backends ignore it. Each value is checked as it is set: a color that doesn’t parse, or a text color that a reader can’t tell from its background, raises ValueError.

class composeui.core.webstyle.Palette[source]

Bases: object

The colors of a theme, light or dark, each #rrggbb or oklch(L C H).

A color left out keeps ComposeUI’s. A *_content color is the text on its color, e.g. a primary button’s text on primary; base_content is the text on the page.

base_100: str | None

The background of the boxes, such as the page’s card and the fields.

base_200: str | None

The background of the page, and of a group of rows.

base_300: str | None

The borders.

base_content: str | None
primary: str | None

Main buttons, current tab, links.

primary_content: str | None
secondary: str | None
secondary_content: str | None
accent: str | None
accent_content: str | None
neutral: str | None
neutral_content: str | None
info: str | None
info_content: str | None
success: str | None
success_content: str | None
warning: str | None
warning_content: str | None
error: str | None

Danger buttons, invalid fields, error messages.

error_content: str | None
colors()[source]

Get the colors set, by field name.

Return type:

dict[str, str]

__init__(*, base_100=None, base_200=None, base_300=None, base_content=None, primary=None, primary_content=None, secondary=None, secondary_content=None, accent=None, accent_content=None, neutral=None, neutral_content=None, info=None, info_content=None, success=None, success_content=None, warning=None, warning_content=None, error=None, error_content=None)

Method generated by attrs for class Palette.

Parameters:
  • base_100 (str | None)

  • base_200 (str | None)

  • base_300 (str | None)

  • base_content (str | None)

  • primary (str | None)

  • primary_content (str | None)

  • secondary (str | None)

  • secondary_content (str | None)

  • accent (str | None)

  • accent_content (str | None)

  • neutral (str | None)

  • neutral_content (str | None)

  • info (str | None)

  • info_content (str | None)

  • success (str | None)

  • success_content (str | None)

  • warning (str | None)

  • warning_content (str | None)

  • error (str | None)

  • error_content (str | None)

Return type:

None

class composeui.core.webstyle.Theme[source]

Bases: object

The colors of the web app, light and dark, its shapes and its font.

The header’s Theme menu still picks light, dark, or the browser’s preference. A value left out keeps ComposeUI’s. Where a palette sets a text color or its background, the two must keep a contrast of 4.5:1 (WCAG AA), ComposeUI’s color standing in for the one left out.

light: Palette
dark: Palette
radius_field: str | None

The corners of the fields and buttons, e.g. "0" for square ones.

radius_box: str | None

The corners of the boxes: the page’s card, groups, dialogs, menus.

radius_selector: str | None

The corners of the small controls: checkboxes, toggles, badges.

border: str | None

The width of the borders, e.g. "1px".

font: str | None

The text’s font, e.g. '"Inter", sans-serif': a font the browser has, or one that a stylesheet of the WebStyle declares with @font-face.

is_default()[source]

Tell whether the theme changes nothing of ComposeUI’s.

Return type:

bool

__init__(*, light=NOTHING, dark=NOTHING, radius_field=None, radius_box=None, radius_selector=None, border=None, font=None)

Method generated by attrs for class Theme.

Parameters:
  • light (Palette)

  • dark (Palette)

  • radius_field (str | None)

  • radius_box (str | None)

  • radius_selector (str | None)

  • border (str | None)

  • font (str | None)

Return type:

None

class composeui.core.webstyle.WebStyle[source]

Bases: object

The look of the web app: its theme, then stylesheets of its own.

The web server serves folder at /_composeui/style/files/: the stylesheets, and the fonts and images they name by a relative url(...). Its hidden files, and any file outside it, are not served. The stylesheets load after ComposeUI’s, in their order, so their rules win over its. They select the parts of the page by their data-cui attribute, such as [data-cui="header"]: ComposeUI’s classes are not part of the API. The server checks them as it starts. A missing file, an @import, or a url(...) that names an address or a file the folder doesn’t serve stops it: the page’s policy would block them.

theme: Theme
folder: Path | None
stylesheets: tuple[str, ...]
__init__(*, theme=NOTHING, folder=None, stylesheets=())

Method generated by attrs for class WebStyle.

Parameters:
  • theme (Theme)

  • stylesheets (Iterable[str])

Return type:

None