feat: migrate DateField and shared date input group
This commit is contained in:
@@ -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");
|
||||
Reference in New Issue
Block a user