-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from atellmer/feature/router-link
Link & NavLink
- Loading branch information
Showing
20 changed files
with
260 additions
and
117 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
export { type Routes } from './create-routes'; | ||
export { type RouterRef, Router } from './router'; | ||
export { useLocation } from './use-location'; | ||
export { RouterLink } from './router-link'; | ||
export { useHistory } from './use-history'; | ||
export { useParams } from './use-params'; | ||
export { useMatch } from './use-match'; | ||
export { VERSION } from './constants'; | ||
export { NavLink } from './nav-link'; | ||
export { Link } from './link'; |
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 @@ | ||
export * from './link'; |
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,35 @@ | ||
import { type DarkElement, component, forwardRef, useEvent, detectIsFunction } from '@dark-engine/core'; | ||
import { type SyntheticEvent, type DarkJSX } from '@dark-engine/platform-browser'; | ||
|
||
import { useHistory } from '../use-history'; | ||
|
||
export type LinkProps = { | ||
to: string; | ||
slot: DarkElement; | ||
} & Omit<DarkJSX.Elements['a'], 'href'>; | ||
|
||
const Link = forwardRef<LinkProps, HTMLAnchorElement>( | ||
component( | ||
(props, ref) => { | ||
const { to, class: cn1, className: cn2, slot, onClick, ...rest } = props; | ||
const history = useHistory(); | ||
const className = cn1 || cn2; | ||
const handleClick = useEvent((e: SyntheticEvent<MouseEvent, HTMLAnchorElement>) => { | ||
e.preventDefault(); | ||
history.push(to); | ||
detectIsFunction(onClick) && onClick(e); | ||
}); | ||
|
||
return ( | ||
<a ref={ref} {...rest} href={to} class={className} onClick={handleClick}> | ||
{slot} | ||
</a> | ||
); | ||
}, | ||
{ | ||
displayName: 'Link', | ||
}, | ||
), | ||
); | ||
|
||
export { Link }; |
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 @@ | ||
export * from './nav-link'; |
Oops, something went wrong.