Checkbox
PortedA checkbox with its label. Checked, unchecked or indeterminate (mixed). Inside a CheckboxGroup, give it a value. readOnly shows the value without a way to change it. Native attributes and ref go to the checkbox.
import { Checkbox } from "@etched/monet/checkbox";
export function Preview() {
return <Checkbox label="Retry failed runs" defaultChecked />;
}Installation
import { Checkbox, CheckboxGroup, CheckboxItem, CheckboxLegend } from "@etched/monet/checkbox";Examples
States
import { Checkbox } from "@etched/monet/checkbox";
export function States() {
return (
<div className="row">
<Checkbox aria-label="Unchecked" />
<Checkbox aria-label="Checked" defaultChecked />
<Checkbox aria-label="Some rows selected" indeterminate />
<Checkbox aria-label="Error" aria-invalid />
<Checkbox aria-label="Disabled" disabled />
<Checkbox aria-label="Disabled and checked" disabled defaultChecked />
</div>
);
}Labels
import { Checkbox } from "@etched/monet/checkbox";
export function Labels() {
return (
<div className="grid">
<Checkbox label="Retry failed runs" defaultChecked />
<Checkbox label="Use default statuses" description="Queued, Running, Passed and Failed." />
<Checkbox label="Label first" controlFirst={false} />
<Checkbox label="Copy the owner on reports" required={false} />
<Checkbox label="Lock the bench (admins only)" disabled />
</div>
);
}Groups
Notify me by
Alerts go to your Etched account.
Sites (optional)
Required checks
Choose at least one check.
Archived checks
Benches to drain
import { useState } from "react";
import { Checkbox, CheckboxGroup, CheckboxItem } from "@etched/monet/checkbox";
const benches = ["b-14", "b-15", "p-02"];
function SelectAll() {
const [value, setValue] = useState(["b-14"]);
return (
<CheckboxGroup legend="Benches to drain" value={value} onValueChange={setValue} allValues={benches}>
<Checkbox parent label="All benches" />
{benches.map((bench) => (
<CheckboxItem key={bench} value={bench} label={bench.toUpperCase()} />
))}
</CheckboxGroup>
);
}
export function Groups() {
return (
<div className="grid">
<CheckboxGroup legend="Notify me by" description="Alerts go to your Etched account." defaultValue={["email"]}>
<CheckboxItem value="email" label="Email" />
<CheckboxItem value="slack" label="Slack" />
<CheckboxItem value="sms" label="Text message" disabled />
</CheckboxGroup>
<CheckboxGroup legend="Sites" orientation="horizontal" required={false} defaultValue={["tpe-2"]}>
<CheckboxItem value="tpe-2" label="TPE-2" />
<CheckboxItem value="sjc-1" label="SJC-1" />
<CheckboxItem value="aus-3" label="AUS-3" />
</CheckboxGroup>
<CheckboxGroup legend="Required checks" error="Choose at least one check.">
<CheckboxItem value="thermal" label="Thermal" />
<CheckboxItem value="power" label="Power" />
</CheckboxGroup>
<CheckboxGroup legend="Archived checks" disabled defaultValue={["thermal"]}>
<CheckboxItem value="thermal" label="Thermal" />
<CheckboxItem value="power" label="Power" />
</CheckboxGroup>
<SelectAll />
</div>
);
}Cards
Senders
Shifts
Terms (box first)
Burn-in checks
Choose at least one check.
import { Checkbox, CheckboxGroup, CheckboxItem } from "@etched/monet/checkbox";
export function Cards() {
return (
<div className="grid">
<CheckboxGroup legend="Senders" appearance="card" defaultValue={["ana"]}>
<CheckboxItem value="ana" label="Ana Ruiz" description="ana@etched.com · Recruiter" />
<CheckboxItem value="sam" label="Sam Lee" description="sam@etched.com · Coordinator" />
<CheckboxItem value="kai" label="Kai Park" description="kai@etched.com · On leave" disabled />
</CheckboxGroup>
<CheckboxGroup legend="Shifts" appearance="card" orientation="horizontal" defaultValue={["day"]}>
<CheckboxItem value="day" label="Day" description="06:00 to 14:00" />
<CheckboxItem value="swing" label="Swing" description="14:00 to 22:00" />
<CheckboxItem value="night" label="Night" description="22:00 to 06:00" />
</CheckboxGroup>
<CheckboxGroup legend="Terms (box first)" appearance="card" controlFirst defaultValue={["fall"]}>
<CheckboxItem value="spring" label="Spring" />
<CheckboxItem value="summer" label="Summer" />
<CheckboxItem value="fall" label="Fall" />
</CheckboxGroup>
<CheckboxGroup legend="Burn-in checks" appearance="card" error="Choose at least one check.">
<CheckboxItem value="thermal" label="Thermal" description="Holds 85 °C for an hour." />
<CheckboxItem value="power" label="Power" description="Draws peak load for ten minutes." />
</CheckboxGroup>
<Checkbox appearance="card" label="Send a weekly digest" description="Failed runs, every Monday." defaultChecked />
</div>
);
}Read-only
readOnly shows the value without a way to change it: no hover, the default cursor, and the read-only fill in an empty box.
import { Checkbox } from "@etched/monet/checkbox";
export function ReadOnly() {
return (
<div className="grid">
<Checkbox label="Background check passed" description="Set by the vendor." readOnly defaultChecked />
<Checkbox label="Needs relocation" description="Set by the vendor." readOnly />
<Checkbox appearance="card" label="Referral bonus paid" description="Set by payroll." readOnly />
</div>
);
}In a field
A bare checkbox in a Field takes the Field's label. A checkbox with its own label takes labelTooltip and error too.
Archived runs are hidden from the list.
We keep your answers for one year.
Accept the data policy to continue.
import { Field } from "@etched/monet/field";
import { Checkbox } from "@etched/monet/checkbox";
export function InAField() {
return (
<div className="grid">
<Field label="Archived" description="Archived runs are hidden from the list.">
<Checkbox />
</Field>
<Checkbox label="I accept the data policy" labelTooltip="We keep your answers for one year." error="Accept the data policy to continue." />
</div>
);
}Accessibility
Spacetoggles it.Enterdoes not; in a form, it presses the form's submit button.- A
checkbox, named bylabel(or aField's label, oraria-label);descriptionanderrordescribe it, and an error oraria-invalidmarks it invalid. ACheckboxGroupis agroup, named by itslegend. aria-checkedistrue,falseormixed(indeterminate).readOnlysetsaria-readonly;disabledsetsaria-disabledand takes the box out of theTaborder.- A group's
descriptionorerrordescribes the group, and anerrormarks each boxaria-invalid. Aparentbox hasaria-controlsfor the boxes it checks. - Without
label, give the box anaria-label. Withoutlegend, give the group aCheckboxLegendoraria-label. Do not put aCheckboxGroupin aField.
API reference
CheckboxGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| legend | ReactNode | – | Title of the group. Without it, add a legend child or an aria-label. |
| description | ReactNode | – | Help text below the group. Hidden while an error shows. |
| error | FieldError | – | Error below the group. It marks every control in it invalid. |
| orientation | "vertical" | "horizontal" | "vertical" | |
| required | boolean | – | false adds the optional marker after the legend. |
| children * | ReactNode | – | CheckboxItem children, and optionally a CheckboxLegend. |
| appearance | "default" | "card" | "default" | Default appearance of every item. Card items join into one card. |
| controlFirst | boolean | true, or false for cards | Default controlFirst of every item. |
| className | string | – | Class on the outer element, for layout. |
CheckboxItem
| Prop | Type | Default | Description |
|---|---|---|---|
| labelTooltip | ReactNode | – | More about the field, behind an info button after the label. |
| labelTooltipLabel | string | "More information" | Names the info button. |
| description | ReactNode | – | Help text below the control. Hidden while an error shows. |
| error | FieldError | FieldShortcuts["error"] | – | A message under the checkbox; it marks it invalid. Without a message, aria-invalid marks it alone. |
| appearance | "default" | "card" | "default" | Inside a CheckboxGroup, the group's appearance is the default. |
| controlFirst | boolean | true, or false for a card | Box before the label. false puts the label first. Inside a CheckboxGroup, the group sets the default. |
| className | string | – | Class on the outer element, for layout. |
| label * | ReactNode | – |
CheckboxLegend
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | – |
Checkbox
| Prop | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | – | Visible label. Without one, give the control an aria-label. |
| labelTooltip | ReactNode | – | More about the field, behind an info button after the label. |
| labelTooltipLabel | string | "More information" | Names the info button. |
| description | ReactNode | – | Help text below the control. Hidden while an error shows. |
| error | FieldError | FieldShortcuts["error"] | – | A message under the checkbox; it marks it invalid. Without a message, aria-invalid marks it alone. |
| appearance | "default" | "card" | "default" | Inside a CheckboxGroup, the group's appearance is the default. |
| controlFirst | boolean | true, or false for a card | Box before the label. false puts the label first. Inside a CheckboxGroup, the group sets the default. |
| className | string | – | Class on the outer element, for layout. |