import React from 'react' import { View, Text } from '@tarojs/components' import { useRouter } from '@tarojs/taro' import clsx from 'clsx' export interface TabBarItem { key: string title: string icon?: string selectedIcon?: string badge?: number | string dot?: boolean } export interface TabBarProps { items: TabBarItem[] activeKey?: string onChange?: (key: string) => void className?: string style?: React.CSSProperties fixed?: boolean safeArea?: boolean color?: string selectedColor?: string backgroundColor?: string } const TabBar = React.forwardRef(({ items, activeKey, onChange, className, style, fixed = true, safeArea = true, color = '#7f7f7f', selectedColor = '#1890ff', backgroundColor = '#ffffff', }, ref) => { const router = useRouter() const currentActiveKey = activeKey || items[0]?.key const handleTabChange = (key: string) => { if (key !== currentActiveKey) { onChange?.(key) } } return ( {items.map((item) => { const isActive = item.key === currentActiveKey return ( handleTabChange(item.key)} > {item.icon && ( {isActive && item.selectedIcon ? item.selectedIcon : item.icon} )} {item.badge && ( {typeof item.badge === 'number' && item.badge > 99 ? '99+' : item.badge} )} {item.dot && ( )} {item.title} ) })} ) }) TabBar.displayName = 'TabBar' export { TabBar }