aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/nav/nav-list
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-20 14:06:48 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:14:41 +0100
commitc6f6f8f895e68f2d85ca681997ef613d982bac14 (patch)
tree50e21f0721781aad231445c4e5af24deadb2d0de /src/components/molecules/nav/nav-list
parentc3cde71e60ae22d17c1d162f678f592915ac5398 (diff)
refactor(components): rewrite NavList component
* extract NavItem from NavList * remove `kind` and `listClassName` props (since the consumer has control over NavList, NavItem and NavLink components these props are obsolete)
Diffstat (limited to 'src/components/molecules/nav/nav-list')
-rw-r--r--src/components/molecules/nav/nav-list/index.ts1
-rw-r--r--src/components/molecules/nav/nav-list/nav-list.stories.tsx51
-rw-r--r--src/components/molecules/nav/nav-list/nav-list.test.tsx15
-rw-r--r--src/components/molecules/nav/nav-list/nav-list.tsx23
4 files changed, 90 insertions, 0 deletions
diff --git a/src/components/molecules/nav/nav-list/index.ts b/src/components/molecules/nav/nav-list/index.ts
new file mode 100644
index 0000000..8f253d2
--- /dev/null
+++ b/src/components/molecules/nav/nav-list/index.ts
@@ -0,0 +1 @@
+export * from './nav-list';
diff --git a/src/components/molecules/nav/nav-list/nav-list.stories.tsx b/src/components/molecules/nav/nav-list/nav-list.stories.tsx
new file mode 100644
index 0000000..c165ac7
--- /dev/null
+++ b/src/components/molecules/nav/nav-list/nav-list.stories.tsx
@@ -0,0 +1,51 @@
+import type { ComponentMeta, ComponentStory } from '@storybook/react';
+import { NavItem } from '../nav-item';
+import { NavLink } from '../nav-link';
+import { NavList } from './nav-list';
+
+/**
+ * Nav - Storybook Meta
+ */
+export default {
+ title: 'Molecules/Nav/NavList',
+ component: NavList,
+} as ComponentMeta<typeof NavList>;
+
+const Template: ComponentStory<typeof NavList> = (args) => (
+ <NavList {...args} />
+);
+
+const NavItems = () => (
+ <>
+ <NavItem>
+ <NavLink href="#item1" label="Item 1" />
+ </NavItem>
+ <NavItem>
+ <NavLink href="#item2" label="Item 2" />
+ </NavItem>
+ <NavItem>
+ <NavLink href="#item3" label="Item 3" />
+ </NavItem>
+ <NavItem>
+ <NavLink href="#item4" label="Item 4" />
+ </NavItem>
+ </>
+);
+
+/**
+ * NavList Stories - Default
+ */
+export const Default = Template.bind({});
+Default.args = {
+ children: <NavItems />,
+};
+
+/**
+ * NavList Stories - Inlined
+ */
+export const Inlined = Template.bind({});
+Inlined.args = {
+ children: <NavItems />,
+ isInline: true,
+ spacing: 'sm',
+};
diff --git a/src/components/molecules/nav/nav-list/nav-list.test.tsx b/src/components/molecules/nav/nav-list/nav-list.test.tsx
new file mode 100644
index 0000000..ac08681
--- /dev/null
+++ b/src/components/molecules/nav/nav-list/nav-list.test.tsx
@@ -0,0 +1,15 @@
+import { describe, expect, it } from '@jest/globals';
+import { render, screen as rtlScreen } from '@testing-library/react';
+import { NavList } from './nav-list';
+
+describe('NavList', () => {
+ it('renders its children', () => {
+ render(
+ <NavList>
+ <li>Nav item</li>
+ </NavList>
+ );
+
+ expect(rtlScreen.getByRole('list')).toBeInTheDocument();
+ });
+});
diff --git a/src/components/molecules/nav/nav-list/nav-list.tsx b/src/components/molecules/nav/nav-list/nav-list.tsx
new file mode 100644
index 0000000..bdf7487
--- /dev/null
+++ b/src/components/molecules/nav/nav-list/nav-list.tsx
@@ -0,0 +1,23 @@
+import { forwardRef, type ReactNode, type ForwardedRef } from 'react';
+import { List, type ListProps } from '../../../atoms';
+
+export type NavListProps<T extends boolean> = Omit<
+ ListProps<T, false>,
+ 'children' | 'hideMarker'
+> & {
+ /**
+ * The nav items.
+ */
+ children: ReactNode;
+};
+
+const NavListWithRef = <T extends boolean>(
+ { children, isInline, ...props }: NavListProps<T>,
+ ref: ForwardedRef<HTMLUListElement | HTMLOListElement>
+) => (
+ <List {...props} hideMarker isInline={isInline} ref={ref}>
+ {children}
+ </List>
+);
+
+export const NavList = forwardRef(NavListWithRef);