# react.form.styles An optional stylesheet for the `react.form` elements, as a function that returns CSS text. The elements are fully usable without it: they render plain, accessible HTML with stable `caps-*` class names, and a browser's default styles work. This gives them a clean GOV.UK-like look in one line, and every colour, the radius and the font are CSS custom properties, so an app can restyle it with its own CSS without calling it again. ```tsx // app/layout.tsx: a server component, so the CSS is in the HTML, not in JavaScript import { formStyles } from "#fune/react.form.styles@^1"; export default function Layout({ children }: { children: React.ReactNode }) { return (
{children} ); } ``` Or write it to a file at build time and link it like any other stylesheet: ```ts import { writeFileSync } from "node:fs"; writeFileSync("public/forms.css", formStyles({ accent: "#00703c", radius: "4px" })); ``` ## The theme Every field is optional; `{}` is the default, and an empty string is the same as leaving a field out. | Field | Custom property | Default | |---|---|---| | `text` | `--caps-form-text` | `#0b0c0c` | | `muted` | `--caps-form-muted` (hints, counts) | `#505a5f` | | `background` | `--caps-form-background` (inputs) | `#ffffff` | | `border` | `--caps-form-border` | `#0b0c0c` | | `accent` | `--caps-form-accent` (buttons, ticked boxes) | `#1d70b8` | | | `--caps-form-accent-text` (text on the accent and warning buttons) | `#ffffff` | | | `--caps-form-secondary` (secondary button, prefix and suffix) | `#f3f2f1` | | `focus` | `--caps-form-focus` (the focus ring) | `#ffdd00` | | | `--caps-form-focus-text` (text on focus yellow, the ring's dark edge) | `#0b0c0c` | | `error` | `--caps-form-error` | `#d4351c` | | `radius` | `--caps-form-radius` | `0` | | `font` | `--caps-form-font` | the system UI font; no web font is loaded | | `scope` | | none: rules apply to the whole page | | `dark` | | `media` | - **scope** is one selector, such as `.signup` or `main > form`: every rule becomes `.signup .fune-field`, and the custom properties are set on `.signup` instead of `:root`, so the styles stay inside that container. - **dark** is `media` (the dark palette under `@media (prefers-color-scheme: dark)`), `attribute` (under `[data-theme=dark]` on any ancestor, or on the scope's element itself, for a site with its own theme switch) or `none`. The dark palette replaces the colours, the theme's included, because a colour picked for a light page is rarely readable on a dark one; to theme dark mode too, set the custom properties in your own dark rule (or use `dark: "none"` and do it all yourself). To theme without calling again, override the properties anywhere after the stylesheet: `.checkout { --caps-form-accent: #00703c; --caps-form-radius: 6px }`. Theme values are put into the CSS as they are, so anything that could end a declaration or a rule, or close the `