UNPKG

@keycloakify/keycloak-account-ui

Version:

<p align="center"> <img src="https://github.com/user-attachments/assets/e31c4910-7205-441c-9a35-e134b806b3a8"> </p> <p align="center"> <i>Repackaged Keycloak Account UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-a

44 lines 2.74 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useEnvironment } from "../ui-shared"; import { Nav, NavExpandable, NavItem, NavList, PageSidebar, PageSidebarBody, Spinner, } from "@patternfly/react-core"; import { Suspense, useMemo, useState, } from "react"; import { useTranslation } from "react-i18next"; import { matchPath, useHref, useLinkClickHandler, useLocation, } from "react-router-dom"; import fetchContentJson from "../content/fetchContent"; import { environment } from "../environment"; import { usePromise } from "../utils/usePromise"; export const PageNav = () => { const [menuItems, setMenuItems] = useState(); const context = useEnvironment(); usePromise((signal) => fetchContentJson({ signal, context }), setMenuItems); return (_jsx(PageSidebar, { children: _jsx(PageSidebarBody, { children: _jsx(Nav, { children: _jsx(NavList, { children: _jsx(Suspense, { fallback: _jsx(Spinner, {}), children: menuItems === null || menuItems === void 0 ? void 0 : menuItems.filter((menuItem) => menuItem.isVisible ? context.environment.features[menuItem.isVisible] : true).map((menuItem) => (_jsx(NavMenuItem, { menuItem: menuItem }, menuItem.label))) }) }) }) }) })); }; function NavMenuItem({ menuItem }) { const { t } = useTranslation(); const { environment: { features }, } = useEnvironment(); const { pathname } = useLocation(); const isActive = useMemo(() => matchMenuItem(pathname, menuItem), [pathname, menuItem]); if ("path" in menuItem) { return (_jsx(NavLink, { to: menuItem.path, isActive: isActive, children: t(menuItem.label) })); } return (_jsx(NavExpandable, { "data-testid": menuItem.label, title: t(menuItem.label), isActive: isActive, isExpanded: isActive, children: menuItem.children .filter((menuItem) => menuItem.isVisible ? features[menuItem.isVisible] : true) .map((child) => (_jsx(NavMenuItem, { menuItem: child }, child.label))) })); } function matchMenuItem(currentPath, menuItem) { if ("path" in menuItem) { return !!matchPath(menuItem.path, currentPath); } return menuItem.children.some((child) => matchMenuItem(currentPath, child)); } export const NavLink = ({ to, isActive, children, }) => { const menuItemPath = `${new URL(environment.baseUrl).pathname}${to}`; const href = useHref(menuItemPath); const handleClick = useLinkClickHandler(menuItemPath); return (_jsx(NavItem, { "data-testid": to, to: href, isActive: isActive, onClick: (event) => // PatternFly does not have the correct type for this event, so we need to cast it. handleClick(event), children: children })); }; //# sourceMappingURL=PageNav.js.map