feat: add Checkbox and Radio field families

This commit is contained in:
maoyingjie
2026-10-22 09:15:27 +08:00
parent a4fb3c550a
commit bcadbeaf8c
75 changed files with 5293 additions and 22 deletions
@@ -0,0 +1,60 @@
import type { ComputedRef, InjectionKey, Ref } from "vue";
import type { checkboxVariants, radioVariants } from "@heroui-vue/styles";
import type { FieldContext } from "../field/context";
export interface ChoiceState {
isSelected: boolean;
isIndeterminate: boolean;
isDisabled: boolean;
isReadOnly: boolean;
isRequired: boolean;
isInvalid: boolean;
isHovered: boolean;
isPressed: boolean;
isFocused: boolean;
isFocusVisible: boolean;
}
export interface ChoiceMember {
value: () => string;
disabled: ComputedRef<boolean>;
readOnly: ComputedRef<boolean>;
input: Ref<HTMLInputElement | undefined>;
}
export interface ChoiceGroupContext {
kind: "checkbox" | "radio";
field: FieldContext;
behavior: ComputedRef<import("../field/context").ValidationBehavior>;
name: () => string | undefined;
form: () => string | undefined;
variant: ComputedRef<"primary" | "secondary" | undefined>;
selected: (value: string) => boolean;
select: (value: string) => void;
register: (member: ChoiceMember) => () => void;
tabIndex: (member: ChoiceMember) => number;
keydown: (event: KeyboardEvent, member: ChoiceMember) => void;
describedBy: () => string | undefined;
restore: () => void;
}
export const choiceGroupKey: InjectionKey<ChoiceGroupContext> = Symbol(
"HeroUIVue.ChoiceGroup",
);
export interface ChoiceContext {
kind: "checkbox" | "radio";
field: FieldContext;
slots: ComputedRef<
ReturnType<typeof checkboxVariants> | ReturnType<typeof radioVariants>
>;
state: () => ChoiceState;
input: Ref<HTMLInputElement | undefined>;
rootAttrs: () => Record<string, unknown>;
inputAttrs: () => Record<string, unknown>;
onChange: (event: Event) => void;
onInvalid: (event: Event) => void;
guard: (event: Event) => void;
keydown: (event: KeyboardEvent) => void;
hover: Ref<boolean>;
pressed: Ref<boolean>;
focused: Ref<boolean>;
focusVisible: Ref<boolean>;
}
export const choiceKey: InjectionKey<ChoiceContext> =
Symbol("HeroUIVue.Choice");