Compare commits

...
59 Commits
Author SHA1 Message Date
Tanner Linsley f70d453caa v6.7.6 2017-12-21 15:15:32 -07:00
Gary MenzelandGitHub 54f3cc791c Focus bug (#686)
* Merge fork from master (#6)

* Examples Refactor + multiSort flag (#619)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Docs testing cleanup (#645)

* Examples Refactor + multiSort flag (#619) (#4)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Examples Refactor + multiSort flag (#619) (#5)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Fork Update (#7)

* Examples Refactor + multiSort flag (#619)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Docs testing cleanup (#645)

* Examples Refactor + multiSort flag (#619) (#4)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Examples Refactor + multiSort flag (#619) (#5)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Update README.md (#584)

* Update README.md

Missing " on Features list,
Extra comma removed

* Update README.md

Added space for component uniformity.

* Update the devDependencies for the linter (#596)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix ThComponent classnames ordering (#673)

Allow for custom classname to overwrite base styles

* Add column to getResizerProps (#667)

* CHANGELOG update

* Header focus bug fix

Fixes #685
2017-12-20 08:27:35 +11:00
Gary MenzelandTanner Linsley 05c56f0da4 CHANGELOG update for 6.7.5 (#679)
* Merge fork from master (#6)

* Examples Refactor + multiSort flag (#619)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Docs testing cleanup (#645)

* Examples Refactor + multiSort flag (#619) (#4)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Examples Refactor + multiSort flag (#619) (#5)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Fork Update (#7)

* Examples Refactor + multiSort flag (#619)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Docs testing cleanup (#645)

* Examples Refactor + multiSort flag (#619) (#4)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Examples Refactor + multiSort flag (#619) (#5)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Update README.md (#584)

* Update README.md

Missing " on Features list,
Extra comma removed

* Update README.md

Added space for component uniformity.

* Update the devDependencies for the linter (#596)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix ThComponent classnames ordering (#673)

Allow for custom classname to overwrite base styles

* Add column to getResizerProps (#667)

* CHANGELOG update
2017-12-12 16:44:17 -07:00
Simon AngellandTanner Linsley ddf877bcac Add column to getResizerProps (#667) 2017-12-12 15:09:23 -08:00
Edward BramantiandTanner Linsley 928ad11a07 Fix ThComponent classnames ordering (#673)
Allow for custom classname to overwrite base styles
2017-12-12 15:05:31 -08:00
Will OlsonandTanner Linsley 0783837786 Update the devDependencies for the linter (#596)
* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors
2017-12-12 14:56:51 -08:00
Amir ShresthaandTanner Linsley cf0f8bb729 Update README.md (#584)
* Update README.md

Missing " on Features list,
Extra comma removed

* Update README.md

Added space for component uniformity.
2017-12-12 14:54:23 -08:00
Gary MenzelandGitHub 1e849df999 Merge branch 'master' into master 2017-11-27 14:08:05 +11:00
Gary MenzelandGitHub 62da8880e6 Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update

* Examples Refactor + multiSort flag (#619) (#5)

* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update
2017-11-27 13:47:58 +11:00
Gary Menzel 656522eb71 Comment out 2017-11-27 12:33:58 +11:00
Gary MenzelandGitHub b0c50509ee Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update
2017-11-27 12:32:18 +11:00
Gary MenzelandGitHub 01ca4518fc Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update
2017-11-27 09:57:12 +11:00
Gary MenzelandGitHub cdf806b3f6 Merge branch 'master' into master 2017-11-27 09:56:49 +11:00
Gary Menzel 0443644ccd Fixes #643
Still requires some basic sanity test to ensure ReactTable does
not have any fundamental coding errors.
Modified some of the /docs code to help with manual testing.
2017-11-27 09:50:36 +11:00
Gary MenzelandGitHub f74ba3cc16 Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid

* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)

* Refactor complete
May need to remove some redundant code

* Text change for the HOC samples

* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.

* refactor: Fix defaultProps.js linter errors

* refactor: Fix lifecycle.js linter errors

* refactor: Fix pagination.js linter errors

* refactor: Fix propTypes.js linter errors

* refactor: Fix utils.js linter errors

* refactor: Fix methods.js linter errors

* refactor: Fix index.js linter errors

* Fix for linter changes + CHANGELOG update
2017-11-23 15:30:07 +11:00
Gary Menzel 2e8596618a Fix for linter changes + CHANGELOG update 2017-11-23 13:53:00 +11:00
Gary MenzelandGitHub b2db31c9bd Merge pull request #3 from frankolson/linter_dependencies
Linter dependencies
2017-11-23 13:45:41 +11:00
Gary MenzelandGitHub 6a5400b247 Merge branch 'master' into linter_dependencies 2017-11-23 13:45:25 +11:00
Will Olson ed6dd5af4c refactor: Fix index.js linter errors 2017-11-22 10:04:26 -08:00
Will Olson 80aa2ea7f4 refactor: Fix methods.js linter errors 2017-11-22 09:48:13 -08:00
Will Olson b310a2ebc4 refactor: Fix utils.js linter errors 2017-11-22 09:33:10 -08:00
Will Olson bcfa658257 refactor: Fix propTypes.js linter errors 2017-11-22 09:19:36 -08:00
Will Olson ad151b5ff0 refactor: Fix pagination.js linter errors 2017-11-22 09:17:21 -08:00
Will Olson 3f1b0d36ed refactor: Fix lifecycle.js linter errors 2017-11-22 09:13:59 -08:00
Will Olson a6036004af refactor: Fix defaultProps.js linter errors 2017-11-22 09:07:26 -08:00
Will Olson 913d214e94 Merge branch 'master' into linter_dependencies 2017-11-22 08:59:08 -08:00
Gary MenzelandGitHub 2fbd0d49db Merge branch 'master' into master 2017-11-16 09:31:31 +11:00
Gary Menzel fc47d4f258 Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
2017-11-16 03:05:44 +11:00
Gary Menzel 6df336215d Text change for the HOC samples 2017-11-15 20:54:29 +11:00
Gary Menzel feec96359b Refactor complete
May need to remove some redundant code
2017-11-15 20:43:29 +11:00
Gary Menzel 33252adfab Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
2017-11-14 15:38:50 +11:00
Gary MenzelandTanner Linsley 1cf9e49952 Example HOCs for TreeTable and CheckboxTable (#609)
* chore: Update the devDependencies for the linter

* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.

* Missing dependency - shortid
2017-11-12 15:13:05 -07:00
Gary Menzel b585c4b8db Missing dependency - shortid 2017-11-13 08:09:45 +11:00
Gary Menzel 710891f0c0 A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
2017-11-12 16:32:29 +11:00
Gary MenzelandGitHub cb0000e588 Merge pull request #2 from frankolson/linter_dependencies
chore: Update the devDependencies for the linter
2017-11-03 22:11:22 +11:00
Gary MenzelandGitHub d0bd56729b Merge pull request #1 from react-tools/master
Update to 6.7.4 from original
2017-11-03 21:47:52 +11:00
Will Olson e4c819039f chore: Update the devDependencies for the linter 2017-11-02 11:54:53 -07:00
Tanner Linsley adc07de817 6.7.4 2017-10-27 14:55:17 -06:00
Tanner Linsley e94e88849a Fix Prop types for columns 2017-10-27 14:55:11 -06:00
Tanner Linsley 2dcfef884f 6.7.3 2017-10-27 14:27:24 -06:00
Tanner Linsley d798584208 Fix the rest of the proptypes 2017-10-27 14:27:20 -06:00
Tanner Linsley 5759885983 6.7.2 2017-10-27 14:23:07 -06:00
Tanner Linsley e59ddc1f8d Fix getPropTypes proptype check 2017-10-27 14:23:03 -06:00
Tanner Linsley 35e8636fd1 6.7.1
Fixes #582
2017-10-27 13:45:06 -06:00
Tanner Linsley bb2f969db9 Fix: eslint-config moved to dev deps 2017-10-27 13:44:38 -06:00
Tanner Linsley cd0222fcd2 6.7.0 2017-10-27 13:02:40 -06:00
Tanner Linsley 93ceffbf26 6.7.0-alpha-0 2017-10-27 13:00:57 -06:00
Tanner Linsley 879a6ac273 Deps, linting, and style upgrades 2017-10-27 13:00:54 -06:00
Tanner Linsley b285288849 Merge branch 'master' of https://github.com/react-tools/react-table 2017-10-27 12:14:50 -06:00
Aaron FreidusandTanner Linsley 05f4aaef2e Update README.md to include npm as option for installing. (#523)
* add npm as option for installing

* Update README.md
2017-10-27 12:12:54 -06:00
Abu ShamsutdinovandTanner Linsley 2b9c546132 Added a comma into an array (#524) 2017-10-27 12:12:02 -06:00
Jon TanseyandTanner Linsley 55ef8a9e7d Fix missing comma in Component Overrides docs (#525) 2017-10-27 12:11:46 -06:00
simon-bondandTanner Linsley 189ee436f9 Supply sort direction to custom sort methods (#476) (#533) 2017-10-27 12:11:34 -06:00
SudhanshuandTanner Linsley 225a74770b Update index.styl (#537) 2017-10-27 12:11:09 -06:00
Will OlsonandTanner Linsley fa425a162a Linter cleanup (#548)
* chore: Add local dependencies needed to run the test suite

* style: Fix eslint errors regarding multilines JSX
2017-10-27 12:10:41 -06:00
Will OlsonandTanner Linsley e42b7bbd7d Add the PropTypes node module (#550)
* feat: Add prop types to the library

* fix: Update typos in src/propTypes.js
2017-10-27 12:08:33 -06:00
Erkam UyanikandTanner Linsley 9efee144a8 Update README.md (#551)
Correct a typo
2017-10-27 12:07:47 -06:00
Mike DeVitaandTanner Linsley 56b721c185 fixes issue #564 - IE not displaying rows (#569) 2017-10-27 12:07:29 -06:00
Dylan MarkowandTanner Linsley e91bb91ea1 Expose page/pageSize to rows/cells (#581) 2017-10-27 12:06:46 -06:00
31 changed files with 10137 additions and 1376 deletions
+1 -75
View File
@@ -1,77 +1,3 @@
module.exports = {
parserOptions: {
ecmaVersion: 8,
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true,
node: false,
classes: true
},
sourceType: 'module'
},
parser: 'babel-eslint',
extends: ['standard'],
plugins: ['react'],
rules: {
// Nozzle
'jsx-quotes': [2, 'prefer-single'],
'comma-dangle': [2, 'always-multiline'],
// // React
'react/jsx-boolean-value': 2,
'react/jsx-curly-spacing': [2, 'never'],
'react/jsx-equals-spacing': [2, 'never'],
// 'react/jsx-indent': 2,
'react/jsx-indent-props': [2, 2],
'react/jsx-no-duplicate-props': 2,
'react/jsx-no-undef': 2,
'react/jsx-tag-spacing': [
2,
{
closingSlash: 'never',
beforeSelfClosing: 'always',
afterOpening: 'never'
}
],
'react/jsx-uses-react': 2,
'react/jsx-uses-vars': 2,
'react/self-closing-comp': 2,
'react/jsx-no-bind': [
2,
{
allowArrowFunctions: true,
allowBind: false,
ignoreRefs: true
}
],
'react/no-did-update-set-state': 2,
'react/no-unknown-property': 2,
'react/react-in-jsx-scope': 2,
'react/jsx-closing-bracket-location': [0, 'tag-aligned'],
'react/jsx-tag-spacing': [2, { beforeSelfClosing: 'always' }],
'react/jsx-wrap-multilines': 2,
'react/self-closing-comp': 2,
'react/jsx-key': 2,
'react/jsx-no-comment-textnodes': 2,
'react/jsx-no-duplicate-props': 2,
'react/jsx-no-target-blank': 2,
'react/jsx-no-undef': 2,
'react/jsx-uses-react': 2,
'react/jsx-uses-vars': 2,
'react/no-danger-with-children': 2,
'react/no-deprecated': 2,
'react/no-direct-mutation-state': 2,
'react/no-find-dom-node': 2,
'react/no-is-mounted': 2,
'react/no-render-return-value': 2,
'react/no-string-refs': 2,
'react/no-unknown-property': 2,
'react/react-in-jsx-scope': 2,
'react/require-render-return': 2
// 'react/jsx-max-props-per-line': [2, { maximum: 1 }]
}
extends: 'react-tools'
}
+62
View File
@@ -1,3 +1,65 @@
## 6.7.5
#### Fixes & Optimizations
- Now passes `column` to `getResizerProps` (#667)
- NOTE: `getResizerProps` is now only called if the column is resizable
- Fixes the `className` ordering in defaultProps for ThComponent (#673)
- NOTE: user supplied classNames now come at the end so they can extend the defaults
## 6.7.4
#### Fixes & Optimizations
- Fix Prop types for columns
## 6.7.3
#### Fixes & Optimizations
- Fix the rest of the proptypes
## 6.7.2
#### Fixes & Optimizations
- `getPropTypes` proptype check
## 6.7.1
#### Fixes & Optimizations
- `eslint-config` moved to dev deps
## 6.7.0
## 6.7.0-alpha-0
#### New Features
- Expose page/pageSize to rows/cells
- Supply sort direction to custom sort methods
#### Fixes & Optimizations
- README updates
- Linter cleanup
- Added PropTypes node module
- Deps, linting and style upgrades
## 6.6.0
#### Fixes & Optimizations
- moved repo to react-tools
- Doc examples moved to codesandbox.io
- README updates
- CSS refacting for rt-tfoot to match rt-thead
- CSS more specific for input and select
## 6.5.3
#### Fixes & Optimizations
- `onClick` proxying and eslint
## 6.5.2
#### New Features
- Provide onClick handleOriginal function - #406
#### Fixes & Optimizations
- README updates
- `makePathArray` in utils - #326
- Various fixes: #294, #376, #398, #415,
## 6.5.1
#### Fixes & Optimizations
- `defaultExpanded` now works correctly - #372
- `column.getProps().rest` props are now applied correctly
- `makeTemplateComponent` now supports `displayName` - #289
## 6.5.0
##### New Features
- `column.filterAll` - defaults to `false`, but when set to `true` will provide the entire array of rows to `filterMethod` as opposed to one row at a time. This allows for more fine-grained filtering using any method you can dream up. See the [Custom Filtering example](https://react-table.js.org/#/story/custom-filtering) for more info.
+19 -11
View File
@@ -38,7 +38,7 @@
- Pivoting & Aggregation
- Minimal design & easily themeable
- Fully controllable via optional props and callbacks
- <a href="https://medium.com/@tannerlinsley/why-i-wrote-react-table-and-the-problems-it-has-solved-for-nozzle-others-445c4e93d4a8#.axza4ixba" target="\_parent">"Why I wrote React Table and the problems it has solved for Nozzle.io</a> by Tanner Linsley
- <a href="https://medium.com/@tannerlinsley/why-i-wrote-react-table-and-the-problems-it-has-solved-for-nozzle-others-445c4e93d4a8#.axza4ixba" target="\_parent">"Why I wrote React Table and the problems it has solved for Nozzle.io"</a> by Tanner Linsley
## [Demos and examples](http://react-table.js.org/#/story/simple-table)
@@ -74,7 +74,11 @@
## Installation
1. Install React Table as a dependency
```bash
# Yarn
$ yarn add react-table
# NPM
$ npm install react-table
```
2. Import the `react-table` module
```javascript
@@ -167,6 +171,7 @@ These are all of the available props (and their default values) for the main `<R
collapseOnDataChange: true,
freezeWhenExpanded: false,
sortable: true,
multiSort: true,
resizable: true,
filterable: false,
defaultSortDesc: false,
@@ -178,7 +183,7 @@ These are all of the available props (and their default values) for the main `<R
const id = filter.pivotId || filter.id
return row[id] !== undefined ? String(row[id]).startsWith(filter.value) : true
},
defaultSortMethod: (a, b) => {
defaultSortMethod: (a, b, desc) => {
// force null and undefined to the bottom
a = (a === null || a === undefined) ? -Infinity : a
b = (b === null || b === undefined) ? -Infinity : b
@@ -338,7 +343,7 @@ Or just define them as props
```
## Columns
`<ReactTable/>` requires a `columns` prop, which is an array of objects containing the following properties
`<ReactTable />` requires a `columns` prop, which is an array of objects containing the following properties
```javascript
[{
@@ -353,7 +358,7 @@ Or just define them as props
Aggregated: JSX | String | Function // Used to render aggregated cells. Defaults to a comma separated list of values.
Pivot: JSX | String | Function | cellInfo => ( // Used to render a pivoted cell
<span>
<Expander/><PivotValue /> // By default, will utilize the the PivotValue and Expander components at run time
<Expander /><PivotValue /> // By default, will utilize the the PivotValue and Expander components at run time
</span>
),
PivotValue: JSX | String | Function // Used to render the value inside of a Pivot cell
@@ -475,7 +480,7 @@ If your data has a field/key with a dot (`.`) you will need to supply a custom a
## Column Header Groups
To group columns with another header column, just nest your columns in a header column. Header columns utilize the same header properties as regular columns.
To group columns with another header column, just nest your columns in a header column. Header columns utilize the same header properties as regular columns.
```javascript
const columns = [{
Header: 'Favorites',
@@ -486,7 +491,7 @@ const columns = [{
}, {
Header: 'Food',
accessor: 'favorites.food'
} {
}, {
Header: 'Actor',
accessor: 'favorites.actor'
}]
@@ -829,6 +834,9 @@ Sorting comes built in with React-Table.
## Multi-Sort
When clicking on a column header, hold shift to multi-sort! You can toggle `ascending` `descending` and `none` for multi-sort columns. Clicking on a header without holding shift will clear the multi-sort and replace it with the single sort of that column. It's quite handy!
You can set the `multiSort` prop to `false` to disable this feature (which may be useful for server-side sorting when you are not
going to sort multiple columns).
## Custom Sorting Algorithm
To override the default sorting algorithm for the whole table use the `defaultSortMethod` prop.
@@ -837,9 +845,9 @@ To override the sorting algorithm for a single column, use the `sortMethod` colu
Supply a function that implements the native javascript [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) interface. This is React Table's default sorting algorithm:
- `a` the first value to compare
- `b` the second value to compare
- `dir` the
- `desc` true if sort is descending, false if ascending
```javascript
defaultSortMethod = (a, b) => {
defaultSortMethod = (a, b, desc) => {
// force null and undefined to the bottom
a = (a === null || a === undefined) ? -Infinity : a
b = (b === null || b === undefined) ? -Infinity : b
@@ -871,7 +879,7 @@ By default, `filterMethod` is passed a single row of data at a time, and you are
Alternatively, you can set `filterAll` to `true`, and `filterMethod` will be passed the entire array of rows to be filtered, and you will then be responsible for returning the new filtered array. This is extremely handy when you need to utilize a utility like fuzzy matching that requires the entire array of items.
To completely override the filter that is shown, you can set the `Filter` column option. Using this option you can specify the JSX that is shown. The option is passed an `onChange` method which must be called with the the value that you wan't to pass to the `filterMethod` option whenever the filter has changed.
To completely override the filter that is shown, you can set the `Filter` column option. Using this option you can specify the JSX that is shown. The option is passed an `onChange` method which must be called with the the value that you want to pass to the `filterMethod` option whenever the filter has changed.
See <a href="http://react-table.js.org/#/story/custom-filtering" target="\_parent">Custom Filtering</a> demo for examples.
@@ -886,7 +894,7 @@ Object.assign(ReactTableDefaults, {
TbodyComponent: component,
TrGroupComponent: component,
TrComponent: component,
ThComponent: component
ThComponent: component,
TdComponent: component,
TfootComponent: component,
ExpanderComponent: component,
@@ -922,7 +930,7 @@ If you would like to help develop a suggested feature follow these steps:
- Auto-build files as you edit with `$ yarn run watch`
- Implement your changes to files in the `src/` directory
- Run the <a href="https://github.com/tannerlinsley/react-story">React Story</a> locally with `$ yarn run docs`
- View changes as you edit `docs/src`,
- View changes as you edit `docs/src`
- Submit PR for review
#### Scripts
+15 -5
View File
@@ -3,8 +3,6 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.9.5",
"standard": "^10.0.2",
"autoprefixer": "^6.7.0",
"babel-cli": "6.14.0",
"babel-eslint": "6.1.2",
@@ -12,6 +10,15 @@
"babel-preset-react": "6.11.1",
"babel-preset-stage-2": "6.13.0",
"eslint": "^4.1.1",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-class-property": "^1.0.6",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-standard": "^3.0.1",
"html-element-attributes": "^1.3.0",
"match-sorter": "^1.8.0",
"npm-run-all": "^3.1.1",
"onchange": "^3.0.2",
@@ -21,10 +28,10 @@
"react-json-tree": "^0.10.9",
"rimraf": "^2.6.1",
"standard": "^10.0.2",
"stylus": "^0.54.5",
"webpack": "^2.5.1"
"stylus": "^0.54.5"
},
"dependencies": {
"eslint-config-react-tools": "^1.0.10",
"github-markdown-css": "^2.6.0",
"marked": "^0.3.6",
"namor": "^1.0.1",
@@ -32,7 +39,10 @@
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-json-tree": "^0.10.9",
"react-story": "^0.0.10"
"react-script": "^2.0.5",
"react-scripts": "^0.9.5",
"react-story": "^0.0.10",
"shortid": "^2.2.8"
},
"scripts": {
"start": "react-scripts start",
File diff suppressed because it is too large Load Diff
+13
View File
@@ -1,3 +1,5 @@
/* eslint-disable */
import React from 'react'
//
import ReactStory, { defaultProps } from 'react-story'
@@ -6,9 +8,17 @@ import './stories/utils/prism.css'
import '../../react-table.css'
import Readme from './stories/Readme.js'
import HOCReadme from './stories/HOCReadme.js'
// import Test from './stories/test.js'
// import Tester from './examples/expander';
const stories = [
{ name: 'Readme', component: Readme },
{ name: 'HOC Readme', component: HOCReadme },
// { name: 'Tester', component: Test },
{ name: 'Simple Table', component: CodeSandbox('X6npLXPRW') },
{
name: 'Cell Renderers & Custom Components',
@@ -51,6 +61,9 @@ const stories = [
name: 'Multiple Pagers (Top and Bottom)',
component: CodeSandbox('VEZ8OgvX'),
},
{ name: 'Tree Table (HOC)', component: CodeSandbox('lxmr4wynzq') },
{ name: 'Select Table (HOC)', component: CodeSandbox('7yq5ylw09j') },
{ name: 'Select Tree Table (HOC)', component: CodeSandbox('2p7jp4klwp') },
]
export default class App extends React.Component {
+88
View File
@@ -0,0 +1,88 @@
import React from 'react';
export default (Component) => {
const wrapper = class RTCheckboxTable extends React.Component {
// we only need a Component so we can get the 'ref' - pure components can't get a 'ref'
rowSelector = (row) =>
{
if(!row || !row.hasOwnProperty(this.props.keyField)) return null;
const checked = this.props.isSelected(row[this.props.keyField]);
return (
<input
type='checkbox'
checked={checked}
onClick={(e)=>{
const { shiftKey } = e;
e.stopPropagation();
this.props.toggleSelection(row[this.props.keyField],shiftKey,row);
}}
onChange={()=>{}}
value=''
/>
);
}
headSelector = (row) =>
{
const checked = this.props.selectAll;
return (
<input
type='checkbox'
checked={checked}
onClick={(e)=>{
e.stopPropagation();
this.props.toggleAll();
}}
onChange={()=>{}}
value=''
/>
);
}
// this is so we can expose the underlying ReactTable to get at the sortedData for selectAll
getWrappedInstance = ()=>this.wrappedInstance
render()
{
const { columns:originalCols, isSelected, toggleSelection, toggleAll, keyField, selectAll, ...rest } = this.props;
const { rowSelector, headSelector, } = this;
const select = {
id: '_selector',
accessor: ()=>'x', // this value is not important
Header: headSelector,
Cell: (ci) => { return rowSelector(ci.original); },
width: 30,
filterable: false,
sortable: false,
resizable: false,
style: { textAlign: 'center' },
}
const columns = [
select,
...originalCols,
];
const extra = {
columns,
};
return (
<Component {...rest} {...extra} ref={(r)=>this.wrappedInstance=r}/>
)
}
}
wrapper.displayName = 'RTCheckboxTable';
wrapper.defaultProps =
{
keyField: '_id',
isSelected: (key)=>{ console.log('No isSelected handler provided:',{key})},
selectAll: false,
toggleSelection: (key, shift, row)=>{ console.log('No toggleSelection handler provided:', { key, shift, row }) },
toggleAll: () => { console.log('No toggleAll handler provided.') },
}
return wrapper;
}
+160
View File
@@ -0,0 +1,160 @@
import React from 'react';
import shortid from 'shortid';
import ReactTable from '../../../../lib/index'
import '../../../../react-table.css'
import checkboxTableHOC from './checkboxHOC';
const CheckboxTable = checkboxTableHOC(ReactTable);
async function getData()
{
const result = await ( await fetch('/au_500_tree.json') ).json();
// we are adding a unique ID to the data for tracking the selected records
return result.map((item)=>{
const _id = shortid.generate();
return {
_id,
...item,
}
});
}
function getColumns(data)
{
const columns = [];
const sample = data[0];
for(let key in sample)
{
if(key==='_id') continue;
columns.push({
accessor: key,
Header: key,
})
}
return columns;
}
export class ComponentTest extends React.Component {
constructor(props) {
super(props);
this.state =
{
data: null,
columns: null,
selection: [],
selectAll: false,
};
}
componentDidMount()
{
getData().then((data)=>{
const columns = getColumns(data);
this.setState({ data, columns });
});
}
toggleSelection = (key,shift,row) => {
/*
Implementation of how to manage the selection state is up to the developer.
This implementation uses an array stored in the component state.
Other implementations could use object keys, a Javascript Set, or Redux... etc.
*/
// start off with the existing state
let selection = [
...this.state.selection
];
const keyIndex = selection.indexOf(key);
// check to see if the key exists
if(keyIndex>=0) {
// it does exist so we will remove it using destructing
selection = [
...selection.slice(0,keyIndex),
...selection.slice(keyIndex+1)
]
} else {
// it does not exist so add it
selection.push(key);
}
// update the state
this.setState({selection});
}
toggleAll = () => {
/*
'toggleAll' is a tricky concept with any filterable table
do you just select ALL the records that are in your data?
OR
do you only select ALL the records that are in the current filtered data?
The latter makes more sense because 'selection' is a visual thing for the user.
This is especially true if you are going to implement a set of external functions
that act on the selected information (you would not want to DELETE the wrong thing!).
So, to that end, access to the internals of ReactTable are required to get what is
currently visible in the table (either on the current page or any other page).
The HOC provides a method call 'getWrappedInstance' to get a ref to the wrapped
ReactTable and then get the internal state and the 'sortedData'.
That can then be iterrated to get all the currently visible records and set
the selection state.
*/
const selectAll = this.state.selectAll?false:true;
const selection = [];
if(selectAll)
{
// we need to get at the internals of ReactTable
const wrappedInstance = this.checkboxTable.getWrappedInstance();
// the 'sortedData' property contains the currently accessible records based on the filter and sort
const currentRecords = wrappedInstance.getResolvedState().sortedData;
// we just push all the IDs onto the selection array
currentRecords.forEach((item)=>{
selection.push(item._original._id);
})
}
this.setState({selectAll,selection})
}
isSelected = (key) => {
/*
Instead of passing our external selection state we provide an 'isSelected'
callback and detect the selection state ourselves. This allows any implementation
for selection (either an array, object keys, or even a Javascript Set object).
*/
return this.state.selection.includes(key);
}
logSelection = () => {
console.log('selection:',this.state.selection);
}
render(){
const { toggleSelection, toggleAll, isSelected, logSelection } = this;
const { data, columns, selectAll } = this.state;
const extraProps =
{
selectAll,
isSelected,
toggleAll,
toggleSelection,
}
return (
<div style={{ padding: '10px'}}>
<h1>react-table - Checkbox Table</h1>
<button onClick={logSelection}>Log Selection to Console</button>
{` (${this.state.selection.length}) selected`}
{
data?
<CheckboxTable
data={data}
columns={columns}
ref={(r)=>this.checkboxTable = r}
className="-striped -highlight"
{...extraProps}
/>
:null
}
</div>
);
}
}
// export default treeTableHOC(ComponentTest);
export default ComponentTest;
+61
View File
@@ -0,0 +1,61 @@
import React from 'react'
export default class ComponentTest extends React.component {
render () {
return <div>Bozo</div>
}
}
// import ReactTable from '../../../../lib/index'
// import '../../../../react-table.css'
//
// console.log('ReactTable:',ReactTable)
//
// const data = [
// {one:"1.1",two:"1.2"},
// {one:"2.1",two:"2.2"},
// {one:"3.1",two:"3.2"},
// {one:"4.1",two:"4.2"},
// ]
//
// const columns = [
// {accessor:'one', Header: 'One'},
// {accessor:'two', Header: 'Two'},
// ]
//
// class ExpanderComponent extends React.Component {
// render()
// {
// return (
// <div className={`rt-expander ${this.props.isExpanded ? '-open' : ''}`}>
// &bull;
// </div>
// )
// }
// }
//
// class SubComponent extends React.Component {
// render()
// {
// return <div>Nothing</div>
// }
// }
//
// export default class ComponentTest extends React.Component {
// render()
// {
// const rtProps = {
// data,
// columns,
// // ExpanderComponent: (props)=><ExpanderComponent {...props} />,
// // SubComponent: (props)=><SubComponent {...props} />,
// // multiSort: false,
// }
// return (
// <ReactTable
// {...rtProps}
// />
// )
// }
// }
+11
View File
@@ -0,0 +1,11 @@
/* eslint-disable */
import TreeTable from './treetable'
import SelectTable from './selecttable'
import SelectTreeTable from './selecttreetable'
export {
TreeTable,
SelectTable,
SelectTreeTable,
}
+174
View File
@@ -0,0 +1,174 @@
import React from 'react';
import shortid from 'shortid';
import ReactTable from '../../../../lib/index'
import '../../../../react-table.css'
import selectTableHOC from '../../../../lib/hoc/selectTable'
const SelectTable = selectTableHOC(ReactTable);
async function getData()
{
const result = await ( await fetch('/au_500_tree.json') ).json();
// we are adding a unique ID to the data for tracking the selected records
return result.map((item)=>{
const _id = shortid.generate();
return {
_id,
...item,
}
});
}
function getColumns(data)
{
const columns = [];
const sample = data[0];
for(let key in sample)
{
if(key==='_id') continue;
columns.push({
accessor: key,
Header: key,
})
}
return columns;
}
export class ComponentTest extends React.Component {
constructor(props) {
super(props);
this.state =
{
data: null,
columns: null,
selection: [],
selectAll: false,
selectType: 'checkbox',
};
}
componentDidMount()
{
getData().then((data)=>{
const columns = getColumns(data);
this.setState({ data, columns });
});
}
toggleSelection = (key,shift,row) => {
/*
Implementation of how to manage the selection state is up to the developer.
This implementation uses an array stored in the component state.
Other implementations could use object keys, a Javascript Set, or Redux... etc.
*/
// start off with the existing state
if (this.state.selectType === 'radio') {
let selection = [];
if (selection.indexOf(key)<0) selection.push(key);
this.setState({selection});
} else {
let selection = [
...this.state.selection
];
const keyIndex = selection.indexOf(key);
// check to see if the key exists
if(keyIndex>=0) {
// it does exist so we will remove it using destructing
selection = [
...selection.slice(0,keyIndex),
...selection.slice(keyIndex+1)
]
} else {
// it does not exist so add it
selection.push(key);
}
// update the state
this.setState({selection});
}
}
toggleAll = () => {
/*
'toggleAll' is a tricky concept with any filterable table
do you just select ALL the records that are in your data?
OR
do you only select ALL the records that are in the current filtered data?
The latter makes more sense because 'selection' is a visual thing for the user.
This is especially true if you are going to implement a set of external functions
that act on the selected information (you would not want to DELETE the wrong thing!).
So, to that end, access to the internals of ReactTable are required to get what is
currently visible in the table (either on the current page or any other page).
The HOC provides a method call 'getWrappedInstance' to get a ref to the wrapped
ReactTable and then get the internal state and the 'sortedData'.
That can then be iterrated to get all the currently visible records and set
the selection state.
*/
const selectAll = this.state.selectAll?false:true;
const selection = [];
if(selectAll)
{
// we need to get at the internals of ReactTable
const wrappedInstance = this.selectTable.getWrappedInstance();
// the 'sortedData' property contains the currently accessible records based on the filter and sort
const currentRecords = wrappedInstance.getResolvedState().sortedData;
// we just push all the IDs onto the selection array
currentRecords.forEach((item)=>{
if(item._original)
{
selection.push(item._original._id);
}
})
}
this.setState({selectAll,selection})
}
isSelected = (key) => {
/*
Instead of passing our external selection state we provide an 'isSelected'
callback and detect the selection state ourselves. This allows any implementation
for selection (either an array, object keys, or even a Javascript Set object).
*/
return this.state.selection.includes(key);
}
logSelection = () => {
console.log('selection:',this.state.selection);
}
toggleType = () => {
this.setState({ selectType: this.state.selectType === 'radio' ? 'checkbox' : 'radio', selection: [], selectAll: false, });
}
render(){
const { toggleSelection, toggleAll, isSelected, logSelection, toggleType } = this;
const { data, columns, selectAll, selectType } = this.state;
const extraProps =
{
selectAll,
isSelected,
toggleAll,
toggleSelection,
selectType,
}
return (
<div style={{ padding: '10px'}}>
<h1>react-table - Select Table</h1>
<button onClick={toggleType}>Select Type: <strong>{selectType}</strong></button>
<button onClick={logSelection}>Log Selection to Console</button>
{` (${this.state.selection.length}) selected`}
{
data?
<SelectTable
data={data}
columns={columns}
ref={(r)=>this.selectTable = r}
className="-striped -highlight"
{...extraProps}
/>
:null
}
</div>
);
}
}
export default ComponentTest;
+216
View File
@@ -0,0 +1,216 @@
import React from 'react';
import shortid from 'shortid';
import ReactTable from '../../../../lib/index'
import '../../../../react-table.css'
import selectTableHOC from '../../../../lib/hoc/selectTable'
import treeTableHOC from '../../../../lib/hoc/treeTable'
const SelectTreeTable = selectTableHOC(treeTableHOC(ReactTable));
async function getData()
{
const result = await ( await fetch('/au_500_tree.json') ).json();
// we are adding a unique ID to the data for tracking the selected records
return result.map((item)=>{
const _id = shortid.generate();
return {
_id,
...item,
}
});
}
function getColumns(data)
{
const columns = [];
const sample = data[0];
for(let key in sample)
{
if(key==='_id') continue;
columns.push({
accessor: key,
Header: key,
})
}
return columns;
}
function getNodes(data,node=[])
{
data.forEach((item)=>{
if(item.hasOwnProperty('_subRows') && item._subRows)
{
node = getNodes(item._subRows,node);
} else {
node.push(item._original);
}
});
return node;
}
export class ComponentTest extends React.Component {
constructor(props) {
super(props);
this.state =
{
data: null,
columns: null,
selection: [],
selectAll: false,
selectType: 'checkbox',
};
}
componentDidMount()
{
getData().then((data)=>{
const columns = getColumns(data);
const pivotBy = ['state','post'];
this.setState({ data, columns, pivotBy });
});
}
toggleSelection = (key,shift,row) => {
/*
Implementation of how to manage the selection state is up to the developer.
This implementation uses an array stored in the component state.
Other implementations could use object keys, a Javascript Set, or Redux... etc.
*/
// start off with the existing state
if (this.state.selectType === 'radio') {
let selection = [];
if (selection.indexOf(key)<0) selection.push(key);
this.setState({selection});
} else {
let selection = [
...this.state.selection
];
const keyIndex = selection.indexOf(key);
// check to see if the key exists
if(keyIndex>=0) {
// it does exist so we will remove it using destructing
selection = [
...selection.slice(0,keyIndex),
...selection.slice(keyIndex+1)
]
} else {
// it does not exist so add it
selection.push(key);
}
// update the state
this.setState({selection});
}
}
toggleAll = () => {
/*
'toggleAll' is a tricky concept with any filterable table
do you just select ALL the records that are in your data?
OR
do you only select ALL the records that are in the current filtered data?
The latter makes more sense because 'selection' is a visual thing for the user.
This is especially true if you are going to implement a set of external functions
that act on the selected information (you would not want to DELETE the wrong thing!).
So, to that end, access to the internals of ReactTable are required to get what is
currently visible in the table (either on the current page or any other page).
The HOC provides a method call 'getWrappedInstance' to get a ref to the wrapped
ReactTable and then get the internal state and the 'sortedData'.
That can then be iterrated to get all the currently visible records and set
the selection state.
*/
const selectAll = this.state.selectAll?false:true;
const selection = [];
if(selectAll)
{
// we need to get at the internals of ReactTable
const wrappedInstance = this.selectTable.getWrappedInstance();
// the 'sortedData' property contains the currently accessible records based on the filter and sort
const currentRecords = wrappedInstance.getResolvedState().sortedData;
// we need to get all the 'real' (original) records out to get at their IDs
const nodes = getNodes(currentRecords);
// we just push all the IDs onto the selection array
nodes.forEach((item)=>{
selection.push(item._id);
})
}
this.setState({selectAll,selection})
}
isSelected = (key) => {
/*
Instead of passing our external selection state we provide an 'isSelected'
callback and detect the selection state ourselves. This allows any implementation
for selection (either an array, object keys, or even a Javascript Set object).
*/
return this.state.selection.includes(key);
}
logSelection = () => {
console.log('selection:',this.state.selection);
}
toggleType = () => {
this.setState({ selectType: this.state.selectType === 'radio' ? 'checkbox' : 'radio', selection: [], selectAll: false, });
}
toggleTree = () => {
if(this.state.pivotBy.length) {
this.setState({pivotBy:[],expanded:{}});
} else {
this.setState({pivotBy:['state','post'],expanded:{}});
}
}
onExpandedChange = (expanded) => {
this.setState({expanded});
}
render(){
const { toggleSelection, toggleAll, isSelected, logSelection, toggleType, toggleTree, onExpandedChange, } = this;
const { data, columns, selectAll, selectType, pivotBy, expanded, } = this.state;
const extraProps =
{
selectAll,
isSelected,
toggleAll,
toggleSelection,
selectType,
pivotBy,
expanded,
onExpandedChange,
pageSize: 5,
}
return (
<div style={{ padding: '10px'}}>
<h1>react-table - Select Tree Table</h1>
<p>This example combines two HOCs (the TreeTable and the SelectTable) to make a composite component.</p>
<p>We'll call it SelectTreeTable!</p>
<p>Here is what the buttons do:</p>
<ul>
<li><strong>Toggle Tree:</strong> enables or disabled the pivotBy on the table.</li>
<li><strong>Select Type:</strong> changes from 'checkbox' to 'radio' and back again.</li>
<li><strong>Log Selection to Console:</strong> open your console to see what has been selected.</li>
</ul>
<p>
<strong>NOTE:</strong> the selection is maintained when toggling the tree on and off but is cleared
when switching between select types (radio, checkbox).
</p>
<button onClick={toggleTree}>Toggle Tree [{pivotBy && pivotBy.length ? pivotBy.join(', ') : ''}]</button>
<button onClick={toggleType}>Select Type: <strong>{selectType}</strong></button>
<button onClick={logSelection}>Log Selection to Console</button>
{` (${this.state.selection.length}) selected`}
{
data?
<SelectTreeTable
data={data}
columns={columns}
ref={(r)=>this.selectTable = r}
className="-striped -highlight"
freezeWhenExpanded={true}
{...extraProps}
/>
:null
}
</div>
);
}
}
export default ComponentTest;
+80
View File
@@ -0,0 +1,80 @@
import React from 'react';
import ReactTable from '../../../../lib/index'
import '../../../../react-table.css'
import treeTableHOC from '../../../../lib/hoc/treeTable'
async function getData()
{
const result = await ( await fetch('/au_500_tree.json') ).json();
return result;
}
function getColumns(data,pivotBy)
{
const columns = [];
const sample = data[0];
for(let key in sample)
{
columns.push({
accessor: key,
Header: key,
})
}
return columns;
}
export class ComponentTest extends React.Component {
constructor(props) {
super(props);
this.state =
{
data: null,
columns: null,
pivotBy: null, // ["firstName", "lastName"],
};
}
componentDidMount()
{
getData().then((data)=>{
// console.log('cwm data:',data);
const pivotBy = ['state','post','city'];
const columns = getColumns(data,pivotBy);
// console.log('cwm cols:',columns);
this.setState({data,columns,pivotBy});
});
}
showState = ()=>
{
console.log('state:',this.reactTable.getResolvedState());
}
render(){
const { data, columns, pivotBy } = this.state;
const extraProps =
{
data,
columns,
pivotBy,
}
const TreeTable = treeTableHOC(ReactTable);
return (
<div style={{ padding: '10px'}}>
<h1>react-table - Tree Table</h1>
{
data?
<TreeTable
ref={(r)=>this.reactTable=r}
className="-striped -highlight"
defaultPageSize={5}
{...extraProps}
/>
:null
}
</div>
);
}
}
export default ComponentTest;
@@ -0,0 +1,58 @@
import React from 'react';
export default (Component) => {
const wrapper = (componentProps) => {
const TrComponent = (props) => {
const { ri, ...rest } = props;
if(ri && ri.groupedByPivot) {
const cell = props.children[ri.level];
cell.props.style.flex = 'unset';
cell.props.style.width = '100%';
cell.props.style.maxWidth = 'unset';
cell.props.style.paddingLeft = `${componentProps.treeTableIndent*ri.level}px`;
cell.props.style.backgroundColor = '#DDD';
cell.props.style.borderBottom = '1px solid rgba(128,128,128,0.2)';
return <div {...rest}>{cell}</div>;
}
return <Component.defaultProps.TrComponent {...rest} />;
}
const getTrProps = (state,ri,ci,instance) => {
return {ri};
}
const { columns, ...rest } = componentProps;
const extra = {
columns: columns.map((col)=>{
let column = col;
if(rest.pivotBy && rest.pivotBy.includes(col.accessor))
{
column = {
accessor: col.accessor,
width: `${componentProps.treeTableIndent}px`,
show: false,
Header: '',
}
}
return column;
}),
TrComponent,
getTrProps,
};
return (
<Component {...rest} {...extra} />
)
}
wrapper.displayName = 'RTTreeTable';
wrapper.defaultProps =
{
treeTableRowBackground: '#EEE',
treeTableIndent: 10,
}
return wrapper;
}
+34
View File
@@ -0,0 +1,34 @@
import namor from "namor";
const range = len => {
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(i);
}
return arr;
};
const newPerson = () => {
const statusChance = Math.random();
return {
firstName: namor.generate({ words: 1, numbers: 0 }),
lastName: namor.generate({ words: 1, numbers: 0 }),
age: Math.floor(Math.random() * 30),
visits: Math.floor(Math.random() * 100),
progress: Math.floor(Math.random() * 100),
status:
statusChance > 0.66
? "relationship"
: statusChance > 0.33 ? "complicated" : "single"
};
};
export function makeData(len = 5553) {
return range(len).map(d => {
return {
...newPerson(),
children: range(10).map(newPerson)
};
});
}
+23
View File
@@ -0,0 +1,23 @@
/* eslint-disable */
import React from 'react'
import marked from 'marked'
//
import HOCReadme from '!raw!../../../src/hoc/README.md'
import 'github-markdown-css/github-markdown.css'
import './utils/prism.js'
export default class HOCStory extends React.Component {
render () {
return (
<div style={{ padding: '10px' }}>
<span
className='markdown-body'
dangerouslySetInnerHTML={{ __html: marked(HOCReadme) }}
/>
</div>
)
}
componentDidMount () {
global.Prism && global.Prism.highlightAll()
}
}
+31
View File
@@ -0,0 +1,31 @@
import React from 'react'
import ReactTable from '../../../lib/index'
import '../../../react-table.css'
const data = [
{ one: '1.1', two: '1.2' },
{ one: '2.1', two: '2.2' },
{ one: '3.1', two: '3.2' },
{ one: '4.1', two: '4.2' },
]
const columns = [
{ accessor: 'one', Header: 'One' },
{ accessor: 'two', Header: 'Two' },
]
export default class Story extends React.Component {
render () {
return (
<div>
Test
<ReactTable
data={data}
columns={columns}
/>
</div>
)
}
}
+1113 -764
View File
File diff suppressed because it is too large Load Diff
+8 -2
View File
@@ -1,6 +1,6 @@
{
"name": "react-table",
"version": "6.6.0",
"version": "6.7.6",
"description": "A fast, lightweight, opinionated table and datagrid built on React",
"license": "MIT",
"homepage": "https://github.com/react-tools/react-table#readme",
@@ -35,7 +35,7 @@
"prepublish": "npm run build && npm run umd",
"postpublish": "git push --tags",
"docs": "yarn watch & cd docs && yarn && yarn start",
"docs:build": "yarn build && cd docs && yarn && yarn run build"
"docs:build": "yarn build && cd docs && yarn && yarn build"
},
"dependencies": {
"classnames": "^2.2.5"
@@ -51,10 +51,16 @@
"babel-preset-react": "6.11.1",
"babel-preset-stage-2": "6.13.0",
"eslint": "^4.1.1",
"eslint-config-react-tools": "^1.0.10",
"eslint-plugin-class-property": "^1.0.6",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"match-sorter": "^1.8.0",
"npm-run-all": "^3.1.1",
"onchange": "^3.0.2",
"postcss-cli": "^2.6.0",
"prop-types": "^15.6.0",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-json-tree": "^0.10.9",
+35 -27
View File
@@ -22,6 +22,7 @@ export default {
collapseOnDataChange: true,
freezeWhenExpanded: false,
sortable: true,
multiSort: true,
resizable: true,
filterable: false,
defaultSortDesc: false,
@@ -29,13 +30,15 @@ export default {
defaultFiltered: [],
defaultResized: [],
defaultExpanded: {},
// eslint-disable-next-line no-unused-vars
defaultFilterMethod: (filter, row, column) => {
const id = filter.pivotId || filter.id
return row[id] !== undefined
? String(row[id]).startsWith(filter.value)
: true
},
defaultSortMethod: (a, b) => {
// eslint-disable-next-line no-unused-vars
defaultSortMethod: (a, b, desc) => {
// force null and undefined to the bottom
a = a === null || a === undefined ? '' : a
b = b === null || b === undefined ? '' : b
@@ -49,7 +52,8 @@ export default {
if (a < b) {
return -1
}
// returning 0, undefined or any falsey value will use subsequent sorts or the index as a tiebreaker
// returning 0, undefined or any falsey value will use subsequent sorts or
// the index as a tiebreaker
return 0
},
@@ -176,47 +180,50 @@ export default {
TbodyComponent: _.makeTemplateComponent('rt-tbody', 'Tbody'),
TrGroupComponent: _.makeTemplateComponent('rt-tr-group', 'TrGroup'),
TrComponent: _.makeTemplateComponent('rt-tr', 'Tr'),
ThComponent: ({ toggleSort, className, children, ...rest }) => {
return (
<div
className={classnames(className, 'rt-th')}
onClick={e => {
toggleSort && toggleSort(e)
}}
{...rest}
>
{children}
</div>
)
},
ThComponent: ({ toggleSort, className, children, ...rest }) => (
<div
className={classnames('rt-th', className)}
onClick={e => (
toggleSort && toggleSort(e)
)}
role="heading"
{...rest}
>
{children}
</div>
),
TdComponent: _.makeTemplateComponent('rt-td', 'Td'),
TfootComponent: _.makeTemplateComponent('rt-tfoot', 'Tfoot'),
FilterComponent: ({ filter, onChange }) =>
FilterComponent: ({ filter, onChange }) => (
<input
type='text'
type="text"
style={{
width: '100%',
}}
value={filter ? filter.value : ''}
onChange={event => onChange(event.target.value)}
/>,
ExpanderComponent: ({ isExpanded }) =>
/>
),
ExpanderComponent: ({ isExpanded }) => (
<div className={classnames('rt-expander', isExpanded && '-open')}>
&bull;
</div>,
PivotValueComponent: ({ subRows, value }) =>
</div>
),
PivotValueComponent: ({ subRows, value }) => (
<span>
{value} {subRows && `(${subRows.length})`}
</span>,
</span>
),
AggregatedComponent: ({ subRows, column }) => {
const previewValues = subRows
.filter(d => typeof d[column.id] !== 'undefined')
.map((row, i) =>
.map((row, i) => (
// eslint-disable-next-line react/no-array-index-key
<span key={i}>
{row[column.id]}
{i < subRows.length - 1 ? ', ' : ''}
</span>
)
))
return (
<span>
{previewValues}
@@ -228,15 +235,16 @@ export default {
PaginationComponent: Pagination,
PreviousComponent: undefined,
NextComponent: undefined,
LoadingComponent: ({ className, loading, loadingText, ...rest }) =>
LoadingComponent: ({ className, loading, loadingText, ...rest }) => (
<div
className={classnames('-loading', { '-active': loading }, className)}
{...rest}
>
<div className='-loading-inner'>
<div className="-loading-inner">
{loadingText}
</div>
</div>,
</div>
),
NoDataComponent: _.makeTemplateComponent('rt-noData', 'NoData'),
ResizerComponent: _.makeTemplateComponent('rt-resizer', 'Resizer'),
PadRowComponent: () => <span>&nbsp;</span>,
+122
View File
@@ -0,0 +1,122 @@
<div style="text-align:center;">
<a href="https://github.com/react-tools/react-table" target="\_parent"><img src="https://github.com/react-tools/media/raw/master/logo-react-table.png" alt="React Table Logo" style="width:450px;"/></a>
</div>
# ReactTable - expanding with HOCs
This documentation is about expanding ReactTable using Higher Order Components/Functions.
## Covered in this README
- A Brief explanation of HOCs and why they are a good approach for ReactTable enhancements
- Documentation of the currently available HOCs
- TreeTable
- SelectTable
- Documentation of the standard for writing HOCs with ReactTable
## What are HOCs and why use them with ReactTable
HOCs (or Higher Order Components/Functions) are either a React Component (or a function that returns a React Component)
that are used to enhance the functionality of an existing component. How much you can enhance depends on the props that
the component exposes.
Fortunately, ReactTable exposes a LOT of functionality as props to the component. In some cases there are too many
props to keep track of and that is where HOCs come in.
You can write a HOC that just focusses on the additional functionality you want to enhance and keep those enhancements to
reuse over and over again when you need them. You don't have to edit the ReactSource code, just wrap ReactTable in one or
more HOCs (more on some issues related to chaining HOCs later) that provide the additional functionality you want to expose.
The most obvious HOC is one that can add `checkbox` or select functionality. The HOC included provides `select` functionality
that allows the developer to specify if they want a `checkbox` or `radio` style of select column. The implementation of the
selection is recorded (e.g. in component state, Redux, etc.) and how to manage multiple selections. The HOC really only handles
the rendering pieces.
But there is more documentation on the `select` HOC below.
## Currently Available HOCs
### TreeTable
TreeTable takes over the rendering of the generated pivot rows of ReactTable so that they appear more like an expandable Tree.
It accomplishes this by rendering a 100% wide div and then only rendering the cell that controls the pivot at that level.
Using it is as simple as doing the following:
```javascript
import ReactTable from 'react-table'
import treeTableHOC from 'react-table/lib/hoc/treeTable'
const TreeTable = treeTableHOC(ReactTable)
```
After you have done the above, you can then use `TreeTable` just as you would `ReactTable` but it will render pivots using
the Tree style described above.
### SelectTable
SelectTable is a little trickier. The HOCs attempt to avoid adding additional state and, as there is no internal ID for a row that
can be relied on to be static (ReactTable just reuses indexes when rendering) the developer has to maintain the state outside of even
the wrapped component. So it is largely based on callbacks.
You include the HOC in the same manner as you would for the treeTableHOC but then need to provide the following overrides:
- isSelected - returns `true` if the key passed is selected otherwise it should return `false`
- selectAll - a property that indicates if the selectAll is set (`true|false`)
- toggleAll - called when the user clicks the `selectAll` checkbox/radio
- toggleSelection - called when the use clicks a specific checkbox/radio in a row
- selectType - either `checkbox|radio` to indicate what type of selection is required
In the case of `radio` there is no `selectAll` displayed but the developer is responsible for only making one selection in
the controlling component's state. You could select multiple but it wouldn't make sense and you should use `checkbox` instead.
You also have to decide what `selectAll` means. Given ReactTable is a paged solution there are other records off-page. When someone
selects the `selectAll` checkbox, should it mark every possible record, only what might be visible to due a Filter or only those items
on the current page?
The example opts for the middle approach so it gets a `ref` to the ReactTable instance and pulls the `sortedData` out of the resolved
state (then walks through those records and pulls their ID into the `selection` state of the controlling component).
You can also replace the input component that is used to render the select box and select all box:
- SelectAllInputComponent - the checkbox in the top left corner
- SelectInputComponent - the checkbox used on a row
### SelectTreeTable
SelectTreeTable is a combination of TreeTable and SelectTable.
To function correctly the chain has to be in the correct order as follows (see the comments in the guid on HOCs below).
```Javascript
const SelectTreeTable = selectTableHOC(treeTableHOC(ReactTable));
```
In this particular instance it is (probably) because the functions need access to the state on the wrapped component to manage
the selected items. Although that is not totally clearly the issue.
## HOC Guide for ReactTable
There are a few rules required when writing a HOC for ReactTable (other than meeting the normal lint standards - which are
still being developed).
Firstly, there are issues with `ref` when you write a HOC. Consider a deeply nested component wrapped in multiple HOCs...
A HOC in the middle of the chain requires access to the instance of the component it thinks it is wrapping but there is at
least one other wrapper in the way. The challenge is: How do I get to the actual wrapped component?
Each HOC is required to be a React Class so that a `ref` can be obtained against each component:
```Javascript
<Component ... ref={r => this.wrappedInstance = r} />
```
*NOTE:* "Component" can also be the `<ReactTable />` instance.
Then the following method needs
to be placed on the class so that it exposes the correct instance of ReactTable:
```Javascript
getWrappedInstance() {
if (!this.wrappedInstance) console.warn('<component name here> - No wrapped instance')
if (this.wrappedInstance.getWrappedInstance) return this.wrappedInstance.getWrappedInstance()
else return this.wrappedInstance
}
```
Essentially this will walk down the chain (if there are chained HOCs) and stop when it gets to the end and return the wrapped instance.
Finally, sometimes the chains need to be in a specific order to function correctly. It is not clear if this is just an architectural
issue or if it would be better solved using a library like `recompose`. Anyone who is able to contribute a reliable solution to this
is welcome to submit a PR.
+111
View File
@@ -0,0 +1,111 @@
/* eslint-disable */
import React from 'react';
const defaultSelectInputComponent = (props) => {
return (
<input
type={props.selectType || 'checkbox'}
checked={props.checked}
onClick={(e)=>{
const { shiftKey } = e;
e.stopPropagation();
props.onClick(props.id, shiftKey, props.row);
}}
onChange={()=>{}}
/>
)
}
export default (Component) => {
const wrapper = class RTSelectTable extends React.Component {
constructor(props)
{
super(props);
}
rowSelector(row) {
if(!row || !row.hasOwnProperty(this.props.keyField)) return null;
const { toggleSelection, selectType, keyField } = this.props;
const checked = this.props.isSelected(row[this.props.keyField]);
const inputProps =
{
checked,
onClick: toggleSelection,
selectType,
id: row[keyField],
row,
}
return React.createElement(this.props.SelectInputComponent,inputProps);
}
headSelector(row) {
const { selectType } = this.props;
if (selectType === 'radio') return null;
const { toggleAll, selectAll: checked, SelectAllInputComponent, } = this.props;
const inputProps =
{
checked,
onClick: toggleAll,
selectType,
}
return React.createElement(SelectAllInputComponent,inputProps);
}
// this is so we can expose the underlying ReactTable to get at the sortedData for selectAll
getWrappedInstance() {
if (!this.wrappedInstance) console.warn('RTSelectTable - No wrapped instance');
if (this.wrappedInstance.getWrappedInstance) return this.wrappedInstance.getWrappedInstance();
else return this.wrappedInstance
}
render()
{
const {
columns:originalCols, isSelected, toggleSelection, toggleAll, keyField, selectAll,
selectType, SelectAllInputComponent, SelectInputComponent,
...rest
} = this.props;
const select = {
id: '_selector',
accessor: ()=>'x', // this value is not important
Header: this.headSelector.bind(this),
Cell: (ci) => { return this.rowSelector.bind(this)(ci.original); },
width: 30,
filterable: false,
sortable: false,
resizable: false,
style: { textAlign: 'center' },
}
const columns = [
select,
...originalCols,
];
const extra = {
columns,
};
return (
<Component {...rest} {...extra} ref={(r)=>this.wrappedInstance=r}/>
)
}
}
wrapper.displayName = 'RTSelectTable';
wrapper.defaultProps =
{
keyField: '_id',
isSelected: (key)=>{ console.log('No isSelected handler provided:',{key})},
selectAll: false,
toggleSelection: (key, shift, row)=>{ console.log('No toggleSelection handler provided:', { key, shift, row }) },
toggleAll: () => { console.log('No toggleAll handler provided.') },
selectType: 'check',
SelectInputComponent: defaultSelectInputComponent,
SelectAllInputComponent: defaultSelectInputComponent,
}
return wrapper;
}
+80
View File
@@ -0,0 +1,80 @@
/* eslint-disable */
import React from 'react'
export default (Component) => {
const wrapper = class RTTreeTable extends React.Component {
constructor(props)
{
super(props);
this.getWrappedInstance.bind(this);
this.TrComponent.bind(this);
this.getTrProps.bind(this);
}
// this is so we can expose the underlying ReactTable to get at the sortedData for selectAll
getWrappedInstance = () => {
if (!this.wrappedInstance) console.warn('RTTreeTable - No wrapped instance');
if (this.wrappedInstance.getWrappedInstance) return this.wrappedInstance.getWrappedInstance();
else return this.wrappedInstance
}
TrComponent = (props) => {
const {
ri,
...rest
} = props;
if(ri && ri.groupedByPivot) {
const cell = {...props.children[ri.level]};
cell.props.style.flex = 'unset';
cell.props.style.width = '100%';
cell.props.style.maxWidth = 'unset';
cell.props.style.paddingLeft = `${this.props.treeTableIndent*ri.level}px`;
// cell.props.style.backgroundColor = '#DDD';
cell.props.style.borderBottom = '1px solid rgba(128,128,128,0.2)';
return <div className={`rt-tr ${rest.className}`} style={rest.style}>{cell}</div>;
}
return <Component.defaultProps.TrComponent {...rest} />;
}
getTrProps = (state,ri,ci,instance) => {
return {ri};
}
render() {
const { columns, treeTableIndent, ...rest } = this.props;
const { TrComponent, getTrProps } = this;
const extra = {
columns: columns.map((col)=>{
let column = col;
if(rest.pivotBy && rest.pivotBy.includes(col.accessor))
{
column = {
accessor: col.accessor,
width: `${treeTableIndent}px`,
show: false,
Header: '',
}
}
return column;
}),
TrComponent,
getTrProps,
};
return (
<Component {...rest} {...extra} ref={ r => this.wrappedInstance=r }/>
)
}
}
wrapper.displayName = 'RTTreeTable';
wrapper.defaultProps =
{
treeTableIndent: 10,
}
return wrapper;
}
+240 -233
View File
@@ -5,10 +5,12 @@ import _ from './utils'
import Lifecycle from './lifecycle'
import Methods from './methods'
import defaultProps from './defaultProps'
import propTypes from './propTypes'
export const ReactTableDefaults = defaultProps
export default class ReactTable extends Methods(Lifecycle(Component)) {
static propTypes = propTypes
static defaultProps = defaultProps
constructor (props) {
@@ -78,6 +80,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
loadingText,
noDataText,
sortable,
multiSort,
resizable,
filterable,
// Pivoting State
@@ -139,27 +142,25 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const hasColumnFooter = allVisibleColumns.some(d => d.Footer)
const hasFilters = filterable || allVisibleColumns.some(d => d.filterable)
const recurseRowsViewIndex = (rows, path = [], index = -1) => {
return [
rows.map((row, i) => {
index++
const rowWithViewIndex = {
...row,
_viewIndex: index,
}
const newPath = path.concat([i])
if (rowWithViewIndex[subRowsKey] && _.get(expanded, newPath)) {
;[rowWithViewIndex[subRowsKey], index] = recurseRowsViewIndex(
rowWithViewIndex[subRowsKey],
newPath,
index
)
}
return rowWithViewIndex
}),
index,
]
}
const recurseRowsViewIndex = (rows, path = [], index = -1) => ([
rows.map((row, i) => {
index += 1
const rowWithViewIndex = {
...row,
_viewIndex: index,
}
const newPath = path.concat([i])
if (rowWithViewIndex[subRowsKey] && _.get(expanded, newPath)) {
[rowWithViewIndex[subRowsKey], index] = recurseRowsViewIndex(
rowWithViewIndex[subRowsKey],
newPath,
index,
)
}
return rowWithViewIndex
}),
index,
])
;[pageRows] = recurseRowsViewIndex(pageRows)
const canPrevious = page > 0
@@ -169,7 +170,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
allVisibleColumns.map(d => {
const resizedColumn = resized.find(x => x.id === d.id) || {}
return _.getFirstDefined(resizedColumn.value, d.width, d.minWidth)
})
}),
)
let rowIndex = -1
@@ -187,59 +188,44 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
rowMinWidth,
}
// Visual Components
const rootProps = _.splitProps(
getProps(finalState, undefined, undefined, this),
)
const tableProps = _.splitProps(
getTableProps(finalState, undefined, undefined, this),
)
const tBodyProps = _.splitProps(
getTbodyProps(finalState, undefined, undefined, this),
)
const loadingProps = getLoadingProps(finalState, undefined, undefined, this)
const noDataProps = getNoDataProps(finalState, undefined, undefined, this)
const makeHeaderGroups = () => {
const theadGroupProps = _.splitProps(
getTheadGroupProps(finalState, undefined, undefined, this)
)
const theadGroupTrProps = _.splitProps(
getTheadGroupTrProps(finalState, undefined, undefined, this)
)
return (
<TheadComponent
className={classnames('-headerGroups', theadGroupProps.className)}
style={{
...theadGroupProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadGroupProps.rest}
>
<TrComponent
className={theadGroupTrProps.className}
style={theadGroupTrProps.style}
{...theadGroupTrProps.rest}
>
{headerGroups.map(makeHeaderGroup)}
</TrComponent>
</TheadComponent>
)
}
// Visual Components
const makeHeaderGroup = (column, i) => {
const resizedValue = col =>
(resized.find(x => x.id === col.id) || {}).value
const flex = _.sum(
column.columns.map(
col => (col.width || resizedValue(col) ? 0 : col.minWidth)
)
col => (col.width || resizedValue(col) ? 0 : col.minWidth),
),
)
const width = _.sum(
column.columns.map(col =>
_.getFirstDefined(resizedValue(col), col.width, col.minWidth)
)
_.getFirstDefined(resizedValue(col), col.width, col.minWidth),
),
)
const maxWidth = _.sum(
column.columns.map(col =>
_.getFirstDefined(resizedValue(col), col.width, col.maxWidth)
)
_.getFirstDefined(resizedValue(col), col.width, col.maxWidth),
),
)
const theadGroupThProps = _.splitProps(
getTheadGroupThProps(finalState, undefined, column, this)
getTheadGroupThProps(finalState, undefined, column, this),
)
const columnHeaderProps = _.splitProps(
column.getHeaderProps(finalState, undefined, column, this)
column.getHeaderProps(finalState, undefined, column, this),
)
const classes = [
@@ -267,7 +253,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
return (
<ThComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(classes)}
style={{
...styles,
@@ -277,34 +263,34 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
>
{_.normalizeComponent(column.Header, {
data: sortedData,
column: column,
column,
})}
</ThComponent>
)
}
const makeHeaders = () => {
const theadProps = _.splitProps(
getTheadProps(finalState, undefined, undefined, this)
const makeHeaderGroups = () => {
const theadGroupProps = _.splitProps(
getTheadGroupProps(finalState, undefined, undefined, this),
)
const theadTrProps = _.splitProps(
getTheadTrProps(finalState, undefined, undefined, this)
const theadGroupTrProps = _.splitProps(
getTheadGroupTrProps(finalState, undefined, undefined, this),
)
return (
<TheadComponent
className={classnames('-header', theadProps.className)}
className={classnames('-headerGroups', theadGroupProps.className)}
style={{
...theadProps.style,
...theadGroupProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadProps.rest}
{...theadGroupProps.rest}
>
<TrComponent
className={theadTrProps.className}
style={theadTrProps.style}
{...theadTrProps.rest}
className={theadGroupTrProps.className}
style={theadGroupTrProps.style}
{...theadGroupTrProps.rest}
>
{allVisibleColumns.map(makeHeader)}
{headerGroups.map(makeHeaderGroup)}
</TrComponent>
</TheadComponent>
)
@@ -318,18 +304,18 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const theadThProps = _.splitProps(
getTheadThProps(finalState, undefined, column, this)
getTheadThProps(finalState, undefined, column, this),
)
const columnHeaderProps = _.splitProps(
column.getHeaderProps(finalState, undefined, column, this)
column.getHeaderProps(finalState, undefined, column, this),
)
const classes = [
@@ -354,7 +340,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
? (<ResizerComponent
onMouseDown={e => this.resizeColumnStart(e, column, false)}
onTouchStart={e => this.resizeColumnStart(e, column, true)}
{...resizerProps}
{...getResizerProps('finalState', undefined, column, this)}
/>)
: null
@@ -362,7 +348,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
return (
<ThComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(
classes,
isResizable && 'rt-resizable-header',
@@ -371,7 +357,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
!show && '-hidden',
pivotBy &&
pivotBy.slice(0, -1).includes(column.id) &&
'rt-header-pivot'
'rt-header-pivot',
)}
style={{
...styles,
@@ -380,14 +366,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
maxWidth: _.asPx(maxWidth),
}}
toggleSort={e => {
isSortable && this.sortColumn(column, e.shiftKey)
if (isSortable) this.sortColumn(column, multiSort ? e.shiftKey : false)
}}
{...rest}
>
<div className={classnames(isResizable && 'rt-resizable-header-content')}>
{_.normalizeComponent(column.Header, {
data: sortedData,
column: column,
column,
})}
</div>
{resizer}
@@ -395,28 +381,28 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makeFilters = () => {
const theadFilterProps = _.splitProps(
getTheadFilterProps(finalState, undefined, undefined, this)
const makeHeaders = () => {
const theadProps = _.splitProps(
getTheadProps(finalState, undefined, undefined, this),
)
const theadFilterTrProps = _.splitProps(
getTheadFilterTrProps(finalState, undefined, undefined, this)
const theadTrProps = _.splitProps(
getTheadTrProps(finalState, undefined, undefined, this),
)
return (
<TheadComponent
className={classnames('-filters', theadFilterProps.className)}
className={classnames('-header', theadProps.className)}
style={{
...theadFilterProps.style,
...theadProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadFilterProps.rest}
{...theadProps.rest}
>
<TrComponent
className={theadFilterTrProps.className}
style={theadFilterTrProps.style}
{...theadFilterTrProps.rest}
className={theadTrProps.className}
style={theadTrProps.style}
{...theadTrProps.rest}
>
{allVisibleColumns.map(makeFilter)}
{allVisibleColumns.map(makeHeader)}
</TrComponent>
</TheadComponent>
)
@@ -427,18 +413,18 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const theadFilterThProps = _.splitProps(
getTheadFilterThProps(finalState, undefined, column, this)
getTheadFilterThProps(finalState, undefined, column, this),
)
const columnHeaderProps = _.splitProps(
column.getHeaderProps(finalState, undefined, column, this)
column.getHeaderProps(finalState, undefined, column, this),
)
const classes = [
@@ -465,12 +451,12 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const isFilterable = _.getFirstDefined(
column.filterable,
filterable,
false
false,
)
return (
<ThComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(classes)}
style={{
...styles,
@@ -488,19 +474,48 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
filter,
onChange: value => this.filterColumn(column, value),
},
defaultProps.column.Filter
defaultProps.column.Filter,
)
: null}
</ThComponent>
)
}
const makeFilters = () => {
const theadFilterProps = _.splitProps(
getTheadFilterProps(finalState, undefined, undefined, this),
)
const theadFilterTrProps = _.splitProps(
getTheadFilterTrProps(finalState, undefined, undefined, this),
)
return (
<TheadComponent
className={classnames('-filters', theadFilterProps.className)}
style={{
...theadFilterProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadFilterProps.rest}
>
<TrComponent
className={theadFilterTrProps.className}
style={theadFilterTrProps.style}
{...theadFilterTrProps.rest}
>
{allVisibleColumns.map(makeFilter)}
</TrComponent>
</TheadComponent>
)
}
const makePageRow = (row, i, path = []) => {
const rowInfo = {
original: row[originalKey],
row: row,
row,
index: row[indexKey],
viewIndex: ++rowIndex,
viewIndex: rowIndex += 1,
pageSize,
page,
level: path.length,
nestingPath: path.concat([i]),
aggregated: row[aggregatedKey],
@@ -510,14 +525,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const isExpanded = _.get(expanded, rowInfo.nestingPath)
const trGroupProps = getTrGroupProps(finalState, rowInfo, undefined, this)
const trProps = _.splitProps(
getTrProps(finalState, rowInfo, undefined, this)
getTrProps(finalState, rowInfo, undefined, this),
)
return (
<TrGroupComponent key={rowInfo.nestingPath.join('_')} {...trGroupProps}>
<TrComponent
className={classnames(
trProps.className,
row._viewIndex % 2 ? '-even' : '-odd'
row._viewIndex % 2 ? '-even' : '-odd',
)}
style={trProps.style}
{...trProps.rest}
@@ -529,18 +544,18 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const tdProps = _.splitProps(
getTdProps(finalState, rowInfo, column, this)
getTdProps(finalState, rowInfo, column, this),
)
const columnProps = _.splitProps(
column.getProps(finalState, rowInfo, column, this)
column.getProps(finalState, rowInfo, column, this),
)
const classes = [
@@ -590,10 +605,10 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{
expanded: newExpanded,
},
() => {
() => (
onExpandedChange &&
onExpandedChange(newExpanded, cellInfo.nestingPath, e)
}
),
)
}
@@ -601,7 +616,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
let resolvedCell = _.normalizeComponent(
column.Cell,
cellInfo,
value
value,
)
// Resolve Renderers
@@ -614,11 +629,12 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
column.PivotValue || PivotValueComponent
const DefaultResolvedPivotComponent =
PivotComponent ||
(props =>
(props => (
<div>
<ResolvedExpanderComponent {...props} />
<ResolvedPivotValueComponent {...props} />
</div>)
</div>
))
const ResolvedPivotComponent =
column.Pivot || DefaultResolvedPivotComponent
@@ -627,7 +643,8 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
// Make it expandable by defualt
cellInfo.expandable = true
useOnExpanderClick = true
// If pivoted, has no subRows, and does not have a subComponent, do not make expandable
// If pivoted, has no subRows, and does not have a subComponent,
// do not make expandable
if (cellInfo.pivoted && !cellInfo.subRows && !SubComponent) {
cellInfo.expandable = false
}
@@ -650,14 +667,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
...cellInfo,
value: row[pivotValKey],
},
row[pivotValKey]
row[pivotValKey],
)
} else if (isPreview) {
// Show the pivot preview
resolvedCell = _.normalizeComponent(
ResolvedAggregatedComponent,
cellInfo,
value
value,
)
} else {
resolvedCell = null
@@ -666,7 +683,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
resolvedCell = _.normalizeComponent(
ResolvedAggregatedComponent,
cellInfo,
value
value,
)
}
@@ -674,7 +691,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
resolvedCell = _.normalizeComponent(
ResolvedExpanderComponent,
cellInfo,
row[pivotValKey]
row[pivotValKey],
)
if (pivotBy) {
if (cellInfo.groupedByPivot) {
@@ -690,7 +707,9 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
? onExpanderClick
: () => {}
// If there are multiple onClick events, make sure they don't override eachother. This should maybe be expanded to handle all function attributes
// If there are multiple onClick events, make sure they don't
// override eachother. This should maybe be expanded to handle all
// function attributes
const interactionProps = {
onClick: resolvedOnExpanderClick,
}
@@ -710,12 +729,13 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
// Return the cell
return (
<TdComponent
key={i2 + '-' + column.id}
// eslint-disable-next-line react/no-array-index-key
key={`${i2}-${column.id}`}
className={classnames(
classes,
!show && 'hidden',
cellInfo.expandable && 'rt-expandable',
(isBranch || isPreview) && 'rt-pivot'
(isBranch || isPreview) && 'rt-pivot',
)}
style={{
...styles,
@@ -735,7 +755,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{rowInfo.subRows &&
isExpanded &&
rowInfo.subRows.map((d, i) =>
makePageRow(d, i, rowInfo.nestingPath)
makePageRow(d, i, rowInfo.nestingPath),
)}
{SubComponent &&
!rowInfo.subRows &&
@@ -745,52 +765,26 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makePadRow = (row, i) => {
const trGroupProps = getTrGroupProps(
finalState,
undefined,
undefined,
this
)
const trProps = _.splitProps(
getTrProps(finalState, undefined, undefined, this)
)
return (
<TrGroupComponent key={i} {...trGroupProps}>
<TrComponent
className={classnames(
'-padRow',
(pageRows.length + i) % 2 ? '-even' : '-odd',
trProps.className
)}
style={trProps.style || {}}
>
{allVisibleColumns.map(makePadColumn)}
</TrComponent>
</TrGroupComponent>
)
}
const makePadColumn = (column, i) => {
const resizedCol = resized.find(x => x.id === column.id) || {}
const show =
typeof column.show === 'function' ? column.show() : column.show
let width = _.getFirstDefined(
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
let flex = width
let maxWidth = _.getFirstDefined(
const flex = width
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const tdProps = _.splitProps(
getTdProps(finalState, undefined, column, this)
getTdProps(finalState, undefined, column, this),
)
const columnProps = _.splitProps(
column.getProps(finalState, undefined, column, this)
column.getProps(finalState, undefined, column, this),
)
const classes = [
@@ -807,7 +801,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
return (
<TdComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(classes, !show && 'hidden')}
style={{
...styles,
@@ -822,10 +816,96 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makePadRow = (row, i) => {
const trGroupProps = getTrGroupProps(
finalState,
undefined,
undefined,
this,
)
const trProps = _.splitProps(
getTrProps(finalState, undefined, undefined, this),
)
return (
<TrGroupComponent key={i} {...trGroupProps}>
<TrComponent
className={classnames(
'-padRow',
(pageRows.length + i) % 2 ? '-even' : '-odd',
trProps.className,
)}
style={trProps.style || {}}
>
{allVisibleColumns.map(makePadColumn)}
</TrComponent>
</TrGroupComponent>
)
}
const makeColumnFooter = (column, i) => {
const resizedCol = resized.find(x => x.id === column.id) || {}
const show =
typeof column.show === 'function' ? column.show() : column.show
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth,
)
const tFootTdProps = _.splitProps(
getTfootTdProps(finalState, undefined, undefined, this),
)
const columnProps = _.splitProps(
column.getProps(finalState, undefined, column, this),
)
const columnFooterProps = _.splitProps(
column.getFooterProps(finalState, undefined, column, this),
)
const classes = [
tFootTdProps.className,
column.className,
columnProps.className,
columnFooterProps.className,
]
const styles = {
...tFootTdProps.style,
...column.style,
...columnProps.style,
...columnFooterProps.style,
}
return (
<TdComponent
key={`${i}-${column.id}`}
className={classnames(classes, !show && 'hidden')}
style={{
...styles,
flex: `${width} 0 auto`,
width: _.asPx(width),
maxWidth: _.asPx(maxWidth),
}}
{...columnProps.rest}
{...tFootTdProps.rest}
{...columnFooterProps.rest}
>
{_.normalizeComponent(column.Footer, {
data: sortedData,
column,
})}
</TdComponent>
)
}
const makeColumnFooters = () => {
const tFootProps = getTfootProps(finalState, undefined, undefined, this)
const tFootTrProps = _.splitProps(
getTfootTrProps(finalState, undefined, undefined, this)
getTfootTrProps(finalState, undefined, undefined, this),
)
return (
<TfootComponent
@@ -847,69 +927,9 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makeColumnFooter = (column, i) => {
const resizedCol = resized.find(x => x.id === column.id) || {}
const show =
typeof column.show === 'function' ? column.show() : column.show
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
)
const tFootTdProps = _.splitProps(
getTfootTdProps(finalState, undefined, undefined, this)
)
const columnProps = _.splitProps(
column.getProps(finalState, undefined, column, this)
)
const columnFooterProps = _.splitProps(
column.getFooterProps(finalState, undefined, column, this)
)
const classes = [
tFootTdProps.className,
column.className,
columnProps.className,
columnFooterProps.className,
]
const styles = {
...tFootTdProps.style,
...column.style,
...columnProps.style,
...columnFooterProps.style,
}
return (
<TdComponent
key={i + '-' + column.id}
className={classnames(classes, !show && 'hidden')}
style={{
...styles,
flex: `${width} 0 auto`,
width: _.asPx(width),
maxWidth: _.asPx(maxWidth),
}}
{...columnProps.rest}
{...tFootTdProps.rest}
{...columnFooterProps.rest}
>
{_.normalizeComponent(column.Footer, {
data: sortedData,
column: column,
})}
</TdComponent>
)
}
const makePagination = () => {
const paginationProps = _.splitProps(
getPaginationProps(finalState, undefined, undefined, this)
getPaginationProps(finalState, undefined, undefined, this),
)
return (
<PaginationComponent
@@ -926,19 +946,6 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const rootProps = _.splitProps(
getProps(finalState, undefined, undefined, this)
)
const tableProps = _.splitProps(
getTableProps(finalState, undefined, undefined, this)
)
const tBodyProps = _.splitProps(
getTbodyProps(finalState, undefined, undefined, this)
)
const loadingProps = getLoadingProps(finalState, undefined, undefined, this)
const noDataProps = getNoDataProps(finalState, undefined, undefined, this)
const resizerProps = getResizerProps(finalState, undefined, undefined, this)
const makeTable = () => {
const pagination = makePagination()
return (
@@ -951,14 +958,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{...rootProps.rest}
>
{showPagination && showPaginationTop
? <div className='pagination-top'>
? <div className="pagination-top">
{pagination}
</div>
: null}
<TableComponent
className={classnames(
tableProps.className,
currentlyResizing ? 'rt-resizing' : ''
currentlyResizing ? 'rt-resizing' : '',
)}
style={tableProps.style}
{...tableProps.rest}
@@ -980,7 +987,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{hasColumnFooter ? makeColumnFooters() : null}
</TableComponent>
{showPagination && showPaginationBottom
? <div className='pagination-bottom'>
? <div className="pagination-bottom">
{pagination}
</div>
: null}
+15 -8
View File
@@ -2,6 +2,15 @@ $easeOutQuad = cubic-bezier(0.250, 0.460, 0.450, 0.940)
$easeOutBack = cubic-bezier(0.175, 0.885, 0.320, 1.275)
$expandSize = 7px
input-select-style()
border: 1px solid rgba(0,0,0,0.1)
background: white
padding: 5px 7px
font-size: inherit
border-radius: 3px
font-weight: normal
outline:none
.ReactTable
position:relative
display: flex
@@ -10,7 +19,7 @@ $expandSize = 7px
*
box-sizing: border-box
.rt-table
flex: 1
flex: auto 1
display: flex
flex-direction: column
align-items: stretch
@@ -34,6 +43,10 @@ $expandSize = 7px
&.-filters
border-bottom: 1px solid alpha(black, 0.05)
input
select
input-select-style();
.rt-th
border-right: 1px solid alpha(black, 0.02)
@@ -198,13 +211,7 @@ $expandSize = 7px
input
select
border: 1px solid rgba(0,0,0,0.1)
background: white
padding: 5px 7px
font-size: inherit
border-radius: 3px
font-weight: normal
outline:none
input-select-style()
.-btn
appearance:none
+4 -4
View File
@@ -64,7 +64,7 @@ export default Base =>
if (freezeWhenExpanded) {
// if any rows are expanded, freeze the existing data and sorting
const keys = Object.keys(newResolvedState.expanded)
for (var i = 0; i < keys.length; i++) {
for (let i = 0; i < keys.length; i += 1) {
if (newResolvedState.expanded[keys[i]]) {
newResolvedState.frozen = true
break
@@ -109,18 +109,18 @@ export default Base =>
newResolvedState.pages = newResolvedState.manual
? newResolvedState.pages
: Math.ceil(
newResolvedState.sortedData.length / newResolvedState.pageSize
newResolvedState.sortedData.length / newResolvedState.pageSize,
)
newResolvedState.page = Math.max(
newResolvedState.page >= newResolvedState.pages
? newResolvedState.pages - 1
: newResolvedState.page,
0
0,
)
}
return this.setState(newResolvedState, () => {
cb && cb()
if (cb) { cb() }
if (
oldState.page !== newResolvedState.page ||
oldState.pageSize !== newResolvedState.pageSize ||
+93 -101
View File
@@ -42,7 +42,7 @@ export default Base =>
let expanderColumn = columns.find(
col =>
col.expander ||
(col.columns && col.columns.some(col2 => col2.expander))
(col.columns && col.columns.some(col2 => col2.expander)),
)
// The actual expander might be in the columns field of a group column
if (expanderColumn && !expanderColumn.expander) {
@@ -91,48 +91,48 @@ export default Base =>
if (dcol.accessor && !dcol.id) {
console.warn(dcol)
throw new Error(
'A column id is required if using a non-string accessor for column above.'
'A column id is required if using a non-string accessor for column above.',
)
}
// Fall back to an undefined accessor
if (!dcol.accessor) {
dcol.accessor = d => undefined
dcol.accessor = () => undefined
}
return dcol
}
const allDecoratedColumns = []
// Decorate the columns
const decorateAndAddToAll = (column, parentColumn) => {
const decoratedColumn = makeDecoratedColumn(column, parentColumn)
allDecoratedColumns.push(decoratedColumn)
return decoratedColumn
}
const allDecoratedColumns = []
const decoratedColumns = columnsWithExpander.map((column, i) => {
const decoratedColumns = columnsWithExpander.map(column => {
if (column.columns) {
return {
...column,
columns: column.columns.map(d => decorateAndAddToAll(d, column)),
}
} else {
return decorateAndAddToAll(column)
}
return decorateAndAddToAll(column)
})
// Build the visible columns, headers and flat column list
let visibleColumns = decoratedColumns.slice()
let allVisibleColumns = []
visibleColumns = visibleColumns.map((column, i) => {
visibleColumns = visibleColumns.map(column => {
if (column.columns) {
const visibleSubColumns = column.columns.filter(
d =>
pivotBy.indexOf(d.id) > -1
? false
: _.getFirstDefined(d.show, true)
)
const visibleSubColumns = column.columns.filter(d => (
pivotBy.indexOf(d.id) > -1
? false
: _.getFirstDefined(d.show, true)
))
return {
...column,
columns: visibleSubColumns,
@@ -141,13 +141,13 @@ export default Base =>
return column
})
visibleColumns = visibleColumns.filter(column => {
return column.columns
visibleColumns = visibleColumns.filter(column => (
column.columns
? column.columns.length
: pivotBy.indexOf(column.id) > -1
? false
: _.getFirstDefined(column.show, true)
})
))
// Find any custom pivot location
const pivotIndex = visibleColumns.findIndex(col => col.pivot)
@@ -163,10 +163,10 @@ export default Base =>
}
})
let PivotParentColumn = pivotColumns.reduce(
const PivotParentColumn = pivotColumns.reduce(
(prev, current) =>
prev && prev === current.parentColumn && current.parentColumn,
pivotColumns[0].parentColumn
pivotColumns[0].parentColumn,
)
let PivotGroupHeader = hasHeaderGroups && PivotParentColumn.Header
@@ -202,13 +202,13 @@ export default Base =>
headerGroups.push({
...this.props.column,
...column,
columns: columns,
columns,
})
currentSpan = []
}
// Build flast list of allVisibleColumns and HeaderGroups
visibleColumns.forEach((column, i) => {
visibleColumns.forEach(column => {
if (column.columns) {
allVisibleColumns = allVisibleColumns.concat(column.columns)
if (currentSpan.length > 0) {
@@ -238,13 +238,18 @@ export default Base =>
})
if (row[subRowsKey]) {
row[subRowsKey] = row[subRowsKey].map((d, i) =>
accessRow(d, i, level + 1)
accessRow(d, i, level + 1),
)
}
return row
}
let resolvedData = data.map((d, i) => accessRow(d, i))
// TODO: Make it possible to fabricate nested rows without pivoting
const aggregatingColumns = allVisibleColumns.filter(
d => !d.expander && d.aggregate,
)
// If pivoting, recursively group the data
const aggregate = rows => {
const aggregationValues = {}
@@ -254,11 +259,6 @@ export default Base =>
})
return aggregationValues
}
// TODO: Make it possible to fabricate nested rows without pivoting
const aggregatingColumns = allVisibleColumns.filter(
d => !d.expander && d.aggregate
)
if (pivotBy.length) {
const groupRecursively = (rows, keys, i = 0) => {
// This is the last level, just return the rows
@@ -267,20 +267,18 @@ export default Base =>
}
// Group the rows together for this level
let groupedRows = Object.entries(
_.groupBy(rows, keys[i])
).map(([key, value]) => {
return {
[pivotIDKey]: keys[i],
[pivotValKey]: key,
[keys[i]]: key,
[subRowsKey]: value,
[nestingLevelKey]: i,
[groupedByPivotKey]: true,
}
})
_.groupBy(rows, keys[i]),
).map(([key, value]) => ({
[pivotIDKey]: keys[i],
[pivotValKey]: key,
[keys[i]]: key,
[subRowsKey]: value,
[nestingLevelKey]: i,
[groupedByPivotKey]: true,
}))
// Recurse into the subRows
groupedRows = groupedRows.map(rowGroup => {
let subRows = groupRecursively(rowGroup[subRowsKey], keys, i + 1)
const subRows = groupRecursively(rowGroup[subRowsKey], keys, i + 1)
return {
...rowGroup,
[subRowsKey]: subRows,
@@ -329,10 +327,10 @@ export default Base =>
resolvedData,
filtered,
defaultFilterMethod,
allVisibleColumns
allVisibleColumns,
),
sorted,
sortMethodsByColumnID
sortMethodsByColumnID,
),
}
}
@@ -366,11 +364,10 @@ export default Base =>
// If 'filterAll' is set to true, pass the entire dataset to the filter method
if (column.filterAll) {
return filterMethod(nextFilter, filteredSoFar, column)
} else {
return filteredSoFar.filter(row => {
return filterMethod(nextFilter, row, column)
})
}
return filteredSoFar.filter(row => (
filterMethod(nextFilter, row, column)
))
}, filteredData)
// Apply the filter to the subrows if we are pivoting, and then
@@ -386,7 +383,7 @@ export default Base =>
row[this.props.subRowsKey],
filtered,
defaultFilterMethod,
allVisibleColumns
allVisibleColumns,
),
}
})
@@ -411,16 +408,16 @@ export default Base =>
sorted.map(sort => {
// Support custom sorting methods for each column
if (sortMethodsByColumnID[sort.id]) {
return (a, b) => {
return sortMethodsByColumnID[sort.id](a[sort.id], b[sort.id])
}
}
return (a, b) => {
return this.props.defaultSortMethod(a[sort.id], b[sort.id])
return (a, b) => (
sortMethodsByColumnID[sort.id](a[sort.id], b[sort.id], sort.desc)
)
}
return (a, b) => (
this.props.defaultSortMethod(a[sort.id], b[sort.id], sort.desc)
)
}),
sorted.map(d => !d.desc),
this.props.indexKey
this.props.indexKey,
)
sortedData.forEach(row => {
@@ -430,7 +427,7 @@ export default Base =>
row[this.props.subRowsKey] = this.sortData(
row[this.props.subRowsKey],
sorted,
sortMethodsByColumnID
sortMethodsByColumnID,
)
})
@@ -440,7 +437,7 @@ export default Base =>
getMinRows () {
return _.getFirstDefined(
this.props.minRows,
this.getStateOrProp('pageSize')
this.getStateOrProp('pageSize'),
)
}
@@ -452,9 +449,9 @@ export default Base =>
if (collapseOnPageChange) {
newState.expanded = {}
}
this.setStateWithData(newState, () => {
this.setStateWithData(newState, () => (
onPageChange && onPageChange(page)
})
))
}
onPageSizeChange (newPageSize) {
@@ -470,16 +467,16 @@ export default Base =>
pageSize: newPageSize,
page: newPage,
},
() => {
() => (
onPageSizeChange && onPageSizeChange(newPageSize, newPage)
}
),
)
}
sortColumn (column, additive) {
const { sorted, skipNextSort, defaultSortDesc } = this.getResolvedState()
const firstSortDirection = column.hasOwnProperty('defaultSortDesc')
const firstSortDirection = Object.prototype.hasOwnProperty.call(column, 'defaultSortDesc')
? column.defaultSortDesc
: defaultSortDesc
const secondSortDirection = !firstSortDirection
@@ -519,20 +516,18 @@ export default Base =>
newSorted = [existing]
}
}
} else if (additive) {
newSorted.push({
id: column.id,
desc: firstSortDirection,
})
} else {
if (additive) {
newSorted.push({
newSorted = [
{
id: column.id,
desc: firstSortDirection,
})
} else {
newSorted = [
{
id: column.id,
desc: firstSortDirection,
},
]
}
},
]
}
} else {
// Multi-Sort
@@ -556,21 +551,19 @@ export default Base =>
if (!additive) {
newSorted = newSorted.slice(existingIndex, column.length)
}
} else {
// New Sort Column
if (additive) {
newSorted = newSorted.concat(
column.map(d => ({
id: d.id,
desc: firstSortDirection,
}))
)
} else {
newSorted = column.map(d => ({
// New Sort Column
} else if (additive) {
newSorted = newSorted.concat(
column.map(d => ({
id: d.id,
desc: firstSortDirection,
}))
}
})),
)
} else {
newSorted = column.map(d => ({
id: d.id,
desc: firstSortDirection,
}))
}
}
@@ -582,9 +575,9 @@ export default Base =>
: this.state.page,
sorted: newSorted,
},
() => {
() => (
onSortedChange && onSortedChange(newSorted, column, additive)
}
),
)
}
@@ -593,16 +586,14 @@ export default Base =>
const { onFilteredChange } = this.props
// Remove old filter first if it exists
const newFiltering = (filtered || []).filter(x => {
if (x.id !== column.id) {
return true
}
})
const newFiltering = (filtered || []).filter(x => (
x.id !== column.id
))
if (value !== '') {
newFiltering.push({
id: column.id,
value: value,
value,
})
}
@@ -610,9 +601,9 @@ export default Base =>
{
filtered: newFiltering,
},
() => {
() => (
onFilteredChange && onFilteredChange(newFiltering, column, value)
}
),
)
}
@@ -634,7 +625,7 @@ export default Base =>
currentlyResizing: {
id: column.id,
startX: pageX,
parentWidth: parentWidth,
parentWidth,
},
},
() => {
@@ -647,7 +638,7 @@ export default Base =>
document.addEventListener('mouseup', this.resizeColumnEnd)
document.addEventListener('mouseleave', this.resizeColumnEnd)
}
}
},
)
}
@@ -667,10 +658,11 @@ export default Base =>
pageX = event.pageX
}
// Set the min size to 10 to account for margin and border or else the group headers don't line up correctly
// Set the min size to 10 to account for margin and border or else the
// group headers don't line up correctly
const newWidth = Math.max(
currentlyResizing.parentWidth + pageX - currentlyResizing.startX,
11
11,
)
newResized.push({
@@ -682,15 +674,15 @@ export default Base =>
{
resized: newResized,
},
() => {
() => (
onResizedChange && onResizedChange(newResized, event)
}
),
)
}
resizeColumnEnd (event) {
event.stopPropagation()
let isTouch = event.type === 'touchend' || event.type === 'touchcancel'
const isTouch = event.type === 'touchend' || event.type === 'touchcancel'
if (isTouch) {
document.removeEventListener('touchmove', this.resizeColumnMoving)
+20 -20
View File
@@ -3,10 +3,11 @@ import classnames from 'classnames'
//
// import _ from './utils'
const defaultButton = props =>
<button type='button' {...props} className='-btn'>
const defaultButton = props => (
<button type="button" {...props} className="-btn">
{props.children}
</button>
)
export default class ReactTablePagination extends Component {
constructor (props) {
@@ -41,7 +42,7 @@ export default class ReactTablePagination extends Component {
}
applyPage (e) {
e && e.preventDefault()
if (e) { e.preventDefault() }
const page = this.state.page
this.changePage(page === '' ? this.props.page : page)
}
@@ -69,9 +70,9 @@ export default class ReactTablePagination extends Component {
className={classnames(className, '-pagination')}
style={this.props.paginationStyle}
>
<div className='-previous'>
<div className="-previous">
<PreviousComponent
onClick={e => {
onClick={() => {
if (!canPrevious) return
this.changePage(page - 1)
}}
@@ -80,11 +81,11 @@ export default class ReactTablePagination extends Component {
{this.props.previousText}
</PreviousComponent>
</div>
<div className='-center'>
<span className='-pageInfo'>
<div className="-center">
<span className="-pageInfo">
{this.props.pageText}{' '}
{showPageJump
? <div className='-pageJump'>
? <div className="-pageJump">
<input
type={this.state.page === '' ? 'text' : 'number'}
onChange={e => {
@@ -104,31 +105,30 @@ export default class ReactTablePagination extends Component {
}}
/>
</div>
: <span className='-currentPage'>
: <span className="-currentPage">
{page + 1}
</span>}{' '}
{this.props.ofText}{' '}
<span className='-totalPages'>{pages || 1}</span>
<span className="-totalPages">{pages || 1}</span>
</span>
{showPageSizeOptions &&
<span className='select-wrap -pageSizeOptions'>
<span className="select-wrap -pageSizeOptions">
<select
onChange={e => onPageSizeChange(Number(e.target.value))}
value={pageSize}
>
{pageSizeOptions.map((option, i) => {
return (
<option key={i} value={option}>
{option} {this.props.rowsText}
</option>
)
})}
{pageSizeOptions.map((option, i) => (
// eslint-disable-next-line react/no-array-index-key
<option key={i} value={option}>
{option} {this.props.rowsText}
</option>
))}
</select>
</span>}
</div>
<div className='-next'>
<div className="-next">
<NextComponent
onClick={e => {
onClick={() => {
if (!canNext) return
this.changePage(page + 1)
}}
+194
View File
@@ -0,0 +1,194 @@
import PropTypes from 'prop-types'
export default {
// General
data: PropTypes.array,
loading: PropTypes.bool,
showPagination: PropTypes.bool,
showPaginationTop: PropTypes.bool,
showPaginationBottom: PropTypes.bool,
showPageSizeOptions: PropTypes.bool,
pageSizeOptions: PropTypes.array,
defaultPageSize: PropTypes.number,
showPageJump: PropTypes.bool,
collapseOnSortingChange: PropTypes.bool,
collapseOnPageChange: PropTypes.bool,
collapseOnDataChange: PropTypes.bool,
freezeWhenExpanded: PropTypes.bool,
sortable: PropTypes.bool,
resizable: PropTypes.bool,
filterable: PropTypes.bool,
defaultSortDesc: PropTypes.bool,
defaultSorted: PropTypes.array,
defaultFiltered: PropTypes.array,
defaultResized: PropTypes.array,
defaultExpanded: PropTypes.object,
defaultFilterMethod: PropTypes.func,
defaultSortMethod: PropTypes.func,
// Controlled State Callbacks
onPageChange: PropTypes.func,
onPageSizeChange: PropTypes.func,
onSortedChange: PropTypes.func,
onFilteredChange: PropTypes.func,
onResizedChange: PropTypes.func,
onExpandedChange: PropTypes.func,
// Pivoting
pivotBy: PropTypes.array,
// Key Constants
pivotValKey: PropTypes.string,
pivotIDKey: PropTypes.string,
subRowsKey: PropTypes.string,
aggregatedKey: PropTypes.string,
nestingLevelKey: PropTypes.string,
originalKey: PropTypes.string,
indexKey: PropTypes.string,
groupedByPivotKey: PropTypes.string,
// Server-side Callbacks
onFetchData: PropTypes.func,
// Classes
className: PropTypes.string,
style: PropTypes.object,
// Component decorators
getProps: PropTypes.func,
getTableProps: PropTypes.func,
getTheadGroupProps: PropTypes.func,
getTheadGroupTrProps: PropTypes.func,
getTheadGroupThProps: PropTypes.func,
getTheadProps: PropTypes.func,
getTheadTrProps: PropTypes.func,
getTheadThProps: PropTypes.func,
getTheadFilterProps: PropTypes.func,
getTheadFilterTrProps: PropTypes.func,
getTheadFilterThProps: PropTypes.func,
getTbodyProps: PropTypes.func,
getTrGroupProps: PropTypes.func,
getTrProps: PropTypes.func,
getTdProps: PropTypes.func,
getTfootProps: PropTypes.func,
getTfootTrProps: PropTypes.func,
getTfootTdProps: PropTypes.func,
getPaginationProps: PropTypes.func,
getLoadingProps: PropTypes.func,
getNoDataProps: PropTypes.func,
getResizerProps: PropTypes.func,
// Global Column Defaults
columns: PropTypes.arrayOf(
PropTypes.shape({
// Renderers
Cell: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
Header: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
Footer: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
Aggregated: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
Pivot: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
PivotValue: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
Expander: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func,
]),
Filter: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
// All Columns
sortable: PropTypes.bool, // use table default
resizable: PropTypes.bool, // use table default
filterable: PropTypes.bool, // use table default
show: PropTypes.bool,
minWidth: PropTypes.number,
// Cells only
className: PropTypes.string,
style: PropTypes.object,
getProps: PropTypes.func,
// Pivot only
aggregate: PropTypes.func,
// Headers only
headerClassName: PropTypes.string,
headerStyle: PropTypes.object,
getHeaderProps: PropTypes.func,
// Footers only
footerClassName: PropTypes.string,
footerStyle: PropTypes.object,
getFooterProps: PropTypes.object,
filterMethod: PropTypes.func,
filterAll: PropTypes.bool,
sortMethod: PropTypes.func,
}),
),
// Global Expander Column Defaults
expanderDefaults: PropTypes.shape({
sortable: PropTypes.bool,
resizable: PropTypes.bool,
filterable: PropTypes.bool,
width: PropTypes.number,
}),
pivotDefaults: PropTypes.object,
// Text
previousText: PropTypes.node,
nextText: PropTypes.node,
loadingText: PropTypes.node,
noDataText: PropTypes.node,
pageText: PropTypes.node,
ofText: PropTypes.node,
rowsText: PropTypes.node,
// Components
TableComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
TheadComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
TbodyComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
TrGroupComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
TrComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
ThComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
TdComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
TfootComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
FilterComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
ExpanderComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PivotValueComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
AggregatedComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
// this is a computed default generated using
PivotComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
// the ExpanderComponent and PivotValueComponent at run-time in methods.js
PaginationComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PreviousComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
NextComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
LoadingComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
NoDataComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
ResizerComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PadRowComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
}
+27 -21
View File
@@ -30,7 +30,9 @@ function get (obj, path, def) {
let val
try {
val = pathObj.reduce((current, pathPart) => current[pathPart], obj)
} catch (e) {}
} catch (e) {
// continue regardless of error
}
return typeof val !== 'undefined' ? val : def
}
@@ -59,7 +61,7 @@ function last (arr) {
function range (n) {
const arr = []
for (let i = 0; i < n; i++) {
for (let i = 0; i < n; i += 1) {
arr.push(n)
}
return arr
@@ -67,7 +69,7 @@ function range (n) {
function orderBy (arr, funcs, dirs, indexKey) {
return arr.sort((rowA, rowB) => {
for (let i = 0; i < funcs.length; i++) {
for (let i = 0; i < funcs.length; i += 1) {
const comp = funcs[i]
const desc = dirs[i] === false || dirs[i] === 'desc'
const sortInt = comp(rowA, rowB)
@@ -83,8 +85,8 @@ function orderBy (arr, funcs, dirs, indexKey) {
}
function remove (a, b) {
return a.filter(function (o, i) {
var r = b(o)
return a.filter((o, i) => {
const r = b(o)
if (r) {
a.splice(i, 1)
return true
@@ -101,7 +103,7 @@ function clone (a) {
return value.toString()
}
return value
})
}),
)
} catch (e) {
return a
@@ -109,7 +111,7 @@ function clone (a) {
}
function getFirstDefined (...args) {
for (var i = 0; i < args.length; i++) {
for (let i = 0; i < args.length; i += 1) {
if (typeof args[i] !== 'undefined') {
return args[i]
}
@@ -117,19 +119,20 @@ function getFirstDefined (...args) {
}
function sum (arr) {
return arr.reduce((a, b) => {
return a + b
}, 0)
return arr.reduce((a, b) => (
a + b
), 0)
}
function makeTemplateComponent (compClass, displayName) {
if (!displayName) {
throw new Error('No displayName found for template component:', compClass)
}
const cmp = ({ children, className, ...rest }) =>
const cmp = ({ children, className, ...rest }) => (
<div className={classnames(compClass, className)} {...rest}>
{children}
</div>
)
cmp.displayName = displayName
return cmp
}
@@ -145,7 +148,7 @@ function groupBy (xs, key) {
function asPx (value) {
value = Number(value)
return Number.isNaN(value) ? null : value + 'px'
return Number.isNaN(value) ? null : `${value}px`
}
function isArray (a) {
@@ -168,7 +171,7 @@ function flattenDeep (arr, newArr = []) {
if (!isArray(arr)) {
newArr.push(arr)
} else {
for (var i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i += 1) {
flattenDeep(arr[i], newArr)
}
}
@@ -185,14 +188,17 @@ function splitProps ({ className, style, ...rest }) {
function compactObject (obj) {
const newObj = {}
for (var key in obj) {
if (
obj.hasOwnProperty(key) &&
obj[key] !== undefined &&
typeof obj[key] !== 'undefined'
) {
newObj[key] = obj[key]
}
if (obj) {
Object.keys(obj).map(key => {
if (
Object.prototype.hasOwnProperty.call(obj, key) &&
obj[key] !== undefined &&
typeof obj[key] !== 'undefined'
) {
newObj[key] = obj[key]
}
return true
})
}
return newObj
}
+527 -105
View File
File diff suppressed because it is too large Load Diff