-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the Navigation types when generating links. (#786)
* Fix the Navigation types when generating links.
- Loading branch information
Showing
13 changed files
with
148 additions
and
85 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
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
48 changes: 25 additions & 23 deletions
48
src/components/Navigation/NavigationLink/NavigationLink.tsx
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,48 +1,50 @@ | ||
import type { HTMLProps } from "react"; | ||
import React from "react"; | ||
import { PropsWithSpread } from "types"; | ||
import { isNavigationAnchor, isNavigationButton } from "utils"; | ||
|
||
import type { GenerateLink, NavLink } from "../types"; | ||
|
||
type Props = PropsWithSpread< | ||
NavLink & { | ||
generateLink?: GenerateLink; | ||
}, | ||
HTMLProps<HTMLAnchorElement> | ||
>; | ||
type Props = { | ||
generateLink?: GenerateLink; | ||
link: NavLink; | ||
}; | ||
|
||
/** | ||
* This component is used internally to display links inside the Navigation component. | ||
*/ | ||
const NavigationLink = ({ | ||
generateLink, | ||
isSelected, | ||
label, | ||
url, | ||
...props | ||
}: Props): JSX.Element => { | ||
const ariaCurrent = isSelected ? "page" : undefined; | ||
const NavigationLink = ({ generateLink, link }: Props): JSX.Element | null => { | ||
// const ariaCurrent = isSelected ? "page" : undefined; | ||
if (generateLink) { | ||
const { isSelected, ...linkProps } = link; | ||
// If a function has been provided then use it to generate the link element. | ||
return ( | ||
<> | ||
{generateLink({ | ||
isSelected, | ||
label, | ||
url, | ||
"aria-current": ariaCurrent, | ||
...props, | ||
"aria-current": isSelected ? "page" : undefined, | ||
...linkProps, | ||
})} | ||
</> | ||
); | ||
} else { | ||
// If a function has not been provided then use a standard anchor element. | ||
} else if (isNavigationAnchor(link)) { | ||
const { isSelected, label, url, ...linkProps } = link; | ||
return ( | ||
<a href={url} {...props} aria-current={ariaCurrent}> | ||
<a | ||
{...linkProps} | ||
href={url} | ||
aria-current={isSelected ? "page" : undefined} | ||
> | ||
{label} | ||
</a> | ||
); | ||
} else if (isNavigationButton(link)) { | ||
const { isSelected, label, url, ...linkProps } = link; | ||
return ( | ||
<button {...linkProps} aria-current={isSelected ? "page" : undefined}> | ||
{label} | ||
</button> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export default NavigationLink; |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* The Vanilla theme types. | ||
*/ | ||
export enum Theme { | ||
/** | ||
* The dark Vanilla theme. | ||
*/ | ||
DARK = "dark", | ||
/** | ||
* The light Vanilla theme. | ||
*/ | ||
LIGHT = "light", | ||
} |
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