diff --git a/docs-site/src/examples/ts/holidayDates.tsx b/docs-site/src/examples/ts/holidayDates.tsx index e8a091f68..90013a1fa 100644 --- a/docs-site/src/examples/ts/holidayDates.tsx +++ b/docs-site/src/examples/ts/holidayDates.tsx @@ -4,14 +4,18 @@ type Holiday = { }; const HolidayDates = () => { - const [selectedDate, setSelectedDate] = useState(new Date()); + const today = new Date(); + const [selectedDate, setSelectedDate] = useState(today); const holidays: Holiday[] = [ - { date: "2023-08-15", holidayName: "India's Independence Day" }, - { date: "2023-12-31", holidayName: "New Year's Eve" }, - { date: "2023-12-25", holidayName: "Christmas" }, - { date: "2024-01-01", holidayName: "New Year's Day" }, - { date: "2023-11-23", holidayName: "Thanksgiving Day" }, + { + date: `${today.getFullYear()}-03-15`, + holidayName: "India's Independence Day", + }, + { date: `${today.getFullYear()}-12-31`, holidayName: "New Year's Eve" }, + { date: `${today.getFullYear()}-12-25`, holidayName: "Christmas" }, + { date: `${today.getFullYear()}-01-01`, holidayName: "New Year's Day" }, + { date: `${today.getFullYear()}-11-23`, holidayName: "Thanksgiving Day" }, ]; return ( diff --git a/src/day.tsx b/src/day.tsx index 28a16c477..04c8c9a75 100644 --- a/src/day.tsx +++ b/src/day.tsx @@ -484,33 +484,27 @@ export default class Day extends Component { return `${prefix} ${formatDate(day, "PPPP", this.props.locale)}`; }; + getHolidayTitle = () => { + const { day, holidays } = this.props; + const compareDt = formatDate(day, "MM.dd.yyyy"); + return holidays?.has(compareDt) + ? holidays.get(compareDt)?.holidayNames.join(", ") + : ""; + }; + // A function to return the holiday's name as title's content getTitle = () => { - const { day, holidays = new Map(), excludeDates } = this.props; - const compareDt = formatDate(day, "MM.dd.yyyy"); - const titles = []; - if (holidays.has(compareDt)) { - titles.push(...holidays.get(compareDt).holidayNames); - } - if (this.isExcluded()) { - titles.push( - excludeDates - ?.filter((excludeDate) => { - if (excludeDate instanceof Date) { - return isSameDay(excludeDate, day); - } - return isSameDay(excludeDate?.date, day); - }) - .map((excludeDate) => { - if (excludeDate instanceof Date) { - return undefined; - } - return excludeDate?.message; - }), - ); - } - // I'm not sure that this is a right output, but all tests are green - return titles.join(", "); + const { day, excludeDates } = this.props; + + return this.isExcluded() + ? excludeDates + ?.flatMap((excludeDate) => + !(excludeDate instanceof Date) && isSameDay(excludeDate?.date, day) + ? excludeDate?.message + : [], + ) + .join(", ") + : ""; }; getTabIndex = () => { @@ -588,31 +582,32 @@ export default class Day extends Component { : getDate(this.props.day); }; - render = () => ( + render = () => { + const holidayTitle = this.getHolidayTitle(); // TODO: Use