Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CalendarPickerView): title support boolean value to control whether to hide #6676

Merged
merged 7 commits into from
Jul 23, 2024
6 changes: 4 additions & 2 deletions src/components/calendar-picker-view/calendar-picker-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type CalendarPickerViewRef = {
}

export type CalendarPickerViewProps = {
title?: React.ReactNode
title?: React.ReactNode | boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true 算什么?这里改成 React.ReactNode | false

confirmText?: string
weekStartsOn?: 'Monday' | 'Sunday'
renderTop?: (date: Date) => React.ReactNode
Expand Down Expand Up @@ -117,6 +117,8 @@ export const CalendarPickerView = forwardRef<
dayjs(dateRange ? dateRange[0] : today).date(1)
)

const isDisplayHeader = useMemo(() => props.title !== false, [props.title])
crazyair marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 useMemo 可以不写, !== false 速度比 func call 快多了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外直接叫 showHeader 就行了


// =============================== Scroll ===============================
const context = useContext(Context)
const scrollTo = useSyncScroll(current, context.visible, bodyRef)
Expand Down Expand Up @@ -356,7 +358,7 @@ export const CalendarPickerView = forwardRef<
return withNativeProps(
props,
<div className={classPrefix}>
{header}
{isDisplayHeader && header}
{mark}
{body}
</div>
Expand Down
Loading