UNPKG

@crossed/ui

Version:

A universal & performant styling library for React Native, Next.js & React

33 lines (32 loc) 779 B
import { jsx } from "react/jsx-runtime"; import { Children, cloneElement, forwardRef, isValidElement } from "react"; const Slot = forwardRef( ({ Comp, asChild, ...props }, ref) => { if (asChild && "children" in props) { return Children.toArray(props.children).map((c) => { if (isValidElement(c)) { const { children, ...rest } = props; return cloneElement(c, { ...c.props, ...rest, ...c.props.style && rest.style ? { style: [c.props.style, rest.style] } : {}, ref }); } else { return c; } }); } return /* @__PURE__ */ jsx(Comp, { ...props, ref }); } ); Slot.displayName = "Slot"; export { Slot }; //# sourceMappingURL=Slot.js.map