Skip to content

Commit c7b4732

Browse files
authored
feat: support components (#375)
1 parent a5706e5 commit c7b4732

File tree

5 files changed

+190
-124
lines changed

5 files changed

+190
-124
lines changed

src/Context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from 'react';
2-
import type { StepsProps } from './Steps';
2+
import type { ComponentType, StepsProps } from './Steps';
33

44
export interface StepsContextProps {
55
prefixCls: string;
66
classNames: NonNullable<StepsProps['classNames']>;
77
styles: NonNullable<StepsProps['styles']>;
8+
ItemComponent: ComponentType;
89
}
910

1011
export const StepsContext = React.createContext<StepsContextProps>(null!);

src/Step.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Status, StepItem, StepsProps } from './Steps';
66
import Rail from './Rail';
77
import { UnstableContext } from './UnstableContext';
88
import StepIcon, { StepIconSemanticContext } from './StepIcon';
9+
import { StepsContext } from './Context';
910

1011
function hasContent<T>(value: T) {
1112
return value !== undefined && value !== null;
@@ -59,8 +60,9 @@ export default function Step(props: StepProps) {
5960

6061
const itemCls = `${prefixCls}-item`;
6162

62-
// ==================== Internal Context ====================
63+
// ======================== Contexts ========================
6364
const { railFollowPrevStatus } = React.useContext(UnstableContext);
65+
const { ItemComponent } = React.useContext(StepsContext);
6466

6567
// ========================== Data ==========================
6668
const {
@@ -233,7 +235,7 @@ export default function Step(props: StepProps) {
233235
);
234236

235237
let stepNode: React.ReactNode = (
236-
<li
238+
<ItemComponent
237239
{...restItemProps}
238240
{...accessibilityProps}
239241
className={classString}
@@ -244,7 +246,7 @@ export default function Step(props: StepProps) {
244246
}}
245247
>
246248
{itemWrapperRender ? itemWrapperRender(wrapperNode) : wrapperNode}
247-
</li>
249+
</ItemComponent>
248250
);
249251

250252
if (itemRender) {

src/Steps.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export type ItemSemanticName =
3232
| 'icon'
3333
| 'rail';
3434

35+
export type ComponentType = React.ComponentType<any> | string;
36+
3537
export type StepItem = {
3638
/** @deprecated Please use `content` instead. */
3739
description?: React.ReactNode;
@@ -74,6 +76,13 @@ export interface StepsProps {
7476
orientation?: 'horizontal' | 'vertical';
7577
titlePlacement?: 'horizontal' | 'vertical';
7678

79+
// a11y
80+
/** Internal usage of antd. Do not deps on this. */
81+
components?: {
82+
root?: ComponentType;
83+
item?: ComponentType;
84+
};
85+
7786
// data
7887
status?: Status;
7988
current?: number;
@@ -107,6 +116,7 @@ export default function Steps(props: StepsProps) {
107116
// layout
108117
orientation,
109118
titlePlacement,
119+
components,
110120

111121
// data
112122
status = 'process',
@@ -167,14 +177,18 @@ export default function Steps(props: StepsProps) {
167177
}
168178
};
169179

180+
// =========================== components ===========================
181+
const { root: RootComponent = 'div', item: ItemComponent = 'div' } = components || {};
182+
170183
// ============================ contexts ============================
171184
const stepIconContext = React.useMemo<StepsContextProps>(
172185
() => ({
173186
prefixCls,
174187
classNames,
175188
styles,
189+
ItemComponent,
176190
}),
177-
[prefixCls, classNames, styles],
191+
[prefixCls, classNames, styles, ItemComponent],
178192
);
179193

180194
// ============================= render =============================
@@ -212,7 +226,7 @@ export default function Steps(props: StepsProps) {
212226
};
213227

214228
return (
215-
<ol
229+
<RootComponent
216230
className={classString}
217231
style={{
218232
...style,
@@ -223,6 +237,6 @@ export default function Steps(props: StepsProps) {
223237
<StepsContext.Provider value={stepIconContext}>
224238
{mergedItems.map<React.ReactNode>(renderStep)}
225239
</StepsContext.Provider>
226-
</ol>
240+
</RootComponent>
227241
);
228242
}

0 commit comments

Comments
 (0)