Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import type { StepsProps } from './Steps';
import type { ComponentType, StepsProps } from './Steps';

export interface StepsContextProps {
prefixCls: string;
classNames: NonNullable<StepsProps['classNames']>;
styles: NonNullable<StepsProps['styles']>;
ItemComponent: ComponentType;
}

export const StepsContext = React.createContext<StepsContextProps>(null!);
8 changes: 5 additions & 3 deletions src/Step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Status, StepItem, StepsProps } from './Steps';
import Rail from './Rail';
import { UnstableContext } from './UnstableContext';
import StepIcon, { StepIconSemanticContext } from './StepIcon';
import { StepsContext } from './Context';

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

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

// ==================== Internal Context ====================
// ======================== Contexts ========================
const { railFollowPrevStatus } = React.useContext(UnstableContext);
const { ItemComponent } = React.useContext(StepsContext);

// ========================== Data ==========================
const {
Expand Down Expand Up @@ -233,7 +235,7 @@ export default function Step(props: StepProps) {
);

let stepNode: React.ReactNode = (
<li
<ItemComponent
{...restItemProps}
{...accessibilityProps}
className={classString}
Expand All @@ -244,7 +246,7 @@ export default function Step(props: StepProps) {
}}
>
{itemWrapperRender ? itemWrapperRender(wrapperNode) : wrapperNode}
</li>
</ItemComponent>
);

if (itemRender) {
Expand Down
20 changes: 17 additions & 3 deletions src/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type ItemSemanticName =
| 'icon'
| 'rail';

export type ComponentType = React.ComponentType<any> | string;

export type StepItem = {
/** @deprecated Please use `content` instead. */
description?: React.ReactNode;
Expand Down Expand Up @@ -74,6 +76,13 @@ export interface StepsProps {
orientation?: 'horizontal' | 'vertical';
titlePlacement?: 'horizontal' | 'vertical';

// a11y
/** Internal usage of antd. Do not deps on this. */
components?: {
root?: ComponentType;
item?: ComponentType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单独rc这边不给默认值吗?olli之类的

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 是定义,实现里给了默认值。另外这个库是 rc-steps,所以默认值是 div,antd里的 Timeline 才会改成 ol 和 li

};

// data
status?: Status;
current?: number;
Expand Down Expand Up @@ -107,6 +116,7 @@ export default function Steps(props: StepsProps) {
// layout
orientation,
titlePlacement,
components,

// data
status = 'process',
Expand Down Expand Up @@ -167,14 +177,18 @@ export default function Steps(props: StepsProps) {
}
};

// =========================== components ===========================
const { root: RootComponent = 'div', item: ItemComponent = 'div' } = components || {};

// ============================ contexts ============================
const stepIconContext = React.useMemo<StepsContextProps>(
() => ({
prefixCls,
classNames,
styles,
ItemComponent,
}),
[prefixCls, classNames, styles],
[prefixCls, classNames, styles, ItemComponent],
);

// ============================= render =============================
Expand Down Expand Up @@ -212,7 +226,7 @@ export default function Steps(props: StepsProps) {
};

return (
<ol
<RootComponent
className={classString}
style={{
...style,
Expand All @@ -223,6 +237,6 @@ export default function Steps(props: StepsProps) {
<StepsContext.Provider value={stepIconContext}>
{mergedItems.map<React.ReactNode>(renderStep)}
</StepsContext.Provider>
</ol>
</RootComponent>
);
}
Loading