ant-design/components/layout/hooks/useHasSider.ts
二货爱吃白萝卜 7f9aff2cfb
enhance: auto layout hasSider (#45361)
* enhance: auto layout hasSider

* test: update snapshot
2023-10-16 14:49:01 +08:00

23 lines
444 B
TypeScript

import type * as React from 'react';
import toArray from 'rc-util/lib/Children/toArray';
import Sider from '../Sider';
export default function useHasSider(
siders: string[],
children?: React.ReactNode,
hasSider?: boolean,
) {
if (typeof hasSider === 'boolean') {
return hasSider;
}
if (siders.length) {
return true;
}
const childNodes = toArray(children);
return childNodes.some((node) => node.type === Sider);
}