Skip to content

Commit 17653bb

Browse files
committed
feat: add 'horizontal-alternate'
1 parent b8fc53e commit 17653bb

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

src/Step.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import KeyCode from '@rc-component/util/lib/KeyCode';
55
import type { Status, StepItem, StepsProps } from './Steps';
66
import Rail from './Rail';
77

8+
function hasContent<T>(value: T) {
9+
return value !== undefined && value !== null;
10+
}
11+
812
export interface StepProps {
913
// style
1014
prefixCls?: string;
@@ -18,12 +22,6 @@ export interface StepProps {
1822
index: number;
1923
last: boolean;
2024

21-
// stepIndex?: number;
22-
// stepNumber?: number;
23-
// title?: React.ReactNode;
24-
// subTitle?: React.ReactNode;
25-
// description?: React.ReactNode;
26-
2725
// render
2826
iconRender?: StepsProps['iconRender'];
2927
icon?: React.ReactNode;
@@ -115,29 +113,37 @@ export default function Step(props: StepProps) {
115113
// ========================= Render =========================
116114
const mergedStatus = status || 'wait';
117115

116+
const hasTitle = hasContent(title);
117+
const hasSubTitle = hasContent(subTitle);
118+
118119
const classString = cls(
119120
itemCls,
120121
`${itemCls}-${mergedStatus}`,
121122
{
122123
[`${itemCls}-custom`]: icon,
123124
[`${itemCls}-active`]: active,
124125
[`${itemCls}-disabled`]: disabled === true,
126+
[`${itemCls}-empty-header`]: !hasTitle && !hasSubTitle,
125127
},
126128
className,
127129
classNames.item,
128130
);
129131

132+
// !hasContent(title) && !hasContent(subTitle) && `${itemCls}-header-empty`
133+
130134
const wrapperNode = (
131135
<div className={cls(`${itemCls}-wrapper`, classNames.itemWrapper)} style={styles.itemWrapper}>
132136
<div className={cls(`${itemCls}-icon`, classNames.itemIcon)} style={styles.itemIcon}>
133137
{iconRender?.(renderInfo)}
134138
</div>
135139
<div className={cls(`${itemCls}-section`, classNames.itemSection)} style={styles.itemSection}>
136140
<div className={cls(`${itemCls}-header`, classNames.itemHeader)} style={styles.itemHeader}>
137-
<div className={cls(`${itemCls}-title`, classNames.itemTitle)} style={styles.itemTitle}>
138-
{title}
139-
</div>
140-
{subTitle && (
141+
{hasTitle && (
142+
<div className={cls(`${itemCls}-title`, classNames.itemTitle)} style={styles.itemTitle}>
143+
{title}
144+
</div>
145+
)}
146+
{hasSubTitle && (
141147
<div
142148
title={typeof subTitle === 'string' ? subTitle : undefined}
143149
className={cls(`${itemCls}-subtitle`, classNames.itemSubtitle)}
@@ -151,7 +157,7 @@ export default function Step(props: StepProps) {
151157
<Rail prefixCls={itemCls} classNames={classNames} styles={styles} status={nextStatus} />
152158
)}
153159
</div>
154-
{mergedContent && (
160+
{hasContent(mergedContent) && (
155161
<div
156162
className={cls(`${itemCls}-content`, classNames.itemContent)}
157163
style={styles.itemContent}

src/Steps.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface StepsProps {
5555

5656
// layout
5757
orientation?: 'horizontal' | 'vertical';
58-
titlePlacement?: 'horizontal' | 'vertical';
58+
titlePlacement?: 'horizontal' | 'vertical' | 'horizontal-alternate';
5959

6060
// data
6161
status?: Status;
@@ -81,8 +81,8 @@ export default function Steps(props: StepsProps) {
8181
rootClassName,
8282

8383
// layout
84-
orientation = 'horizontal',
85-
titlePlacement = 'horizontal',
84+
orientation,
85+
titlePlacement,
8686

8787
// data
8888
status = 'process',
@@ -102,8 +102,17 @@ export default function Steps(props: StepsProps) {
102102
// ============================= layout =============================
103103
const isVertical = orientation === 'vertical';
104104
const mergedOrientation = isVertical ? 'vertical' : 'horizontal';
105-
const mergeTitlePlacement =
106-
!isVertical && titlePlacement === 'vertical' ? 'vertical' : 'horizontal';
105+
const mergeTitlePlacement = React.useMemo(() => {
106+
if (isVertical) {
107+
return titlePlacement === 'horizontal' || titlePlacement === 'horizontal-alternate'
108+
? titlePlacement
109+
: 'horizontal';
110+
}
111+
112+
return titlePlacement === 'vertical' || titlePlacement === 'horizontal'
113+
? titlePlacement
114+
: 'horizontal';
115+
}, [isVertical, titlePlacement]);
107116

108117
// ============================= styles =============================
109118
const classString = cls(

tests/alternate.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import Steps from '../src';
4+
5+
describe('Steps.alternate', () => {
6+
it('should have empty className', () => {
7+
const { container } = render(<Steps items={[{}]} />);
8+
9+
expect(container.querySelector('.rc-steps-item')).toHaveClass('rc-steps-item-empty-header');
10+
});
11+
12+
it('', () => {
13+
const { container } = render(
14+
<Steps orientation="vertical" titlePlacement="horizontal-alternate" />,
15+
);
16+
expect(container.querySelector('.rc-steps')).toHaveClass('rc-steps-title-horizontal-alternate');
17+
});
18+
});

0 commit comments

Comments
 (0)