feat: establish shared calendar range selection foundation

This commit is contained in:
maoyingjie
2026-10-25 10:22:22 +08:00
parent 5c4375a98a
commit cfc97fdc07
27 changed files with 2475 additions and 401 deletions
+6 -1
View File
@@ -1,5 +1,9 @@
<script setup lang="ts">
import { ref } from "vue";
import RangeCalendarFoundationLab from "./RangeCalendarFoundationLab.vue";
const rangeFoundation =
typeof window !== "undefined" &&
new URLSearchParams(window.location.search).has("range-calendar-foundation");
import SelectLifecycle from "../../../packages/vue/tests/fixtures/SelectLifecycle.vue";
const selectLifecycle =
typeof window !== "undefined" &&
@@ -31,7 +35,8 @@ function save() {
}
</script>
<template>
<SelectLifecycle v-if="selectLifecycle" />
<RangeCalendarFoundationLab v-if="rangeFoundation" />
<SelectLifecycle v-else-if="selectLifecycle" />
<ScrollTabsLab v-else-if="scrollTabsLab" />
<OverlayAnimationLab v-else-if="animationLab" />
<OverlayComponentsLab v-else-if="componentsLab" />
@@ -0,0 +1,146 @@
<script setup lang="ts">
import { shallowRef } from "vue";
import { CalendarDate } from "@internationalized/date";
import Range from "../../../packages/vue/tests/fixtures/RangeCalendarFoundation.vue";
import {
Button,
CalendarGrid,
CalendarGridBody,
CalendarGridHeader,
CalendarHeader,
CalendarHeading,
CalendarNavButton,
} from "@heroui-vue/components";
import type { CalendarRangeModel } from "../../../packages/vue/src/components/date/range-selection";
const initial = new CalendarDate(2024, 2, 10);
const value = shallowRef<CalendarRangeModel>(null),
changes = shallowRef(0),
rejected = shallowRef(0);
const initialRange = { start: initial, end: initial.add({ days: 5 }) };
</script>
<template>
<main class="range-foundation-lab">
<h1>RangeCalendar · 私有基建验收</h1>
<p>尚未公开组件;这里只验证共享日期视图、范围状态和手势。</p>
<div class="range-lab-grid">
<section id="range-basic">
<h2>选择 / 拖动 / 键盘</h2>
<Range
v-model="value"
:default-focused-value="initial"
time-zone="UTC"
aria-label="基础日期范围"
@change="changes++"
/>
<output>
已接受:{{ value ? `${value.start} → ${value.end}` : "空" }};提交
{{ changes }} 次
</output>
<Button
size="sm"
variant="secondary"
@click="
value = null;
changes = 0;
"
>
清空接受值
</Button>
</section>
<section id="range-barrier">
<h2>12 日不可用,禁止跨越</h2>
<Range
:default-focused-value="initial"
time-zone="UTC"
aria-label="不可用日期范围"
:is-date-unavailable="(d) => d.day === 12"
/>
</section>
<section id="range-rejected">
<h2>受控拒绝(拖动端点可重试)</h2>
<Range
:model-value="initialRange"
:default-focused-value="initial"
time-zone="UTC"
aria-label="拒绝提案的日期范围"
@change="rejected++"
/>
<output>拒绝提案 {{ rejected }} 次</output>
</section>
<section id="range-multiple">
<h2>两个月共享同一范围 / 焦点</h2>
<Range
:default-focused-value="initial"
:visible-duration="{ months: 2 }"
selection-alignment="start"
class="range-lab-wide"
aria-label="两个月的日期范围"
>
<CalendarHeader>
<CalendarHeading />
<CalendarNavButton slot="previous" />
<CalendarNavButton slot="next" />
</CalendarHeader>
<div class="range-lab-months">
<CalendarGrid>
<CalendarGridHeader />
<CalendarGridBody />
</CalendarGrid>
<CalendarGrid :offset="{ months: 1 }">
<CalendarGridHeader />
<CalendarGridBody />
</CalendarGrid>
</div>
</Range>
</section>
</div>
</main>
</template>
<style>
.range-foundation-lab {
padding: 32px;
font-family: Inter, sans-serif;
color: var(--foreground);
background: var(--background);
min-height: 100vh;
}
.range-foundation-lab h1 {
font-size: 24px;
margin-bottom: 8px;
}
.range-foundation-lab h2 {
font-size: 14px;
margin-bottom: 20px;
}
.range-foundation-lab p {
color: var(--muted);
margin-bottom: 28px;
}
.range-lab-grid {
display: flex;
flex-wrap: wrap;
gap: 40px;
align-items: flex-start;
}
.range-lab-grid section {
padding: 20px;
border: 1px solid var(--border);
border-radius: 16px;
}
.range-lab-grid output {
display: block;
margin: 16px 0;
font-size: 12px;
}
.range-lab-wide {
width: 524px;
max-width: 100%;
}
.range-lab-months {
display: flex;
gap: 20px;
}
.range-lab-months > table {
width: 252px;
}
</style>
+10 -13
View File
@@ -10,11 +10,8 @@ body {
margin: 0;
font-family: "Avenir Next", "Segoe UI", "PingFang SC", sans-serif;
}
button,
input {
font: inherit;
}
a {
.lab > header a,
.lab .text-link {
color: inherit;
text-decoration: none;
}
@@ -26,7 +23,7 @@ a {
background 0.2s,
color 0.2s;
}
header {
.lab > header {
max-width: 1240px;
margin: auto;
padding: 28px 48px;
@@ -53,7 +50,7 @@ header {
background: var(--default);
margin-left: 8px;
}
nav {
.lab > header > nav {
display: flex;
gap: 30px;
font-size: 14px;
@@ -65,7 +62,7 @@ nav {
font-size: 13px;
color: var(--muted);
}
main {
.lab > main {
max-width: 1240px;
margin: auto;
padding: 0 48px;
@@ -78,7 +75,7 @@ main {
color: var(--muted);
margin: 0 0 22px;
}
h1 {
.lab h1 {
font-size: clamp(40px, 5.4vw, 68px);
font-weight: 650;
line-height: 1.18;
@@ -249,22 +246,22 @@ footer {
}
}
@media (max-width: 640px) {
header {
.lab > header {
padding: 20px 22px;
}
nav {
.lab > header > nav {
display: none;
}
.theme {
font-size: 12px;
}
main {
.lab > main {
padding: 0 22px;
}
.intro {
padding: 50px 0;
}
h1 {
.lab h1 {
letter-spacing: -1.5px;
}
.grid {