feat: migrate NumberField with form integration and docs

This commit is contained in:
maoyingjie
2026-10-23 11:48:06 +08:00
parent 7fc8315037
commit 23527d4e4c
43 changed files with 2788 additions and 9 deletions
@@ -0,0 +1,28 @@
import { inject, type ComputedRef, type InjectionKey, type Ref } from "vue";
import type { numberFieldVariants } from "@heroui-vue/styles";
import type { ValidationBehavior } from "../field/context";
export interface NumberFieldContext {
styles: ComputedRef<ReturnType<typeof numberFieldVariants>>;
value: ComputedRef<number | null>;
disabled: ComputedRef<boolean>;
readOnly: ComputedRef<boolean>;
required: ComputedRef<boolean>;
invalid: ComputedRef<boolean>;
behavior: ComputedRef<ValidationBehavior>;
controlId: ComputedRef<string>;
element: Ref<HTMLInputElement | undefined>;
focused: Ref<boolean>;
focusVisible: Ref<boolean>;
inputAttrs: () => Record<string, unknown>;
describedBy: () => string | undefined;
commit: () => void;
invalidEvent: () => void;
}
export const numberFieldKey: InjectionKey<NumberFieldContext> =
Symbol("hv-number-field");
export function useNumberFieldContext() {
const field = inject(numberFieldKey, undefined);
if (!field) throw new Error("NumberField parts require a NumberField root.");
return field;
}