welcome-ui
Version:
Customizable design system with react, typescript, tailwindcss and ariakit.
62 lines (61 loc) • 2.11 kB
JavaScript
"use client";
import { c as q, M as l, B as A, K as F, u as N, e as I, d as h, U as x, V as p, W as M, q as Y, X as H, f as L, a as V } from "./U6HHPQDW-CzxyP5H7.js";
import { useRef as T, useState as b, useEffect as W } from "react";
var X = "button";
function v(a) {
if (!a.isTrusted) return !1;
const t = a.currentTarget;
return a.key === "Enter" ? l(t) || t.tagName === "SUMMARY" || t.tagName === "A" : a.key === " " ? l(t) || t.tagName === "SUMMARY" || t.tagName === "INPUT" || t.tagName === "SELECT" : !1;
}
var j = Symbol("command"), z = q(
function({ clickOnEnter: t = !0, clickOnSpace: s = !0, ...r }) {
const i = T(null), [C, D] = b(!1);
W(() => {
i.current && D(l(i.current));
}, []);
const [K, m] = b(!1), o = T(!1), d = A(r), [y, S] = F(r, j, !0), k = r.onKeyDown, U = N((e) => {
k == null || k(e);
const n = e.currentTarget;
if (e.defaultPrevented || y || d || !I(e) || h(n) || n.isContentEditable) return;
const u = t && e.key === "Enter", f = s && e.key === " ", c = e.key === "Enter" && !t, R = e.key === " " && !s;
if (c || R) {
e.preventDefault();
return;
}
if (u || f) {
const g = v(e);
if (u) {
if (!g) {
e.preventDefault();
const { view: G, ...B } = e, P = () => M(n, B);
x() ? p(n, "keyup", P) : queueMicrotask(P);
}
} else f && (o.current = !0, g || (e.preventDefault(), m(!0)));
}
}), E = r.onKeyUp, w = N((e) => {
if (E == null || E(e), e.defaultPrevented || y || d || e.metaKey) return;
const n = s && e.key === " ";
if (o.current && n && (o.current = !1, !v(e))) {
e.preventDefault(), m(!1);
const u = e.currentTarget, { view: f, ...c } = e;
queueMicrotask(() => M(u, c));
}
});
return r = {
"data-active": K || void 0,
type: C ? "button" : void 0,
...S,
...r,
ref: Y(i, r.ref),
onKeyDown: U,
onKeyUp: w
}, r = H(r), r;
}
);
L(function(t) {
const s = z(t);
return V(X, s);
});
export {
z as u
};