Skip to content

Commit 511eb8e

Browse files
committedMay 28, 2022
refactor(steps):抽离icon图标(#826)
1 parent 7564f17 commit 511eb8e

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed
 

‎packages/react-steps/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Steps from '@uiw/react-steps';
2121
```jsx mdx:preview
2222
import React from 'react';
2323
import { Steps } from 'uiw';
24-
2524
function Demo() {
2625
return (
2726
<Steps current={1} style={{ padding:"20px 0" }}>
@@ -66,13 +65,15 @@ export default Demo
6665
```jsx mdx:preview
6766
import React from 'react';
6867
import { Steps, Icon } from 'uiw';
68+
import { StepsItemHeadInnerSvg } from 'uiw';
69+
import { Message } from "@uiw/icons"
6970

7071
function Demo() {
7172
return (
7273
<Steps current={1} style={{padding:"20px 0"}}>
7374
<Steps.Step icon={<Icon type="user"/>} title="注册" description="这里是步骤一的说明,可以很长很长哦。" />
7475
<Steps.Step icon={<Icon type="picasa" spin={true} color="red" />} title="上传头像" description="这里是步骤一的说明,可以很长很长哦。" />
75-
<Steps.Step icon="message" title="验证邮箱" description="这里是步骤一的说明,可以很长很长哦。" />
76+
<Steps.Step icon={<StepsItemHeadInnerSvg as={Message} />} title="验证邮箱" description="这里是步骤一的说明,可以很长很长哦。" />
7677
</Steps>
7778
)
7879
}
@@ -230,4 +231,4 @@ export default Demo
230231
| status | 指定状态。当不配置该属性时,会使用 Steps 的 current 来自动指定状态。可选:`wait` `process` `finish` `error` | String | `wait` |
231232
| title | 指定每个步骤标题 | String/ReactNode | - |
232233
| description | 步骤的详情描述,可选 | String/ReactNode | - |
233-
| icon | 步骤的图标,字符串类型从`<Icon/>`组件中找,可选 | String/ReactNode | - |
234+
| icon | 步骤的图标,字符串类型从`<Icon/>`组件中找,可选 | ReactNode | - |

‎packages/react-steps/src/Step.tsx

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, { CSSProperties } from 'react';
22
import Icon, { IconProps, IconsName } from '@uiw/react-icon';
33
import { IProps, HTMLDivProps } from '@uiw/utils';
4+
import { Check } from '@uiw/icons/lib/Check';
5+
import { Close } from '@uiw/icons/lib/Close';
6+
47
// import './style/index.less';
58
import {
69
StepsItem,
@@ -13,8 +16,8 @@ import {
1316
StepsItemMainDescription,
1417
StepsItemHeadInnerDot,
1518
StepsItemHeadInnerIcon,
19+
StepsItemHeadInnerSvg,
1620
} from './style';
17-
1821
export interface StepProps extends IProps, Omit<HTMLDivProps, 'title'> {
1922
nextError?: boolean | undefined;
2023
title?: React.ReactNode;
@@ -24,7 +27,7 @@ export interface StepProps extends IProps, Omit<HTMLDivProps, 'title'> {
2427
itemWidth?: number;
2528
stepNumber?: string;
2629
adjustMarginRight?: number;
27-
icon?: IconProps['type'];
30+
icon?: React.ReactNode;
2831
direction?: 'horizontal' | 'vertical';
2932
}
3033

@@ -73,23 +76,14 @@ export default function Step(props: StepProps) {
7376
{icon}
7477
</StepsItemHeadInnerIcon>
7578
);
76-
} else if ((icon && typeof icon === 'string') || status === 'finish' || status === 'error') {
79+
} else if (status === 'finish' || status === 'error') {
80+
iconNode = <StepsItemHeadInnerSvg as={status === 'finish' ? Check : Close} />;
81+
} else {
7782
iconNode = (
78-
<Icon
79-
type={
80-
[
81-
icon && typeof icon === 'string' ? `${icon}` : null,
82-
!icon && status === 'finish' ? 'check' : null,
83-
!icon && status === 'error' ? 'close' : null,
84-
]
85-
.filter(Boolean)
86-
.join(' ')
87-
.trim() as IconsName | null
88-
}
89-
/>
83+
<StepsItemHeadInnerIcon params={{ status, icon: !!icon }} className={`${prefixCls}-icon`}>
84+
{stepNumber}
85+
</StepsItemHeadInnerIcon>
9086
);
91-
} else {
92-
iconNode = <span className={`${prefixCls}-icon`}>{stepNumber}</span>;
9387
}
9488
return (
9589
<StepsItem

‎packages/react-steps/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Steps from './Steps';
2-
2+
export * from './style';
33
export * from './Steps';
44
export * from './Step';
55

‎packages/react-steps/src/style/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,17 @@ export const StepsItemHeadInnerIcon = styled.span<StepsItemHeadInnerIconProps>`
425425
`;
426426
StepsItemHeadInnerIcon.defaultProps = { defaultTheme: StepsBaseDefaultTheme };
427427

428+
export const StepsItemHeadInnerSvg = styled.svg`
429+
fill: currentcolor;
430+
height: 1em;
431+
width: 1em;
432+
display: inline-flex;
433+
align-self: center;
434+
position: relative;
435+
transition: color 0.3s;
436+
box-sizing: inherit;
437+
`;
438+
428439
export interface StepsItemMainProps extends StepsBaseProps {
429440
params?: {
430441
dot?: boolean;

0 commit comments

Comments
 (0)
Please sign in to comment.