Ô 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 Grid và Day. Đ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ính | Kiểu | Mô tả |
|---|---|---|
date | Date | Đối tượng Date |
day | number | Ngày trong tháng (1-31) |
isToday | boolean | Liệu đây có phải là ngày hôm nay |
isSelected | boolean | Liệu ngày này có được chọn |
isDisabled | boolean | Liệu ngày này có bị vô hiệu hóa |
isInRange | boolean | Liệu ngày này có nằm trong một khoảng đã chọn |
isRangeStart | boolean | Liệu đây có phải là điểm bắt đầu của khoảng |
isRangeEnd | boolean | Liệu đây có phải là điểm kết thúc của khoảng |
isInHoverRange | boolean | Liệu ngày này có nằm trong khoảng xem trước khi di chuột |
isHoverTarget | boolean | Liệu đây có phải là điểm cuối khi di chuột |
isOutsideDay | boolean | Liệu ngày này có thuộc về một tháng liền kề |
isHighlighted | boolean | Liệu ngày này có dấu chấm nổi bật |
isFocused | boolean | Liệu ngày này có đang được tập trung bằng bàn phím |
onClick | () => void | Trình xử lý sự kiện click |
onMouseEnter | () => void | Trình xử lý sự kiện mouse enter |
onMouseLeave | () => void | Trình xử lý sự kiện mouse leave |