Ô Ngày Tùy Chỉnh

Tùy chỉnh cách mỗi ngày được hiển thị bằng cách sử dụng render props GridDay. Điều này cho phép bạn thêm các chỉ báo sự kiện, kiểu dáng tùy chỉnh hoặc bất kỳ nội dung bổ sung nào vào từng ô ngày.

import { useState } from "react";
import { DatePicker } from "react-date-range-picker-tailwind4";
const eventDates = new Set([5, 12, 18, 25]);
function CompoundCustomDay() {
const [value, setValue] = useState<Date | null>(null);
return (
<DatePicker.Root value={value} onChange={setValue} inline>
<DatePicker.Content>
<DatePicker.Header>
<DatePicker.PrevButton />
<DatePicker.Title />
<DatePicker.NextButton />
</DatePicker.Header>
<DatePicker.Grid>
{({ date }) => (
<DatePicker.Day date={date}>
{({ day, isDisabled, isSelected, isToday, onClick, onMouseEnter, onMouseLeave }) => (
<button
type="button"
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
disabled={isDisabled}
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
width: 36,
height: 36,
border: "none",
borderRadius: 6,
cursor: isDisabled ? "default" : "pointer",
background: isSelected ? "#3b82f6" : "transparent",
color: isSelected ? "#fff" : isToday ? "#2563eb" : undefined,
fontWeight: isToday || isSelected ? 600 : 400,
fontSize: 13,
position: "relative",
}}
>
{day}
{eventDates.has(date.getDate()) && (
<span
style={{
position: "absolute",
bottom: 2,
width: 4,
height: 4,
borderRadius: "50%",
background: isSelected ? "#fff" : "#f59e0b",
}}
/>
)}
</button>
)}
</DatePicker.Day>
)}
</DatePicker.Grid>
</DatePicker.Content>
</DatePicker.Root>
);
}
March 2026
Su
Mo
Tu
We
Th
Fr
Sa

Render Props cho Ngày

Thuộc tínhKiểuMô tả
dateDateĐối tượng Date
daynumberNgày trong tháng (1-31)
isTodaybooleanLiệu đây có phải là ngày hôm nay
isSelectedbooleanLiệu ngày này có được chọn
isDisabledbooleanLiệu ngày này có bị vô hiệu hóa
isInRangebooleanLiệu ngày này có nằm trong một khoảng đã chọn
isRangeStartbooleanLiệu đây có phải là điểm bắt đầu của khoảng
isRangeEndbooleanLiệu đây có phải là điểm kết thúc của khoảng
isInHoverRangebooleanLiệu ngày này có nằm trong khoảng xem trước khi di chuột
isHoverTargetbooleanLiệu đây có phải là điểm cuối khi di chuột
isOutsideDaybooleanLiệu ngày này có thuộc về một tháng liền kề
isHighlightedbooleanLiệu ngày này có dấu chấm nổi bật
isFocusedbooleanLiệu ngày này có đang được tập trung bằng bàn phím
onClick() => voidTrình xử lý sự kiện click
onMouseEnter() => voidTrình xử lý sự kiện mouse enter
onMouseLeave() => voidTrình xử lý sự kiện mouse leave