Toggle Group
A set of two-state buttons that can be toggled on or off.
Usage
ToggleGroupcomponent takes intypeandclassNameprops.typecan be"single"or"multiple". Default is"single".ChildrenofToggleGroupcomponent are rendered as togglable buttons. Every child ofToggleGroupcomponent should havevalueprop.valueprop of every child ofToggleGroupcomponent is the value of the button. If not passed, then inner text of the child is considered as value.
Example of using value generated by ToggleGroup of "single" type
Note how
data-value prop is passed to every child of ToggleGroup componentimport { ToggleGroup } from "dubsui"
import { useEffect, useState } from "react";
const Single = () => {
const [value, setValue] = useState();
useEffect(() => {
console.log(value);
}, [value]);
return (
<ToggleGroup value={value} onValueChange={setValue} type="single">
<div data-value="a">A</div>
<div data-value="b">B</div>
<div data-value="c">C</div>
</ToggleGroup>
);
};Example of using value generated by ToggleGroup of "multiple" type
Note how
value state us an array. In ToggleGroup of "multiple" type you have to use array to catch the valuesimport { ToggleGroup } from "dubsui"
import { useEffect, useState } from "react";
const Single = () => {
const [value, setValue] = useState([]);
useEffect(() => {
console.log(value);
}, [value]);
return (
<ToggleGroup value={value} onValueChange={setValue} type="multiple">
<div data-value="a">A</div>
<div data-value="b">B</div>
<div data-value="c">C</div>
</ToggleGroup>
);
};Customizable Design
More granular components provide you with more control over the design of the ToggleGroup component. You can customize the design of the ToggleGroup component by using the following sub-components:
Note how
value prop is passed to every child of ToggleGroupRoot component which is different compared to ToggleGroup which used data-value prop- Style of every sub-component of the ToggleGroup component can be customized using the
classNameprop. - Pass in a
CSS classor useTailwind CSSutility classes to style the ToggleGroup component.