From 351532e9906e32c862bf6810a3871993cde13ba2 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Thu, 31 Mar 2022 15:30:07 +0200
Subject: chore: add a button link component

---
 src/components/atoms/buttons/button-link.tsx | 49 ++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 src/components/atoms/buttons/button-link.tsx

(limited to 'src/components/atoms/buttons/button-link.tsx')

diff --git a/src/components/atoms/buttons/button-link.tsx b/src/components/atoms/buttons/button-link.tsx
new file mode 100644
index 0000000..c33a4b7
--- /dev/null
+++ b/src/components/atoms/buttons/button-link.tsx
@@ -0,0 +1,49 @@
+import Link from 'next/link';
+import { FC } from 'react';
+import styles from './buttons.module.scss';
+
+type ButtonLinkProps = {
+  /**
+   * ButtonLink accessible label.
+   */
+  'aria-label'?: string;
+  /**
+   * True if it is an external link. Default: false.
+   */
+  external?: boolean;
+  /**
+   * ButtonLink kind. Default: secondary.
+   */
+  kind?: 'primary' | 'secondary';
+  /**
+   * Define an URL as target.
+   */
+  target: string;
+};
+
+/**
+ * ButtonLink component
+ *
+ * Use a button-like link as call to action.
+ */
+const ButtonLink: FC<ButtonLinkProps> = ({
+  children,
+  target,
+  kind = 'secondary',
+  external = false,
+  ...props
+}) => {
+  const kindClass = styles[`btn--${kind}`];
+
+  return external ? (
+    <a href={target} className={`${styles.btn} ${kindClass}`} {...props}>
+      {children}
+    </a>
+  ) : (
+    <Link href={target} {...props}>
+      <a className={`${styles.btn} ${kindClass}`}>{children}</a>
+    </Link>
+  );
+};
+
+export default ButtonLink;
-- 
cgit v1.2.3

