-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: fix header navigation active nested menu highlight (#167) * feat: update selected match util (#167) --------- Co-authored-by: Fran McDade <franmcdade@Frans-MacBook-Pro.local>
- Loading branch information
Showing
15 changed files
with
223 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 9 additions & 17 deletions
26
...ponents/Layout/components/Header/components/Content/components/Navigation/common/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import { SELECTED_MATCH } from "../../../../../common/entities"; | ||
|
||
/** | ||
* Returns true if the navigation link is selected. | ||
* @param url - The URL of the navigation link. | ||
* The pathname is matched against the selected patterns. | ||
* @param pathname - The current pathname. | ||
* @param selectedMatch - The selected match type. | ||
* @param selectedPatterns - Selected match patterns. | ||
* @returns true if the navigation link is selected. | ||
*/ | ||
export function isNavigationLinkSelected( | ||
url: string, | ||
pathname?: string, | ||
selectedMatch: SELECTED_MATCH = SELECTED_MATCH.STARTS_WITH | ||
selectedPatterns?: string[] | ||
): boolean { | ||
if (!pathname) return false; | ||
if (isSelectedMatchEqual(selectedMatch)) return url === pathname; | ||
return pathname.startsWith(url); | ||
} | ||
|
||
/** | ||
* Returns true if the selected match type is "EQUAL". | ||
* @param selectedMatch - The selected match type. | ||
* @returns True if the selected match type is "EQUAL". | ||
*/ | ||
export function isSelectedMatchEqual(selectedMatch: SELECTED_MATCH): boolean { | ||
return selectedMatch === SELECTED_MATCH.EQUALS; | ||
for (const selectedPattern of selectedPatterns ?? []) { | ||
if (new RegExp(selectedPattern).test(pathname)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.