Tabs
Tabs 顶部 tab
代码示例
import { BfTabs } from '@bud-fe/react-taro-ui';import { View } from '@tarojs/components';import Taro from '@tarojs/taro';import React, { useState } from 'react';export default () => {const [currValue, setCurrValue] = useState(1);const [currValue2, setCurrValue2] = useState(1);const onClickDot = (index: number, tab: any) => {Taro.showToast({ title: `dot索引:${index},tab值${tab.value}`, icon: 'none' });};const onClickMore = () => {Taro.showToast({ title: '更多操作', icon: 'none' });};return (<><View className="group-title">基础用法</View><BfTabs// style={{ backgroundColor: 'white' }}current={currValue}tabs={[{ label: 'aa', value: 1, dot: true },{label: 'bbbbbbb',value: 2,bottom: <View style={{ boxSizing: 'border-box', height: 30, border: '1px solid #ddd' }}>高60</View>,},{label: 'ccccccccccccccccccc',value: 3,bottom: (<Viewstyle={{ boxSizing: 'border-box', width: '50%', margin: 'auto', height: 20, border: '1px solid #ddd' }}>50%宽</View>),},{label: 'ddd',value: 4,bottom: (<View style={{ boxSizing: 'border-box', height: 60, border: '1px solid #ddd' }}>宽度最大为上方text的宽度</View>),},]}onChange={(val) => setCurrValue(val)}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}/><BfTabscurrent={currValue}tabs={[{ label: 'aaaaaaaaaaaaa', value: 1, dot: <View> 自定义dot</View> },{ label: 'bb', value: 2 },{ label: 'ccccccccccccc', value: 3 },{ label: 'ddddddddddddd', value: 4 },{ label: 'eeeeeeeeeeeee', value: 5 },{ label: 'fffffffffffff', value: 6 },]}onChange={(val) => setCurrValue(val)}showMore={true}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}onClickMore={onClickMore}/><BfTabscurrent={currValue}tabs={[{ label: 'aa', value: 1, dot: true },{ label: 'bb', value: 2 },{ label: 'ccccccccccccc', value: 3 },{ label: 'ddddddddddddd', value: 4 },{ label: 'eeeeeeeeeeeee', value: 5 },{ label: 'fffffffffffff', value: 6 },]}onChange={(val) => setCurrValue(val)}showMore={<View> 自定义更多</View>}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}onClickMore={onClickMore}/><View className="group-title"> 固定布局,标签个数必须小于5</View><BfTabsstyle={{ backgroundColor: 'white' }}current={currValue2}fixedtabs={[{ label: '审批中', value: 1, dot: true },{ label: '审批通过', value: 2 },{ label: '审批拒绝', value: 3 },]}onChange={(val) => setCurrValue2(val)}showMore={true}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}onClickMore={onClickMore}/><View className="group-title">styleMode='bf'</View><BfTabscurrent={currValue2}styleMode="bf"tabs={[{ label: 'aa', value: 1, dot: true },{ label: 'bb', value: 2 },]}onChange={(val) => setCurrValue2(val)}showMore={true}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}onClickMore={onClickMore}/><BfTabscurrent={currValue2}styleMode="bf"tabs={[{ label: 'aa', value: 1, dot: true },{ label: 'bb', value: 2 },{ label: 'cccccc', value: 3 },{ label: 'dddddd', value: 4 },{ label: 'eeeeee', value: 5 },{ label: 'ffffff', value: 6 },]}onChange={(val) => setCurrValue2(val)}showMore={true}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}onClickMore={onClickMore}/><BfTabsstyle={{ marginBottom: 20 }}current={currValue2}styleMode="bf"fixedtabs={[{ label: '审批中', value: 1, dot: true },{ label: '审批通过', value: 2 },{ label: '审批拒绝', value: 3 },]}onChange={(val) => setCurrValue2(val)}showMore={true}onClickDot={(index: number, tab: any) => {onClickDot(index, tab);}}onClickMore={onClickMore}/></>);};
API
属性名 | 描述 | 类型 | 默认值 |
---|---|---|---|
tabs | tab 的数据 | IBfTabItem[] | (必选) |
current | tab 选中的对应的value值 | any | (必选) |
fixed | 固定标签排布,不支持滚动。 NOTE: 当标签大于5个时,此属性强制为 false | boolean | false |
styleMode | 弹框样式 | "base" | "bf" | 'base' |
showMore | 是否展示更多操作图标 | ReactNode | -- |
onChange | 点击 tab 时的回调 | (value: any) => void | -- |
onClickMore | 点击更多操作 icon 的回调 | () => void | -- |
onClickDot | 点击右上角 dot 的回调 | (index: number, value: any) => void | -- |