Files
heroui-vue/tests/package/time-field-contract.ts

99 lines
2.5 KiB
TypeScript

import {
TimeField,
TimeFieldRoot,
TimeFieldGroup,
TimeFieldInput,
TimeFieldSegment,
TimeFieldInputContainer,
TimeFieldPrefix,
TimeFieldSuffix,
timeFieldVariants,
type TimeValue,
type TimeFieldProps,
type TimeFieldGroupProps,
type TimeFieldInputProps,
type TimeFieldSegmentProps,
} from "@heroui-vue/components";
import {
Time,
CalendarDateTime,
CalendarDate,
parseZonedDateTime,
} from "@internationalized/date";
const values: TimeValue[] = [
new Time(9, 30),
new CalendarDateTime(2024, 2, 10, 9, 30),
parseZonedDateTime("2024-01-01T09:30+08:00[Asia/Shanghai]"),
];
const props: TimeFieldProps = {
modelValue: values[0],
value: null,
defaultValue: values[1],
placeholderValue: values[2],
minValue: new Time(9),
maxValue: new Time(17),
granularity: "second",
hourCycle: 24,
shouldForceLeadingZeros: true,
form: "appointment",
locale: "zh-CN",
dir: "rtl",
validate: (value) => (value ? null : "Missing"),
"onUpdate:modelValue": (value) => {
const t: TimeValue | null = value;
void t;
},
onChange: (value) => {
const t: TimeValue | null = value;
void t;
},
};
const group: TimeFieldGroupProps = { variant: "secondary", fullWidth: true };
const input: TimeFieldInputProps = { as: "div" };
const segment: TimeFieldSegmentProps = {
segment: {
part: "hour",
type: "hour",
value: "09",
text: "09",
isEditable: true,
isPlaceholder: false,
},
};
// @ts-expect-error values are immutable internationalized time values, not strings
const string: TimeFieldProps = { modelValue: "09:30" };
// @ts-expect-error a plain date has no time
const date: TimeFieldProps = { modelValue: new CalendarDate(2024, 2, 10) };
// @ts-expect-error day granularity belongs to DateField
const day: TimeFieldProps = { granularity: "day" };
// @ts-expect-error no arbitrary visual variant
const variant: TimeFieldGroupProps = { variant: "outline" };
// @ts-expect-error no arbitrary hour cycle
const cycle: TimeFieldProps = { hourCycle: 23 };
// @ts-expect-error TimeField is not a range
const range: TimeFieldProps = { modelValue: values };
// @ts-expect-error real segment object is required
const badSegment: TimeFieldSegmentProps = { segment: "hour" };
void [
TimeField,
TimeFieldRoot,
TimeFieldGroup,
TimeFieldInput,
TimeFieldSegment,
TimeFieldInputContainer,
TimeFieldPrefix,
TimeFieldSuffix,
timeFieldVariants({ fullWidth: true }),
props,
group,
input,
segment,
string,
date,
day,
variant,
cycle,
range,
badSegment,
];