From 9c3a1ea7efcd97acbbb41c64606f6d324e7397d8 Mon Sep 17 00:00:00 2001 From: yehezkielgunawan Date: Tue, 1 Feb 2022 19:25:32 +0700 Subject: [PATCH] feat(components and RegularLink): :sparkles: initiate regular link (still messy) --- src/components/links/RegularLink.tsx | 43 ++++++++++++++++++++++++++++ src/pages/components.tsx | 21 ++++++++++++++ src/pages/index.tsx | 21 ++++++++++++-- 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/components/links/RegularLink.tsx create mode 100644 src/pages/components.tsx diff --git a/src/components/links/RegularLink.tsx b/src/components/links/RegularLink.tsx new file mode 100644 index 0000000..2f848a4 --- /dev/null +++ b/src/components/links/RegularLink.tsx @@ -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; +} & 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 ( + + {children} + + ); + } + return ( + + {children} + + ); +}; + +export default RegularLink; diff --git a/src/pages/components.tsx b/src/pages/components.tsx new file mode 100644 index 0000000..5fc6493 --- /dev/null +++ b/src/pages/components.tsx @@ -0,0 +1,21 @@ +import React from "react"; + +import RegularLink from "@/components/links/RegularLink"; +import Layout from "@/layouts/Layout"; + +const Components = () => { + return ( + +
+

Reusable Components

+

Regular Link

+
+ Internal Link + External Link +
+
+
+ ); +}; + +export default Components; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index bc7285e..056fe14 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,6 +1,7 @@ import clsx from "clsx"; import type { NextPage } from "next"; import Image from "next/image"; +import Link from "next/link"; import { AiFillGithub } from "react-icons/ai"; import { SiNetlify, SiVercel } from "react-icons/si"; @@ -10,7 +11,7 @@ const Home: NextPage = () => { return (
-

Hello World!

+

Hello World!

{ This is just a starter template, made using Next.js + Typescript + Tailwind CSS.

-
+
Next.jsLogo { Use This Template + + +