1
1
import * as React from 'react' ;
2
- import { isValidElement } from 'react' ;
2
+ import { isValidElement , ReactElement , ReactNode } from 'react' ;
3
3
import PropTypes from 'prop-types' ;
4
4
import { Link } from 'react-router-dom' ;
5
- import MuiTab from '@material-ui/core/Tab' ;
6
- import { useTranslate } from 'ra-core' ;
5
+ import MuiTab , { TabProps as MuiTabProps } from '@material-ui/core/Tab' ;
6
+ import { useTranslate , Record } from 'ra-core' ;
7
7
import classnames from 'classnames' ;
8
8
9
9
import Labeled from '../input/Labeled' ;
10
10
11
- const sanitizeRestProps = ( {
12
- contentClassName,
13
- label,
14
- icon,
15
- value,
16
- translate,
17
- ...rest
18
- } ) => rest ;
19
-
20
11
/**
21
12
* Tab element for the SimpleShowLayout.
22
13
*
@@ -71,7 +62,7 @@ const Tab = ({
71
62
resource,
72
63
value,
73
64
...rest
74
- } ) => {
65
+ } : TabProps ) => {
75
66
const translate = useTranslate ( ) ;
76
67
77
68
const renderHeader = ( ) => (
@@ -81,16 +72,15 @@ const Tab = ({
81
72
value = { value }
82
73
icon = { icon }
83
74
className = { classnames ( 'show-tab' , className ) }
84
- component = { Link }
85
- to = { value }
86
- { ...sanitizeRestProps ( rest ) }
75
+ { ...( { component : Link , to : value } as any ) } // to avoid TypeScript screams, see https://github.com/mui-org/material-ui/issues/9106#issuecomment-451270521
76
+ { ...rest }
87
77
/>
88
78
) ;
89
79
90
80
const renderContent = ( ) => (
91
81
< span className = { contentClassName } >
92
82
{ React . Children . map ( children , field =>
93
- field && isValidElement ( field ) ? (
83
+ field && isValidElement < any > ( field ) ? (
94
84
< div
95
85
key = { field . props . source }
96
86
className = { classnames (
@@ -137,4 +127,17 @@ Tab.propTypes = {
137
127
value : PropTypes . string ,
138
128
} ;
139
129
130
+ export interface TabProps extends MuiTabProps {
131
+ basePath ?: string ;
132
+ children : ReactNode ;
133
+ contentClassName ?: string ;
134
+ context ?: 'header' | 'content' ;
135
+ className ?: string ;
136
+ icon ?: ReactElement ;
137
+ label : string ;
138
+ record ?: Record ;
139
+ resource ?: string ;
140
+ value ?: string ;
141
+ }
142
+
140
143
export default Tab ;
0 commit comments