@crossed/primitive
Version:
A universal & performant styling library for React Native, Next.js & React
49 lines (48 loc) • 1.06 kB
JavaScript
"use client";
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Slot } from "./Slot";
const NODES = [
"a",
"button",
"div",
"form",
"h2",
"h3",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"span",
"svg",
"ul"
];
const Primitive = NODES.reduce((primitive, node) => {
const Node = React.forwardRef(
(props, forwardedRef) => {
const { asChild, ...primitiveProps } = props;
const Comp = asChild ? Slot : node;
React.useEffect(() => {
window[Symbol.for("radix-ui")] = true;
}, []);
return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
}
);
Node.displayName = `Primitive.${node}`;
return { ...primitive, [node]: Node };
}, {});
function dispatchDiscreteCustomEvent(target, event) {
if (target)
ReactDOM.flushSync(() => target.dispatchEvent(event));
}
const Root = Primitive;
export {
Primitive,
Root,
dispatchDiscreteCustomEvent
};
//# sourceMappingURL=Primitive.js.map