1
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
import * as React from 'react';
|
||||
import { toArray } from '@rc-component/util';
|
||||
import { isPlainObject } from '../../_util/is';
|
||||
function getCollapsible(collapsible) {
|
||||
if (isPlainObject(collapsible)) {
|
||||
return {
|
||||
...collapsible,
|
||||
showCollapsibleIcon: collapsible.showCollapsibleIcon === undefined ? 'auto' : collapsible.showCollapsibleIcon
|
||||
};
|
||||
}
|
||||
const mergedCollapsible = !!collapsible;
|
||||
return {
|
||||
start: mergedCollapsible,
|
||||
end: mergedCollapsible,
|
||||
showCollapsibleIcon: 'auto'
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Convert `children` into `items`.
|
||||
*/
|
||||
function useItems(children) {
|
||||
const items = React.useMemo(() => toArray(children).filter(item => /*#__PURE__*/React.isValidElement(item)).map(node => {
|
||||
const {
|
||||
props
|
||||
} = node;
|
||||
const {
|
||||
collapsible,
|
||||
...restProps
|
||||
} = props;
|
||||
return {
|
||||
...restProps,
|
||||
collapsible: getCollapsible(collapsible)
|
||||
};
|
||||
}), [children]);
|
||||
return items;
|
||||
}
|
||||
export default useItems;
|
||||
Reference in New Issue
Block a user