chore: type optimization (#38698)

* chore: type optimization

* fix: rename direction

* Update index.tsx
This commit is contained in:
lijianan 2022-11-18 23:11:03 +08:00 committed by GitHub
parent a552a5eea5
commit c39e1223f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 21 deletions

View File

@ -375,7 +375,7 @@ function InternalFormItem<Values = any>(props: FormItemProps<Values>): React.Rea
</MemoInput> </MemoInput>
); );
} else if (isRenderProps && (shouldUpdate || dependencies) && !hasName) { } else if (isRenderProps && (shouldUpdate || dependencies) && !hasName) {
childNode = (children as RenderChildren)(context); childNode = children(context);
} else { } else {
warning( warning(
!mergedName.length, !mergedName.length,

View File

@ -2,7 +2,11 @@ import CheckOutlined from '@ant-design/icons/CheckOutlined';
import CloseOutlined from '@ant-design/icons/CloseOutlined'; import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames'; import classNames from 'classnames';
import RcSteps from 'rc-steps'; import RcSteps from 'rc-steps';
import type { ProgressDotRender } from 'rc-steps/lib/Steps'; import type {
ProgressDotRender,
StepIconRender,
StepsProps as RcStepsProps,
} from 'rc-steps/lib/Steps';
import * as React from 'react'; import * as React from 'react';
import Tooltip from '../tooltip'; import Tooltip from '../tooltip';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
@ -47,7 +51,7 @@ interface StepsType extends React.FC<StepsProps> {
Step: typeof RcSteps.Step; Step: typeof RcSteps.Step;
} }
const Steps: StepsType = props => { const Steps: StepsType = (props) => {
const { const {
percent, percent,
size, size,
@ -62,7 +66,7 @@ const Steps: StepsType = props => {
const { xs } = useBreakpoint(responsive); const { xs } = useBreakpoint(responsive);
const { getPrefixCls, direction: rtlDirection } = React.useContext(ConfigContext); const { getPrefixCls, direction: rtlDirection } = React.useContext(ConfigContext);
const getDirection = React.useCallback( const realDirectionValue = React.useMemo<RcStepsProps['direction']>(
() => (responsive && xs ? 'vertical' : direction), () => (responsive && xs ? 'vertical' : direction),
[xs, direction], [xs, direction],
); );
@ -89,16 +93,7 @@ const Steps: StepsType = props => {
error: <CloseOutlined className={`${prefixCls}-error-icon`} />, error: <CloseOutlined className={`${prefixCls}-error-icon`} />,
}; };
const stepIconRender = ({ const stepIconRender: StepIconRender = ({ node, status }) => {
node,
status,
}: {
node: React.ReactNode;
index: number;
status: string;
title: string | React.ReactNode;
description: string | React.ReactNode;
}) => {
if (status === 'process' && mergedPercent !== undefined) { if (status === 'process' && mergedPercent !== undefined) {
// currently it's hard-coded, since we can't easily read the actually width of icon // currently it's hard-coded, since we can't easily read the actually width of icon
const progressWidth = size === 'small' ? 32 : 40; const progressWidth = size === 'small' ? 32 : 40;
@ -119,11 +114,8 @@ const Steps: StepsType = props => {
return node; return node;
}; };
let itemRender; const itemRender = (item: StepProps, stepItem: React.ReactNode) =>
if (isInline) {
itemRender = (item: StepProps, stepItem: React.ReactNode) =>
item.description ? <Tooltip title={item.description}>{stepItem}</Tooltip> : stepItem; item.description ? <Tooltip title={item.description}>{stepItem}</Tooltip> : stepItem;
}
return wrapSSR( return wrapSSR(
<RcSteps <RcSteps
@ -132,9 +124,9 @@ const Steps: StepsType = props => {
current={current} current={current}
size={size} size={size}
items={mergedItems} items={mergedItems}
itemRender={itemRender} itemRender={isInline ? itemRender : undefined}
direction={getDirection()}
stepIcon={stepIconRender} stepIcon={stepIconRender}
direction={realDirectionValue}
prefixCls={prefixCls} prefixCls={prefixCls}
iconPrefix={iconPrefix} iconPrefix={iconPrefix}
className={stepsClassName} className={stepsClassName}