diff --git a/src/components/Navigation.js b/src/components/Navigation.js index 4dd998a4a..1f33c28c3 100644 --- a/src/components/Navigation.js +++ b/src/components/Navigation.js @@ -17,7 +17,23 @@ const iconLibrary = { 'Explore docs': 'book-open', }; -const NavigationItems = ({ pages, filteredPageNames, depthLevel = 0 }) => { +const getHighlightedText = (text, highlight) => { + const parts = text.split(new RegExp(`(${highlight})`, 'gi')); + return ( + + {parts.map((part) => + part.toLowerCase() === highlight.toLowerCase() ? {part} : part + )} + + ); +}; + +const NavigationItems = ({ + pages, + filteredPageNames, + searchTerm, + depthLevel = 0, +}) => { const crumbs = useContext(BreadcrumbContext).flatMap((x) => x.displayName); const isHomePage = crumbs.length === 0 && depthLevel === 0; @@ -32,9 +48,12 @@ const NavigationItems = ({ pages, filteredPageNames, depthLevel = 0 }) => { return Object.entries(groupedPages).map(([group, pages]) => ( - {group && ( -
  • {group}
  • - )} + {(group && !filteredPageNames) || + (group && + filteredPageNames && + pages.some((el) => filteredPageNames.includes(el.displayName)) && ( +
  • {group}
  • + ))} {pages.map((page) => { const [isExpanded, setIsExpanded] = useState( isHomePage || crumbs.includes(page.displayName) @@ -47,6 +66,9 @@ const NavigationItems = ({ pages, filteredPageNames, depthLevel = 0 }) => { name={iconLibrary[page.displayName]} /> ); + const display = filteredPageNames + ? getHighlightedText(page.displayName, searchTerm) + : page.displayName; return (
  • { > {headerIcon} - {page.displayName} + {display} {isCurrentPage && ( { /> )} {headerIcon} - {page.displayName} + {display} )} {page.children && ( @@ -117,6 +139,7 @@ const NavigationItems = ({ pages, filteredPageNames, depthLevel = 0 }) => { pages={page.children} filteredPageNames={filteredPageNames} depthLevel={depthLevel + 1} + searchTerm={searchTerm} /> )} @@ -127,23 +150,6 @@ const NavigationItems = ({ pages, filteredPageNames, depthLevel = 0 }) => { )); }; -// const filterPages = (pages, _searchTerm, parent = {}) => { -// const filteredPage = parent; -// return pages.map((page) => { -// if (page.children) { -// return filterPages(page.children, _searchTerm, page); -// } else if (matchSearchString(page.displayName, _searchTerm)) { -// filteredPage.children = filteredPage.children.filter((el) => -// matchSearchString(el.displayName, _searchTerm) -// ); -// return filteredPage; -// } else if (matchSearchString(parent.displayName, _searchTerm)) { -// delete filteredPage.children; -// return filteredPage; -// } -// }); -// }; - const filterPageNames = (pages, searchTerm, parent = []) => { return [ ...new Set( @@ -174,7 +180,11 @@ const Navigation = ({ className, searchTerm }) => { aria-label="Navigation" >
      - +
    ); diff --git a/src/components/Navigation.module.scss b/src/components/Navigation.module.scss index 25a6be44b..09d79ab13 100644 --- a/src/components/Navigation.module.scss +++ b/src/components/Navigation.module.scss @@ -99,4 +99,7 @@ button.navLink { ul { display: block; } + .nestedChevron { + transform: rotate(90deg); + } }