@@ -38,43 +38,22 @@ const inBrowser = typeof window !== 'undefined';
38
38
const matchMedia = inBrowser && window . matchMedia !== null ;
39
39
40
40
class HyperResponsiveTable extends Component {
41
- static propTypes = {
42
- headers : objectOfStringOrElement . isRequired ,
43
- rows : PropTypes . arrayOf ( objectOfStringOrElement ) . isRequired ,
44
- breakpoint : PropTypes . oneOfType ( [
45
- PropTypes . string ,
46
- PropTypes . number ,
47
- ] ) . isRequired ,
48
- keyGetter : PropTypes . func . isRequired ,
49
- tableStyling : PropTypes . oneOfType ( [
50
- PropTypes . string ,
51
- PropTypes . object ,
52
- PropTypes . func ,
53
- ] ) ,
54
- initialNarrow : PropTypes . bool ,
55
- withClasses : PropTypes . bool ,
56
- } ;
57
-
58
- static defaultProps = {
59
- initialNarrow : false ,
60
- withClasses : false ,
61
- tableStyling : null ,
62
- } ;
63
-
64
41
constructor ( props , context ) {
65
42
super ( props , context ) ;
66
43
this . state = {
67
44
narrow : props . initialNarrow ,
68
45
} ;
69
46
}
70
47
71
- componentWillMount ( ) {
48
+ // eslint-disable-next-line camelcase
49
+ UNSAFE_componentWillMount ( ) {
72
50
if ( inBrowser ) {
73
51
this . updateQuery ( this . props ) ;
74
52
}
75
53
}
76
54
77
- componentWillReceiveProps ( nextProps ) {
55
+ // eslint-disable-next-line camelcase
56
+ UNSAFE_componentWillReceiveProps ( nextProps ) {
78
57
this . updateQuery ( nextProps ) ;
79
58
}
80
59
@@ -92,7 +71,7 @@ class HyperResponsiveTable extends Component {
92
71
const { breakpoint } = props ;
93
72
if ( matchMedia ) {
94
73
mql = window . matchMedia ( typeof breakpoint === 'string' ? breakpoint : `screen and (min-width: ${ breakpoint } px)` ) ;
95
- mql . addListener ( this . handleMatch ) ;
74
+ mql . addEventListener ( 'change' , this . handleMatch ) ;
96
75
narrow = ! mql . matches ;
97
76
}
98
77
@@ -132,33 +111,60 @@ class HyperResponsiveTable extends Component {
132
111
if ( narrow ) {
133
112
return (
134
113
< table { ...getClassNameOrStyleProps ( tableStyling , this . state ) } >
135
- { rows . map ( row => (
114
+ { rows . map ( ( row ) => (
136
115
< tbody key = { keyGetter ( row ) } >
137
- { dataKeys . map ( key => (
116
+ { dataKeys . map ( ( key ) => (
138
117
< tr key = { key } { ...rowClass ( withClasses , keyGetter ( row ) ) } >
139
118
< th { ...headerClass ( withClasses , key ) } scope = "row" > { headers [ key ] } </ th >
140
119
< td > { row [ key ] } </ td >
141
- </ tr > ) ) }
142
- </ tbody > ) )
143
- }
144
- </ table > ) ;
120
+ </ tr >
121
+ ) ) }
122
+ </ tbody >
123
+ ) ) }
124
+ </ table >
125
+ ) ;
145
126
}
146
127
147
128
return (
148
129
< table { ...getClassNameOrStyleProps ( tableStyling , this . state ) } >
149
130
< thead >
150
131
< tr >
151
- { dataKeys . map ( key => < th key = { key } { ...headerClass ( withClasses , key ) } scope = "col" > { headers [ key ] } </ th > ) }
132
+ { dataKeys . map ( ( key ) => < th key = { key } { ...headerClass ( withClasses , key ) } scope = "col" > { headers [ key ] } </ th > ) }
152
133
</ tr >
153
134
</ thead >
154
135
< tbody >
155
- { rows . map ( row => (
136
+ { rows . map ( ( row ) => (
156
137
< tr key = { keyGetter ( row ) } { ...rowClass ( withClasses , keyGetter ( row ) ) } >
157
- { dataKeys . map ( key => < td key = { key } > { row [ key ] } </ td > ) }
158
- </ tr > ) ) }
138
+ { dataKeys . map ( ( key ) => < td key = { key } > { row [ key ] } </ td > ) }
139
+ </ tr >
140
+ ) ) }
159
141
</ tbody >
160
- </ table > ) ;
142
+ </ table >
143
+ ) ;
161
144
}
162
145
}
163
146
147
+ HyperResponsiveTable . propTypes = {
148
+ headers : objectOfStringOrElement . isRequired ,
149
+ rows : PropTypes . arrayOf ( objectOfStringOrElement ) . isRequired ,
150
+ breakpoint : PropTypes . oneOfType ( [
151
+ PropTypes . string ,
152
+ PropTypes . number ,
153
+ ] ) . isRequired ,
154
+ keyGetter : PropTypes . func . isRequired ,
155
+ tableStyling : PropTypes . oneOfType ( [
156
+ PropTypes . string ,
157
+ PropTypes . object ,
158
+ PropTypes . func ,
159
+ ] ) ,
160
+ initialNarrow : PropTypes . bool ,
161
+ withClasses : PropTypes . bool ,
162
+ } ;
163
+
164
+ HyperResponsiveTable . defaultProps = {
165
+ initialNarrow : false ,
166
+ withClasses : false ,
167
+ tableStyling : null ,
168
+ } ;
169
+
164
170
export default HyperResponsiveTable ;
0 commit comments