Cài đặt
Chạy lệnh này trong app, sau shadcn-vue init và theme Beehexa (Button › Code):
npx shadcn-vue@latest add https://beehexa.design/r/calendar.json
Lệnh này cài thêm Button và Native select, hai component mà Lịch dùng.
Cách dùng
Ngày là giá trị của @internationalized/date, như trong reka-ui.
<script setup lang="ts">
import type { DateValue } from '@internationalized/date'
import type { Ref } from 'vue'
import { getLocalTimeZone, today } from '@internationalized/date'
import { ref } from 'vue'
import { Calendar } from '@/components/ui/calendar'
const value = ref(today(getLocalTimeZone())) as Ref<DateValue>
</script>
<template>
<Calendar v-model="value" locale="vi" :min-value="today(getLocalTimeZone())" />
</template>
Prop
| Phần | Prop | Giá trị | Ghi chú |
|---|---|---|---|
Calendar |
v-model |
DateValue |
Ngày đã chọn |
Calendar |
min-value, max-value |
DateValue |
Ngày nằm ngoài bị tắt |
Calendar |
is-date-unavailable |
(date) => boolean |
Chữ xám và gạch ngang |
Calendar |
is-date-disabled |
(date) => boolean |
Chữ xám |
Calendar |
layout |
month-and-year, month-only, year-only |
Ô chọn native ở phần đầu |
Calendar |
year-range |
DateValue[] |
Các năm trong ô chọn năm. Mặc định từ 100 năm trước tới 10 năm sau, trong khoảng min-value và max-value |
Calendar |
number-of-months |
số | Số tháng nằm cạnh nhau |
Calendar |
locale |
chuỗi | Tên thứ, tên tháng, ngày đầu tuần |
Calendar |
initial-focus |
boolean | Focus vào ngày đã chọn, hoặc hôm nay, khi hiện. Dùng trong popover |
Calendar |
slot calendar-heading, calendar-prev-icon, calendar-next-icon |
Thay tiêu đề hoặc mũi tên |
Các phần (CalendarCell, CalendarCellTrigger, CalendarGrid, CalendarHeader, CalendarHeading, CalendarHeadCell, CalendarPrevButton, CalendarNextButton và các hàng của lưới) được export để dựng bố cục riêng.
Dựng từ
Bọc Calendar của reka-ui theo API Calendar của shadcn-vue. reka-ui lo role của lưới, di chuyển bằng bàn phím, locale và quy tắc ngày bị tắt, ngày không khả dụng. Beehexa thêm style. Các ngày dùng style nút Subtle của Beehexa; ô chọn tháng và năm là Native select của Beehexa.
Giới hạn
- Ô chọn tháng và năm vẽ tên ngắn đè lên một ô chọn có chữ trong suốt, giống shadcn-vue.