-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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): add renderTop and renderBottom hide logic #6735
Changes from 1 commit
58e4ec5
230a831
6f01d6b
7b5bf48
5866c28
b839f9d
78e56c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,9 @@ export type CalendarPickerViewProps = { | |
title?: React.ReactNode | false | ||
confirmText?: string | ||
weekStartsOn?: 'Monday' | 'Sunday' | ||
renderTop?: (date: Date) => React.ReactNode | ||
renderTop?: ((date: Date) => React.ReactNode) | false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加一下对应的测试用例 |
||
renderDate?: (date: Date) => React.ReactNode | ||
renderBottom?: (date: Date) => React.ReactNode | ||
renderBottom?: ((date: Date) => React.ReactNode) | false | ||
allowClear?: boolean | ||
max?: Date | ||
min?: Date | ||
|
@@ -118,6 +118,8 @@ export const CalendarPickerView = forwardRef< | |
) | ||
|
||
const showHeader = props.title !== false | ||
const showTop = props.renderTop !== false | ||
const showBottom = props.renderBottom !== false | ||
|
||
// =============================== Scroll =============================== | ||
const context = useContext(Context) | ||
|
@@ -243,6 +245,8 @@ export const CalendarPickerView = forwardRef< | |
(minDay && d.isBefore(minDay, 'day')) | ||
|
||
const renderTop = () => { | ||
if (props.renderTop === false) return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个逻辑看起来没有用?下面的代码里已经写了 if (props.renderXXX === false) return 所有 renderXXX 走到的地方其实已经都判断过了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renderXXX 类型为 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 那可以考虑调整一下代码结构,也不需要这个 |
||
|
||
const top = props.renderTop?.(d.toDate()) | ||
|
||
if (top) { | ||
|
@@ -263,6 +267,13 @@ export const CalendarPickerView = forwardRef< | |
return locale.Calendar.today | ||
} | ||
} | ||
|
||
const renderBottom = () => { | ||
if (props.renderBottom === false) return | ||
|
||
return props.renderBottom?.(d.toDate()) | ||
} | ||
|
||
return ( | ||
<div | ||
key={d.valueOf()} | ||
|
@@ -316,17 +327,21 @@ export const CalendarPickerView = forwardRef< | |
} | ||
}} | ||
> | ||
<div className={`${classPrefix}-cell-top`}> | ||
{renderTop()} | ||
</div> | ||
{showTop && ( | ||
<div className={`${classPrefix}-cell-top`}> | ||
{renderTop()} | ||
</div> | ||
)} | ||
<div className={`${classPrefix}-cell-date`}> | ||
{props.renderDate | ||
? props.renderDate(d.toDate()) | ||
: d.date()} | ||
</div> | ||
<div className={`${classPrefix}-cell-bottom`}> | ||
{props.renderBottom?.(d.toDate())} | ||
</div> | ||
{showBottom && ( | ||
<div className={`${classPrefix}-cell-bottom`}> | ||
{renderBottom()} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
})} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false 这个加一下版本号说明,参考: