From c6212f927daf3c928f479afa052e4772216a2d8a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 21 Nov 2023 16:10:20 +0100 Subject: refactor(components): replace items prop in Navbar component * replace `items` prop with `children` prop: it is more readable this way, * handle navbar item state inside NavbarItem component: it avoid using three differents states and their methods to do exactly the same thing * remove useAutofocus hook since we can't use it anymore * add `onActivation` and `activationHandlerDelay` prop to NavbarItem component to be able to focus the search input only when the item is activated (it replicates the functioning of useAutofocus hook) * replace `ref` type in SearchForm component: it does not make sense to use an input ref for a form. Instead I use useImperativeHandle to provide different a focus method to the given ref. --- src/components/organisms/navbar/navbar.stories.tsx | 117 ++++++++------------- 1 file changed, 42 insertions(+), 75 deletions(-) (limited to 'src/components/organisms/navbar/navbar.stories.tsx') diff --git a/src/components/organisms/navbar/navbar.stories.tsx b/src/components/organisms/navbar/navbar.stories.tsx index fef995e..95b71ef 100644 --- a/src/components/organisms/navbar/navbar.stories.tsx +++ b/src/components/organisms/navbar/navbar.stories.tsx @@ -1,5 +1,6 @@ import type { ComponentMeta, ComponentStory } from '@storybook/react'; import { Navbar as NavbarComponent } from './navbar'; +import { NavbarItem } from './navbar-item'; /** * Navbar - Storybook Meta @@ -7,28 +8,15 @@ import { Navbar as NavbarComponent } from './navbar'; export default { title: 'Organisms/Navbar', component: NavbarComponent, - args: { - searchPage: '#', - }, argTypes: { - nav: { - description: 'The main nav items.', + children: { + description: 'The navbar items.', type: { name: 'object', required: true, value: {}, }, }, - searchPage: { - control: { - type: 'text', - }, - description: 'The search results page url.', - type: { - name: 'string', - required: true, - }, - }, }, parameters: { layout: 'fullscreen', @@ -39,72 +27,51 @@ const Template: ComponentStory = (args) => ( ); -const doNothing = () => { - // do nothing; +/** + * Navbar Stories - 1 item + */ +export const OneItem = Template.bind({}); +OneItem.args = { + children: ( + + The main nav contents + + ), }; /** - * Navbar Stories - With all items inactive + * Navbar Stories - 2 items */ -export const NavbarInactiveItems = Template.bind({}); -NavbarInactiveItems.args = { - items: [ - { - icon: 'hamburger', - id: 'main-nav', - isActive: false, - label: 'Nav', - contents: 'Main nav contents', - onToggle: doNothing, - }, - { - icon: 'magnifying-glass', - id: 'search', - isActive: false, - label: 'Search', - contents: 'Search contents', - onToggle: doNothing, - }, - { - icon: 'cog', - id: 'settings', - isActive: false, - label: 'Settings', - contents: 'Settings contents', - onToggle: doNothing, - }, - ], +export const TwoItems = Template.bind({}); +TwoItems.args = { + children: ( + <> + + The main nav contents + + + A search form + + + ), }; /** - * Navbar Stories - With one item active + * Navbar Stories - 3 items */ -export const NavbarActiveItem = Template.bind({}); -NavbarActiveItem.args = { - items: [ - { - icon: 'hamburger', - id: 'main-nav', - isActive: true, - label: 'Nav', - contents: 'Main nav contents', - onToggle: doNothing, - }, - { - icon: 'magnifying-glass', - id: 'search', - isActive: false, - label: 'Search', - contents: 'Search contents', - onToggle: doNothing, - }, - { - icon: 'cog', - id: 'settings', - isActive: false, - label: 'Settings', - contents: 'Settings contents', - onToggle: doNothing, - }, - ], +export const ThreeItems = Template.bind({}); +ThreeItems.args = { + children: ( + <> + + The main nav contents + + + A search form + + + A settings form + + + ), }; -- cgit v1.2.3