From 5866c281bdd13fd6a1f50f8aa0ae5a1071000258 Mon Sep 17 00:00:00 2001 From: Avan Date: Wed, 23 Oct 2024 15:41:09 +0800 Subject: [PATCH] refactor: optimize code structure --- .../calendar-picker-view.tsx | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/components/calendar-picker-view/calendar-picker-view.tsx b/src/components/calendar-picker-view/calendar-picker-view.tsx index 1012265a40..a0b686217c 100644 --- a/src/components/calendar-picker-view/calendar-picker-view.tsx +++ b/src/components/calendar-picker-view/calendar-picker-view.tsx @@ -120,8 +120,6 @@ export const CalendarPickerView = forwardRef< ) const showHeader = props.title !== false - const showTop = props.renderTop !== false - const showBottom = props.renderBottom !== false // =============================== Scroll =============================== const context = useContext(Context) @@ -247,33 +245,41 @@ export const CalendarPickerView = forwardRef< (minDay && d.isBefore(minDay, 'day')) const renderTop = () => { - const top = ( - props.renderTop as CalendarPickerViewColumRender - )?.(d.toDate()) + if (props.renderTop === false) return null + + const contentWrapper = (content: ReactNode) => ( +
{content}
+ ) + + const top = props.renderTop?.(d.toDate()) if (top) { - return top + return contentWrapper(top) } if (props.selectionMode === 'range') { if (isBegin) { - return locale.Calendar.start + contentWrapper(locale.Calendar.start) } if (isEnd) { - return locale.Calendar.end + contentWrapper(locale.Calendar.end) } } if (d.isSame(today, 'day') && !isSelect) { - return locale.Calendar.today + return contentWrapper(locale.Calendar.today) } } const renderBottom = () => { + if (props.renderBottom === false) return null + return ( - props.renderBottom as CalendarPickerViewColumRender - )?.(d.toDate()) +
+ {props.renderBottom?.(d.toDate())} +
+ ) } return ( @@ -329,21 +335,13 @@ export const CalendarPickerView = forwardRef< } }} > - {showTop && ( -
- {renderTop()} -
- )} + {renderTop()}
{props.renderDate ? props.renderDate(d.toDate()) : d.date()}
- {showBottom && ( -
- {renderBottom()} -
- )} + {renderBottom()} ) })}