日付セルのカスタマイズ
Grid と Day のレンダープロップを使用して、各日付のレンダリング方法をカスタマイズします。これにより、イベントインジケーター、カスタムスタイリング、またはその他の追加コンテンツを個々の日付セルに追加できます。
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
Dayレンダープロップ
| プロップ | 型 | 説明 |
|---|---|---|
date | Date | Dateオブジェクト |
day | number | 月の日 (1-31) |
isToday | boolean | 今日かどうか |
isSelected | boolean | この日が選択されているかどうか |
isDisabled | boolean | この日が無効になっているかどうか |
isInRange | boolean | この日が選択された範囲内にあるかどうか |
isRangeStart | boolean | これが範囲の開始日かどうか |
isRangeEnd | boolean | これが範囲の終了日かどうか |
isInHoverRange | boolean | この日がホバープレビュー範囲内にあるかどうか |
isHoverTarget | boolean | これがホバーの終点かどうか |
isOutsideDay | boolean | この日が隣接する月に属しているかどうか |
isHighlighted | boolean | この日にハイライトドットが付いているかどうか |
isFocused | boolean | この日にキーボードフォーカスが当たっているかどうか |
onClick | () => void | クリックハンドラ |
onMouseEnter | () => void | マウスエンターハンドラ |
onMouseLeave | () => void | マウスリーブハンドラ |