Local Build and Deploy / deploy (push) Canceled after 40s
- Type resolveAsChild generically over Base UI render-prop type - Type catalog/rooms/catalog-items Prisma updates with Prisma.*UpdateInput - Type EventForm/PollForm with explicit form-value interfaces - Type EventPrizesManager/PollQuestionsManager with validator input types - All typecheck, lint, and 312 tests pass
25 lines
691 B
TypeScript
25 lines
691 B
TypeScript
import { isValidElement, type ReactElement, type ReactNode } from "react";
|
|
|
|
/**
|
|
* Map Radix-style `asChild` onto Base UI's `render` prop.
|
|
* Generic over the render-prop type so component-specific Base UI render
|
|
* signatures (e.g. `UseRenderRenderProp<ButtonState>`) are preserved.
|
|
*/
|
|
export function resolveAsChild<R = ReactElement | undefined>(
|
|
asChild: boolean | undefined,
|
|
children: ReactNode,
|
|
render?: R,
|
|
): {
|
|
render?: R;
|
|
children: ReactNode;
|
|
} {
|
|
if (render != null) return { render, children };
|
|
if (asChild && isValidElement(children)) {
|
|
return {
|
|
render: children as R,
|
|
children: (children.props as { children?: ReactNode }).children,
|
|
};
|
|
}
|
|
return { children };
|
|
}
|