Skip to content

Commit 8b79057

Browse files
committed
Fix lint
1 parent cf295ab commit 8b79057

File tree

6 files changed

+54
-46
lines changed

6 files changed

+54
-46
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"rules": {
88
"react/jsx-filename-extension": 0,
9-
"import/no-extraneous-dependencies": 0
9+
"import/no-extraneous-dependencies": 0,
10+
"react/jsx-props-no-spreading": 0
1011
}
1112
}

demo/src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* globals document */
21
import React from 'react';
32
import { render } from 'react-dom';
43

@@ -60,7 +59,7 @@ const rows = [
6059
</a>),
6160
},
6261
];
63-
const keyGetter = row => row.name;
62+
const keyGetter = (row) => row.name;
6463

6564
const Demo = () => (
6665
<div>
@@ -78,7 +77,7 @@ const Demo = () => (
7877
withClasses
7978
tableStyling={({ narrow }) => (narrow ? 'narrowtable' : 'widetable')}
8079
/>
81-
</div>);
82-
80+
</div>
81+
);
8382

8483
render(<Demo />, document.querySelector('#demo'));

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"eslint-plugin-import": "^2.20.1",
1414
"eslint-plugin-jsx-a11y": "^6.2.3",
1515
"eslint-plugin-react": "^7.18.3",
16+
"expect": "^1.20.2",
1617
"gh-pages": "^3.1.0",
1718
"match-media-mock": "^0.1.1",
1819
"nwb": "^0.25.2",

src/index.js

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,22 @@ const inBrowser = typeof window !== 'undefined';
3838
const matchMedia = inBrowser && window.matchMedia !== null;
3939

4040
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-
6441
constructor(props, context) {
6542
super(props, context);
6643
this.state = {
6744
narrow: props.initialNarrow,
6845
};
6946
}
7047

71-
componentWillMount() {
48+
// eslint-disable-next-line camelcase
49+
UNSAFE_componentWillMount() {
7250
if (inBrowser) {
7351
this.updateQuery(this.props);
7452
}
7553
}
7654

77-
componentWillReceiveProps(nextProps) {
55+
// eslint-disable-next-line camelcase
56+
UNSAFE_componentWillReceiveProps(nextProps) {
7857
this.updateQuery(nextProps);
7958
}
8059

@@ -92,7 +71,7 @@ class HyperResponsiveTable extends Component {
9271
const { breakpoint } = props;
9372
if (matchMedia) {
9473
mql = window.matchMedia(typeof breakpoint === 'string' ? breakpoint : `screen and (min-width: ${breakpoint}px)`);
95-
mql.addListener(this.handleMatch);
74+
mql.addEventListener('change', this.handleMatch);
9675
narrow = !mql.matches;
9776
}
9877

@@ -132,33 +111,60 @@ class HyperResponsiveTable extends Component {
132111
if (narrow) {
133112
return (
134113
<table {...getClassNameOrStyleProps(tableStyling, this.state)}>
135-
{rows.map(row => (
114+
{rows.map((row) => (
136115
<tbody key={keyGetter(row)}>
137-
{dataKeys.map(key => (
116+
{dataKeys.map((key) => (
138117
<tr key={key} {...rowClass(withClasses, keyGetter(row))}>
139118
<th {...headerClass(withClasses, key)} scope="row">{headers[key]}</th>
140119
<td>{row[key]}</td>
141-
</tr>))}
142-
</tbody>))
143-
}
144-
</table>);
120+
</tr>
121+
))}
122+
</tbody>
123+
))}
124+
</table>
125+
);
145126
}
146127

147128
return (
148129
<table {...getClassNameOrStyleProps(tableStyling, this.state)}>
149130
<thead>
150131
<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>)}
152133
</tr>
153134
</thead>
154135
<tbody>
155-
{rows.map(row => (
136+
{rows.map((row) => (
156137
<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+
))}
159141
</tbody>
160-
</table>);
142+
</table>
143+
);
161144
}
162145
}
163146

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+
164170
export default HyperResponsiveTable;

tests/index-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const rows = [
2222
b: 'B 2',
2323
},
2424
];
25-
const keyGetter = r => r.a;
25+
const keyGetter = (r) => r.a;
2626

2727
describe('Component', () => {
2828
let node;
@@ -88,7 +88,7 @@ describe('Component', () => {
8888
});
8989

9090
it('tableStyling function value should give dynamic class when string is returned', () => {
91-
const tableStyling = opts => (opts.narrow ? 'narrow' : 'wide');
91+
const tableStyling = (opts) => (opts.narrow ? 'narrow' : 'wide');
9292
const props = {
9393
headers,
9494
rows,
@@ -129,7 +129,7 @@ describe('Component', () => {
129129

130130
it('wide to narrow change should trigger tableStyling function call', (done) => {
131131
const breakpoint = 1000;
132-
const tableStyling = opts => (opts.narrow ? 'narrow' : 'wide');
132+
const tableStyling = (opts) => (opts.narrow ? 'narrow' : 'wide');
133133
const props = {
134134
headers,
135135
rows,

0 commit comments

Comments
 (0)