@yamada-ui/checkbox
Version:
Yamada UI checkbox component
54 lines (51 loc) • 1.92 kB
text/typescript
import * as react from 'react';
import { ChangeEvent, ReactNode } from 'react';
import { PropGetter } from '@yamada-ui/core';
import { Dict } from '@yamada-ui/utils';
import { CheckboxProps } from './checkbox.mjs';
import '@yamada-ui/form-control';
import '@yamada-ui/motion';
import './use-checkbox.mjs';
interface CheckboxItem<Y extends number | string = string> extends CheckboxProps<Y> {
label?: ReactNode;
}
interface UseCheckboxGroupProps<Y extends number | string = string> {
/**
* The initial value of the checkbox group.
*/
defaultValue?: Y[];
/**
* If `true`, input elements will receive `checked` attribute instead of `isChecked`.
*
* This assumes, you're using native radio inputs.
*
* @default false
*
* @deprecated It will be deprecated in version 2.0.
*/
isNative?: boolean;
/**
* The value of the checkbox group.
*/
value?: Y[];
/**
* The callback fired when any children checkbox is checked or unchecked.
*/
onChange?: (value: Y[]) => void;
}
declare const useCheckboxGroup: <Y extends number | string, M extends Dict = Dict>({ defaultValue, isNative, value: valueProp, onChange: onChangeProp, ...props }: M & UseCheckboxGroupProps<Y>) => {
props: Omit<M & UseCheckboxGroupProps<Y>, "defaultValue" | "onChange" | "value" | "isNative">;
setValue: react.Dispatch<react.SetStateAction<Y[]>>;
value: Y[];
getCheckboxProps: PropGetter<{
value?: Y;
}, {
checked?: boolean;
isChecked?: boolean;
value?: Y;
}>;
getContainerProps: PropGetter<"div", undefined>;
onChange: (evOrValue: ChangeEvent<HTMLInputElement> | Y) => void;
};
type UseCheckboxGroupReturn<Y extends number | string = string> = ReturnType<typeof useCheckboxGroup<Y>>;
export { type CheckboxItem, type UseCheckboxGroupProps, type UseCheckboxGroupReturn, useCheckboxGroup };