mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
65f067eb13
* feat: support items * feat: update demo * test: update package * test: update use type * test: update for test * test: update for lint * feat: update doc * test: update for lint * test: update for lint * test: update for lint * test: add deprecated dome * test: add deprecated dome * doc: update doc * feat: update package * test: add test case
31 lines
767 B
TypeScript
31 lines
767 B
TypeScript
import * as React from 'react';
|
|
import toArray from 'rc-util/lib/Children/toArray';
|
|
import type { StepProps } from '.';
|
|
import warning from '../_util/warning';
|
|
|
|
function filter<T>(items: (T | null)[]): T[] {
|
|
return items.filter(item => item) as T[];
|
|
}
|
|
|
|
export default function useLegacyItems(items?: StepProps[], children?: React.ReactNode) {
|
|
if (items) {
|
|
return items;
|
|
}
|
|
|
|
warning(!children, 'Steps', 'Step is deprecated. Please use `items` directly.');
|
|
|
|
const childrenItems = toArray(children).map((node: React.ReactElement<StepProps>) => {
|
|
if (React.isValidElement(node)) {
|
|
const { props } = node;
|
|
const item: StepProps = {
|
|
...props,
|
|
};
|
|
return item;
|
|
}
|
|
|
|
return null;
|
|
});
|
|
|
|
return filter(childrenItems);
|
|
}
|