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