23 lines
496 B
TypeScript
23 lines
496 B
TypeScript
import { isValidElement, type ReactNode } from "react";
|
|
|
|
/**
|
|
* Map Radix-style `asChild` onto Base UI's `render` prop.
|
|
*/
|
|
export function resolveAsChild(
|
|
asChild: boolean | undefined,
|
|
children: ReactNode,
|
|
render?: any,
|
|
): {
|
|
render?: any;
|
|
children: ReactNode;
|
|
} {
|
|
if (render != null) return { render, children };
|
|
if (asChild && isValidElement(children)) {
|
|
return {
|
|
render: children,
|
|
children: (children.props as { children?: ReactNode }).children,
|
|
};
|
|
}
|
|
return { children };
|
|
}
|