🎛️ 优化日期选择器视觉

This commit is contained in:
2026-06-05 13:08:32 +08:00
parent 0be56a5b0c
commit 0a3246dcb4
+107 -10
View File
@@ -1,34 +1,33 @@
<template> <template>
<div class="grid w-full grid-cols-3 gap-2 sm:w-auto"> <div class="native-date-strip" :aria-label="ariaLabel">
<select <select
:value="parts.year" :value="parts.year"
class="h-12 min-w-0 rounded-[30px] border px-3 text-sm" class="native-date-part native-date-year"
:class="fieldClass"
:aria-label="`${ariaLabel}年`" :aria-label="`${ariaLabel}年`"
@change="updatePart('year', ($event.target as HTMLSelectElement).value)" @change="updatePart('year', ($event.target as HTMLSelectElement).value)"
> >
<option v-for="year in years" :key="year" :value="year">{{ year }}</option> <option v-for="year in years" :key="year" :value="year">{{ year }}</option>
</select> </select>
<span class="native-date-separator">/</span>
<select <select
:value="parts.month" :value="parts.month"
class="h-12 min-w-0 rounded-[30px] border px-3 text-sm" class="native-date-part native-date-month"
:class="fieldClass"
:aria-label="`${ariaLabel}月`" :aria-label="`${ariaLabel}月`"
@change="updatePart('month', ($event.target as HTMLSelectElement).value)" @change="updatePart('month', ($event.target as HTMLSelectElement).value)"
> >
<option v-for="month in months" :key="month" :value="month"> <option v-for="month in months" :key="month" :value="month">
{{ month.toString().padStart(2, '0') }} {{ month.toString().padStart(2, '0') }}
</option> </option>
</select> </select>
<span class="native-date-separator">/</span>
<select <select
:value="parts.day" :value="parts.day"
class="h-12 min-w-0 rounded-[30px] border px-3 text-sm" class="native-date-part native-date-day"
:class="fieldClass"
:aria-label="`${ariaLabel}日`" :aria-label="`${ariaLabel}日`"
@change="updatePart('day', ($event.target as HTMLSelectElement).value)" @change="updatePart('day', ($event.target as HTMLSelectElement).value)"
> >
<option v-for="day in days" :key="day" :value="day"> <option v-for="day in days" :key="day" :value="day">
{{ day.toString().padStart(2, '0') }} {{ day.toString().padStart(2, '0') }}
</option> </option>
</select> </select>
</div> </div>
@@ -95,3 +94,101 @@ const updatePart = (part: DatePart, value: string) => {
emit('change') emit('change')
} }
</script> </script>
<style scoped>
.native-date-strip {
display: inline-flex;
width: 100%;
min-height: 2.75rem;
align-items: center;
justify-content: center;
gap: 0.15rem;
border: 1px solid transparent;
border-radius: 30px;
background: rgba(237, 244, 245, 0.52);
color: #2d4650;
font-variant-numeric: tabular-nums;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.62);
transition:
background 180ms ease,
border-color 180ms ease,
box-shadow 180ms ease,
transform 180ms ease;
}
.native-date-strip:hover,
.native-date-strip:focus-within {
border-color: rgba(143, 178, 191, 0.7);
background: rgba(226, 236, 238, 0.78);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.72),
0 10px 24px rgba(126, 149, 154, 0.16);
}
.native-date-strip:focus-within {
transform: translateY(-1px);
}
.native-date-part {
height: 2.65rem;
appearance: none;
border: 0;
border-radius: 0;
background: transparent;
color: inherit;
cursor: pointer;
text-align: center;
font-size: 0.95rem;
font-weight: 600;
line-height: 1;
outline: none;
}
.native-date-part:focus-visible {
border-radius: 999px;
box-shadow: 0 0 0 2px rgba(143, 178, 191, 0.58);
}
.native-date-year {
width: 4.4rem;
}
.native-date-month,
.native-date-day {
width: 2.65rem;
}
.native-date-separator {
color: #789096;
font-size: 0.95rem;
opacity: 0.78;
pointer-events: none;
}
.dark .native-date-strip {
background: rgba(38, 57, 65, 0.62);
color: #d8e3e5;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.dark .native-date-strip:hover,
.dark .native-date-strip:focus-within {
border-color: rgba(113, 153, 168, 0.72);
background: rgba(45, 71, 81, 0.76);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.1),
0 10px 24px rgba(4, 10, 14, 0.28);
}
.dark .native-date-separator {
color: #aabdc2;
}
@media (min-width: 640px) {
.native-date-strip {
width: max-content;
min-width: 12rem;
padding-inline: 0.75rem;
}
}
</style>