Shared styles for native buttons and fields, to use on your own elements.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { button, Field, field } from "./ui/uicontext/components/Controls.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ form: { display: "grid", gap: 12, inlineSize: "min(100%, 20rem)" }, row: { display: "flex", flexWrap: "wrap", gap: 8 },})// native elements wearing the kit's styles: a quick form with no components behind itexport const QuickForm = <M>(h: Html.H<M>) => h.form.attrs({ novalidate: "", ...sx(styles.form) }).children( Field(h, { label: "Webhook URL", children: [h.input.attrs({ type: "url", placeholder: "https://", ...sx(field.input) })] }), Field(h, { label: "Retry", children: [ h.select.attrs(sx(field.input)).children( h.option.attr("value", "3").children("Three times"), h.option.attr("value", "0").children("Never"), ), ], }), Field(h, { label: "Signing secret", children: [h.input.attrs({ readonly: "", value: "whsec_••••••••3f9a", ...sx(field.input) })] }), h.div.attrs(sx(styles.row)).children( h.button.attrs({ type: "submit", ...sx(button.base, button.primary) }).children("Save webhook"), h.button.attrs({ type: "button", ...sx(button.base, button.secondary) }).children("Send a test"), h.button.attrs({ type: "button", disabled: "", ...sx(button.base, button.ghost) }).children("Delete"), ), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/controlsUsage
import { button, field } from "./ui/uicontext/components/Controls.ts"import { sx } from "./ui/uicontext/components/Sx.ts"export const NameInput = <M>(h: Html.H<M>) => h.input.attrs({ "aria-label": "Name", ...sx(field.input) })export const SaveButton = <M>(h: Html.H<M>) => h.button.attrs({ type: "submit", ...sx(button.base, button.primary) }).children("Save")API reference
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | The label's text. |
childrenrequired | View.Children | The control it labels, such as an input with field.input; clicking the label focuses it. |
Accessibility
- These are styles for native elements, so buttons, inputs and selects keep the browser's keyboard, form and screen reader behavior.
- Each control shows a focus ring on keyboard focus only, and
Fieldwraps its control in a<label>, so the label names it and a click on it focuses it.