feat: migrate NumberField with form integration and docs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user