import { type UseStateInitializer, type UseStateSetter } from "./types.js"; /** * @since 6.0.0 */ export interface ReadonlySetOptions { /** * Sets the behavior for when the * {@link ReadonlySetImplementation.toggleValue} is triggered and mostly for * internal usage. The default behavior (`"multiple"`) is to work how most * would expect: * - If the item does not exist in the set, add it. * - If the item exists in the set, remove it. * * Setting this to `"single"` makes it so that only a single item can be in * the set at once and will toggle like normal: * - If the item does not exist in the set, return a new set only including * the item. * - If the item exists in the set, return an empty set. * An example usage is the `useExpansionPanels` to allow only a single panel * to be expanded at a time. * * Setting this to `"single-select"` makes it so that only a single item can * be in the set at once but will not toggle: * - If the item does not exist in the set, return a new set only including * the item. * - If the item exists in the set, do nothing * An example usage is the `useTreeSelection` to always require at least one * tree item to be selected. It is impossible to deselect an item. * * @defaultValue `"multiple"` */ toggleType?: "single" | "multiple" | "single-select"; defaultValue?: UseStateInitializer | readonly T[]>; } /** * @since 6.0.0 */ export interface ReadonlySetImplementation { value: ReadonlySet; setValue: UseStateSetter>; toggleValue: (item: T) => void; } /** * The `useReadonlySet` hook is used to create a more performant lookup * behavior for lists/arrays. This is most likely an internal only hook to * manage state for a `ReadonlySet`. You most likely want to use one of the * other hooks that leverage this instead: * * - `useCheckboxGroup` * - `useExpansionPanels` * - `useTreeSelection` * - `useTreeExpansion` * - etc * * @example Simple Example * ```tsx * import { cnb } from "cnbuilder"; * import { useReadonlySet } from "@react-md/core/useReadonlySet"; * * function Example() { * const { value, toggleValue } = useReadonlySet(); * * return ( * <> * {someList.map((item) => ( *
* {item.name} * *
* ))} * * ); * } * ``` * @since 6.0.0 */ export declare function useReadonlySet(options?: ReadonlySetOptions): ReadonlySetImplementation;