ToggleChip
An on/off pill button for filters.
Overview
A filter the person switches on and off, usually one of several side by side.
Toggle
Do
import { useState } from "react";
import { Cluster, ToggleChip } from "@hackcove/ui";
function Example() {
const [on, setOn] = useState(["Vintage"]);
const toggle = (name: string) =>
setOn((now) => (now.includes(name) ? now.filter((n) => n !== name) : [...now, name]));
return (
<Cluster gap="xs" wrap>
{["Charity", "Vintage", "Books"].map((name) => (
<ToggleChip key={name} pressed={on.includes(name)} onClick={() => toggle(name)}>
{name}
</ToggleChip>
))}
</Cluster>
);
}ToggleChip: pressed shows whether it is on, and the caller toggles it in onClick.Don't
import { ToggleChip } from "@hackcove/ui";
<ToggleChip pressed={false}>Clear filters</ToggleChip>
Button.Dot
Do
import { Cluster, ToggleChip } from "@hackcove/ui";
<Cluster gap="xs" wrap>
<ToggleChip pressed dot="#7c3aed">
Vintage
</ToggleChip>
<ToggleChip pressed={false} dot="#0891b2">
Books
</ToggleChip>
</Cluster>dot is a category colour before the label, so a chip matches its marker elsewhere.Usage
pressedis the state; the caller flips it inonClick.- Put chips that filter one thing in a
FilterGroup, so the set has a name. dotis a category colour before the label, for a chip that matches a marker elsewhere.- An action is a
Button; a setting in a form is aCheckbox.
Accessibility
- A native
<button type="button">witharia-pressed, so a screen reader announces it as a toggle button and its state. - The
dotis decorative and hidden from assistive tech. - The focus ring comes from the component.
API
ToggleChip
An on/off pill button for filters. pressed sets its state; dot adds a leading colour dot. The caller toggles it in onClick.
dotA CSS colour for a leading dot (e.g. a category colour); no dot when omitted.
- Type
string
pressed required- Type
boolean