-
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.
* Added hooks for using custom links * Added custom link context hook * Added optional prop in layout component * Updated package.json
- Loading branch information
1 parent
2c86220
commit 17f4fe7
Showing
11 changed files
with
84 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ReactNode, createContext } from "react"; | ||
import type { LinkComponentType } from "./index"; | ||
|
||
const defaultLinkComponent: LinkComponentType = ({ | ||
href, | ||
className, | ||
children, | ||
}) => { | ||
return ( | ||
<a href={href} className={className}> | ||
{children} | ||
</a> | ||
); | ||
}; | ||
|
||
export const LinkContext = | ||
createContext<LinkComponentType>(defaultLinkComponent); | ||
|
||
type LinkProviderProps = { | ||
linkComponent?: LinkComponentType; | ||
children?: ReactNode; | ||
}; | ||
|
||
export const LinkProvider = ({ | ||
children, | ||
linkComponent = defaultLinkComponent, | ||
}: LinkProviderProps) => { | ||
return ( | ||
<LinkContext.Provider value={linkComponent}> | ||
{children} | ||
</LinkContext.Provider> | ||
); | ||
}; |
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 @@ | ||
import React, { useContext } from "react"; | ||
import { LinkContext } from "./components"; | ||
|
||
export type LinkComponentType = React.FC<{ | ||
href: string; | ||
className?: string; | ||
title?: string; | ||
onClick?: () => void; | ||
children?: React.ReactNode; | ||
}>; | ||
|
||
export const useLinkComponent = () => | ||
useContext<LinkComponentType>(LinkContext); |
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