|
1 | 1 | import { Dispatch, SetStateAction, useState } from "react"; |
2 | 2 |
|
3 | 3 | /** |
4 | | - * This is the `useState` initializer that can be used if some checkboxes should |
5 | | - * be checked by default. |
6 | | - * |
7 | 4 | * @internal |
8 | 5 | * @remarks \@since 2.8.5 |
9 | 6 | */ |
@@ -32,10 +29,17 @@ export interface IndeterminateCheckedHookOptions<V extends string> { |
32 | 29 | */ |
33 | 30 | menu?: boolean; |
34 | 31 |
|
35 | | - /** {@inheritDoc OnChange} */ |
| 32 | + /** |
| 33 | + * This is the `useState` initializer that can be used if some checkboxes should |
| 34 | + * be checked by default. |
| 35 | + */ |
36 | 36 | onChange?: OnChange<V>; |
37 | 37 |
|
38 | | - /** {@inheritDoc Initializer} */ |
| 38 | + /** |
| 39 | + * The change handler for indeterminate checkboxes. |
| 40 | + * |
| 41 | + * @param values - The current list of checked values. |
| 42 | + */ |
39 | 43 | defaultCheckedValues?: Initializer<V>; |
40 | 44 | } |
41 | 45 |
|
@@ -181,12 +185,30 @@ interface OnCheckedChangeReturnValue<V extends string> |
181 | 185 | * @typeParam V - The values allowed for the list of checkboxes. |
182 | 186 | * @internal |
183 | 187 | */ |
184 | | -interface CombinedReturnValue<V extends string> |
| 188 | +export interface CombinedIndeterminateCheckedHookReturnValue<V extends string> |
185 | 189 | extends BaseIndeterminateCheckedHookReturnValue<V> { |
186 | 190 | rootProps: ProvidedCombinedIndeterminateProps; |
187 | 191 | getProps(value: V): ProvidedCombinedIndeterminateControlledProps<V>; |
188 | 192 | } |
189 | 193 |
|
| 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 | + |
190 | 212 | /** |
191 | 213 | * This hook allows you to toggle the state of multiple checkboxes in a single |
192 | 214 | * place along with an indeterminate checkbox that can check/uncheck all |
@@ -301,25 +323,25 @@ interface CombinedReturnValue<V extends string> |
301 | 323 | * </DropdownMenu> |
302 | 324 | * ); |
303 | 325 | * ``` |
| 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. |
304 | 339 | */ |
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>; |
318 | 340 | export function useIndeterminateChecked<V extends string>( |
319 | 341 | values: readonly V[], |
320 | 342 | defaultOrOptions?: IndeterminateCheckedHookOptions<V> | Initializer<V>, |
321 | 343 | optionalOnChange?: OnChange<V> |
322 | | -): CombinedReturnValue<V> { |
| 344 | +): CombinedIndeterminateCheckedHookReturnValue<V> { |
323 | 345 | let menu = false; |
324 | 346 | let propOnChange: OnChange<V> | undefined = optionalOnChange; |
325 | 347 | let defaultCheckedValues: Initializer<V>; |
|
0 commit comments