diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-25 17:23:53 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | c21a137e1991af1331fe5768fc6bac15ea9230b1 (patch) | |
| tree | 80569408dbed888273a15d9ae543f553f2798a9b /src/components/organisms/nav/main-nav/main-nav.tsx | |
| parent | 73e12fe8ae059ef70bbdf8716af421cb72aec76c (diff) | |
refactor(components): extract MainNav component from toolbar
Diffstat (limited to 'src/components/organisms/nav/main-nav/main-nav.tsx')
| -rw-r--r-- | src/components/organisms/nav/main-nav/main-nav.tsx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/components/organisms/nav/main-nav/main-nav.tsx b/src/components/organisms/nav/main-nav/main-nav.tsx new file mode 100644 index 0000000..5a19399 --- /dev/null +++ b/src/components/organisms/nav/main-nav/main-nav.tsx @@ -0,0 +1,47 @@ +import { + type ForwardRefRenderFunction, + type ReactNode, + forwardRef, +} from 'react'; +import { Nav, type NavProps } from '../../../atoms'; +import { NavItem, NavLink, NavList } from '../../../molecules'; + +export type MainNavItem = { + id: string; + href: string; + label: string; + logo?: ReactNode; +}; + +export type MainNavProps = Omit<NavProps, 'children'> & { + /** + * The main nav items. + */ + items: MainNavItem[]; +}; + +const MainNavWithRef: ForwardRefRenderFunction<HTMLElement, MainNavProps> = ( + { className = '', items, ...props }, + ref +) => { + const wrapperClass = `${className}`; + + return ( + <Nav {...props} className={wrapperClass} ref={ref}> + <NavList isInline spacing="2xs"> + {items.map(({ id, ...link }) => ( + <NavItem key={id}> + <NavLink {...link} isStack variant="main" /> + </NavItem> + ))} + </NavList> + </Nav> + ); +}; + +/** + * MainNav component + * + * Render the main navigation. + */ +export const MainNav = forwardRef(MainNavWithRef); |
