Skip to content

Commit a0c5cc2

Browse files
committed
Modernize code
* Typescript * Rollup * Function component
1 parent cee1f0a commit a0c5cc2

18 files changed

+13023
-27543
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
es
22
lib
3-
umd
43
demo/dist

.eslintrc.json

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
{
2-
"extends": "airbnb",
3-
"parser": "babel-eslint",
4-
"env": {
5-
"browser": true
6-
},
7-
"rules": {
8-
"react/jsx-filename-extension": 0,
9-
"import/no-extraneous-dependencies": 0,
10-
"react/jsx-props-no-spreading": 0
11-
}
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2020,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
}
9+
},
10+
"settings": {
11+
"react": {
12+
"version": "detect"
13+
}
14+
},
15+
"extends": [
16+
// Uses the recommended rules from @eslint-plugin-react
17+
"plugin:react/recommended",
18+
// No react-import
19+
"plugin:react/jsx-runtime",
20+
"plugin:react-hooks/recommended",
21+
// Uses the recommended rules from the @typescript-eslint/eslint-plugin
22+
"plugin:@typescript-eslint/recommended",
23+
// Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array
24+
"plugin:prettier/recommended"
25+
],
26+
"rules": {
27+
}
1228
}

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jobs:
77

88
runs-on: ubuntu-latest
99

10+
env:
11+
CI: true
12+
1013
strategy:
1114
matrix:
1215
node-version: [14.x, 16.x, 18.x]
@@ -17,9 +20,7 @@ jobs:
1720
uses: actions/setup-node@v3
1821
with:
1922
node-version: ${{ matrix.node-version }}
23+
- run: npm install -g npm@latest # to support newer lock file
2024
- run: npm ci
2125
- run: npm run lint
22-
- run: echo "NODE_OPTIONS=--openssl-legacy-provider" >> $GITHUB_ENV
23-
if: ${{ matrix.node-version == '18.x' }}
24-
- run: npm run test:coverage
25-
- run: echo "NODE_OPTIONS=" >> $GITHUB_ENV
26+
- run: npm run test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
/es
44
/lib
55
/node_modules
6-
/umd
76
npm-debug.log*
87
.idea

CONTRIBUTING.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ A responsive container for displaying tables traditionally on wide screens and w
1010

1111
`npm install react-hyper-responsive-table`
1212

13+
This module uses `useSyncExternalStore`, which was introduced in React 18. If you are still using React 17 or older, also install
14+
[use-sync-external-store](https://www.npmjs.com/package/use-sync-external-store):
15+
16+
`npm install use-sync-external-store`
17+
1318
## Example
1419

1520
```jsx

babel.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-typescript',
5+
{
6+
isTSX: true,
7+
jsxPragma: 'h',
8+
allExtensions: true,
9+
allowNamespaces: false,
10+
allowDeclareFields: true,
11+
},
12+
],
13+
14+
['@babel/preset-env', { targets: { node: 'current' } }],
15+
['@babel/preset-react', { runtime: 'automatic' }],
16+
],
17+
plugins: ['@babel/plugin-transform-runtime'],
18+
};
Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { render } from 'react-dom';
32

43
import './demo.css';
@@ -9,66 +8,45 @@ const headers = {
98
name: 'Name',
109
role: 'Role',
1110
};
11+
1212
const rows = [
1313
{
1414
name: 'Marlon Brando',
15-
role: (
16-
<a href="https://en.wikipedia.org/wiki/Vito_Corleone">
17-
Vito Corleone
18-
</a>),
15+
role: <a href="https://en.wikipedia.org/wiki/Vito_Corleone">Vito Corleone</a>,
1916
image: <img src="https://upload.wikimedia.org/wikipedia/en/2/21/Godfather15_flip.jpg" alt="Vito Corleone" />,
2017
},
2118
{
2219
image: <img src="https://upload.wikimedia.org/wikipedia/en/d/df/Michaelcoreleone.jpg" alt="Al Pacino" />,
2320
name: 'Al Pacino',
24-
role: (
25-
<a href="https://en.wikipedia.org/wiki/Michael_Corleone">
26-
Michael Corleone
27-
</a>),
21+
role: <a href="https://en.wikipedia.org/wiki/Michael_Corleone">Michael Corleone</a>,
2822
},
2923
{
3024
image: <img src="https://upload.wikimedia.org/wikipedia/en/9/9d/Santino_corleone_2.jpg" alt="Santino Corleone" />,
3125
name: 'James Caan',
32-
role: (
33-
<a href="https://en.wikipedia.org/wiki/Santino_Corleone">
34-
Santino Corleone
35-
</a>),
26+
role: <a href="https://en.wikipedia.org/wiki/Santino_Corleone">Santino Corleone</a>,
3627
},
3728
{
3829
image: <img src="https://upload.wikimedia.org/wikipedia/en/6/67/Tom_Hagen.jpg" alt="Tom Hagen" />,
3930
name: 'Robert Duvall',
40-
role: (
41-
<a href="https://en.wikipedia.org/wiki/Tom_Hagen">
42-
Tom Hagen
43-
</a>),
31+
role: <a href="https://en.wikipedia.org/wiki/Tom_Hagen">Tom Hagen</a>,
4432
},
4533
{
4634
image: <img src="https://upload.wikimedia.org/wikipedia/en/e/e7/FredoCorleone.jpg" alt="Fredo Corleone" />,
4735
name: 'John Cazale',
48-
role: (
49-
<a href="https://en.wikipedia.org/wiki/Fredo_Corleone">
50-
Fredo Corleone
51-
</a>),
36+
role: <a href="https://en.wikipedia.org/wiki/Fredo_Corleone">Fredo Corleone</a>,
5237
},
5338
{
5439
image: <img src="https://upload.wikimedia.org/wikipedia/tr/9/9c/Godf3Connie2.jpg" alt="Connie Corleone" />,
5540
name: 'Talia Shire',
56-
role: (
57-
<a href="https://en.wikipedia.org/wiki/Connie_Corleone">
58-
Connie Corleone
59-
</a>),
41+
role: <a href="https://en.wikipedia.org/wiki/Connie_Corleone">Connie Corleone</a>,
6042
},
6143
];
62-
const keyGetter = (row) => row.name;
44+
const keyGetter = row => row.name;
6345

6446
const Demo = () => (
6547
<div>
66-
<h1>
67-
react-hyper-responsive-table demo
68-
</h1>
69-
<p>
70-
The breakpoint of this demo is set to 578 pixels.
71-
</p>
48+
<h1>react-hyper-responsive-table demo</h1>
49+
<p>The breakpoint of this demo is set to 578 pixels.</p>
7250
<ReactHyperResponsiveTable
7351
headers={headers}
7452
rows={rows}
@@ -80,4 +58,4 @@ const Demo = () => (
8058
</div>
8159
);
8260

83-
render(<Demo />, document.querySelector('#demo'));
61+
render(<Demo />, document.querySelector('body'));

demo/src/rollup.config.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { join, dirname } from 'path';
2+
import { fileURLToPath } from 'url';
3+
import nodeResolve from '@rollup/plugin-node-resolve';
4+
import typescript from 'rollup-plugin-typescript2';
5+
import css from 'rollup-plugin-import-css';
6+
import commonjs from '@rollup/plugin-commonjs';
7+
import html from '@rollup/plugin-html';
8+
import terser from '@rollup/plugin-terser';
9+
10+
const inputDir = dirname(fileURLToPath(import.meta.url));
11+
const outputDir = join(inputDir, '..', 'dist');
12+
13+
export default {
14+
input: join(inputDir, 'index.tsx'),
15+
external: [''],
16+
output: [
17+
{
18+
dir: outputDir,
19+
format: 'es',
20+
sourcemap: false,
21+
},
22+
],
23+
plugins: [
24+
nodeResolve({ browser: true }),
25+
commonjs({}),
26+
typescript({
27+
tsconfigOverride: {
28+
compilerOptions: {
29+
declaration: false,
30+
},
31+
},
32+
}),
33+
terser({
34+
compress: { global_defs: { 'process.env.NODE_ENV': 'production' } },
35+
}),
36+
css({}),
37+
html({
38+
meta: [
39+
{ charset: 'utf-8' },
40+
{ name: 'viewport', content: 'width=device-width,initial-scale=1,shrink-to-fit=no' },
41+
],
42+
title: 'react-hyper-responsive-table demo',
43+
}),
44+
],
45+
};

0 commit comments

Comments
 (0)