diff --git a/components/Common/Sidebar/SidebarGroup/index.tsx b/components/Common/Sidebar/SidebarGroup/index.tsx index f9d734d43d512..8870a08602b34 100644 --- a/components/Common/Sidebar/SidebarGroup/index.tsx +++ b/components/Common/Sidebar/SidebarGroup/index.tsx @@ -1,38 +1,33 @@ -import type { FC } from 'react'; +import type { ComponentProps, FC } from 'react'; import SidebarItem from '@/components/Common/Sidebar/SidebarItem'; import styles from './index.module.css'; -import type { ActiveItem, SidebarGroupType } from '..'; -type SideBarGroupProps = SidebarGroupType & { - activeItem?: ActiveItem; - setActiveItem: (item: ActiveItem) => void; +type SidebarGroupProps = { + groupName: string; + items: ComponentProps[]; + activeItem?: ComponentProps; }; -const SidebarGroup: FC = ({ +const SidebarGroup: FC = ({ groupName, items, activeItem, - setActiveItem, }) => { - const handleSideBarItemClick = (title: string) => { - setActiveItem({ groupName, title }); - }; - return (
    - {items.map(item => ( + {items.map(({ title, url, isActive }) => ( ))}
diff --git a/components/Common/Sidebar/SidebarItem/index.tsx b/components/Common/Sidebar/SidebarItem/index.tsx index 235388c3e3946..b43c684643c0a 100644 --- a/components/Common/Sidebar/SidebarItem/index.tsx +++ b/components/Common/Sidebar/SidebarItem/index.tsx @@ -4,24 +4,22 @@ import type { FC } from 'react'; import LocalizedLink from '@/components/LocalizedLink'; import styles from './index.module.css'; -import type { SidebarItemType } from '..'; -type SideBarItemProps = SidebarItemType & { +type SidebarItemProps = { + title: string; + url: string; isActive?: boolean; - onClick: (title: string) => void; }; -const SidebarItem: FC = ({ +const SidebarItem: FC = ({ url, title, - onClick, - isActive, + isActive = false, }) => (
  • onClick(title)} > {title}
  • diff --git a/components/Common/Sidebar/index.stories.tsx b/components/Common/Sidebar/index.stories.tsx index 1001085962544..edca05565931e 100644 --- a/components/Common/Sidebar/index.stories.tsx +++ b/components/Common/Sidebar/index.stories.tsx @@ -38,4 +38,41 @@ export const Default: Story = { }, }; +export const ActiveItem: Story = { + args: { + groups: [ + { + groupName: 'group1', + items: [ + { + url: '/item1', + title: 'item1', + }, + { + url: '/item2', + title: 'item2', + }, + ], + }, + { + groupName: 'group2', + items: [ + { + url: '/item3', + title: 'item3', + }, + { + url: '/item4', + title: 'item4', + }, + ], + }, + ], + activeItem: { + url: '/item2', + title: 'item2', + }, + }, +}; + export default { component: Sidebar } as Meta; diff --git a/components/Common/Sidebar/index.tsx b/components/Common/Sidebar/index.tsx index 8c723147f110b..330f9364cc1ad 100644 --- a/components/Common/Sidebar/index.tsx +++ b/components/Common/Sidebar/index.tsx @@ -1,31 +1,16 @@ -import type { Url } from 'url'; +import type { ComponentProps, FC } from 'react'; -import { useState } from 'react'; -import type { FC } from 'react'; +import SidebarGroup from '@/components/Common/Sidebar/SidebarGroup'; +import type SidebarItem from '@/components/Common/Sidebar/SidebarItem'; import styles from './index.module.css'; -import SidebarGroup from './SidebarGroup'; - -export type SidebarItemType = { - url: string | Url; - title: string; -}; - -export type SidebarGroupType = { - groupName: string; - items: SidebarItemType[]; -}; - -export type ActiveItem = Pick & - Pick; type SidebarProps = { - groups: SidebarGroupType[]; + groups: ComponentProps[]; + activeItem?: ComponentProps; }; -const SideBar: FC = ({ groups }) => { - const [activeItem, setActiveItem] = useState(); - +const SideBar: FC = ({ groups, activeItem }) => { return (