@@ -15,25 +15,28 @@ import {
15
15
prefixClaName ,
16
16
} from 'mo/common/className' ;
17
17
import TabDot from './tabDot' ;
18
-
19
- export interface TabData < T = any > {
20
- modified ?: boolean ;
21
- language ?: string | undefined ;
22
- path ?: string ;
23
- value ?: string ;
24
- }
25
- export interface ITab extends TabData {
18
+ export interface ITab < T > {
19
+ active ?: boolean ;
20
+ closable ?: boolean ;
21
+ index ?: number ;
26
22
key ?: string ;
23
+ propsKey ?: string ;
27
24
name ?: string ;
28
25
label ?: React . ReactNode ;
29
26
tip ?: string | React . ReactNode ;
30
27
renderPanel ?: React . ReactNode ;
28
+ data ?: T
31
29
}
32
30
31
+ export interface ITabEvent {
32
+ onMoveTab ?: ( dragIndex : number , hoverIndex : number ) => void ;
33
+ onCloseTab ?: ( key ?: string ) => void ;
34
+ onSelectTab ?: ( key ?: string ) => void ;
35
+ }
33
36
export const tabClassName = prefixClaName ( 'tab' ) ;
34
37
export const tabItemClassName = getBEMElement ( tabClassName , 'item' ) ;
35
38
36
- export const Tab = ( props ) => {
39
+ export function Tab < T > ( props : ITab < T > & ITabEvent ) {
37
40
const {
38
41
closable,
39
42
index,
@@ -67,7 +70,7 @@ export const Tab = (props) => {
67
70
if ( ! ref . current ) return ;
68
71
const component = ref . current ;
69
72
const dragIndex = monitor . getItem ( ) . index ;
70
- let hoverIndex = index ;
73
+ let hoverIndex = index ! ;
71
74
// Don't replace items with themselves
72
75
if ( dragIndex === hoverIndex ) {
73
76
return ;
@@ -89,7 +92,7 @@ export const Tab = (props) => {
89
92
if ( dragIndex > hoverIndex && hoverClientX > hoverMiddleX ) {
90
93
return ;
91
94
}
92
- onMoveTab ( dragIndex , hoverIndex ) ;
95
+ onMoveTab ?. ( dragIndex , hoverIndex ) ;
93
96
monitor . getItem ( ) . index = hoverIndex ;
94
97
} ,
95
98
} ) ;
@@ -101,7 +104,7 @@ export const Tab = (props) => {
101
104
className = { classNames ( tabItemClassName , {
102
105
[ getBEMModifier ( tabItemClassName , 'active' ) ] : active ,
103
106
} ) }
104
- onClick = { ( event : React . MouseEvent ) => onSelectTab ( propsKey ) }
107
+ onClick = { ( event : React . MouseEvent ) => onSelectTab ?. ( propsKey ) }
105
108
onMouseOver = { handleMouseOver }
106
109
onMouseOut = { handleMouseOut }
107
110
>
@@ -118,5 +121,3 @@ export const Tab = (props) => {
118
121
</ div >
119
122
) ;
120
123
} ;
121
-
122
- export default Tab ;
0 commit comments