One choice among a few visible options.
Plan
Up to 3 members and 250 issues.
Unlimited issues, cycles and guests.
Single sign-on and audit logs. Talk to sales.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Schema } from "effect"import { RadioGroup } from "./ui/uicontext/components/RadioGroup.ts"const plans = [ { value: "free", label: "Free", description: "Up to 3 members and 250 issues." }, { value: "team", label: "Team", description: "Unlimited issues, cycles and guests." }, { value: "enterprise", label: "Enterprise", description: "Single sign-on and audit logs. Talk to sales.", disabled: true },]const Message = UiSchema.TaggedEnum({ PickedPlan: { value: Schema.String } })export const PlanPicker = Html.component({ name: "PlanPicker", model: Schema.Struct({ plan: Schema.String }), message: Message,}).make({ init: () => ({ plan: "team" }), update: { PickedPlan: ($, { value }) => $.evolve({ plan: value }) }, view: (h, { plan }) => RadioGroup(h, { id: "workspace-plan", label: "Plan", value: plan, options: plans, name: "plan", onPick: (value) => Message.PickedPlan({ value }), }),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/radio-groupUsage
import { RadioGroup } from "./ui/uicontext/components/RadioGroup.ts"const Message = UiSchema.TaggedEnum({ PickedDensity: { value: Schema.String } })export const DensityPicker = (h: Html.H<typeof Message.Type>, density: string) => RadioGroup(h, { id: "row-density", label: "Row density", value: density, options: [ { value: "compact", label: "Compact" }, { value: "comfortable", label: "Comfortable" }, ], onPick: (value) => Message.PickedDensity({ value }), })Examples
Nothing picked yet
With value: null no option is picked. Inside a FormField with group: true, the label names the group and the error marks every option.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { FormField } from "./ui/uicontext/components/FormControls.ts"import { RadioGroup } from "./ui/uicontext/components/RadioGroup.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ form: { display: "grid", gap: 16, justifyItems: "start" },})const Message = UiSchema.TaggedEnum({ PickedVisibility: { value: Schema.String }, Submitted: {} })export const ProjectVisibility = Html.component({ name: "ProjectVisibility", model: Schema.Struct({ visibility: Schema.NullOr(Schema.String), tried: Schema.Boolean }), message: Message,}).make({ init: () => ({ visibility: null, tried: false }), update: { PickedVisibility: ($, { value }) => $.evolve({ visibility: value }), Submitted: ($) => $.evolve({ tried: true }), }, view: (h, { visibility, tried }) => h.form.attrs({ novalidate: "", ...sx(styles.form) }).on("submit", Message.Submitted()).children( FormField( h, { id: "project-visibility", label: "Who can see this project?", group: true, ...(tried && visibility === null ? { error: "Choose who can see it." } : { description: "You can change this later." }), }, (field) => RadioGroup(h, { id: field.id, value: visibility, options: [ { value: "team", label: "Everyone on the team" }, { value: "private", label: "Only people I invite" }, ], required: true, field, onPick: (value) => Message.PickedVisibility({ value }), }), ), Button(h, { tone: "primary", type: "submit" }).children("Create project"), ),})In a row, and read-only
A row of short options wraps on a narrow screen. Read-only keeps the arrow keys working but picks nothing.
Row density
Workspace default (set by an owner)
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { RadioGroup } from "./ui/uicontext/components/RadioGroup.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ stack: { display: "grid", gap: 20 },})const densities = [ { value: "compact", label: "Compact" }, { value: "comfortable", label: "Comfortable" }, { value: "spacious", label: "Spacious" },]const Message = UiSchema.TaggedEnum({ PickedDensity: { value: Schema.String } })export const DensityRow = Html.component({ name: "DensityRow", model: Schema.Struct({ density: Schema.String }), message: Message,}).make({ init: () => ({ density: "comfortable" }), update: { PickedDensity: ($, { value }) => $.evolve({ density: value }) }, view: (h, { density }) => h.div.attrs(sx(styles.stack)).children( RadioGroup(h, { key: "density", id: "table-density", label: "Row density", orientation: "horizontal", value: density, options: densities, onPick: (value) => Message.PickedDensity({ value }), }), // the workspace sets this one; members see it and can move through it, but not change it RadioGroup(h, { key: "workspace-density", id: "workspace-density", label: "Workspace default (set by an owner)", orientation: "horizontal", readOnly: true, value: "compact", options: densities, onPick: (value) => Message.PickedDensity({ value }), }), ),})API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
idrequired | string | — | The group's id; each option's description is identified from it |
key | string | — | Names the group among others in the same view; needed for more than one |
valuerequired | string | null | — | The picked option's value, or null when none is picked yet. The caller keeps it. |
optionsrequired | RadioOption[] | — | The choices, each with a value, a label and an optional description. |
onPickrequired | (value: string) => Message | — | What a pick asks for: the value to store and pass back as value |
label | string | — | A visible name above the options; leave it out inside a FormField |
ariaLabel | string | — | The accessible name when there's no visible label |
orientation | "vertical" | "horizontal" | vertical | Stacked or in a row; arrow keys move along either way; vertical by default. |
disabled | boolean | — | No option can be picked or focused. |
readOnly | boolean | — | Shows the pick and stays navigable, but no option can be picked. |
required | boolean | — | An option must be picked before its form submits. |
name | string | — | The form field: the picked value submits under name |
field | FieldControlAttrs | — | A FormField's attributes: its label names the group, its description and error describe it |
style | Style | — | StyleX styles applied after the group’s own. |
Accessibility
- A radio group and one Tab stop: the arrow keys move between options and pick as they go, and Space picks.
- The group is named by its label and each option is described by its own description. Disabled options are skipped.