Skip to content

Commit

Permalink
chore: code optimization (#344)
Browse files Browse the repository at this point in the history
* chore: code optimization

* type: fix lint
  • Loading branch information
li-jia-nan authored Dec 5, 2023
1 parent b312fb7 commit 0199d38
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/Step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface StepProps {
render?: (stepItem: React.ReactElement) => React.ReactNode;
}

function Step(props: StepProps) {
const Step: React.FC<StepProps> = (props) => {
const {
className,
prefixCls,
Expand Down Expand Up @@ -85,7 +85,7 @@ function Step(props: StepProps) {

// ========================= Render =========================
const renderIconNode = () => {
let iconNode;
let iconNode: React.ReactNode;
const iconClassName = classNames(`${prefixCls}-icon`, `${iconPrefix}icon`, {
[`${iconPrefix}icon-${icon}`]: icon && isString(icon),
[`${iconPrefix}icon-check`]:
Expand Down Expand Up @@ -147,9 +147,10 @@ function Step(props: StepProps) {
[`${prefixCls}-item-disabled`]: disabled === true,
},
);
const stepItemStyle = { ...style };

let stepNode: React.ReactElement = (
const stepItemStyle: React.CSSProperties = { ...style };

let stepNode: React.ReactNode = (
<div {...restProps} className={classString} style={stepItemStyle}>
<div onClick={onClick} {...accessibilityProps} className={`${prefixCls}-item-container`}>
<div className={`${prefixCls}-item-tail`}>{tailContent}</div>
Expand Down Expand Up @@ -177,6 +178,10 @@ function Step(props: StepProps) {
}

return stepNode;
};

if (process.env.NODE_ENV !== 'production') {
Step.displayName = 'rc-step';
}

export default Step;
16 changes: 11 additions & 5 deletions src/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type StepIconRender = (info: {
}) => React.ReactNode;

export type ProgressDotRender = (
iconDot,
iconDot: React.ReactNode,
info: {
index: number;
status: Status;
Expand Down Expand Up @@ -44,7 +44,9 @@ export interface StepsProps {
onChange?: (current: number) => void;
}

function Steps(props: StepsProps) {
const Steps: React.FC<StepsProps> & {
Step: typeof Step;
} = (props) => {
const {
prefixCls = 'rc-steps',
style = {},
Expand Down Expand Up @@ -91,7 +93,7 @@ function Steps(props: StepsProps) {
};

const renderStep = (item: StepProps, index: number) => {
const mergedItem = { ...item };
const mergedItem: StepProps = { ...item };
const stepNumber = initial + index;
// fix tail color
if (status === 'error' && index === current - 1) {
Expand Down Expand Up @@ -137,11 +139,15 @@ function Steps(props: StepsProps) {

return (
<div className={classString} style={style} {...restProps}>
{items.filter((item) => item).map(renderStep)}
{items.filter(Boolean).map<React.ReactNode>(renderStep)}
</div>
);
}
};

Steps.Step = Step;

if (process.env.NODE_ENV !== 'production') {
Steps.displayName = 'rc-steps';
}

export default Steps;

0 comments on commit 0199d38

Please sign in to comment.