From f914ff8376dd91c4f6f8ca149e1cb6becb622d88 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 2 Oct 2023 18:45:30 +0200
Subject: refactor(components): rewrite Link component

* rename `external` prop to `isExternal`
* rename `download` prop to `isDownload`
* rewrite CSS to reduce code length and complexity
* move link styles in Sass placeholders to avoid repeats because of WordPress
articles
* move NavLink component to molecules
---
 src/components/molecules/nav/nav-link/nav-link.tsx | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/components/molecules/nav/nav-link/nav-link.tsx

(limited to 'src/components/molecules/nav/nav-link/nav-link.tsx')

diff --git a/src/components/molecules/nav/nav-link/nav-link.tsx b/src/components/molecules/nav/nav-link/nav-link.tsx
new file mode 100644
index 0000000..f9fc529
--- /dev/null
+++ b/src/components/molecules/nav/nav-link/nav-link.tsx
@@ -0,0 +1,44 @@
+import {
+  type ForwardRefRenderFunction,
+  forwardRef,
+  type ReactNode,
+} from 'react';
+import { Link, type LinkProps } from '../../../atoms';
+import styles from './nav-link.module.scss';
+
+export type NavLinkProps = Omit<LinkProps, 'children' | 'disableTransition'> & {
+  /**
+   * Should the logo and label be inlined?
+   *
+   * @default false
+   */
+  isInline?: boolean;
+  /**
+   * The link label.
+   */
+  label: string;
+  /**
+   * The link logo.
+   */
+  logo?: ReactNode;
+};
+
+const NavLinkWithRef: ForwardRefRenderFunction<
+  HTMLAnchorElement,
+  NavLinkProps
+> = ({ className = '', isInline = false, label, logo, ...props }, ref) => {
+  const linkClass = [
+    styles.link,
+    styles[isInline ? 'link--inline' : 'link--stack'],
+    className,
+  ].join(' ');
+
+  return (
+    <Link {...props} className={linkClass} disableTransition ref={ref}>
+      {logo ? <span className={styles.logo}>{logo}</span> : null}
+      {label}
+    </Link>
+  );
+};
+
+export const NavLink = forwardRef(NavLinkWithRef);
-- 
cgit v1.2.3

