import type { ExtractPropTypes, InjectionKey, Ref } from 'vue'; import type { MouseEventHandler } from '../_util/EventInterface'; import type { VueNode } from '../_util/type'; import PropTypes from '../_util/vue-types'; import { booleanType, functionType, stringType, arrayType } from '../_util/type'; export type CheckboxValueType = string | number | boolean; export interface CheckboxOptionType { label?: VueNode; value: CheckboxValueType; disabled?: boolean; indeterminate?: boolean; onChange?: (e: CheckboxChangeEvent) => void; } export interface CheckboxChangeEvent { target: CheckboxChangeEventTarget; stopPropagation: () => void; preventDefault: () => void; nativeEvent: MouseEvent; } export interface CheckboxChangeEventTarget extends CheckboxProps { checked: boolean; } export const abstractCheckboxGroupProps = () => { return { name: String, prefixCls: String, options: arrayType>( [] as Array, ), disabled: Boolean, id: String, }; }; export const checkboxGroupProps = () => { return { ...abstractCheckboxGroupProps(), defaultValue: arrayType>(), value: arrayType>(), onChange: functionType<(checkedValue: Array) => void>(), 'onUpdate:value': functionType<(checkedValue: Array) => void>(), }; }; export type CheckboxGroupProps = Partial>>; export const abstractCheckboxProps = () => { return { prefixCls: String, defaultChecked: booleanType(), checked: booleanType(), disabled: booleanType(), isGroup: booleanType(), value: PropTypes.any, name: String, id: String, indeterminate: booleanType(), type: stringType('checkbox'), autofocus: booleanType(), onChange: functionType<(e: CheckboxChangeEvent) => void>(), 'onUpdate:checked': functionType<(checked: boolean) => void>(), onClick: functionType(), skipGroup: booleanType(false), }; }; export const checkboxProps = () => { return { ...abstractCheckboxProps(), indeterminate: booleanType(false), }; }; export type CheckboxProps = Partial>>; export type CheckboxGroupContext = { cancelValue: (id: Symbol) => void; registerValue: (id: Symbol, value: string) => void; toggleOption: (option: CheckboxOptionType) => void; name: Ref; disabled: Ref; mergedValue: Ref; }; export const CheckboxGroupContextKey: InjectionKey = Symbol('CheckboxGroupContext');