@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
38 lines (37 loc) • 1.09 kB
JavaScript
import { c as _c } from "react-compiler-runtime";
import { forwardRef } from "react";
/**
* Wraps a client component as a server component, so that submodules can be assigned to it
*
* @private only meant for internal use
*
* @param ClientComponent the component to wrap (function reference)
* @param displayName name of the ClientComponent (string)
* @returns A Server Component with the same type signature as the input component
*
* @example
* Object.assign(wrapClientComponent(Dropdown, "Dropdown"), {
* Item: DropdownItem,
* });
*/
import { jsx as _jsx } from "react/jsx-runtime";
export function wrapClientComponent(ClientComponent, displayName) {
const WrappedComponent = /*#__PURE__*/forwardRef((props, ref) => {
const $ = _c(3);
let t0;
if ($[0] !== props || $[1] !== ref) {
t0 = /*#__PURE__*/_jsx(ClientComponent, {
...props,
ref: ref
});
$[0] = props;
$[1] = ref;
$[2] = t0;
} else {
t0 = $[2];
}
return t0;
});
WrappedComponent.displayName = displayName;
return WrappedComponent;
}