1
- import React from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
import classNames from 'classnames' ;
3
- import PropTypes from 'prop-types' ;
4
3
import { makeStyles } from '@material-ui/core/styles' ;
5
4
import Tabs from '@material-ui/core/Tabs' ;
6
5
import Tab from '@material-ui/core/Tab' ;
7
6
import Card from '../Card/Card' ;
8
7
import CardBody from '../Card/CardBody' ;
9
8
import CardHeader from '../Card/CardHeader' ;
10
-
11
9
import styles from '../../assets/jss/material-dashboard-react/components/customTabsStyle' ;
12
10
13
- const useStyles = makeStyles ( styles ) ;
11
+ const useStyles = makeStyles ( styles as any ) ;
14
12
15
- export default function CustomTabs ( props ) {
16
- const [ value , setValue ] = React . useState ( 0 ) ;
17
- const handleChange = ( event , val ) => {
18
- setValue ( val ) ;
19
- } ;
13
+ type HeaderColor = 'warning' | 'success' | 'danger' | 'info' | 'primary' | 'rose' ;
14
+
15
+ interface TabItem {
16
+ tabName : string ;
17
+ tabIcon ?: React . ComponentType ;
18
+ tabContent : React . ReactNode ;
19
+ }
20
+
21
+ interface CustomTabsProps {
22
+ headerColor ?: HeaderColor ;
23
+ title ?: string ;
24
+ tabs : TabItem [ ] ;
25
+ rtlActive ?: boolean ;
26
+ plainTabs ?: boolean ;
27
+ }
28
+
29
+ const CustomTabs : React . FC < CustomTabsProps > = ( {
30
+ headerColor = 'primary' ,
31
+ plainTabs = false ,
32
+ tabs,
33
+ title,
34
+ rtlActive = false ,
35
+ } ) => {
36
+ const [ value , setValue ] = useState ( 0 ) ;
20
37
const classes = useStyles ( ) ;
21
- const { headerColor, plainTabs, tabs, title, rtlActive } = props ;
38
+
39
+ const handleChange = ( event : React . ChangeEvent < unknown > , newValue : number ) => {
40
+ setValue ( newValue ) ;
41
+ } ;
42
+
22
43
const cardTitle = classNames ( {
23
44
[ classes . cardTitle ] : true ,
24
45
[ classes . cardTitleRTL ] : rtlActive ,
25
46
} ) ;
47
+
26
48
return (
27
49
< Card plain = { plainTabs } >
28
50
< CardHeader color = { headerColor } plain = { plainTabs } >
@@ -39,12 +61,7 @@ export default function CustomTabs(props) {
39
61
scrollButtons = 'auto'
40
62
>
41
63
{ tabs . map ( ( prop , key ) => {
42
- let icon = { } ;
43
- if ( prop . tabIcon ) {
44
- icon = {
45
- icon : < prop . tabIcon /> ,
46
- } ;
47
- }
64
+ const icon = prop . tabIcon ? { icon : < prop . tabIcon /> } : { } ;
48
65
return (
49
66
< Tab
50
67
classes = { {
@@ -61,27 +78,14 @@ export default function CustomTabs(props) {
61
78
</ Tabs >
62
79
</ CardHeader >
63
80
< CardBody >
64
- { tabs . map ( ( prop , key ) => {
65
- if ( key === value ) {
66
- return < div key = { key } > { prop . tabContent } </ div > ;
67
- }
68
- return null ;
69
- } ) }
81
+ { tabs . map ( ( prop , key ) => (
82
+ < div key = { key } style = { { display : key === value ? 'block' : 'none' } } >
83
+ { prop . tabContent }
84
+ </ div >
85
+ ) ) }
70
86
</ CardBody >
71
87
</ Card >
72
88
) ;
73
- }
74
-
75
- CustomTabs . propTypes = {
76
- headerColor : PropTypes . oneOf ( [ 'warning' , 'success' , 'danger' , 'info' , 'primary' , 'rose' ] ) ,
77
- title : PropTypes . string ,
78
- tabs : PropTypes . arrayOf (
79
- PropTypes . shape ( {
80
- tabName : PropTypes . string . isRequired ,
81
- tabIcon : PropTypes . object ,
82
- tabContent : PropTypes . node . isRequired ,
83
- } ) ,
84
- ) ,
85
- rtlActive : PropTypes . bool ,
86
- plainTabs : PropTypes . bool ,
87
89
} ;
90
+
91
+ export default CustomTabs ;
0 commit comments