diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..d18969d8c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,16 @@ +const base = require('@umijs/fabric/dist/eslint'); + +module.exports = { + ...base, + rules: { + ...base.rules, + 'react/no-array-index-key': 0, + 'react/sort-comp': 0, + '@typescript-eslint/no-explicit-any': 1, + 'react/no-find-dom-node': 1, + 'react/require-default-props': 0, + 'no-confusing-arrow': 0, + 'jsx-a11y/label-has-for': 0, + 'jsx-a11y/label-has-associated-control': 0, + }, +}; diff --git a/.fatherrc.js b/.fatherrc.js new file mode 100644 index 000000000..767a2abfe --- /dev/null +++ b/.fatherrc.js @@ -0,0 +1,8 @@ +export default { + cjs: 'babel', + esm: { type: 'babel', importLibToEs: true }, + preCommit: { + eslint: true, + prettier: true, + }, +}; diff --git a/.gitignore b/.gitignore index a3b5eb63d..15278f7ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.storybook *.iml *.log .idea/ diff --git a/.travis.yml b/.travis.yml index 1b9f79ca2..d16a491a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ notifications: - yesmeck@gmail.com node_js: -- 8 +- 10 script: - | diff --git a/assets/bordered.less b/assets/bordered.less index f3ad2e84a..239059136 100644 --- a/assets/bordered.less +++ b/assets/bordered.less @@ -1,11 +1,55 @@ -@tablePrefixCls: rc-table; -@table-border-color: #e9e9e9; - -.@{tablePrefixCls}.bordered { - table { - border-collapse: collapse; - } - th, td { - border: 1px solid @table-border-color; +.move-enter, +.move-appear { + opacity: 0; + animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1); + animation-duration: 2.5s; + animation-fill-mode: both; + animation-play-state: paused; +} +.move-leave { + animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19); + animation-duration: 0.5s; + animation-fill-mode: both; + animation-play-state: paused; +} +.move-enter.move-enter-active, +.move-appear.move-enter-active { + animation-name: moveLeftIn; + animation-play-state: running; +} +.move-leave.move-leave-active { + animation-name: moveRightOut; + animation-play-state: running; +} +@keyframes moveLeftIn { + 0% { + transform-origin: 0 0; + transform: translateX(30px); + opacity: 0; + background: #fff6de; + } + 20% { + transform-origin: 0 0; + transform: translateX(0); + opacity: 1; + } + 80% { + background: #fff6de; + } + 100% { + background: transparent; + opacity: 1; + } +} +@keyframes moveRightOut { + 0% { + transform-origin: 0 0; + transform: translateX(0); + opacity: 1; + } + 100% { + transform-origin: 0 0; + transform: translateX(-30px); + opacity: 0; } } diff --git a/examples/animation.html b/examples/animation.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/animation.js b/examples/animation.js index 93a7998f0..8ee181b5a 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -1,10 +1,9 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; import Animate from 'rc-animate'; -import 'rc-table/assets/index.less'; -import 'rc-table/assets/animation.less'; +import Table from '../src'; +import '../assets/index.less'; +import '../assets/animation.less'; const AnimateBody = props => ; @@ -38,26 +37,32 @@ class Demo extends React.Component { onDelete(key, e) { console.log('Delete', key); e.preventDefault(); - const data = this.state.data.filter(item => item.key !== key); - this.setState({ data }); + this.setState(({ data }) => ({ + data: data.filter(item => item.key !== key), + })); } onAdd() { - const data = [...this.state.data]; - data.push({ - a: 'new data', - b: 'new data', - c: 'new data', - key: Date.now(), - }); - this.setState({ data }); + this.setState(({ data }) => ({ + data: [ + ...data, + { + a: 'new data', + b: 'new data', + c: 'new data', + key: Date.now(), + }, + ], + })); } render() { return (

Table row with animation

- + , document.getElementById('__react-content')); + +export default Demo; +/* eslint-enable */ diff --git a/examples/childrenIndent.html b/examples/childrenIndent.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/childrenIndent.js b/examples/childrenIndent.js index f77d388eb..99baa6a9d 100644 --- a/examples/childrenIndent.js +++ b/examples/childrenIndent.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { @@ -100,7 +99,9 @@ function onExpand(expanded, record) { console.log('onExpand', expanded, record); } -ReactDOM.render( -
, - document.getElementById('__react-content'), +const Demo = () => ( +
); + +export default Demo; +/* eslint-enable */ diff --git a/examples/className.html b/examples/className.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/className.js b/examples/className.js index b67bc4ecf..5b9b4adb2 100644 --- a/examples/className.js +++ b/examples/className.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { @@ -44,7 +43,7 @@ const data = [ { a: '1333', c: 'eee', d: 2, key: '3' }, ]; -ReactDOM.render( +const Demo = () => (

rowClassName and className

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/colspan-rowspan.html b/examples/colspan-rowspan.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/colspan-rowspan.js b/examples/colspan-rowspan.js index b04d65e58..60b58b9fc 100644 --- a/examples/colspan-rowspan.js +++ b/examples/colspan-rowspan.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { @@ -128,10 +127,12 @@ const data = [ { a: '资料统计完毕于xxxx年xxx月xxx日', key: '6' }, ]; -ReactDOM.render( +const Demo = () => (

colSpan & rowSpan

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/column-resize.html b/examples/column-resize.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/column-resize.js b/examples/column-resize.js index e56bcfc68..cc6bc199a 100644 --- a/examples/column-resize.js +++ b/examples/column-resize.js @@ -1,10 +1,9 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; import { Resizable } from 'react-resizable'; +import Table from '../src'; +import '../assets/index.less'; import 'react-resizable/css/styles.css'; const ResizeableTitle = props => { @@ -84,4 +83,5 @@ class Demo extends React.Component { } } -ReactDOM.render(, document.getElementById('__react-content')); +export default Demo; +/* eslint-enable */ diff --git a/examples/dropdown.html b/examples/dropdown.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/dropdown.js b/examples/dropdown.js index 7950dbda7..06a742646 100644 --- a/examples/dropdown.js +++ b/examples/dropdown.js @@ -1,15 +1,14 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; import Menu, { Item, Divider } from 'rc-menu'; import DropDown from 'rc-dropdown'; -import 'rc-table/assets/index.less'; import 'rc-dropdown/assets/index.css'; import 'rc-menu/assets/index.css'; +import Table from '../src'; +import '../assets/index.less'; const data = []; -for (let i = 0; i < 10; i++) { +for (let i = 0; i < 10; i += 1) { data.push({ key: i, a: `a${i}`, @@ -61,6 +60,7 @@ class Demo extends React.Component {
- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/expandIcon.html b/examples/expandIcon.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/expandIcon.js b/examples/expandIcon.js index ac474c133..61f9996ae 100644 --- a/examples/expandIcon.js +++ b/examples/expandIcon.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,react/prop-types,react/no-danger */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const data = [ { key: 0, a: '123' }, @@ -54,10 +53,12 @@ class Demo extends React.Component { } } -ReactDOM.render( +const Test = () => (

expandIcon

-
, - document.getElementById('__react-content'), + ); + +export default Test; +/* eslint-enable */ diff --git a/examples/expandedRowRender.html b/examples/expandedRowRender.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/expandedRowRender.js b/examples/expandedRowRender.js index cdde359fc..40556c575 100644 --- a/examples/expandedRowRender.js +++ b/examples/expandedRowRender.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const tableData = [ { key: 0, a: '123' }, @@ -50,14 +49,22 @@ class Demo extends React.Component { toggleButton() { if (this.state.expandedRowKeys.length) { const closeAll = () => this.setState({ expandedRowKeys: [] }); - return ; + return ( + + ); } const openAll = () => this.setState({ expandedRowKeys: [0, 1, 2] }); - return ; + return ( + + ); } remove(index) { - const data = this.state.data; + const { data } = this.state; data.splice(index, 1); this.setState({ data }); } @@ -106,10 +113,12 @@ class Demo extends React.Component { } } -ReactDOM.render( +const Test = () => (

expandedRowRender

-
, - document.getElementById('__react-content'), + ); + +export default Test; +/* eslint-enable */ diff --git a/examples/fixedColumns-auto-height.html b/examples/fixedColumns-auto-height.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/fixedColumns-auto-height.js b/examples/fixedColumns-auto-height.js index 94fe34a35..3a67f7ee2 100644 --- a/examples/fixedColumns-auto-height.js +++ b/examples/fixedColumns-auto-height.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, @@ -36,7 +35,7 @@ const data = [ { a: '133', c: 'edd12221', d: 2, key: '9', title: 'hello' }, ]; -ReactDOM.render( +const Demo = () => (

Fixed columns

{ - return { - className: `customize-class-${index}`, - }; - }} + onRow={(record, index) => ({ + className: `customize-class-${index}`, + })} /> - , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/fixedColumns.html b/examples/fixedColumns.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/fixedColumns.js b/examples/fixedColumns.js index 77eb0613c..4eb64e114 100644 --- a/examples/fixedColumns.js +++ b/examples/fixedColumns.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, @@ -14,9 +13,11 @@ const columns = [ { title: (
- title7
+ title7
-
Hello world! +
+
+ Hello world!
), dataIndex: 'b', @@ -41,7 +42,7 @@ const data = [ { a: '133', c: 'edd12221', d: 2, key: '9' }, ]; -ReactDOM.render( +const Demo = () => (

Fixed columns

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/fixedColumnsAndHeader.html b/examples/fixedColumnsAndHeader.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/fixedColumnsAndHeader.js b/examples/fixedColumnsAndHeader.js index 844084ff5..eb7fb9e3c 100644 --- a/examples/fixedColumnsAndHeader.js +++ b/examples/fixedColumnsAndHeader.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, @@ -31,10 +30,12 @@ const data = [ { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '9' }, ]; -ReactDOM.render( +const Demo = () => (

Fixed columns and header

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/fixedColumnsAndHeaderSyncRowHeight.html b/examples/fixedColumnsAndHeaderSyncRowHeight.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/fixedColumnsAndHeaderSyncRowHeight.js b/examples/fixedColumnsAndHeaderSyncRowHeight.js index aab60b9a4..54cef1eda 100644 --- a/examples/fixedColumnsAndHeaderSyncRowHeight.js +++ b/examples/fixedColumnsAndHeaderSyncRowHeight.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, @@ -31,10 +30,12 @@ const data = [ { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '9' }, ]; -ReactDOM.render( +const Demo = () => (

Fixed columns and header, resize window for test

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/fixedColumnsWhenResize.html b/examples/fixedColumnsWhenResize.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/fixedColumnsWhenResize.js b/examples/fixedColumnsWhenResize.js index bc23f413f..23fdd95b2 100644 --- a/examples/fixedColumnsWhenResize.js +++ b/examples/fixedColumnsWhenResize.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, @@ -14,9 +13,11 @@ const columns = [ { title: (
- title7
+ title7
-
Hello world! +
+
+ Hello world!
), dataIndex: 'b', @@ -41,7 +42,7 @@ const data = [ { a: '133', c: 'edd12221', d: 2, key: '9' }, ]; -ReactDOM.render( +const Demo = () => (

See fixed columns when you resize window

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/grouping-columns.html b/examples/grouping-columns.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/grouping-columns.js b/examples/grouping-columns.js index 48b639f84..5837d2f4a 100644 --- a/examples/grouping-columns.js +++ b/examples/grouping-columns.js @@ -1,9 +1,8 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; -import 'rc-table/assets/bordered.less'; +import Table from '../src'; +import '../assets/index.less'; +import '../assets/bordered.less'; const columns = [ { @@ -93,10 +92,12 @@ const data = [ }, ]; -ReactDOM.render( +const Demo = () => (

grouping columns

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/hide-header.html b/examples/hide-header.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/hide-header.js b/examples/hide-header.js index fc9de3fb4..fa905c09a 100644 --- a/examples/hide-header.js +++ b/examples/hide-header.js @@ -1,8 +1,7 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100 }, @@ -24,10 +23,12 @@ const data = [ { a: '1333', c: 'eee', d: 2, key: '3' }, ]; -ReactDOM.render( +const Demo = () => (

hide table head

- , - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/jsx.html b/examples/jsx.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/jsx.js b/examples/jsx.js index aa79a603d..2ea5e9317 100644 --- a/examples/jsx.js +++ b/examples/jsx.js @@ -1,8 +1,8 @@ -/* eslint-disable no-console,func-names,react/no-multi-comp */ +/* eslint-disable + no-console, func-names, react/no-multi-comp, import/no-named-as-default-member */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const { ColumnGroup, Column } = Table; @@ -12,7 +12,7 @@ const data = [ { a: '1333', c: 'eee', d: 2, key: '3' }, ]; -ReactDOM.render( +const Demo = () => (

JSX table

@@ -23,6 +23,8 @@ ReactDOM.render( Operations} />
-
, - document.getElementById('__react-content'), + ); + +export default Demo; +/* eslint-enable */ diff --git a/examples/key.html b/examples/key.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/key.js b/examples/key.js index 8a1081d70..bad10393c 100644 --- a/examples/key.js +++ b/examples/key.js @@ -1,9 +1,8 @@ /* eslint-disable no-console,func-names,react/no-multi-comp */ import React from 'react'; -import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; -import Table from 'rc-table'; -import 'rc-table/assets/index.less'; +import Table from '../src'; +import '../assets/index.less'; const CheckBox = ({ id }) => (