1 | import * as React from "react";
|
2 | import {
|
3 | useSealedState,
|
4 | SealedInitialState,
|
5 | } from "reakit-utils/useSealedState";
|
6 |
|
7 | export type CheckboxState = {
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 | state: boolean | "indeterminate" | Array<number | string>;
|
14 | };
|
15 |
|
16 | export type CheckboxActions = {
|
17 | |
18 |
|
19 |
|
20 | setState: React.Dispatch<React.SetStateAction<CheckboxState["state"]>>;
|
21 | };
|
22 |
|
23 | export type CheckboxInitialState = Partial<Pick<CheckboxState, "state">>;
|
24 |
|
25 | export type CheckboxStateReturn = CheckboxState & CheckboxActions;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | export function useCheckboxState(
|
31 | initialState: SealedInitialState<CheckboxInitialState> = {}
|
32 | ): CheckboxStateReturn {
|
33 | const { state: initialValue = false } = useSealedState(initialState);
|
34 | const [state, setState] = React.useState(initialValue);
|
35 | return { state, setState };
|
36 | }
|