@payfit/unity-components
Version:
106 lines (105 loc) • 3.28 kB
JavaScript
import e from "../../../hooks/use-id.js";
import { navItemBase as t } from "./RawNavItem.js";
import n, { useCallback as r, useMemo as i, useState as a } from "react";
import { uyTv as o } from "@payfit/unity-themes";
import { jsx as s, jsxs as c } from "react/jsx-runtime";
import { Button as l } from "react-aria-components/Button";
import { Icon as u } from "@payfit/unity-icons";
//#region src/core/components/nav/parts/NavGroup.tsx
var d = o({
extend: t,
slots: {
base: "uy:border-1 uy:border-solid",
caret: "uy:transition-transform uy:duration-150 uy:delay-25 uy:ease-linear motion-reduce:transition-none",
contentWrapper: "uy:transition-[max-height] uy:duration-200 uy:ease-linear motion-reduce:transition-none",
content: "uy:list-none uy:flex uy:flex-col uy:gap-50 uy:transition-opacity uy:duration-150 uy:delay-25 uy:ease-linear"
},
variants: { expanded: {
true: {
base: ["", "uy:bg-surface-neutral uy:border-border-neutral uy:shadow-100"],
prefix: ["", "uy:text-content-primary"],
caret: "uy:rotate-180",
contentWrapper: "uy:max-h-[1000px] uy:overflow-visible",
label: "uy:typography-body-strong",
content: "uy:opacity-100 uy:visible"
},
false: {
caret: "uy:rotate-0",
contentWrapper: "uy:max-h-0 uy:overflow-hidden",
content: "uy:opacity-0 uy:invisible uy:pointer-events-none",
label: "uy:typography-body",
base: "uy:border-transparent"
}
} }
});
function f({ children: t, label: o, prefix: f, suffix: p, defaultExpanded: m = !1, isExpanded: h, onToggle: g, ..._ }) {
let v = e(), [y, b] = a(m), x = h !== void 0, S = x ? h : y, C = r(() => {
x || b((e) => !e), g?.(!S);
}, [
x,
S,
g
]), w = n.Children.map(t, (e) => n.isValidElement(e) ? n.cloneElement(e, {
isDisabled: !S,
level: 1
}) : e), T = `${v}-toggle`, E = `${v}-content`, { baseClassName: D, prefixClassName: O, labelClassName: k, suffixClassName: A, contentClassName: j, contentWrapperClassName: M, caretClassName: N } = i(() => {
let e = d({
level: 0,
expanded: S
});
return {
baseClassName: e.base({ className: "uy:w-full" }),
prefixClassName: e.prefix(),
suffixClassName: e.suffix(),
labelClassName: e.label(),
contentWrapperClassName: e.contentWrapper(),
contentClassName: e.content(),
caretClassName: e.caret()
};
}, [S]);
return /* @__PURE__ */ c("li", {
className: "uy:flex uy:flex-col uy:gap-50",
children: [/* @__PURE__ */ c(l, {
id: T,
className: D,
onPress: C,
"aria-expanded": S,
"aria-controls": E,
..._,
children: [
f && /* @__PURE__ */ s("span", {
className: O,
children: f({ isExpanded: S })
}),
/* @__PURE__ */ s("span", {
className: k,
children: o
}),
/* @__PURE__ */ c("span", {
className: A,
role: "presentation",
children: [p, /* @__PURE__ */ s(u, {
src: "CaretDownOutlined",
alt: "expand group",
size: 20,
className: N,
color: "inherit"
})]
})
]
}), /* @__PURE__ */ s("div", {
className: M,
style: { maxHeight: S ? 1e3 : 0 },
children: /* @__PURE__ */ s("ul", {
id: E,
className: j,
"aria-labelledby": T,
"aria-hidden": !S,
children: w
})
})]
});
}
f.displayName = "NavGroup";
//#endregion
export { f as NavGroup };