feat: migrate DateField and shared date input group

This commit is contained in:
maoyingjie
2026-10-23 23:56:18 +08:00
parent 3c878d2582
commit 01f0776805
63 changed files with 3974 additions and 90 deletions
@@ -0,0 +1,37 @@
import { inject, type ComputedRef, type InjectionKey } from "vue";
import type { DateValue } from "@internationalized/date";
import type { DateFieldInputProps } from "reka-ui";
import type { dateInputGroupVariants } from "@heroui-vue/styles";
export interface DateSegment {
part: DateFieldInputProps["part"];
type: DateFieldInputProps["part"];
value: string;
text: string;
isPlaceholder: boolean;
isEditable: boolean;
}
export interface DateFieldContext {
value: ComputedRef<DateValue | null>;
disabled: ComputedRef<boolean>;
readOnly: ComputedRef<boolean>;
required: ComputedRef<boolean>;
invalid: ComputedRef<boolean>;
leadingZeros: () => boolean | undefined;
labelledBy: () => string | undefined;
describedBy: () => string | undefined;
ariaLabel: () => unknown;
}
export const dateFieldKey: InjectionKey<DateFieldContext> =
Symbol("hv-date-field");
export const dateGroupKey: InjectionKey<
ComputedRef<ReturnType<typeof dateInputGroupVariants>>
> = Symbol("hv-date-group");
export function useDateField() {
const value = inject(dateFieldKey, undefined);
if (!value) throw new Error("Date input parts require a DateField root.");
return value;
}
export const dateSegmentsKey: InjectionKey<
ComputedRef<{ part: DateFieldInputProps["part"]; value: string }[]>
> = Symbol("hv-date-segments");