Aller au contenu principal

Toggle & ToggleGroup Component

Description

The Toggle component represents a selectable button that can be used alone or inside a ToggleGroup for grouped selection. It supports exclusive selection (single toggle active) and multiple selection modes.

Props - Toggle

PropTypeDefaultDescription
valueany-Unique identifier for the toggle.
isActivebooleanfalseDefines whether the toggle is active.
disabledbooleanfalseDisables interaction with the toggle.
onClick(event) => void-Click handler for the toggle.

Props - ToggleGroup

PropTypeDefaultDescription
valuestring-The currently selected value (for exclusive mode).
onChange(event, value) => void-Handles toggle state changes.
exclusivebooleantrueIf true, allows only one toggle to be active at a time.

Example Usage

import { Toggle, ToggleGroup } from "@nomana-it/liberty-core"
import { useState } from "react";

export const ToggleExample = () => {
const [selectedValue, setSelectedValue] = useState("option1");

return (
<ToggleGroup value={selectedValue} onChange={(e, value) => setSelectedValue(value)} exclusive>
<Toggle value="option1">Option 1</Toggle>
<Toggle value="option2">Option 2</Toggle>
<Toggle value="option3">Option 3</Toggle>
</ToggleGroup>
);
};

🔗 GitHub Repository (Core): Liberty Core
🔗 GitHub Repository (Test Project): Liberty Test
📖 Live Documentation: Liberty Core Docs
💖 Sponsor & Support: Sponsor Liberty Core