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,48 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import type { DateValue } from "@internationalized/date";
import EmptyDateBridge from "../../src/components/date/EmptyDateBridge";
import DateFieldFoundation from "./DateFieldFoundation.vue";
import { useAcceptedDateValue } from "../../src/components/date/model";
import { serializeDateValue } from "../../src/components/date/value";
import { useChoiceForm } from "../../src/components/choice/shared";
const props = defineProps<{
modelValue?: DateValue | null;
defaultValue?: DateValue;
defaultPlaceholder?: DateValue;
name?: string;
disabled?: boolean;
readonly?: boolean;
}>();
const emit = defineEmits<{ "update:modelValue": [value: DateValue | null] }>();
const accepted = useAcceptedDateValue({
value: () => props.modelValue,
defaultValue: () => props.defaultValue,
onChange: (value) => emit("update:modelValue", value),
disabled: () => !!props.disabled,
readOnly: () => !!props.readonly,
});
const native = ref<HTMLInputElement>();
const serialized = computed(() => serializeDateValue(accepted.value.value));
useChoiceForm(native, accepted.reset, () => {});
</script>
<template>
<div>
<DateFieldFoundation
:model-value="accepted.wire.value"
:default-placeholder="defaultPlaceholder"
:disabled="disabled"
:readonly="readonly"
@update:model-value="accepted.request"
>
<EmptyDateBridge :revision="accepted.emptyRevision.value" />
</DateFieldFoundation>
<input
ref="native"
type="hidden"
:name="name"
:value="serialized"
:disabled="disabled"
/>
</div>
</template>
+87
View File
@@ -0,0 +1,87 @@
<script setup lang="ts">
import {
CalendarRoot,
CalendarHeader,
CalendarHeading,
CalendarPrev,
CalendarNext,
CalendarGrid,
CalendarGridHead,
CalendarGridRow,
CalendarHeadCell,
CalendarGridBody,
CalendarCell,
CalendarCellTrigger,
type CalendarRootProps,
} from "reka-ui";
import type { DateValue } from "@internationalized/date";
defineOptions({ inheritAttrs: false });
withDefaults(
defineProps<
Pick<
CalendarRootProps,
| "modelValue"
| "defaultValue"
| "defaultPlaceholder"
| "locale"
| "disabled"
| "readonly"
| "isDateDisabled"
| "isDateUnavailable"
| "multiple"
| "numberOfMonths"
| "weekStartsOn"
| "minValue"
| "maxValue"
| "fixedWeeks"
>
>(),
{ modelValue: undefined, locale: "en-US" },
);
const emit = defineEmits<{
"update:modelValue": [value: DateValue | DateValue[] | undefined];
}>();
</script>
<template>
<CalendarRoot
v-slot="{ grid, weekDays }"
v-bind="$attrs"
:model-value="modelValue"
:default-value="defaultValue"
:default-placeholder="defaultPlaceholder"
:locale="locale"
:disabled="disabled"
:readonly="readonly"
:is-date-disabled="isDateDisabled"
:is-date-unavailable="isDateUnavailable"
:multiple="multiple"
:number-of-months="numberOfMonths"
:week-starts-on="weekStartsOn"
:min-value="minValue"
:max-value="maxValue"
:fixed-weeks="fixedWeeks"
@update:model-value="emit('update:modelValue', $event)"
>
<CalendarHeader>
<CalendarPrev aria-label="Previous" />
<CalendarHeading />
<CalendarNext aria-label="Next" />
</CalendarHeader>
<CalendarGrid v-for="month in grid" :key="month.value.toString()">
<CalendarGridHead>
<CalendarGridRow>
<CalendarHeadCell v-for="day in weekDays" :key="day">
{{ day }}
</CalendarHeadCell>
</CalendarGridRow>
</CalendarGridHead>
<CalendarGridBody>
<CalendarGridRow v-for="(week, index) in month.rows" :key="index">
<CalendarCell v-for="day in week" :key="day.toString()" :date="day">
<CalendarCellTrigger :day="day" :month="month.value" />
</CalendarCell>
</CalendarGridRow>
</CalendarGridBody>
</CalendarGrid>
</CalendarRoot>
</template>
+63
View File
@@ -0,0 +1,63 @@
<script setup lang="ts">
import {
DateFieldRoot,
DateFieldInput,
type DateFieldRootProps,
} from "reka-ui";
import type { DateValue } from "@internationalized/date";
defineOptions({ inheritAttrs: false });
withDefaults(
defineProps<
Pick<
DateFieldRootProps,
| "modelValue"
| "defaultValue"
| "defaultPlaceholder"
| "granularity"
| "locale"
| "disabled"
| "readonly"
| "required"
| "name"
| "minValue"
| "maxValue"
| "hideTimeZone"
| "hourCycle"
>
>(),
{ modelValue: undefined, locale: "en-US" },
);
const emit = defineEmits<{
"update:modelValue": [value: DateValue | undefined];
}>();
</script>
<template>
<DateFieldRoot
v-slot="{ segments }"
v-bind="$attrs"
:model-value="modelValue"
:default-value="defaultValue"
:default-placeholder="defaultPlaceholder"
:granularity="granularity"
:locale="locale"
:disabled="disabled"
:readonly="readonly"
:required="required"
:name="name"
:min-value="minValue"
:max-value="maxValue"
:hide-time-zone="hideTimeZone"
:hour-cycle="hourCycle"
aria-label="Date audit"
@update:model-value="emit('update:modelValue', $event)"
>
<slot />
<DateFieldInput
v-for="(segment, index) in segments"
:key="`${segment.part}-${index}`"
:part="segment.part"
>
{{ segment.value }}
</DateFieldInput>
</DateFieldRoot>
</template>