From 716a9db70419ab0b4d5039249b01da93e653bf0e Mon Sep 17 00:00:00 2001 From: jzh <1587315093@qq.com> Date: Wed, 12 Jul 2023 15:31:34 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=9B=9E=E9=80=80if=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=E7=AE=80=E5=8C=96,=E4=BF=9D=E7=95=99=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/capsule-tabs/capsule-tabs.tsx | 4 +- .../date-picker/date-picker-date-utils.ts | 60 ++++++++----------- .../date-picker/date-picker-week-utils.ts | 30 ++++------ src/components/dropdown/dropdown.tsx | 1 - src/components/footer/footer.tsx | 52 ++++++++-------- src/components/form/form-array.tsx | 1 - .../image-uploader/image-uploader.tsx | 4 +- src/components/modal/modal.tsx | 32 +++++----- src/components/popover/popover.tsx | 12 ++-- src/components/popup/popup.tsx | 8 +-- src/components/result/result.tsx | 4 +- src/components/stepper/stepper.tsx | 7 +-- src/components/tree-select/multiple.tsx | 8 +-- 13 files changed, 91 insertions(+), 132 deletions(-) diff --git a/src/components/capsule-tabs/capsule-tabs.tsx b/src/components/capsule-tabs/capsule-tabs.tsx index b1bba7f26b..8b50f58421 100644 --- a/src/components/capsule-tabs/capsule-tabs.tsx +++ b/src/components/capsule-tabs/capsule-tabs.tsx @@ -25,9 +25,7 @@ export type CapsuleTabProps = { children?: ReactNode } & NativeProps -export const CapsuleTab: FC = () => { - return null -} +export const CapsuleTab: FC = () => null export type CapsuleTabsProps = { activeKey?: string | null diff --git a/src/components/date-picker/date-picker-date-utils.ts b/src/components/date-picker/date-picker-date-utils.ts index 5ad0f23d0d..94624b01a9 100644 --- a/src/components/date-picker/date-picker-date-utils.ts +++ b/src/components/date-picker/date-picker-date-utils.ts @@ -104,12 +104,10 @@ export function generateDatePickerColumns( const upper = maxYear const years = generateColumn(lower, upper, 'year') ret.push( - years.map(v => { - return { - label: renderLabel('year', v), - value: v.toString(), - } - }) + years.map(v => ({ + label: renderLabel('year', v), + value: v.toString(), + })) ) } @@ -118,12 +116,10 @@ export function generateDatePickerColumns( const upper = isInMaxYear ? maxMonth : 12 const months = generateColumn(lower, upper, 'month') ret.push( - months.map(v => { - return { - label: renderLabel('month', v), - value: v.toString(), - } - }) + months.map(v => ({ + label: renderLabel('month', v), + value: v.toString(), + })) ) } if (rank >= precisionRankRecord.day) { @@ -131,12 +127,10 @@ export function generateDatePickerColumns( const upper = isInMaxMonth ? maxDay : firstDayInSelectedMonth.daysInMonth() const days = generateColumn(lower, upper, 'day') ret.push( - days.map(v => { - return { - label: renderLabel('day', v), - value: v.toString(), - } - }) + days.map(v => ({ + label: renderLabel('day', v), + value: v.toString(), + })) ) } if (rank >= precisionRankRecord.hour) { @@ -144,12 +138,10 @@ export function generateDatePickerColumns( const upper = isInMaxDay ? maxHour : 23 const hours = generateColumn(lower, upper, 'hour') ret.push( - hours.map(v => { - return { - label: renderLabel('hour', v), - value: v.toString(), - } - }) + hours.map(v => ({ + label: renderLabel('hour', v), + value: v.toString(), + })) ) } if (rank >= precisionRankRecord.minute) { @@ -157,12 +149,10 @@ export function generateDatePickerColumns( const upper = isInMaxHour ? maxMinute : 59 const minutes = generateColumn(lower, upper, 'minute') ret.push( - minutes.map(v => { - return { - label: renderLabel('minute', v), - value: v.toString(), - } - }) + minutes.map(v => ({ + label: renderLabel('minute', v), + value: v.toString(), + })) ) } if (rank >= precisionRankRecord.second) { @@ -170,12 +160,10 @@ export function generateDatePickerColumns( const upper = isInMaxMinute ? maxSecond : 59 const seconds = generateColumn(lower, upper, 'second') ret.push( - seconds.map(v => { - return { - label: renderLabel('second', v), - value: v.toString(), - } - }) + seconds.map(v => ({ + label: renderLabel('second', v), + value: v.toString(), + })) ) } diff --git a/src/components/date-picker/date-picker-week-utils.ts b/src/components/date-picker/date-picker-week-utils.ts index 51b9b0db5f..d295cb1683 100644 --- a/src/components/date-picker/date-picker-week-utils.ts +++ b/src/components/date-picker/date-picker-week-utils.ts @@ -77,12 +77,10 @@ export function generateDatePickerColumns( const upper = maxYear const years = generateColumn(lower, upper, 'year') ret.push( - years.map(v => { - return { - label: renderLabel('year', v), - value: v.toString(), - } - }) + years.map(v => ({ + label: renderLabel('year', v), + value: v.toString(), + })) ) } @@ -91,12 +89,10 @@ export function generateDatePickerColumns( const upper = isInMaxYear ? maxWeek : selectedYearWeeks const weeks = generateColumn(lower, upper, 'week') ret.push( - weeks.map(v => { - return { - label: renderLabel('week', v), - value: v.toString(), - } - }) + weeks.map(v => ({ + label: renderLabel('week', v), + value: v.toString(), + })) ) } if (rank >= precisionRankRecord['week-day']) { @@ -104,12 +100,10 @@ export function generateDatePickerColumns( const upper = isInMaxWeek ? maxWeekday : 7 const weeks = generateColumn(lower, upper, 'week-day') ret.push( - weeks.map(v => { - return { - label: renderLabel('week-day', v), - value: v.toString(), - } - }) + weeks.map(v => ({ + label: renderLabel('week-day', v), + value: v.toString(), + })) ) } diff --git a/src/components/dropdown/dropdown.tsx b/src/components/dropdown/dropdown.tsx index 3eb5f2e702..ae76dc8123 100644 --- a/src/components/dropdown/dropdown.tsx +++ b/src/components/dropdown/dropdown.tsx @@ -26,7 +26,6 @@ export type DropdownProps = { closeOnMaskClick?: boolean closeOnClickAway?: boolean onChange?: (key: string | null) => void - // mask?: boolean; arrow?: React.ReactNode getContainer?: PopupProps['getContainer'] } & NativeProps diff --git a/src/components/footer/footer.tsx b/src/components/footer/footer.tsx index 90e337244b..88e9a419c4 100644 --- a/src/components/footer/footer.tsx +++ b/src/components/footer/footer.tsx @@ -60,40 +60,36 @@ export const Footer: FC = p => { {label} )} - {links && links.length > 0 && ( + {!!links?.length && (
- {links.map((link, index) => { - return ( - - clickLinkItem(link, index, event)} - > - {link.text} - - {index !== links.length - 1 && } - - ) - })} + {links.map((link, index) => ( + + clickLinkItem(link, index, event)} + > + {link.text} + + {index !== links.length - 1 && } + + ))}
)} {content &&
{content}
} {chips && chips.length > 0 && (
- {chips.map((chip, index) => { - return ( -
clickChipItem(chip, index)} - className={classNames(`${classPrefix}-chip`, { - [`${classPrefix}-chip-link`]: chip.type === 'link', - })} - > - {chip.text} -
- ) - })} + {chips.map((chip, index) => ( +
clickChipItem(chip, index)} + className={classNames(`${classPrefix}-chip`, { + [`${classPrefix}-chip-link`]: chip.type === 'link', + })} + > + {chip.text} +
+ ))}
)} diff --git a/src/components/form/form-array.tsx b/src/components/form/form-array.tsx index 1f84b1eb7e..64c07a5ed9 100644 --- a/src/components/form/form-array.tsx +++ b/src/components/form/form-array.tsx @@ -16,7 +16,6 @@ export interface FormArrayOperation { export interface FormArrayProps { name: string | number | (string | number)[] - // rules?: ValidatorRule[] initialValue?: any[] renderHeader?: ( field: FormArrayField, diff --git a/src/components/image-uploader/image-uploader.tsx b/src/components/image-uploader/image-uploader.tsx index 94c668730f..c38bd34d30 100644 --- a/src/components/image-uploader/image-uploader.tsx +++ b/src/components/image-uploader/image-uploader.tsx @@ -159,9 +159,7 @@ export const ImageUploader: FC = p => { e.target.value = '' // HACK: fix the same file doesn't trigger onChange if (props.beforeUpload) { - const postFiles = files.map(file => { - return processFile(file, files) - }) + const postFiles = files.map(file => processFile(file, files)) await Promise.all(postFiles).then(filesList => { files = filesList.filter(Boolean) as File[] diff --git a/src/components/modal/modal.tsx b/src/components/modal/modal.tsx index 22d0d22db9..59a2e0900e 100644 --- a/src/components/modal/modal.tsx +++ b/src/components/modal/modal.tsx @@ -72,23 +72,21 @@ export const Modal: FC = p => { props.actions.length === 0 && cls('footer-empty') )} > - {props.actions.map((action, index) => { - return ( - { - await Promise.all([ - action.onClick?.(), - props.onAction?.(action, index), - ]) - if (props.closeOnAction) { - props.onClose?.() - } - }} - /> - ) - })} + {props.actions.map((action, index) => ( + { + await Promise.all([ + action.onClick?.(), + props.onAction?.(action, index), + ]) + if (props.closeOnAction) { + props.onClose?.() + } + }} + /> + ))} ) diff --git a/src/components/popover/popover.tsx b/src/components/popover/popover.tsx index 036a17b867..3a56c4c399 100644 --- a/src/components/popover/popover.tsx +++ b/src/components/popover/popover.tsx @@ -77,13 +77,11 @@ export const Popover = forwardRef((p, ref) => { useImperativeHandle( ref, - () => { - return { - show: () => setVisible(true), - hide: () => setVisible(false), - visible, - } - }, + () => ({ + show: () => setVisible(true), + hide: () => setVisible(false), + visible, + }), [visible] ) diff --git a/src/components/popup/popup.tsx b/src/components/popup/popup.tsx index ab3e7a1b16..8726b3af36 100644 --- a/src/components/popup/popup.tsx +++ b/src/components/popup/popup.tsx @@ -32,7 +32,6 @@ const defaultProps = { export const Popup: FC = p => { const props = mergeProps(defaultProps, p) - const { locale } = useConfig() const bodyCls = classNames( `${classPrefix}-body`, @@ -40,16 +39,17 @@ export const Popup: FC = p => { `${classPrefix}-body-position-${props.position}` ) + const { locale } = useConfig() const [active, setActive] = useState(props.visible) + const ref = useRef(null) + useLockScroll(ref, props.disableBodyScroll && active ? 'strict' : false) + useIsomorphicLayoutEffect(() => { if (props.visible) { setActive(true) } }, [props.visible]) - const ref = useRef(null) - useLockScroll(ref, props.disableBodyScroll && active ? 'strict' : false) - const unmountedRef = useUnmountedRef() const { percent } = useSpring({ percent: props.visible ? 0 : 100, diff --git a/src/components/result/result.tsx b/src/components/result/result.tsx index b5b9c1a3c0..a1311b8fbf 100644 --- a/src/components/result/result.tsx +++ b/src/components/result/result.tsx @@ -42,9 +42,9 @@ export const Result: FC = p => {
{resultIcon}
{title}
- {description ? ( + {!!description && (
{description}
- ) : null} + )}
) } diff --git a/src/components/stepper/stepper.tsx b/src/components/stepper/stepper.tsx index 825b5f2d2c..e66cb7e0d3 100644 --- a/src/components/stepper/stepper.tsx +++ b/src/components/stepper/stepper.tsx @@ -101,7 +101,6 @@ export function InnerStepper( defaultValue = 0 as ValueType, value, onChange, - disabled, step, max, @@ -153,11 +152,7 @@ export function InnerStepper( const formatValue = (value: ValueType | null): string => { if (value === null) return '' - if (formatter) { - return formatter(value) - } else { - return fixedValue(value) - } + return formatter ? formatter(value) : fixedValue(value) } // ======================== Value & InputValue ======================== diff --git a/src/components/tree-select/multiple.tsx b/src/components/tree-select/multiple.tsx index 5ce9b26496..fa6b877648 100644 --- a/src/components/tree-select/multiple.tsx +++ b/src/components/tree-select/multiple.tsx @@ -320,18 +320,14 @@ export const Multiple: FC = p => { return ( <> {renderSelectAllLeafItem(columnOptions, index)} - {columnOptions.map(option => { - return renderLeafItem(option) - })} + {columnOptions.map(option => renderLeafItem(option))} ) } return ( <> {renderSelectAllItem(columnOptions, index)} - {columnOptions.map(option => { - return renderItem(option) - })} + {columnOptions.map(option => renderItem(option))} ) }