-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components and RegularLink): ✨ initiate regular link (still messy)
- Loading branch information
1 parent
7c30b31
commit 9c3a1ea
Showing
3 changed files
with
83 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import clsx from "clsx"; | ||
import Link, { LinkProps } from "next/link"; | ||
import React from "react"; | ||
|
||
type RegularLinkProps = { | ||
href: string; | ||
children: React.ReactNode; | ||
isOpenNewTab?: boolean; | ||
className?: string; | ||
nextLinkProps?: Omit<LinkProps, "href">; | ||
} & React.ComponentPropsWithRef<"a">; | ||
|
||
const RegularLink = ({ | ||
href, | ||
children, | ||
isOpenNewTab, | ||
className, | ||
nextLinkProps, | ||
}: RegularLinkProps) => { | ||
const isNewTab = | ||
isOpenNewTab !== undefined | ||
? (isOpenNewTab = true) | ||
: href && !href.startsWith("/") && !href.startsWith("#"); | ||
if (isNewTab) { | ||
return ( | ||
<a | ||
href={href} | ||
target="_blank" | ||
rel="noreferrer" | ||
className={clsx("cursor-ne-resize", className)} | ||
> | ||
{children} | ||
</a> | ||
); | ||
} | ||
return ( | ||
<Link href={href} {...nextLinkProps}> | ||
<a className={className}>{children}</a> | ||
</Link> | ||
); | ||
}; | ||
|
||
export default RegularLink; |
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,21 @@ | ||
import React from "react"; | ||
|
||
import RegularLink from "@/components/links/RegularLink"; | ||
import Layout from "@/layouts/Layout"; | ||
|
||
const Components = () => { | ||
return ( | ||
<Layout> | ||
<main className="flex flex-col gap-3"> | ||
<h1>Reusable Components</h1> | ||
<h3>Regular Link</h3> | ||
<div className="flex flex-row gap-3"> | ||
<RegularLink href="/">Internal Link</RegularLink> | ||
<RegularLink href="https://yehezgun.com">External Link</RegularLink> | ||
</div> | ||
</main> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default Components; |
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
9c3a1ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: