Skip to content

Commit 8646c28

Browse files
committed
docs(form): Updated documentation for useIndeterminateChecked
1 parent 76c98fe commit 8646c28

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

packages/form/src/useIndeterminateChecked.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Dispatch, SetStateAction, useState } from "react";
22

33
/**
4-
* This is the `useState` initializer that can be used if some checkboxes should
5-
* be checked by default.
6-
*
74
* @internal
85
* @remarks \@since 2.8.5
96
*/
@@ -32,10 +29,17 @@ export interface IndeterminateCheckedHookOptions<V extends string> {
3229
*/
3330
menu?: boolean;
3431

35-
/** {@inheritDoc OnChange} */
32+
/**
33+
* This is the `useState` initializer that can be used if some checkboxes should
34+
* be checked by default.
35+
*/
3636
onChange?: OnChange<V>;
3737

38-
/** {@inheritDoc Initializer} */
38+
/**
39+
* The change handler for indeterminate checkboxes.
40+
*
41+
* @param values - The current list of checked values.
42+
*/
3943
defaultCheckedValues?: Initializer<V>;
4044
}
4145

@@ -181,12 +185,30 @@ interface OnCheckedChangeReturnValue<V extends string>
181185
* @typeParam V - The values allowed for the list of checkboxes.
182186
* @internal
183187
*/
184-
interface CombinedReturnValue<V extends string>
188+
export interface CombinedIndeterminateCheckedHookReturnValue<V extends string>
185189
extends BaseIndeterminateCheckedHookReturnValue<V> {
186190
rootProps: ProvidedCombinedIndeterminateProps;
187191
getProps(value: V): ProvidedCombinedIndeterminateControlledProps<V>;
188192
}
189193

194+
/**
195+
* @deprecated \@since 2.8.5 Use the implementation that accepts options as the
196+
* second argument.
197+
*/
198+
export function useIndeterminateChecked<V extends string>(
199+
values: readonly V[],
200+
defaultCheckedValues: Initializer<V>,
201+
onChange?: OnChange<V>
202+
): OnChangeReturnValue<V>;
203+
export function useIndeterminateChecked<V extends string>(
204+
values: readonly V[],
205+
options?: IndeterminateCheckedHookOptions<V> & { menu?: false }
206+
): OnChangeReturnValue<V>;
207+
export function useIndeterminateChecked<V extends string>(
208+
values: readonly V[],
209+
options: IndeterminateCheckedHookOptions<V> & { menu: true }
210+
): OnCheckedChangeReturnValue<V>;
211+
190212
/**
191213
* This hook allows you to toggle the state of multiple checkboxes in a single
192214
* place along with an indeterminate checkbox that can check/uncheck all
@@ -301,25 +323,25 @@ interface CombinedReturnValue<V extends string>
301323
* </DropdownMenu>
302324
* );
303325
* ```
326+
*
327+
* @typeParam V - The allowed values for the checkboxes
328+
* @param values - The allowed values for the checkboxes which is used to
329+
* control the checked states.
330+
* @param defaultOrOptions - The {@link IndeterminateCheckedHookOptions} or a
331+
* `useState` initializer callback/default value for backwards compatibility
332+
* @param optionalOnChange - This is really just for backwards compatibility and
333+
* should not be used. Use {@link IndeterminateCheckedHookOptions.onChange}
334+
* instead.
335+
* @returns an object containing the `rootProps` to pass to the indeterminate
336+
* checkbox, a `getProps` function to provide the controlled behavior for the
337+
* additional `values` in the checkbox list, a list of `checkedValues`, and a
338+
* `setCheckedValues` function to manually override the state if needed.
304339
*/
305-
export function useIndeterminateChecked<V extends string>(
306-
values: readonly V[],
307-
defaultCheckedValues: Initializer<V>,
308-
onChange?: OnChange<V>
309-
): OnChangeReturnValue<V>;
310-
export function useIndeterminateChecked<V extends string>(
311-
values: readonly V[],
312-
options?: IndeterminateCheckedHookOptions<V> & { menu?: false }
313-
): OnChangeReturnValue<V>;
314-
export function useIndeterminateChecked<V extends string>(
315-
values: readonly V[],
316-
options: IndeterminateCheckedHookOptions<V> & { menu: true }
317-
): OnCheckedChangeReturnValue<V>;
318340
export function useIndeterminateChecked<V extends string>(
319341
values: readonly V[],
320342
defaultOrOptions?: IndeterminateCheckedHookOptions<V> | Initializer<V>,
321343
optionalOnChange?: OnChange<V>
322-
): CombinedReturnValue<V> {
344+
): CombinedIndeterminateCheckedHookReturnValue<V> {
323345
let menu = false;
324346
let propOnChange: OnChange<V> | undefined = optionalOnChange;
325347
let defaultCheckedValues: Initializer<V>;

0 commit comments

Comments
 (0)