From 5d3e8a4d0c2ce2ad8f22df857ab3ce54fcfc38ac Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Fri, 3 Nov 2023 12:22:47 +0100
Subject: refactor(components): replace Toolbar with Navbar component

* remove SearchModal and SettingsModal components
* add a generic NavbarItem component (instead of the previous toolbar
items to avoid unreadable styles...)
* move FlippingLabel component logic into NavbarItem since it is only
used here
---
 src/components/organisms/navbar/navbar.tsx | 65 ++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 src/components/organisms/navbar/navbar.tsx

(limited to 'src/components/organisms/navbar/navbar.tsx')

diff --git a/src/components/organisms/navbar/navbar.tsx b/src/components/organisms/navbar/navbar.tsx
new file mode 100644
index 0000000..ee379e9
--- /dev/null
+++ b/src/components/organisms/navbar/navbar.tsx
@@ -0,0 +1,65 @@
+import {
+  type ForwardRefRenderFunction,
+  forwardRef,
+  type ReactNode,
+} from 'react';
+import { List, type ListProps } from '../../atoms';
+import { NavbarItem, type NavbarItemProps } from './navbar-item';
+import styles from './navbar.module.scss';
+
+export type NavbarItemData = Pick<
+  NavbarItemProps,
+  | 'icon'
+  | 'id'
+  | 'isActive'
+  | 'label'
+  | 'modalHeading'
+  | 'modalVisibleFrom'
+  | 'onDeactivate'
+  | 'onToggle'
+  | 'showIconOnModal'
+> & {
+  contents: ReactNode;
+};
+
+export type NavbarItems = [NavbarItemData, NavbarItemData?, NavbarItemData?];
+
+export type NavbarProps = Omit<
+  ListProps<false, false>,
+  'children' | 'hideMarker' | 'isHierarchical' | 'isInline' | 'isOrdered'
+> & {
+  /**
+   * The navbar items.
+   *
+   * The number of items should not exceed 3 because of the modal position on
+   * small screens.
+   */
+  items: NavbarItems;
+};
+
+const NavbarWithRef: ForwardRefRenderFunction<HTMLUListElement, NavbarProps> = (
+  { className = '', items, ...props },
+  ref
+) => {
+  const wrapperClass = `${styles.wrapper} ${className}`;
+  const navItems = items.filter(
+    (item): item is NavbarItemData => item !== undefined
+  );
+
+  return (
+    <List {...props} className={wrapperClass} hideMarker isInline ref={ref}>
+      {navItems.map(({ contents, ...item }) => (
+        <NavbarItem {...item} className={styles.item} key={item.id}>
+          {contents}
+        </NavbarItem>
+      ))}
+    </List>
+  );
+};
+
+/**
+ * Navbar component
+ *
+ * Render the website navbar.
+ */
+export const Navbar = forwardRef(NavbarWithRef);
-- 
cgit v1.2.3

