feat: migrate public TimeField with shared date input parts

This commit is contained in:
maoyingjie
2026-10-26 17:56:41 +08:00
parent d74ad1b711
commit 97263d82e1
45 changed files with 2415 additions and 61 deletions
+10
View File
@@ -40,6 +40,16 @@ for (const id of process.argv.slice(2)) {
.includes("hv-list-box-item__indicator"),
);
}
if (id === "time-field") {
assert(lib.TimeField === lib.TimeFieldRoot);
assert(lib.TimeFieldGroup === lib.DateInputGroup);
assert(lib.TimeFieldInput === lib.DateInputGroupInput);
assert(
lib
.timeFieldVariants({ fullWidth: true })
.includes("hv-time-field--full-width"),
);
}
if (id === "slider")
assert(lib.sliderVariants().thumb().includes("hv-slider__thumb"));
if (id === "select")
+19
View File
@@ -354,5 +354,24 @@
".hv-color-swatch--xl",
"repeating-conic-gradient"
]
},
"time-field": {
"exports": [
"TimeField",
"TimeFieldRoot",
"TimeFieldGroup",
"TimeFieldInput",
"TimeFieldSegment",
"TimeFieldInputContainer",
"TimeFieldPrefix",
"TimeFieldSuffix",
"timeFieldVariants"
],
"css": [
".hv-time-field",
".hv-time-field--full-width",
".hv-date-input-group",
".hv-date-input-group__segment"
]
}
}
+98
View File
@@ -0,0 +1,98 @@
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,
];