UNPKG

@primer/react-brand

Version:

Primer Brand is a GitHub's design system for creating React-based marketing websites and digital experiences.

73 lines (72 loc) 2.83 kB
import e from "../node_modules/clsx/dist/clsx.js"; import { useProvidedRefOrCreate as t } from "../hooks/useRef.js"; import { useOnClickOutside as n } from "../hooks/useOnClickOutside.js"; import { useKeyboardEscape as r } from "../hooks/useKeyboardEscape.js"; import { ChevronDownIcon as i } from "../node_modules/@primer/octicons-react/dist/index.esm.js"; import { useWindowSize as a } from "../hooks/useWindowSize.js"; import { useVisibilityObserver as o } from "./useVisibilityObserver.js"; import s from "./SubdomainNavBar.module.js"; import c, { forwardRef as l, useCallback as u, useRef as d, useState as f } from "react"; import { jsx as p, jsxs as m } from "react/jsx-runtime"; //#region src/SubdomainNavBar/NavigationVisbilityObserver.tsx var h = l(({ children: n, className: r, ...i }, l) => { let u = t(l), [d] = o(u, n), { isMedium: f } = a(), h = Object.values(d).includes(!1); return /* @__PURE__ */ m("ul", { className: e(s["SubdomainNavBar-primary-nav-list"], r), ref: u, ...i, children: [c.Children.map(n, (t) => { if (c.isValidElement(t)) { let n = t.props["data-navitemid"]; if (!n) return t; let r = d[n]; return c.cloneElement(t, { className: e(t.props.className, f && r && s["SubdomainNavBar-primary-nav-list-item--visible"], f && r === !1 && s["SubdomainNavBar-primary-nav-list-item--invisible"]) }); } return t; }), h && /* @__PURE__ */ p(g, { visibilityMap: d, children: n })] }); }); function g({ children: t, className: a, visibilityMap: o }) { let [l, h] = f(null), g = d(null); n(g, () => y()); let _ = !!l, v = (e) => { l ? y() : h(e.currentTarget); }, y = u(() => { h(null); }, []); return r(y), /* @__PURE__ */ m("li", { className: e(s["SubdomainNavBar-primary-nav-list-item--overflow"], a), ref: g, children: [/* @__PURE__ */ m("button", { "aria-expanded": _ ? "true" : "false", "aria-controls": "more-navigation", "aria-haspopup": "true", onClick: v, className: e(s["SubdomainNavBar-link"], s["SubdomainNavBar-more-link"]), children: ["More", /* @__PURE__ */ p(i, {})] }), /* @__PURE__ */ p("div", { id: "more-navigation", style: { display: _ ? "block" : "none" }, className: e(s["SubdomainNavBar-overflow-menu"]), children: /* @__PURE__ */ p("ul", { className: e(s["SubdomainNavBar-overflow-menu-list"]), children: c.Children.map(t, (t) => { if (c.isValidElement(t)) { let n = t.props["data-navitemid"]; return !n || o[n] ? null : /* @__PURE__ */ p(c.Fragment, { children: c.cloneElement(t, { onClick: y, className: e(s["SubdomainNavBar-overflow-menu-item"], t.props.className) }) }); } return null; }) }) })] }); } //#endregion export { h as NavigationVisbilityObserver }; //# sourceMappingURL=NavigationVisbilityObserver.js.map