Form Indeterminate Checkboxes
src / Demo.tsx
123456789101112131415161718192021222324252627282930313233import React, { ReactElement } from "react";
import { Checkbox, Fieldset, useIndeterminateChecked } from "@react-md/form";
const condiments = ["Lettuce", "Tomato", "Mustard", "Sprouts"];
export default function Demo(): ReactElement {
const {
getProps,
rootProps,
} = useIndeterminateChecked(condiments, {
defaultCheckedValues: ["Sprouts"],
});
return (
<Fieldset legend="Sandwich Condiments" unstyled={false}>
<Checkbox id="condiments-all" label="All Condiments" {...rootProps} />
<ul role="none" style={{ listStyleType: "none" }}>
{condiments.map((condiment, i) => (
<li key={condiment}>
<Checkbox
id={`condiment-${i}`}
label={condiment}
name="condiment"
{...getProps(condiment)}
/>
</li>
))}
</ul>
</Fieldset>
);
}