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