import { View, Image } from "@tarojs/components";
import Taro, { useState, useEffect } from "@tarojs/taro";
import { classNames, isNumber } from "../../lib";
import { BG_COLOR_LIST, TEXT_COLOR_LIST } from "../../lib/model";
import { IProps } from "../../../@types/tabBar";
export default function ClTabBar(props: IProps) {
const [activeIndex, setActiveIndex] = useState(0);
useEffect(() => {
setActiveIndex(props.active || 0);
}, [props.active]);
const onClick = (index: number) => {
setActiveIndex(index);
props.onClick && props.onClick(index);
};
const colorClassName = props.bgColor
? BG_COLOR_LIST[props.bgColor]
: "bg-white";
const activeColorClassName = props.activeColor
? TEXT_COLOR_LIST[props.activeColor]
: "text-blue";
const barComponent = props.tabs.map((item, index) => (
{
onClick(index);
}}
key={"key-" + item.icon}
className={`action ${item.action ? "add-action" : ""} ${
activeIndex === index ? activeColorClassName : ""
}`}
>
{item.img ? : ""}
{item.badge !== false ? (
{isNumber(item.badge) ? item.badge : ""}
) : (
""
)}
{item.title}
));
return (
{barComponent}
);
}
ClTabBar.options = {
addGlobalClass: true
};
ClTabBar.defaultProps = {
bgColor: "white",
activeColor: "blue",
active: 0,
tabs: [],
safeArea: true
} as IProps;