@gmfe/table-x 2.14.20 → 2.14.26-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE.md +4 -0
  2. package/README.md +13 -13
  3. package/package.json +4 -4
  4. package/src/base/index.js +142 -142
  5. package/src/base/td.js +56 -56
  6. package/src/base/th.js +48 -48
  7. package/src/base/thead.js +26 -26
  8. package/src/base/tr.js +53 -53
  9. package/src/base/virtualized.js +219 -219
  10. package/src/hoc/diy_table_x/components/diy_table_x_modal.js +135 -135
  11. package/src/hoc/diy_table_x/components/modal_list.js +78 -78
  12. package/src/hoc/diy_table_x/components/modal_selector.js +56 -56
  13. package/src/hoc/diy_table_x/index.js +196 -196
  14. package/src/hoc/edit_table_x.js +20 -20
  15. package/src/hoc/expand_table_x/index.js +140 -140
  16. package/src/hoc/expand_table_x/util.js +27 -27
  17. package/src/hoc/fixed_columns_table_x.js +29 -29
  18. package/src/hoc/select_table_x/cell.js +51 -51
  19. package/src/hoc/select_table_x/header.js +28 -28
  20. package/src/hoc/select_table_x/index.js +139 -139
  21. package/src/hoc/select_table_x/util.js +10 -10
  22. package/src/hoc/sortable_table_x.js +52 -52
  23. package/src/hoc/sub_table_x.js +44 -44
  24. package/src/index.js +53 -53
  25. package/src/index.less +515 -515
  26. package/src/stories/table_x.stories.js +324 -324
  27. package/src/stories/table_x_hoc.stories.js +427 -427
  28. package/src/stories/table_x_hoc_select_expand.stories.js +256 -256
  29. package/src/util/batch_action_bar.js +124 -124
  30. package/src/util/edit.js +83 -83
  31. package/src/util/index.js +191 -191
  32. package/src/util/operation.js +249 -249
  33. package/src/util/sort_header.js +49 -49
  34. package/src/variables.less +28 -28
  35. package/svg/business.svg +20 -20
  36. package/svg/check-detail.svg +18 -18
  37. package/svg/closeup.svg +20 -20
  38. package/svg/delete.svg +10 -10
  39. package/svg/edit-pen.svg +17 -17
  40. package/svg/empty.svg +27 -27
  41. package/svg/expand.svg +21 -21
  42. package/svg/pen.svg +12 -12
  43. package/svg/recover.svg +33 -33
  44. package/svg/remove.svg +1 -1
  45. package/svg/setting.svg +17 -17
@@ -1,140 +1,140 @@
1
- import React, { useState } from 'react'
2
- import PropTypes from 'prop-types'
3
- import TableX from '../../base'
4
- import _ from 'lodash'
5
- import { TABLE_X, TABLE_X_EXPAND_ID } from '../../util'
6
- import { Expand, ExpandContext } from './util'
7
-
8
- const ExpandHeader = React.memo(() => {
9
- return (
10
- <ExpandContext.Consumer>
11
- {({ isExpandAll, onExpandAll }) => (
12
- <Expand active={isExpandAll} onChange={onExpandAll} />
13
- )}
14
- </ExpandContext.Consumer>
15
- )
16
- })
17
-
18
- const ExpandCell = React.memo(({ row }) => {
19
- return (
20
- <ExpandContext.Consumer>
21
- {({ expanded, onExpand }) => {
22
- const isExpanded = !!expanded[row.index]
23
-
24
- return (
25
- <Expand
26
- active={isExpanded}
27
- onChange={() => {
28
- onExpand({
29
- ...expanded,
30
- [row.index]: !isExpanded
31
- })
32
- }}
33
- />
34
- )
35
- }}
36
- </ExpandContext.Consumer>
37
- )
38
- })
39
-
40
- ExpandCell.propTypes = {
41
- row: PropTypes.object.isRequired
42
- }
43
-
44
- function getNewColumns(columns, fixedExpand) {
45
- return [
46
- {
47
- id: TABLE_X_EXPAND_ID,
48
- width: TABLE_X.WIDTH_FUN,
49
- maxWidth: TABLE_X.WIDTH_FUN,
50
- fixed: fixedExpand ? 'left' : null,
51
- thClassName: 'gm-table-x-icon',
52
- tdClassName: 'gm-table-x-icon',
53
- Header: () => <ExpandHeader />,
54
- // eslint-disable-next-line
55
- Cell: ({ row }) => <ExpandCell row={row} />
56
- }
57
- ].concat(columns)
58
- }
59
-
60
- function expandTableXHOC(Component) {
61
- const ExpandTableX = ({
62
- columns,
63
- data,
64
- SubComponent,
65
- fixedExpand,
66
- expanded: expandedFromProps,
67
- onExpand,
68
- ...rest
69
- }) => {
70
- // expanded状态是否由调用方控制
71
- const isControlByProps = expandedFromProps !== undefined
72
-
73
- const [expanded, setExpanded] = isControlByProps
74
- ? [expandedFromProps, onExpand]
75
- : useState({})
76
-
77
- const isExpandAll = _.filter(expanded, v => v).length === data.length
78
-
79
- const handleExpand = expanded => {
80
- setExpanded(expanded)
81
- }
82
-
83
- const handleExpandAll = () => {
84
- if (isExpandAll) {
85
- setExpanded({})
86
- } else {
87
- const newExpanded = {}
88
- _.each(data, (v, i) => {
89
- newExpanded[i] = true
90
- })
91
- setExpanded(newExpanded)
92
- }
93
- }
94
-
95
- const renderSubComponent = row => {
96
- const isExpanded = expanded[row.index]
97
- if (!isExpanded) {
98
- return null
99
- }
100
-
101
- return SubComponent(row)
102
- }
103
-
104
- // columns 即可,其他都是死的。
105
- const newColumns = React.useMemo(() => {
106
- return getNewColumns(columns, fixedExpand)
107
- }, [columns])
108
-
109
- return (
110
- <ExpandContext.Provider
111
- value={{
112
- expanded,
113
- onExpand: handleExpand,
114
- isExpandAll,
115
- onExpandAll: handleExpandAll
116
- }}
117
- >
118
- <Component
119
- {...rest}
120
- columns={newColumns}
121
- data={data}
122
- SubComponent={renderSubComponent}
123
- />
124
- </ExpandContext.Provider>
125
- )
126
- }
127
-
128
- ExpandTableX.propTypes = {
129
- ...TableX.propTypes,
130
- fixedExpand: PropTypes.bool,
131
- SubComponent: PropTypes.func.isRequired,
132
- /** 传了expanded,组件expand交由外部props控制,则必须也要传onExpand。 */
133
- expanded: PropTypes.object,
134
- onExpand: PropTypes.func
135
- }
136
-
137
- return ExpandTableX
138
- }
139
-
140
- export default expandTableXHOC
1
+ import React, { useState } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import TableX from '../../base'
4
+ import _ from 'lodash'
5
+ import { TABLE_X, TABLE_X_EXPAND_ID } from '../../util'
6
+ import { Expand, ExpandContext } from './util'
7
+
8
+ const ExpandHeader = React.memo(() => {
9
+ return (
10
+ <ExpandContext.Consumer>
11
+ {({ isExpandAll, onExpandAll }) => (
12
+ <Expand active={isExpandAll} onChange={onExpandAll} />
13
+ )}
14
+ </ExpandContext.Consumer>
15
+ )
16
+ })
17
+
18
+ const ExpandCell = React.memo(({ row }) => {
19
+ return (
20
+ <ExpandContext.Consumer>
21
+ {({ expanded, onExpand }) => {
22
+ const isExpanded = !!expanded[row.index]
23
+
24
+ return (
25
+ <Expand
26
+ active={isExpanded}
27
+ onChange={() => {
28
+ onExpand({
29
+ ...expanded,
30
+ [row.index]: !isExpanded
31
+ })
32
+ }}
33
+ />
34
+ )
35
+ }}
36
+ </ExpandContext.Consumer>
37
+ )
38
+ })
39
+
40
+ ExpandCell.propTypes = {
41
+ row: PropTypes.object.isRequired
42
+ }
43
+
44
+ function getNewColumns(columns, fixedExpand) {
45
+ return [
46
+ {
47
+ id: TABLE_X_EXPAND_ID,
48
+ width: TABLE_X.WIDTH_FUN,
49
+ maxWidth: TABLE_X.WIDTH_FUN,
50
+ fixed: fixedExpand ? 'left' : null,
51
+ thClassName: 'gm-table-x-icon',
52
+ tdClassName: 'gm-table-x-icon',
53
+ Header: () => <ExpandHeader />,
54
+ // eslint-disable-next-line
55
+ Cell: ({ row }) => <ExpandCell row={row} />
56
+ }
57
+ ].concat(columns)
58
+ }
59
+
60
+ function expandTableXHOC(Component) {
61
+ const ExpandTableX = ({
62
+ columns,
63
+ data,
64
+ SubComponent,
65
+ fixedExpand,
66
+ expanded: expandedFromProps,
67
+ onExpand,
68
+ ...rest
69
+ }) => {
70
+ // expanded状态是否由调用方控制
71
+ const isControlByProps = expandedFromProps !== undefined
72
+
73
+ const [expanded, setExpanded] = isControlByProps
74
+ ? [expandedFromProps, onExpand]
75
+ : useState({})
76
+
77
+ const isExpandAll = _.filter(expanded, v => v).length === data.length
78
+
79
+ const handleExpand = expanded => {
80
+ setExpanded(expanded)
81
+ }
82
+
83
+ const handleExpandAll = () => {
84
+ if (isExpandAll) {
85
+ setExpanded({})
86
+ } else {
87
+ const newExpanded = {}
88
+ _.each(data, (v, i) => {
89
+ newExpanded[i] = true
90
+ })
91
+ setExpanded(newExpanded)
92
+ }
93
+ }
94
+
95
+ const renderSubComponent = row => {
96
+ const isExpanded = expanded[row.index]
97
+ if (!isExpanded) {
98
+ return null
99
+ }
100
+
101
+ return SubComponent(row)
102
+ }
103
+
104
+ // columns 即可,其他都是死的。
105
+ const newColumns = React.useMemo(() => {
106
+ return getNewColumns(columns, fixedExpand)
107
+ }, [columns])
108
+
109
+ return (
110
+ <ExpandContext.Provider
111
+ value={{
112
+ expanded,
113
+ onExpand: handleExpand,
114
+ isExpandAll,
115
+ onExpandAll: handleExpandAll
116
+ }}
117
+ >
118
+ <Component
119
+ {...rest}
120
+ columns={newColumns}
121
+ data={data}
122
+ SubComponent={renderSubComponent}
123
+ />
124
+ </ExpandContext.Provider>
125
+ )
126
+ }
127
+
128
+ ExpandTableX.propTypes = {
129
+ ...TableX.propTypes,
130
+ fixedExpand: PropTypes.bool,
131
+ SubComponent: PropTypes.func.isRequired,
132
+ /** 传了expanded,组件expand交由外部props控制,则必须也要传onExpand。 */
133
+ expanded: PropTypes.object,
134
+ onExpand: PropTypes.func
135
+ }
136
+
137
+ return ExpandTableX
138
+ }
139
+
140
+ export default expandTableXHOC
@@ -1,27 +1,27 @@
1
- import React, { createContext } from 'react'
2
- import SVGCloseup from '../../../svg/closeup.svg'
3
- import SVGExpand from '../../../svg/expand.svg'
4
- import PropTypes from 'prop-types'
5
-
6
- const ExpandContext = createContext({
7
- dataLength: 0,
8
- expanded: [],
9
- isExpandAll: false,
10
- onExpand: () => {},
11
- onExpandAll: () => {}
12
- })
13
-
14
- const Expand = ({ active, onChange }) => {
15
- return (
16
- <div className='gm-cursor gm-table-x-expand' onClick={onChange}>
17
- {active ? <SVGCloseup className='gm-text-primary' /> : <SVGExpand />}
18
- </div>
19
- )
20
- }
21
-
22
- Expand.propTypes = {
23
- active: PropTypes.bool.isRequired,
24
- onChange: PropTypes.func.isRequired
25
- }
26
-
27
- export { ExpandContext, Expand }
1
+ import React, { createContext } from 'react'
2
+ import SVGCloseup from '../../../svg/closeup.svg'
3
+ import SVGExpand from '../../../svg/expand.svg'
4
+ import PropTypes from 'prop-types'
5
+
6
+ const ExpandContext = createContext({
7
+ dataLength: 0,
8
+ expanded: [],
9
+ isExpandAll: false,
10
+ onExpand: () => {},
11
+ onExpandAll: () => {}
12
+ })
13
+
14
+ const Expand = ({ active, onChange }) => {
15
+ return (
16
+ <div className='gm-cursor gm-table-x-expand' onClick={onChange}>
17
+ {active ? <SVGCloseup className='gm-text-primary' /> : <SVGExpand />}
18
+ </div>
19
+ )
20
+ }
21
+
22
+ Expand.propTypes = {
23
+ active: PropTypes.bool.isRequired,
24
+ onChange: PropTypes.func.isRequired
25
+ }
26
+
27
+ export { ExpandContext, Expand }
@@ -1,29 +1,29 @@
1
- import React from 'react'
2
- import TableX from '../base'
3
- import _ from 'lodash'
4
-
5
- function fixedColumnsTableXHOC(Component) {
6
- const FixedColumnTableX = ({ columns, ...rest }) => {
7
- return <Component {...rest} columns={columns} />
8
- }
9
-
10
- FixedColumnTableX.propTypes = {
11
- ...TableX.propTypes,
12
- /** 需要固定的 column 有 fixed 字段 */
13
- columns: props => {
14
- const { columns } = props
15
-
16
- _.each(columns, column => {
17
- if (column.fixed) {
18
- if (column.fixed !== 'left' && column.fixed !== 'right') {
19
- console.error('column fixed need to be left or right', column)
20
- }
21
- }
22
- })
23
- }
24
- }
25
-
26
- return FixedColumnTableX
27
- }
28
-
29
- export default fixedColumnsTableXHOC
1
+ import React from 'react'
2
+ import TableX from '../base'
3
+ import _ from 'lodash'
4
+
5
+ function fixedColumnsTableXHOC(Component) {
6
+ const FixedColumnTableX = ({ columns, ...rest }) => {
7
+ return <Component {...rest} columns={columns} />
8
+ }
9
+
10
+ FixedColumnTableX.propTypes = {
11
+ ...TableX.propTypes,
12
+ /** 需要固定的 column 有 fixed 字段 */
13
+ columns: props => {
14
+ const { columns } = props
15
+
16
+ _.each(columns, column => {
17
+ if (column.fixed) {
18
+ if (column.fixed !== 'left' && column.fixed !== 'right') {
19
+ console.error('column fixed need to be left or right', column)
20
+ }
21
+ }
22
+ })
23
+ }
24
+ }
25
+
26
+ return FixedColumnTableX
27
+ }
28
+
29
+ export default fixedColumnsTableXHOC
@@ -1,51 +1,51 @@
1
- import { SelectContext } from './util'
2
- import { Checkbox, Radio } from '@gmfe/react'
3
- import _ from 'lodash'
4
- import PropTypes from 'prop-types'
5
- import React from 'react'
6
-
7
- const SelectCell = ({ selectType, keyField, row, isSelectorDisable }) => {
8
- const value = row.original[keyField]
9
-
10
- return (
11
- <SelectContext.Consumer>
12
- {({ selected, onSelect }) => {
13
- const isChecked = selected.includes(value)
14
- const disabled = isSelectorDisable(row.original)
15
-
16
- if (selectType === 'checkbox') {
17
- return (
18
- <Checkbox
19
- className='gm-table-x-select'
20
- disabled={disabled}
21
- checked={isChecked}
22
- onChange={() => {
23
- onSelect(_.xor(selected, [value]))
24
- }}
25
- />
26
- )
27
- } else {
28
- return (
29
- <Radio
30
- className='gm-table-x-select'
31
- disabled={disabled}
32
- checked={isChecked}
33
- onClick={() => {
34
- onSelect(isChecked ? [] : [value])
35
- }}
36
- />
37
- )
38
- }
39
- }}
40
- </SelectContext.Consumer>
41
- )
42
- }
43
-
44
- SelectCell.propTypes = {
45
- selectType: PropTypes.string.isRequired,
46
- keyField: PropTypes.string.isRequired,
47
- row: PropTypes.object.isRequired,
48
- isSelectorDisable: PropTypes.func.isRequired
49
- }
50
-
51
- export default SelectCell
1
+ import { SelectContext } from './util'
2
+ import { Checkbox, Radio } from '@gmfe/react'
3
+ import _ from 'lodash'
4
+ import PropTypes from 'prop-types'
5
+ import React from 'react'
6
+
7
+ const SelectCell = ({ selectType, keyField, row, isSelectorDisable }) => {
8
+ const value = row.original[keyField]
9
+
10
+ return (
11
+ <SelectContext.Consumer>
12
+ {({ selected, onSelect }) => {
13
+ const isChecked = selected.includes(value)
14
+ const disabled = isSelectorDisable(row.original)
15
+
16
+ if (selectType === 'checkbox') {
17
+ return (
18
+ <Checkbox
19
+ className='gm-table-x-select'
20
+ disabled={disabled}
21
+ checked={isChecked}
22
+ onChange={() => {
23
+ onSelect(_.xor(selected, [value]))
24
+ }}
25
+ />
26
+ )
27
+ } else {
28
+ return (
29
+ <Radio
30
+ className='gm-table-x-select'
31
+ disabled={disabled}
32
+ checked={isChecked}
33
+ onClick={() => {
34
+ onSelect(isChecked ? [] : [value])
35
+ }}
36
+ />
37
+ )
38
+ }
39
+ }}
40
+ </SelectContext.Consumer>
41
+ )
42
+ }
43
+
44
+ SelectCell.propTypes = {
45
+ selectType: PropTypes.string.isRequired,
46
+ keyField: PropTypes.string.isRequired,
47
+ row: PropTypes.object.isRequired,
48
+ isSelectorDisable: PropTypes.func.isRequired
49
+ }
50
+
51
+ export default SelectCell
@@ -1,28 +1,28 @@
1
- import React from 'react'
2
- import { SelectContext } from './util'
3
- import { Checkbox } from '@gmfe/react'
4
- import PropTypes from 'prop-types'
5
-
6
- const SelectHeader = React.memo(({ selectType }) => {
7
- if (selectType !== 'checkbox') {
8
- return null
9
- }
10
-
11
- return (
12
- <SelectContext.Consumer>
13
- {({ isSelectAll, onSelectAll }) => (
14
- <Checkbox
15
- className='gm-table-x-select'
16
- checked={isSelectAll}
17
- onChange={onSelectAll}
18
- />
19
- )}
20
- </SelectContext.Consumer>
21
- )
22
- })
23
-
24
- SelectHeader.propTypes = {
25
- selectType: PropTypes.string.isRequired
26
- }
27
-
28
- export default SelectHeader
1
+ import React from 'react'
2
+ import { SelectContext } from './util'
3
+ import { Checkbox } from '@gmfe/react'
4
+ import PropTypes from 'prop-types'
5
+
6
+ const SelectHeader = React.memo(({ selectType }) => {
7
+ if (selectType !== 'checkbox') {
8
+ return null
9
+ }
10
+
11
+ return (
12
+ <SelectContext.Consumer>
13
+ {({ isSelectAll, onSelectAll }) => (
14
+ <Checkbox
15
+ className='gm-table-x-select'
16
+ checked={isSelectAll}
17
+ onChange={onSelectAll}
18
+ />
19
+ )}
20
+ </SelectContext.Consumer>
21
+ )
22
+ })
23
+
24
+ SelectHeader.propTypes = {
25
+ selectType: PropTypes.string.isRequired
26
+ }
27
+
28
+ export default SelectHeader