import React, { useEffect, useState } from 'react' import { TabsItem } from './TabsItem' import { TabsItemInterface } from './TabsItem.interface' const TabsComponent = ({ className = '', items, activeItem, onChange, }: TabsProps) => { const [currentActiveItem, setCurrentActiveItem] = useState(activeItem) useEffect(() => { setCurrentActiveItem(activeItem) }, [activeItem]) const handleChange = (id: string) => { if (id === currentActiveItem) return setCurrentActiveItem(id) onChange?.(id) } if (!items || !Array.isArray(items)) return null return (
{items?.map((item, index) => { if (!item.id) { item.id = encodeURI(item.title) } return ( ) })}
) } export const Tabs = React.memo(TabsComponent) export interface TabsProps { /** * Custom class name * */ className?: string /** * ID of the active item */ activeItem?: string /** * Tab item */ items?: TabsItemInterface[] /** * Callback handle when selected item change * */ onChange?: (arg0: string) => void }