import React, { useEffect } from 'react'
import Tabs from './tabs'
import { TabsProps } from '.'
import { observable } from 'mobx'
const A = ({ value }: { value: string }) => {
useEffect(() => {
console.log(value)
}, [value])
return
{value}
}
const tabs = [
{
text: 'Tab1',
value: '1',
children: ,
},
{
text: 'Tab2',
value: '2',
children: ,
},
{
text: 'Tab3',
value: '3',
children: ,
},
{
text: 'Tab4',
value: '4',
children: ,
},
{
text: '长度比较长的tabs文本',
value: '5',
children: ,
},
]
const store = observable({
tabs: [...tabs],
active: '1',
setActive(index: string) {
this.active = index
},
handleClose(value: string) {
const index = this.tabs.findIndex((f) => f.value === value)
this.tabs.splice(index, 1)
if (store.active === value) {
store.setActive(index === 0 ? this.tabs[index].value : this.tabs[index - 1].value)
}
},
handleCloseDiv(value: string) {
const index = this.tabs.findIndex((f) => f.value === value)
this.tabs.splice(index, 1)
if (store.active === value) {
store.setActive(index === 0 ? this.tabs[index].value : this.tabs[index - 1].value)
}
},
handleAdd() {
store.tabs.push({
text: '长度比较长的tabs文本',
value: '' + store.tabs.length + 1,
children: ,
})
},
})
export const ComTabs = () => (
store.setActive(active)}
/>
)
export const ActiveOnceTabs = () => (
<>
tab active后再次点击不会重新didMount
store.setActive(active)}
/>
>
)
export const FullTabs = () => (
store.setActive(active)}
/>
)
export const LightTabs = () => (
store.setActive(active)}
/>
)
export const closeTabs = () => (
<>
支持关闭弹出Popver
store.setActive(active)}
onClose={(value) => store.handleClose(value)}
/>
>
)
const popup: TabsProps['popup'] = (value, closeFn) => (
asdasd
)
export const diyPoupCloseTabs = () => (
<>
自定义弹出poup+关闭tabs
store.setActive(active)}
onClose={(value) => store.handleClose(value)}
/>
>
)
export const addTabs = () => (
<>
增加添加规格
store.setActive(active)}
onClose={(value) => store.handleClose(value)}
extraAction={}
/>
>
)
export default {
title: '布局/Tabs',
}