From 4a6f3dbde9adaa671e622215654a1dd9b329610d Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 12 Apr 2022 16:28:25 +0200 Subject: chore: add a Nav component --- src/components/atoms/links/nav-link.module.scss | 4 +- src/components/molecules/nav/nav.module.scss | 22 ++++++++ src/components/molecules/nav/nav.stories.tsx | 75 +++++++++++++++++++++++++ src/components/molecules/nav/nav.test.tsx | 28 +++++++++ src/components/molecules/nav/nav.tsx | 71 +++++++++++++++++++++++ 5 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 src/components/molecules/nav/nav.module.scss create mode 100644 src/components/molecules/nav/nav.stories.tsx create mode 100644 src/components/molecules/nav/nav.test.tsx create mode 100644 src/components/molecules/nav/nav.tsx (limited to 'src') diff --git a/src/components/atoms/links/nav-link.module.scss b/src/components/atoms/links/nav-link.module.scss index 24e8737..241c9c3 100644 --- a/src/components/atoms/links/nav-link.module.scss +++ b/src/components/atoms/links/nav-link.module.scss @@ -15,8 +15,7 @@ row-gap: var(--spacing-2xs); min-width: var(--link-min-width, fun.convert-px(85)); padding: var(--spacing-xs); - background: var(--color-bg); - background-repeat: no-repeat; + background: inherit; font-size: var(--font-size-sm); font-variant: small-caps; font-weight: 600; @@ -25,7 +24,6 @@ @include mix.media("screen") { @include mix.dimensions("md") { - background-color: inherit; border-radius: 8%; } } diff --git a/src/components/molecules/nav/nav.module.scss b/src/components/molecules/nav/nav.module.scss new file mode 100644 index 0000000..9c0f6de --- /dev/null +++ b/src/components/molecules/nav/nav.module.scss @@ -0,0 +1,22 @@ +@use "@styles/abstracts/mixins" as mix; +@use "@styles/abstracts/placeholders"; + +.nav { + &__list { + @extend %reset-list; + + display: flex; + flex-flow: row wrap; + gap: var(--spacing-2xs); + align-items: center; + } + + &--footer & { + &__item:not(:first-child) { + &::before { + content: "\2022"; + margin-right: var(--spacing-2xs); + } + } + } +} diff --git a/src/components/molecules/nav/nav.stories.tsx b/src/components/molecules/nav/nav.stories.tsx new file mode 100644 index 0000000..9975bbd --- /dev/null +++ b/src/components/molecules/nav/nav.stories.tsx @@ -0,0 +1,75 @@ +import Envelop from '@components/atoms/icons/envelop'; +import Home from '@components/atoms/icons/home'; +import { ComponentMeta, ComponentStory } from '@storybook/react'; +import { IntlProvider } from 'react-intl'; +import NavComponent, { type NavItem } from './nav'; + +const MainNavItems: NavItem[] = [ + { id: 'homeLink', href: '/', label: 'Home', logo: }, + { id: 'contactLink', href: '/contact', label: 'Contact', logo: }, +]; + +const FooterNavItems: NavItem[] = [ + { id: 'contactLink', href: '/contact', label: 'Contact' }, + { id: 'legalLink', href: '/legal-notice', label: 'Legal notice' }, +]; + +export default { + title: 'Molecules/Nav', + component: NavComponent, + argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames to the navigation wrapper.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, + items: { + control: { + type: null, + }, + description: 'The nav items.', + type: { + name: 'other', + required: true, + value: '', + }, + }, + kind: { + control: { + type: 'select', + }, + description: 'The navigation kind.', + options: ['main', 'footer'], + type: { + name: 'string', + required: true, + }, + }, + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ( + + + +); + +export const MainNav = Template.bind({}); +MainNav.args = { + items: MainNavItems, + kind: 'main', +}; + +export const FooterNav = Template.bind({}); +FooterNav.args = { + items: FooterNavItems, + kind: 'footer', +}; diff --git a/src/components/molecules/nav/nav.test.tsx b/src/components/molecules/nav/nav.test.tsx new file mode 100644 index 0000000..183ca0b --- /dev/null +++ b/src/components/molecules/nav/nav.test.tsx @@ -0,0 +1,28 @@ +import Envelop from '@components/atoms/icons/envelop'; +import Home from '@components/atoms/icons/home'; +import { render, screen } from '@test-utils'; +import Nav, { type NavItem } from './nav'; + +const navItems: NavItem[] = [ + { id: 'homeLink', href: '/', label: 'Home', logo: }, + { id: 'contactLink', href: '/contact', label: 'Contact', logo: }, +]; + +describe('Nav', () => { + it('renders a main navigation', () => { + render(