@sydykov/ui
Version:
Pure ui library
127 lines (126 loc) • 4.74 kB
JavaScript
import { jsx as p, Fragment as N } from "react/jsx-runtime";
import * as s from "react";
import { c as R, a as j } from "../../utils-A5nzBcJc.js";
function v(n, t) {
if (typeof n == "function")
return n(t);
n != null && (n.current = t);
}
function E(...n) {
return (t) => {
let e = !1;
const i = n.map((r) => {
const o = v(r, t);
return !e && typeof o == "function" && (e = !0), o;
});
if (e)
return () => {
for (let r = 0; r < i.length; r++) {
const o = i[r];
typeof o == "function" ? o() : v(n[r], null);
}
};
};
}
var C = s.forwardRef((n, t) => {
const { children: e, ...i } = n, r = s.Children.toArray(e), o = r.find(P);
if (o) {
const a = o.props.children, u = r.map((m) => m === o ? s.Children.count(a) > 1 ? s.Children.only(null) : s.isValidElement(a) ? a.props.children : null : m);
return /* @__PURE__ */ p(g, { ...i, ref: t, children: s.isValidElement(a) ? s.cloneElement(a, void 0, u) : null });
}
return /* @__PURE__ */ p(g, { ...i, ref: t, children: e });
});
C.displayName = "Slot";
var g = s.forwardRef((n, t) => {
const { children: e, ...i } = n;
if (s.isValidElement(e)) {
const r = k(e);
return s.cloneElement(e, {
...S(i, e.props),
// @ts-ignore
ref: t ? E(t, r) : r
});
}
return s.Children.count(e) > 1 ? s.Children.only(null) : null;
});
g.displayName = "SlotClone";
var O = ({ children: n }) => /* @__PURE__ */ p(N, { children: n });
function P(n) {
return s.isValidElement(n) && n.type === O;
}
function S(n, t) {
const e = { ...t };
for (const i in t) {
const r = n[i], o = t[i];
/^on[A-Z]/.test(i) ? r && o ? e[i] = (...u) => {
o(...u), r(...u);
} : r && (e[i] = r) : i === "style" ? e[i] = { ...r, ...o } : i === "className" && (e[i] = [r, o].filter(Boolean).join(" "));
}
return { ...n, ...e };
}
function k(n) {
var i, r;
let t = (i = Object.getOwnPropertyDescriptor(n.props, "ref")) == null ? void 0 : i.get, e = t && "isReactWarning" in t && t.isReactWarning;
return e ? n.ref : (t = (r = Object.getOwnPropertyDescriptor(n, "ref")) == null ? void 0 : r.get, e = t && "isReactWarning" in t && t.isReactWarning, e ? n.props.ref : n.props.ref || n.ref);
}
const b = (n) => typeof n == "boolean" ? `${n}` : n === 0 ? "0" : n, x = R, W = (n, t) => (e) => {
var i;
if ((t == null ? void 0 : t.variants) == null) return x(n, e == null ? void 0 : e.class, e == null ? void 0 : e.className);
const { variants: r, defaultVariants: o } = t, a = Object.keys(r).map((l) => {
const d = e == null ? void 0 : e[l], f = o == null ? void 0 : o[l];
if (d === null) return null;
const c = b(d) || b(f);
return r[l][c];
}), u = e && Object.entries(e).reduce((l, d) => {
let [f, c] = d;
return c === void 0 || (l[f] = c), l;
}, {}), m = t == null || (i = t.compoundVariants) === null || i === void 0 ? void 0 : i.reduce((l, d) => {
let { class: f, className: c, ...V } = d;
return Object.entries(V).every((w) => {
let [h, y] = w;
return Array.isArray(y) ? y.includes({
...o,
...u
}[h]) : {
...o,
...u
}[h] === y;
}) ? [
...l,
f,
c
] : l;
}, []);
return x(n, a, m, e == null ? void 0 : e.class, e == null ? void 0 : e.className);
}, A = W(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline"
},
size: {
default: "h-9 px-4 py-2",
sm: "h-8 rounded-md px-3 text-xs",
lg: "h-10 rounded-md px-8",
icon: "h-9 w-9"
}
},
defaultVariants: {
variant: "default",
size: "default"
}
}
), _ = s.forwardRef(
({ className: n, variant: t, size: e, asChild: i = !1, ...r }, o) => /* @__PURE__ */ p(i ? C : "button", { className: j(A({ variant: t, size: e, className: n })), ref: o, ...r })
);
_.displayName = "Button";
export {
_ as Button,
A as buttonVariants
};