feat: migrate RangeCalendar public components and demos

This commit is contained in:
maoyingjie
2026-10-26 21:25:25 +08:00
parent ebe81f28c7
commit 07f6aeadb6
43 changed files with 2420 additions and 53 deletions
+34
View File
@@ -1813,3 +1813,37 @@ export const timeFieldVariants = tv({
variants: { fullWidth: { false: "", true: "hv-time-field--full-width" } },
});
export type TimeFieldVariants = VariantProps<typeof timeFieldVariants>;
// Ported from HeroUI ce90ea3, Apache-2.0.
export const rangeCalendarVariants = tv({
defaultVariants: {},
slots: {
/** Root range calendar container */
base: "hv-range-calendar",
/** Calendar cell (td) */
cell: "hv-range-calendar__cell",
/** Cell indicator (small dot at bottom of cell) */
cellIndicator: "hv-range-calendar__cell-indicator",
/** Calendar grid (table) */
grid: "hv-range-calendar__grid",
/** Grid body (tbody) */
gridBody: "hv-range-calendar__grid-body",
/** Grid header (thead) */
gridHeader: "hv-range-calendar__grid-header",
/** Grid row (tr) */
gridRow: "hv-range-calendar__grid-row",
/** Calendar header containing heading and navigation */
header: "hv-range-calendar__header",
/** Header cell (th - day names) */
headerCell: "hv-range-calendar__header-cell",
/** Month/year heading text */
heading: "hv-range-calendar__heading",
/** Previous/Next navigation button */
navButton: "hv-range-calendar__nav-button",
/** Navigation button icon */
navButtonIcon: "hv-range-calendar__nav-button-icon",
},
variants: {},
});
export type RangeCalendarVariants = VariantProps<typeof rangeCalendarVariants>;
@@ -489,6 +489,12 @@ export const CalendarCell = defineComponent({
"data-selected": value.isSelected || undefined,
"data-selection-start": value.isSelectionStart || undefined,
"data-selection-end": value.isSelectionEnd || undefined,
"data-selection-in-range":
(ctx.range &&
value.isSelected &&
!value.isSelectionStart &&
!value.isSelectionEnd) ||
undefined,
"data-invalid": value.isInvalid || undefined,
"aria-invalid": value.isInvalid || undefined,
"data-today": value.isToday || undefined,
@@ -566,6 +572,9 @@ export const CalendarCell = defineComponent({
{
class: `hv-${ctx.prefix}__cell-button`,
"data-slot": `${ctx.prefix}-cell-button`,
"data-disabled": value.isDisabled || undefined,
"data-hovered": value.isHovered || undefined,
"data-pressed": value.isPressed || undefined,
"data-selected":
value.isSelectionStart ||
value.isSelectionEnd ||
@@ -0,0 +1,98 @@
<script setup lang="ts">
// Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE.
import { useAttrs } from "vue";
import type { DateValue } from "@internationalized/date";
import {
useRangeCalendar,
type RangeCalendarOptions,
} from "./use-range-calendar";
import {
copyCalendarRange,
type CalendarRangeModel,
} from "../date/range-selection";
import { calendarHeading } from "../date/calendar";
defineOptions({ inheritAttrs: false });
const props = defineProps<RangeCalendarOptions>();
const emit = defineEmits<{
"update:modelValue": [value: CalendarRangeModel];
change: [value: CalendarRangeModel];
"update:focusedValue": [value: DateValue];
focusChange: [value: DateValue];
"update:isYearPickerOpen": [value: boolean];
yearPickerOpenChange: [value: boolean];
}>();
defineSlots<{
default?: (state: {
value: CalendarRangeModel;
anchorDate: import("@internationalized/date").CalendarDate | null;
highlightedRange: CalendarRangeModel;
isDisabled: boolean;
isReadOnly: boolean;
isInvalid: boolean;
focusedValue: DateValue;
visibleRange: { start: DateValue; end: DateValue };
isYearPickerOpen: boolean;
}) => unknown;
}>();
const attrs = useAttrs();
const view = useRangeCalendar(props, emit);
const {
root,
focus,
tabStop,
focusDate,
anchor,
options,
visible,
dir,
disabled,
readOnly,
invalid,
yearOpen,
model,
anchorDate,
highlightedRange,
} = view;
defineExpose({
get element() {
return root.value;
},
focus: () => {
if (tabStop.value) focusDate(tabStop.value, true);
},
});
</script>
<template>
<component
:is="as ?? 'div'"
ref="root"
v-bind="attrs"
class="hv-range-calendar"
:class="{
'hv-range-calendar--week-view': visible.unit === 'weeks',
'hv-range-calendar--day-view': visible.unit === 'days',
}"
role="group"
:dir="dir"
data-slot="range-calendar"
:aria-label="
(attrs['aria-label'] as string | undefined) ??
(attrs['aria-labelledby'] ? undefined : calendarHeading(anchor, options))
"
:aria-disabled="disabled || undefined"
:data-disabled="disabled || undefined"
:aria-invalid="invalid || undefined"
>
<slot
:value="copyCalendarRange(model.value.value)"
:anchor-date="anchorDate?.copy() ?? null"
:highlighted-range="copyCalendarRange(highlightedRange)"
:is-disabled="disabled"
:is-read-only="readOnly"
:is-invalid="invalid"
:focused-value="focus.copy()"
:visible-range="{ start: visible.start.copy(), end: visible.end.copy() }"
:is-year-picker-open="yearOpen"
/>
</component>
</template>
@@ -0,0 +1,21 @@
// Shared parts derive their namespace and state from the nearest calendar owner.
export {
CalendarHeader as RangeCalendarHeader,
CalendarHeading as RangeCalendarHeading,
CalendarNavButton as RangeCalendarNavButton,
CalendarGrid as RangeCalendarGrid,
CalendarGridHeader as RangeCalendarGridHeader,
CalendarGridBody as RangeCalendarGridBody,
CalendarHeaderCell as RangeCalendarHeaderCell,
CalendarCellIndicator as RangeCalendarCellIndicator,
} from "../calendar/parts";
import { CalendarCell } from "../calendar/parts";
// Vue's options-component expose() is runtime-only in inferred declarations.
// Preserve the existing typed props/slots while declaring its actual public ref.
export const RangeCalendarCell = CalendarCell as typeof CalendarCell & {
new (): InstanceType<typeof CalendarCell> & {
readonly element: HTMLButtonElement | undefined;
focus: () => void;
};
};
@@ -27,7 +27,7 @@ import {
import { calendarDayState, dateValueKey } from "../date/value";
import { calendarDuration, calendarRange } from "../date/calendar";
/** Private schema for the next public shell; not exported from the package root. */
/** Public range selection options; geometry and focus share the Calendar owner. */
export interface RangeCalendarOptions extends Omit<
CalendarViewProps,
"isDateUnavailable"
+38
View File
@@ -1137,3 +1137,41 @@ export type {
TimeFieldPrefixProps,
TimeFieldSuffixProps,
} from "./types";
/* RangeCalendar: shared calendar geometry, independent accepted range owner. */
export {
default as RangeCalendar,
default as RangeCalendarRoot,
} from "./components/range-calendar/RangeCalendar.vue";
export {
RangeCalendarHeader,
RangeCalendarHeading,
RangeCalendarNavButton,
RangeCalendarGrid,
RangeCalendarGridHeader,
RangeCalendarGridBody,
RangeCalendarHeaderCell,
RangeCalendarCell,
RangeCalendarCellIndicator,
} from "./components/range-calendar/parts";
export type { RangeCalendarOptions } from "./components/range-calendar/use-range-calendar";
export type {
CalendarDateRange,
CalendarRangeModel,
} from "./components/date/range-selection";
export type { CalendarCellState as RangeCalendarCellRenderProps } from "./components/calendar/context";
export { rangeCalendarVariants } from "@heroui-vue/styles";
export type { RangeCalendarVariants } from "@heroui-vue/styles";
export type {
RangeCalendarProps,
RangeCalendarRootProps,
RangeCalendarHeaderProps,
RangeCalendarHeadingProps,
RangeCalendarNavButtonProps,
RangeCalendarGridProps,
RangeCalendarGridHeaderProps,
RangeCalendarGridBodyProps,
RangeCalendarHeaderCellProps,
RangeCalendarCellProps,
RangeCalendarCellIndicatorProps,
} from "./types";
+13
View File
@@ -890,3 +890,16 @@ export type TimeFieldSegmentProps = DateInputGroupSegmentProps;
export type TimeFieldInputContainerProps = DateInputGroupInputContainerProps;
export type TimeFieldPrefixProps = DateInputGroupPrefixProps;
export type TimeFieldSuffixProps = DateInputGroupSuffixProps;
import type RangeCalendar from "./components/range-calendar/RangeCalendar.vue";
export type RangeCalendarProps = InstanceType<typeof RangeCalendar>["$props"];
export type RangeCalendarRootProps = RangeCalendarProps;
export type RangeCalendarHeaderProps = CalendarHeaderProps;
export type RangeCalendarHeadingProps = CalendarHeadingProps;
export type RangeCalendarNavButtonProps = CalendarNavButtonProps;
export type RangeCalendarGridProps = CalendarGridProps;
export type RangeCalendarGridHeaderProps = CalendarGridHeaderProps;
export type RangeCalendarGridBodyProps = CalendarGridBodyProps;
export type RangeCalendarHeaderCellProps = CalendarHeaderCellProps;
export type RangeCalendarCellProps = CalendarCellProps;
export type RangeCalendarCellIndicatorProps = CalendarCellIndicatorProps;