From 891441a76173c708c6604fa203b175aefa222333 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 9 Oct 2023 16:31:00 +0200
Subject: refactor(components): rewrite Branding component

The component should only be responsible of the layout for the logo,
the name and the optional baseline. Also, the homepage url could
be different from `/` so the consumer should give the right url.
---
 src/components/molecules/branding/branding.tsx | 57 ++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 src/components/molecules/branding/branding.tsx

(limited to 'src/components/molecules/branding/branding.tsx')

diff --git a/src/components/molecules/branding/branding.tsx b/src/components/molecules/branding/branding.tsx
new file mode 100644
index 0000000..bb88a04
--- /dev/null
+++ b/src/components/molecules/branding/branding.tsx
@@ -0,0 +1,57 @@
+import {
+  type HTMLAttributes,
+  type ForwardRefRenderFunction,
+  forwardRef,
+  type ReactElement,
+} from 'react';
+import styles from './branding.module.scss';
+import { Link } from 'src/components/atoms';
+
+export type BrandingProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
+  /**
+   * The brand baseline.
+   */
+  baseline?: ReactElement | null;
+  /**
+   * The brand logo.
+   *
+   * The logo size should not exceed ~200px.
+   */
+  logo: ReactElement;
+  /**
+   * The brand name.
+   */
+  name: ReactElement;
+  /**
+   * The homepage url if you want to wrap the name with a link.
+   */
+  url?: string;
+};
+
+const BrandingWithRef: ForwardRefRenderFunction<
+  HTMLDivElement,
+  BrandingProps
+> = ({ className = '', baseline, logo, name, url, ...props }, ref) => {
+  const wrapperClass = `${styles.wrapper} ${className}`;
+
+  return (
+    <div {...props} className={wrapperClass} ref={ref}>
+      {logo}
+      {url ? (
+        <Link className={styles.link} href={url}>
+          {name}
+        </Link>
+      ) : (
+        name
+      )}
+      {baseline}
+    </div>
+  );
+};
+
+/**
+ * Branding component
+ *
+ * Render the branding logo, title and optional baseline.
+ */
+export const Branding = forwardRef(BrandingWithRef);
-- 
cgit v1.2.3

