Metadata-Version: 2.4
Name: answerui
Version: 0.0.1
Summary: A semantic HTML UI framework for FastHTML apps
Author-email: Jack Hogan <jackhogan4@gmail.com>
License: Apache-2.0
Project-URL: Repository, https://github.com/AnswerDotAI/answerui
Project-URL: Documentation, https://AnswerDotAI.github.io/answerui/
Keywords: nbdev
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: python-fasthtml
Requires-Dist: fastlucide
Provides-Extra: dev
Requires-Dist: nbdev>=3.3.29; extra == "dev"
Requires-Dist: numpy; extra == "dev"
Requires-Dist: scipy; extra == "dev"
Requires-Dist: matplotlib; extra == "dev"
Requires-Dist: pandas; extra == "dev"
Dynamic: license-file

# answerui


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

answerui styles semantic HTML for [FastHTML](https://fastht.ml) apps. A component is an HTML tag, a variant or a state is an attribute, and classes do only utility jobs, so page markup stays small and readable. Every component’s CSS and behavior lives in one registry, and a page carries the whole registry as one stylesheet and one script. An app changes the look by registering ordinary CSS in the same registry, scoped to a token, a component, or a region.
answerui is built for a human working with an LLM in a persistent Python kernel. Its pyskill, `answerui.skill`, teaches the model the library: how a page is built, how to read what is registered, how to change it, and how to check the result.

## Install

``` sh
pip install -e .
```

## Use

`reg.hdrs()` gives the stylesheet and the behavior script, and `reg.ftrs()` gives the sprite sheet for icons. Both render per response, so a rule registered later is in the next page:

``` python
from fasthtml.common import *
from answerui.all import *
```

``` python
app = FastHTML(hdrs=reg.hdrs(), ftrs=reg.ftrs())
rt = app.route
```

`reg.serve(app)` serves the same assets from URLs named by a hash of their content, which the browser caches. They are rebuilt when a rule changes, and the next page links the new build as a new URL.

A page is native HTML inside layout containers, with a component wherever the platform has no element for the job. Variants and severities are attributes:

``` python
page = Card(H2('Profile'), Field('Name', Input(name='name')), Cluster(Button('Save'), Button('Cancel', secondary=True)))
print(to_xml(page, Alert('Saved.', success=True, dismissible=True)))
```

    <div stack card>
      <h2>Profile</h2>
      <div field>
    <label>Name      <input name="name">
    </label>  </div>
      <div cluster>
    <button>Save</button><button secondary>Cancel</button>  </div>
    </div>

    <div card alert success>
      <div stack style="--gap: var(--space-2);">Saved.</div>
    <button type="button" secondary dismiss>Dismiss</button></div>

Rendered with the registry’s stylesheet. In a notebook, `demo(page)` shows the same thing live:

![](index_files/page.png)

## Customise

A change is ordinary CSS registered at the smallest scope that covers it: a token on the root for the whole app, a rule on a component, or a selector for a region. App rules sit in a cascade layer above the framework’s, so nothing in the framework needs editing:

``` python
reg.rule('theme', ':root { --hue: 150; --radius: 0; }')
Button.rule('caps', 'text-transform: uppercase;')
```

    Button.caps [app] button, a[button]

A variant is a new treatment declared on the component. It becomes an attribute the constructor accepts and appears in the component’s documentation:

``` python
Button.variant('cta', '--pad-block: var(--space); --pad-inline: var(--space2); font-size: var(--text1);', doc='The landing page call to action.')
```

    Button.cta [app] :is(button, a[button])[cta]: The landing page call to action.

![](index_files/custom.png)

``` python
Button
```

### `Button(*children, **attrs)`

Raised at rest, down while active, busy, or expanded, latched by `aria-pressed`; `secondary` for the lesser action; a link carrying `button` is styled the same way.

Root selector: `button, a[button]`.

Declared variants:
- `secondary`: The lesser action: the neutral surface with a hairline border, and the accent wash when latched.
- `quiet`: No face, border, or shadow at rest, for an action that should not compete: dismiss, close, and toolbar buttons.
- `editable`: A value drawn as the dashed ghost of the well it becomes; click to edit, and the app swaps the form in.
- `cta`: The landing page call to action.

Rules:
- `base` (components)
- `icon-only` (components): A button whose only child is an svg is square; give it an aria-label.
- `caps` (app)

## Previews in notebooks

`demo(page)` renders markup in an iframe with the current stylesheet and behaviors. It returns a preview with two representations: the frame as HTML, and the markup as Markdown. The frame holds the whole stylesheet. Stored in a notebook, it would make a file with many previews large and rewrite every preview on each style change. The preview therefore marks its HTML with nbdev’s `strip` flag. `nbdev-clean` drops the frame and keeps the Markdown, so the committed notebook records what each preview showed. A fresh clone shows the frames again after the cells run.

For the docs, set `exec_all` in `pyproject.toml`:

``` toml
[tool.nbdev]
exec_all = true
```

`nbdev-docs` then runs every notebook and renders each preview from the current code.

## With an LLM

`answerui.skill` is a [pyskill](https://github.com/AnswerDotAI/pyskills): a module whose docstring teaches a model the library. `list_pyskills()` finds it, `doc(answerui.skill)` is the guide, and `doc(Button)` describes a component, its variants, and its rules.
