feat: migrate public TimeField with shared date input parts
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { inject, type ComputedRef, type InjectionKey } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import {
|
||||
inject,
|
||||
type ComputedRef,
|
||||
type InjectionKey,
|
||||
type Component,
|
||||
} from "vue";
|
||||
import type { DateValue, Time } from "@internationalized/date";
|
||||
import type { DateFieldInputProps } from "reka-ui";
|
||||
import type { dateInputGroupVariants } from "@heroui-vue/styles";
|
||||
export interface DateSegment {
|
||||
@@ -11,11 +16,12 @@ export interface DateSegment {
|
||||
isEditable: boolean;
|
||||
}
|
||||
export interface DateFieldContext {
|
||||
value: ComputedRef<DateValue | null>;
|
||||
value: ComputedRef<DateValue | Time | null>;
|
||||
disabled: ComputedRef<boolean>;
|
||||
readOnly: ComputedRef<boolean>;
|
||||
required: ComputedRef<boolean>;
|
||||
invalid: ComputedRef<boolean>;
|
||||
form?: () => HTMLFormElement | null | undefined;
|
||||
leadingZeros: () => boolean | undefined;
|
||||
labelledBy: () => string | undefined;
|
||||
describedBy: () => string | undefined;
|
||||
@@ -28,10 +34,19 @@ export const dateGroupKey: InjectionKey<
|
||||
> = Symbol("hv-date-group");
|
||||
export function useDateField() {
|
||||
const value = inject(dateFieldKey, undefined);
|
||||
if (!value) throw new Error("Date input parts require a DateField root.");
|
||||
if (!value)
|
||||
throw new Error("Date input parts require a DateField or TimeField root.");
|
||||
return value;
|
||||
}
|
||||
|
||||
export const dateSegmentsKey: InjectionKey<
|
||||
ComputedRef<{ part: DateFieldInputProps["part"]; value: string }[]>
|
||||
> = Symbol("hv-date-segments");
|
||||
|
||||
export const dateSegmentBaseKey: InjectionKey<{
|
||||
base: NonNullable<
|
||||
ReturnType<typeof import("reka-ui").injectDateFieldRootContext>
|
||||
>;
|
||||
input: Component;
|
||||
kind: "date" | "time";
|
||||
}> = Symbol("hv-date-segment-base");
|
||||
|
||||
Reference in New Issue
Block a user