Repository: ionic-team/ionic-framework
File: core/src/components/datetime/datetime.tsx (TypeScript)

Code before:

            const dateIsoString = convertDataToISO(referenceParts);
            let isCalDayDisabled = isCalMonthDisabled || disabled;

            if (!isCalDayDisabled && isDateEnabled !== undefined) {
              try {
                /**
                 * The `isDateEnabled` implementation is try-catch wrapped
                 * to prevent exceptions in the user's function from
                 * interrupting the calendar rendering.
                 */
                isCalDayDisabled = !isDateEnabled(dateIsoString);
              } catch (e) {
                printIonError(
                  'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
                  e
                );
              }
            }

            let dateStyle: DatetimeHighlightStyle | undefined = undefined;

            /**
             * Custom highlight styles should not override the style for selected dates,
             * nor apply to "filler days" at the start of the grid.
             */
            if (highlightedDates !== undefined && !isActive && day !== null) {
              if (Array.isArray(highlightedDates)) {
                const matchingHighlight = highlightedDates.find((hd) => hd.date === dateIsoString);
                if (matchingHighlight) {
                  dateStyle = {
                    color: matchingHighlight.color,
                    backgroundColor: matchingHighlight.backgroundColor,
                  } as DatetimeHighlightStyle;
                }
              } else {
                /**
                 * Wrap in a try-catch to prevent exceptions in the user's function
                 * from interrupting the calendar's rendering.
                 */
                try {
                  dateStyle = highlightedDates(dateIsoString);
                } catch (e) {
                  printIonError(
                    'Exception thrown from provided `highlightedDates` callback. Please check your function and try again.',
                    e
                  );
                }
              }
            }


Review comment (suggestion):
Is it possible to pull this out into a separate method/function? This `renderMonth` method is getting pretty long.

Code after:
            const dateIsoString = convertDataToISO(referenceParts);
            let isCalDayDisabled = isCalMonthDisabled || disabled;

            if (!isCalDayDisabled && isDateEnabled !== undefined) {
              try {
                /**
                 * The `isDateEnabled` implementation is try-catch wrapped
                 * to prevent exceptions in the user's function from
                 * interrupting the calendar rendering.
                 */
                isCalDayDisabled = !isDateEnabled(dateIsoString);
              } catch (e) {
                printIonError(
                  'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
                  el,
                  e
                );
              }
            }

            let dateStyle: DatetimeHighlightStyle | undefined = undefined;

            /**
             * Custom highlight styles should not override the style for selected dates,
             * nor apply to "filler days" at the start of the grid.
             */
            if (highlightedDates !== undefined && !isActive && day !== null) {
              dateStyle = getHighlightStyles(highlightedDates, dateIsoString, el);
            }

            return (
              <button
                tabindex="-1"
                data-day={day}
                data-month={month}
                data-year={year}
                data-index={index}
                data-day-of-week={dayOfWeek}
                disabled={isCalDayDisabled}
                class={{
                  'calendar-day-padding': day === null,
                  'calendar-day': true,
                  'calendar-day-active': isActive,
                  'calendar-day-today': isToday,
                }}
                style={
                  dateStyle && {
                    color: dateStyle.textColor,
                  }
                }
                aria-selected={ariaSelected}