Actions & Basics
@hacline/ui/toggleToggle
Control a single toggle button or a group of pressed-state buttons.
Usage
Click the formatting buttons to inspect multiple simultaneous pressed states. Organize related items in ToggleGroup with a descriptive accessible name on the root.
"use client";
import { Toggle, ToggleGroup } from "@/components/ui/hacline/components/toggle";
export const Example = () => (
<ToggleGroup aria-label="Report text formatting" defaultValue={["bold"]}>
<Toggle value="bold">Bold</Toggle>
<Toggle value="italic">Italic</Toggle>
<Toggle value="underline">Underline</Toggle>
</ToggleGroup>
);Controlled Single Toggle
Sync bookmark state back to your application via pressed and onPressedChange.
"use client";
import { useState } from "react";
import { Toggle } from "@/components/ui/hacline/components/toggle";
export const Example = () => {
const [saved, setSaved] = useState(false);
return (
<div className="flex flex-col items-center gap-2">
<Toggle onPressedChange={setSaved} pressed={saved}>
Bookmark doc
</Toggle>
<output className="text-hl-fg-muted text-xs">
{saved ? "Saved to bookmarks" : "Not bookmarked"}
</output>
</div>
);
};Parts
| Part | Description |
|---|---|
ToggleGroup | Toggles that share one value, with one tab stop and arrow keys between them. T is inferred from value, defaultValue or onValueChange. |
ToggleIcon | An icon inside a toggle. A toggle with only an icon needs an aria-label. Screen readers skip it, and mirror flips it in right-to-left text. |
Props
Prop
Type