mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-23 23:18:36 +08:00
7410b536b4
* feat: Descriptions support row * feat: review * feat: snap * feat: test * feat: review * feat: review * feat: test * feat: test * feat: add calc span * feat: snap * feat: block * feat: test change block * feat: doc * feat: doc * feat: test * feat: empty text test * feat: row > block * feat: remove block * feat: filled * feat: fiiled 逻辑修正 最后一个始终补齐 * feat: doc * feat: review * feat: review * feat: review
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import toArray from 'rc-util/lib/Children/toArray';
|
|
|
|
import type { DescriptionsItemType, InternalDescriptionsItemType } from '..';
|
|
import { matchScreen } from '../../_util/responsiveObserver';
|
|
import type { ScreenMap } from '../../_util/responsiveObserver';
|
|
|
|
// Convert children into items
|
|
const transChildren2Items = (childNodes?: React.ReactNode) =>
|
|
toArray(childNodes).map((node) => ({ ...node?.props, key: node.key }));
|
|
|
|
export default function useItems(
|
|
screens: ScreenMap,
|
|
items?: DescriptionsItemType[],
|
|
children?: React.ReactNode,
|
|
) {
|
|
const mergedItems = React.useMemo<DescriptionsItemType[]>(
|
|
() =>
|
|
// Take `items` first or convert `children` into items
|
|
items || transChildren2Items(children),
|
|
[items, children],
|
|
);
|
|
|
|
const responsiveItems = React.useMemo<InternalDescriptionsItemType[]>(
|
|
() =>
|
|
mergedItems.map(({ span, ...restItem }) => {
|
|
if (span === 'filled') {
|
|
return { ...restItem, filled: true };
|
|
}
|
|
return {
|
|
...restItem,
|
|
span: typeof span === 'number' ? span : matchScreen(screens, span),
|
|
};
|
|
}),
|
|
[mergedItems, screens],
|
|
);
|
|
|
|
return responsiveItems;
|
|
}
|