Tuỳ chỉnh Ô Ngày
Sử dụng render prop của component Day để tuỳ chỉnh từng ô ngày. Điều này hữu ích để thêm chỉ báo sự kiện, áp dụng kiểu dáng tuỳ chỉnh dựa trên thuộc tính ngày, hoặc thay thế hoàn toàn cách hiển thị ngày.
import { useState } from "react";import { DatePicker } from "react-date-range-picker-tailwind3";
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
Day Render Props
| Prop | Type | Mô tả |
|---|---|---|
date | Date | Đối tượng ngày tháng |
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 hay không |
isDisabled | boolean | Liệu ngày này có bị vô hiệu hoá hay không |
isInRange | boolean | Liệu ngày này có nằm trong khoảng đã chọn không |
isRangeStart | boolean | Liệu đây có phải là ngày bắt đầu khoảng |
isRangeEnd | boolean | Liệu đây có phải là ngày kết thúc khoảng |
isInHoverRange | boolean | Liệu ngày này có nằm trong khoảng xem trước khi di chuột không |
isHoverTarget | boolean | Liệu đây có phải là điểm cuối của việc 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 hay không |
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 di chuột vào |
onMouseLeave | () => void | Trình xử lý sự kiện di chuột ra |