Skip to content

Commit

Permalink
feat: Steps support inline
Browse files Browse the repository at this point in the history
* test: update snapshot

* docs: add inline demo

* chore: upgrage rc-steps
  • Loading branch information
JarvisArt committed Nov 5, 2022
1 parent 7cba290 commit 0cc942e
Show file tree
Hide file tree
Showing 9 changed files with 1,789 additions and 7 deletions.
909 changes: 909 additions & 0 deletions components/steps/__tests__/__snapshots__/demo-extend.test.ts.snap

Large diffs are not rendered by default.

621 changes: 621 additions & 0 deletions components/steps/__tests__/__snapshots__/demo.test.ts.snap

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions components/steps/demo/inline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
order: 15
title:
zh-CN: 内联步骤
en-US: Inline Steps
---

## zh-CN

内联类型的步骤条,适用于列表内容场景中展示对象所在流程、当前状态的情况。

## en-US

Inline type steps, suitable for displaying the process and current state of the object in the list content scene.

```tsx
import type { StepsProps } from 'antd';
import { Steps, List, Avatar } from 'antd';

const data = [
{
title: 'Ant Design Title 1',
current: 0,
},
{
title: 'Ant Design Title 2',
current: 1,
status: 'error',
},
{
title: 'Ant Design Title 3',
current: 2,
},
{
title: 'Ant Design Title 4',
current: 1,
},
];

const items = [
{
title: 'Step 1',
description: 'This is a Step 1.',
},
{
title: 'Step 2',
description: 'This is a Step 2.',
},
{
title: 'Step 3',
description: 'This is a Step 3.',
},
];

const App: React.FC = () => (
<div>
<List
itemLayout="horizontal"
dataSource={data}
renderItem={item => (
<List.Item>
<List.Item.Meta
avatar={<Avatar src="https://joeschmoe.io/api/v1/random" />}
title={<a href="https://ant.design">{item.title}</a>}
description="Ant Design, a design language for background applications, is refined by Ant UED Team"
/>
<Steps
style={{ marginTop: 8 }}
type="inline"
current={item.current}
status={item.status as StepsProps['status']}
items={items}
/>
</List.Item>
)}
/>
</div>
);

export default App;
```
13 changes: 12 additions & 1 deletion components/steps/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@ The whole of the step bar.
| responsive | Change to vertical direction when screen width smaller than `532px` | boolean | true | |
| size | To specify the size of the step bar, `default` and `small` are currently supported | string | `default` | |
| status | To specify the status of current step, can be set to one of the following values: `wait` `process` `finish` `error` | string | `process` | |
| type | Type of steps, can be set to one of the following values: `default`, `navigation` | string | `default` | |
| type | Type of steps, can be set to one of the following values: `default` `navigation` `inline` | string | `default` | inline: 5.0 |
| onChange | Trigger when Step is changed | (current) => void | - | |
| items | StepItem content | [StepItem](#StepItem) | [] | 4.24.0 |

### `type="inline"`

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| className | Additional class to Steps | string | - | |
| current | To set the current step, counting from 0. You can overwrite this state by using `status` of `Step` | number | 0 | |
| initial | Set the initial step, counting from 0 | number | 0 | |
| status | To specify the status of current step, can be set to one of the following values: `wait` `process` `finish` `error` | string | `process` | |
| onChange | Trigger when Step is changed | (current) => void | - | |
| items | StepItem content. not supported: `icon` `subtitle` | [StepItem](#StepItem) | [] | 4.24.0 |

### StepItem

A single step in the step bar.
Expand Down
18 changes: 14 additions & 4 deletions components/steps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import RcSteps from 'rc-steps';
import type { ProgressDotRender } from 'rc-steps/lib/Steps';
import * as React from 'react';
import Tooltip from '../tooltip';
import { ConfigContext } from '../config-provider';
import useBreakpoint from '../grid/hooks/useBreakpoint';
import Progress from '../progress';
Expand All @@ -23,7 +24,7 @@ export interface StepProps {
}

export interface StepsProps {
type?: 'default' | 'navigation';
type?: 'default' | 'navigation' | 'inline';
className?: string;
current?: number;
direction?: 'horizontal' | 'vertical';
Expand Down Expand Up @@ -70,13 +71,15 @@ const Steps: StepsType = props => {

const [wrapSSR, hashId] = useStyle(prefixCls);

const isInline = props.type === 'inline';
const iconPrefix = getPrefixCls('', props.iconPrefix);
const mergedItems = useLegacyItems(items, children);
const mergedPercent = isInline ? undefined : percent;

const stepsClassName = classNames(
{
[`${prefixCls}-rtl`]: rtlDirection === 'rtl',
[`${prefixCls}-with-progress`]: percent !== undefined,
[`${prefixCls}-with-progress`]: mergedPercent !== undefined,
},
className,
hashId,
Expand All @@ -96,15 +99,15 @@ const Steps: StepsType = props => {
title: string | React.ReactNode;
description: string | React.ReactNode;
}) => {
if (status === 'process' && percent !== undefined) {
if (status === 'process' && mergedPercent !== undefined) {
// currently it's hard-coded, since we can't easily read the actually width of icon
const progressWidth = size === 'small' ? 32 : 40;
// iconWithProgress
return (
<div className={`${prefixCls}-progress-icon`}>
<Progress
type="circle"
percent={percent}
percent={mergedPercent}
width={progressWidth}
strokeWidth={4}
format={() => null}
Expand All @@ -116,13 +119,20 @@ const Steps: StepsType = props => {
return node;
};

let itemRender;
if (isInline) {
itemRender = (item: StepProps, stepItem: React.ReactNode) =>
item.description ? <Tooltip title={item.description}>{stepItem}</Tooltip> : stepItem;
}

return wrapSSR(
<RcSteps
icons={icons}
{...restProps}
current={current}
size={size}
items={mergedItems}
itemRender={itemRender}
direction={getDirection()}
stepIcon={stepIconRender}
prefixCls={prefixCls}
Expand Down
15 changes: 14 additions & 1 deletion components/steps/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ return <Steps items={items} />;
</Steps>;
```

## API

### Steps

整体步骤条。
Expand All @@ -49,10 +51,21 @@ return <Steps items={items} />;
| responsive | 当屏幕宽度小于 `532px` 时自动变为垂直模式 | boolean | true | |
| size | 指定大小,目前支持普通(`default`)和迷你(`small`| string | `default` | |
| status | 指定当前步骤的状态,可选 `wait` `process` `finish` `error` | string | `process` | |
| type | 步骤条类型, `default` `navigation` 两种 | string | `default` | |
| type | 步骤条类型,可选 `default` `navigation` `inline` | string | `default` | inline: 5.0 |
| onChange | 点击切换步骤时触发 | (current) => void | - | |
| items | 配置选项卡内容 | [StepItem](#StepItem) | [] | 4.24.0 |

### `type="inline"`

| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| className | 步骤条类名 | string | - | |
| current | 指定当前步骤,从 0 开始记数。在子 Step 元素中,可以通过 `status` 属性覆盖状态 | number | 0 | |
| initial | 起始序号,从 0 开始记数 | number | 0 | |
| status | 指定当前步骤的状态,可选 `wait` `process` `finish` `error` | string | `process` | |
| onChange | 点击切换步骤时触发 | (current) => void | - | |
| items | 配置选项卡内容,不支持 `icon` `subtitle` | [StepItem](#StepItem) | [] | 4.24.0 |

### StepItem

步骤条内的每一个步骤。
Expand Down
13 changes: 13 additions & 0 deletions components/steps/style/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import genStepsProgressDotStyle from './progress-dot';
import genStepsRTLStyle from './rtl';
import genStepsSmallStyle from './small';
import genStepsVerticalStyle from './vertical';
import genStepsInlineStyle from './inline';
import { resetComponent } from '../../style';

export interface ComponentToken {
Expand Down Expand Up @@ -60,6 +61,10 @@ export interface StepsToken extends FullToken<'Steps'> {
errorDotColor: string;
stepsNavActiveColor: string;
stepsProgressSize: number;
// Steps inline variable
inlineDotSize: number;
inlineTitleColor: string;
inlineTailColor: string;
}

enum StepItemStatusEnum {
Expand Down Expand Up @@ -311,6 +316,8 @@ const genStepsStyle: GenerateStyle<StepsToken, CSSObject> = token => {
...genStepsRTLStyle(token),
// progress
...genStepsProgressStyle(token),
// inline
...genStepsInlineStyle(token),
},
};
};
Expand All @@ -331,10 +338,12 @@ export default genComponentStyleHook(
colorPrimary,
colorTextLabel,
colorTextDescription,
colorTextQuaternary,
colorFillContent,
controlItemBgActive,
colorError,
colorBgContainer,
colorBorderSecondary,
} = token;

const stepsIconSize = token.controlHeight;
Expand Down Expand Up @@ -385,6 +394,10 @@ export default genComponentStyleHook(
errorDotColor: colorError,
stepsNavActiveColor: colorPrimary,
stepsProgressSize: controlHeightLG,
// Steps inline variable
inlineDotSize: 6,
inlineTitleColor: colorTextQuaternary,
inlineTailColor: colorBorderSecondary,
});

return [genStepsStyle(stepsToken)];
Expand Down
124 changes: 124 additions & 0 deletions components/steps/style/inline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import type { CSSObject } from '@ant-design/cssinjs';
import type { StepsToken } from '.';
import type { GenerateStyle } from '../../theme';

const genStepsInlineStyle: GenerateStyle<StepsToken, CSSObject> = token => {
const { componentCls, inlineDotSize, inlineTitleColor, inlineTailColor } = token;
const containerPaddingTop = token.paddingXS + token.lineWidth;
const titleStyle = {
[`${componentCls}-item-container ${componentCls}-item-content ${componentCls}-item-title`]: {
color: inlineTitleColor,
},
};

return {
[`&${componentCls}-inline`]: {
width: 'auto',
display: 'inline-flex',

[`${componentCls}-item`]: {
flex: 'none',

'&-container': {
padding: `${containerPaddingTop}px ${token.paddingXXS}px 0`,
margin: `0 ${token.marginXXS / 2}px`,
borderRadius: token.borderRadiusSM,
cursor: 'pointer',
'&:hover': {
background: token.controlItemBgHover,
transition: `background-color ${token.motionDurationFast}`,
},
[`&[role='button']:hover`]: {
opacity: 1,
},
},

'&-icon': {
width: inlineDotSize,
height: inlineDotSize,
marginInlineStart: `calc(50% - ${inlineDotSize / 2}px)`,
[`> ${componentCls}-icon`]: {
top: 0,
},
[`${componentCls}-icon-dot`]: {
borderRadius: token.fontSizeSM / 4,
},
},

'&-content': {
width: 'auto',
marginTop: token.marginXS - token.lineWidth,
},
'&-title': {
color: inlineTitleColor,
fontSize: token.fontSizeSM,
lineHeight: token.lineHeightSM,
fontWeight: 'normal',
marginBottom: token.marginXXS / 2,
},
'&-description': {
display: 'none',
},

'&-tail': {
marginInlineStart: 0,
top: containerPaddingTop + inlineDotSize / 2,
transform: `translateY(-50%)`,
'&:after': {
width: '100%',
height: token.lineWidth,
borderRadius: 0,
marginInlineStart: 0,
background: inlineTailColor,
},
},

[`&:first-child ${componentCls}-item-tail`]: {
width: '50%',
marginInlineStart: '50%',
},
[`&:last-child ${componentCls}-item-tail`]: {
display: 'block',
width: '50%',
},

'&-wait': {
[`${componentCls}-item-icon ${componentCls}-icon ${componentCls}-icon-dot`]: {
backgroundColor: token.colorBorderBg,
border: `${token.lineWidth}px ${token.lineType} ${inlineTailColor}`,
},
...titleStyle,
},
'&-finish': {
[`${componentCls}-item-tail::after`]: {
backgroundColor: inlineTailColor,
},
[`${componentCls}-item-icon ${componentCls}-icon ${componentCls}-icon-dot`]: {
backgroundColor: inlineTailColor,
border: `${token.lineWidth}px ${token.lineType} ${inlineTailColor}`,
},
...titleStyle,
},
'&-error': titleStyle,
'&-active, &-process': {
[`${componentCls}-item-icon`]: {
width: inlineDotSize,
height: inlineDotSize,
marginInlineStart: `calc(50% - ${inlineDotSize / 2}px)`,
top: 0,
},
...titleStyle,
},

[`&:not(${componentCls}-item-active) > ${componentCls}-item-container[role='button']:hover`]:
{
[`${componentCls}-item-title`]: {
color: inlineTitleColor,
},
},
},
},
};
};

export default genStepsInlineStyle;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"rc-segmented": "~2.1.0",
"rc-select": "~14.1.13",
"rc-slider": "~10.0.0",
"rc-steps": "~5.0.0-alpha.0",
"rc-steps": "~6.0.0-alpha.1",
"rc-switch": "~4.0.0",
"rc-table": "~7.26.0",
"rc-tabs": "~12.2.0",
Expand Down

0 comments on commit 0cc942e

Please sign in to comment.