@anoki/fse-marche-ui
Version:
FSE UI components library
46 lines (45 loc) • 1.88 kB
JavaScript
import * as l from "react";
import { composeRefs as u } from "./index.es236.js";
import { j as c } from "./index.es137.js";
var m = l.forwardRef((r, n) => {
const { children: e, ...t } = r, o = l.Children.toArray(e), i = o.find(g);
if (i) {
const s = i.props.children, a = o.map((f) => f === i ? l.Children.count(s) > 1 ? l.Children.only(null) : l.isValidElement(s) ? s.props.children : null : f);
return /* @__PURE__ */ c.jsx(p, { ...t, ref: n, children: l.isValidElement(s) ? l.cloneElement(s, void 0, a) : null });
}
return /* @__PURE__ */ c.jsx(p, { ...t, ref: n, children: e });
});
m.displayName = "Slot";
var p = l.forwardRef((r, n) => {
const { children: e, ...t } = r;
if (l.isValidElement(e)) {
const o = h(e), i = y(t, e.props);
return e.type !== l.Fragment && (i.ref = n ? u(n, o) : o), l.cloneElement(e, i);
}
return l.Children.count(e) > 1 ? l.Children.only(null) : null;
});
p.displayName = "SlotClone";
var d = ({ children: r }) => /* @__PURE__ */ c.jsx(c.Fragment, { children: r });
function g(r) {
return l.isValidElement(r) && r.type === d;
}
function y(r, n) {
const e = { ...n };
for (const t in n) {
const o = r[t], i = n[t];
/^on[A-Z]/.test(t) ? o && i ? e[t] = (...a) => {
i(...a), o(...a);
} : o && (e[t] = o) : t === "style" ? e[t] = { ...o, ...i } : t === "className" && (e[t] = [o, i].filter(Boolean).join(" "));
}
return { ...r, ...e };
}
function h(r) {
var t, o;
let n = (t = Object.getOwnPropertyDescriptor(r.props, "ref")) == null ? void 0 : t.get, e = n && "isReactWarning" in n && n.isReactWarning;
return e ? r.ref : (n = (o = Object.getOwnPropertyDescriptor(r, "ref")) == null ? void 0 : o.get, e = n && "isReactWarning" in n && n.isReactWarning, e ? r.props.ref : r.props.ref || r.ref);
}
export {
m as Slot,
d as Slottable
};
//# sourceMappingURL=index.es257.js.map