@king-design/react 3.0.0-beta.0 → 3.0.0-beta.1

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 (202) hide show
  1. package/__tests__/__snapshots__/Dialog.md +1 -1
  2. package/__tests__/__snapshots__/React Demos.md +461 -309
  3. package/__tests__/components/cascader.spec.tsx +53 -0
  4. package/__tests__/components/drawer.spec.tsx +67 -5
  5. package/components/button/index.d.ts +1 -1
  6. package/components/button/index.js +1 -1
  7. package/components/button/styles.js +1 -1
  8. package/components/cascader/index.d.ts +22 -11
  9. package/components/cascader/index.js +9 -12
  10. package/components/cascader/index.spec.js +81 -0
  11. package/components/cascader/index.vdt.js +10 -8
  12. package/components/cascader/styles.js +1 -1
  13. package/components/cascader/useFields.d.ts +2 -0
  14. package/components/cascader/useFields.js +18 -0
  15. package/components/cascader/useFilterable.d.ts +2 -1
  16. package/components/cascader/useFilterable.js +17 -6
  17. package/components/cascader/useLabel.d.ts +2 -1
  18. package/components/cascader/useLabel.js +4 -4
  19. package/components/cascader/useLoad.d.ts +2 -1
  20. package/components/cascader/useLoad.js +9 -7
  21. package/components/colorpicker/index.d.ts +2 -0
  22. package/components/colorpicker/index.js +7 -2
  23. package/components/colorpicker/index.vdt.js +3 -6
  24. package/components/copy/index.d.ts +17 -0
  25. package/components/copy/index.js +43 -0
  26. package/components/copy/index.spec.d.ts +1 -0
  27. package/components/copy/index.spec.js +52 -0
  28. package/components/copy/index.vdt.js +45 -0
  29. package/components/copy/styles.d.ts +2 -0
  30. package/components/copy/styles.js +14 -0
  31. package/components/copy/useCopy.d.ts +4 -0
  32. package/components/copy/useCopy.js +90 -0
  33. package/components/datepicker/index.spec.js +1 -1
  34. package/components/datepicker/index.vdt.js +1 -1
  35. package/components/datepicker/styles.js +1 -1
  36. package/components/diagram/shapes/callout.d.ts +1 -1
  37. package/components/diagram/shapes/circle.d.ts +1 -1
  38. package/components/diagram/shapes/document.d.ts +1 -1
  39. package/components/diagram/shapes/ellipse.d.ts +1 -1
  40. package/components/diagram/shapes/hexagon.d.ts +1 -1
  41. package/components/diagram/shapes/image.d.ts +1 -1
  42. package/components/diagram/shapes/parallelogram.d.ts +1 -1
  43. package/components/diagram/shapes/rectangle.d.ts +1 -1
  44. package/components/diagram/shapes/square.d.ts +1 -1
  45. package/components/diagram/shapes/text.d.ts +1 -1
  46. package/components/dialog/alert.vdt.js +6 -5
  47. package/components/dialog/index.spec.js +6 -6
  48. package/components/dropdown/dropdown.d.ts +6 -6
  49. package/components/dropdown/dropdown.js +58 -75
  50. package/components/dropdown/index.spec.js +96 -17
  51. package/components/dropdown/item.d.ts +1 -1
  52. package/components/dropdown/item.js +19 -7
  53. package/components/dropdown/menu.js +1 -1
  54. package/components/dropdown/usePosition.js +11 -2
  55. package/components/editable/index.d.ts +1 -0
  56. package/components/editable/index.js +20 -6
  57. package/components/editable/index.vdt.js +2 -1
  58. package/components/form/index.spec.js +4 -2
  59. package/components/form/item.vdt.js +2 -1
  60. package/components/form/styles.js +4 -4
  61. package/components/grid/useGutter.js +8 -8
  62. package/components/input/index.d.ts +11 -2
  63. package/components/input/index.js +13 -13
  64. package/components/input/index.spec.js +169 -1
  65. package/components/input/index.vdt.js +28 -7
  66. package/components/input/styles.js +20 -3
  67. package/components/input/useAutoRows.d.ts +2 -0
  68. package/components/input/useAutoRows.js +79 -0
  69. package/components/input/useAutoWidth.js +13 -3
  70. package/components/input/useShowPassword.d.ts +7 -0
  71. package/components/input/useShowPassword.js +31 -0
  72. package/components/menu/index.spec.js +26 -15
  73. package/components/menu/item.d.ts +2 -0
  74. package/components/menu/item.js +5 -0
  75. package/components/pagination/index.d.ts +1 -1
  76. package/components/pagination/index.js +3 -2
  77. package/components/pagination/index.spec.js +49 -0
  78. package/components/pagination/index.vdt.js +8 -10
  79. package/components/pagination/styles.js +1 -1
  80. package/components/popover/content.d.ts +19 -0
  81. package/components/popover/content.js +31 -0
  82. package/components/popover/content.vdt.js +68 -0
  83. package/components/popover/index.d.ts +16 -0
  84. package/components/popover/index.js +44 -0
  85. package/components/popover/index.spec.d.ts +1 -0
  86. package/components/popover/index.spec.js +195 -0
  87. package/components/popover/styles.d.ts +1 -0
  88. package/components/popover/styles.js +22 -0
  89. package/components/portal.d.ts +6 -2
  90. package/components/portal.js +4 -3
  91. package/components/position.js +2 -1
  92. package/components/progress/index.js +1 -1
  93. package/components/progress/index.vdt.js +46 -8
  94. package/components/progress/styles.js +19 -13
  95. package/components/rate/styles.js +1 -1
  96. package/components/select/base.d.ts +7 -3
  97. package/components/select/base.js +9 -3
  98. package/components/select/base.vdt.js +46 -35
  99. package/components/select/index.spec.js +2 -2
  100. package/components/select/menu.vdt.js +1 -1
  101. package/components/select/styles.js +11 -5
  102. package/components/select/useDraggble.d.ts +2 -0
  103. package/components/select/useDraggble.js +11 -0
  104. package/components/select/useNowrap.d.ts +3 -0
  105. package/components/select/useNowrap.js +19 -0
  106. package/components/slider/index.spec.js +48 -9
  107. package/components/slider/index.vdt.js +23 -12
  108. package/components/slider/styles.js +23 -14
  109. package/components/slider/useValue.d.ts +3 -1
  110. package/components/slider/useValue.js +12 -0
  111. package/components/spinner/index.d.ts +0 -1
  112. package/components/spinner/index.js +1 -19
  113. package/components/spinner/index.vdt.js +9 -4
  114. package/components/spinner/useChange.d.ts +1 -1
  115. package/components/spinner/useChange.js +2 -2
  116. package/components/spinner/useValue.d.ts +1 -0
  117. package/components/spinner/useValue.js +16 -1
  118. package/components/split/index.vdt.js +32 -20
  119. package/components/split/memo.d.ts +9 -0
  120. package/components/split/memo.js +26 -0
  121. package/components/steps/index.d.ts +1 -0
  122. package/components/steps/index.js +2 -1
  123. package/components/steps/index.spec.js +1 -1
  124. package/components/steps/index.vdt.js +7 -4
  125. package/components/steps/step.vdt.js +0 -1
  126. package/components/steps/styles.d.ts +1 -0
  127. package/components/steps/styles.js +45 -16
  128. package/components/switch/index.spec.js +82 -65
  129. package/components/table/cell.js +1 -6
  130. package/components/table/index.spec.js +130 -19
  131. package/components/table/row.d.ts +1 -1
  132. package/components/table/row.js +2 -1
  133. package/components/table/styles.js +1 -1
  134. package/components/table/table.d.ts +15 -0
  135. package/components/table/table.js +16 -7
  136. package/components/table/table.vdt.js +20 -6
  137. package/components/table/useChecked.d.ts +3 -2
  138. package/components/table/useChecked.js +23 -12
  139. package/components/table/useDisableRow.d.ts +2 -1
  140. package/components/table/useDisableRow.js +4 -4
  141. package/components/table/useDraggable.d.ts +3 -2
  142. package/components/table/useDraggable.js +11 -15
  143. package/components/table/useGroup.js +3 -0
  144. package/components/table/useMerge.d.ts +2 -1
  145. package/components/table/useMerge.js +5 -4
  146. package/components/table/usePagination.d.ts +8 -0
  147. package/components/table/usePagination.js +81 -0
  148. package/components/table/useStickyScrollbar.js +2 -2
  149. package/components/table/useTree.d.ts +2 -1
  150. package/components/table/useTree.js +3 -4
  151. package/components/table/useWidth.js +2 -2
  152. package/components/tabs/index.d.ts +1 -1
  153. package/components/tabs/index.js +1 -1
  154. package/components/tabs/index.spec.js +67 -0
  155. package/components/tabs/index.vdt.js +4 -4
  156. package/components/tabs/styles.js +32 -34
  157. package/components/tabs/useScroll.d.ts +1 -1
  158. package/components/tabs/useScroll.js +75 -48
  159. package/components/tag/base.d.ts +1 -0
  160. package/components/tag/base.js +1 -1
  161. package/components/tag/index.d.ts +1 -0
  162. package/components/tag/index.js +2 -1
  163. package/components/tag/index.spec.js +147 -4
  164. package/components/tag/styles.d.ts +67 -0
  165. package/components/tag/styles.js +33 -8
  166. package/components/tag/tags.d.ts +27 -0
  167. package/components/tag/tags.js +51 -0
  168. package/components/tag/tags.vdt.js +79 -0
  169. package/components/tag/useChildren.d.ts +2 -0
  170. package/components/tag/useChildren.js +39 -0
  171. package/components/tag/useDraggable.d.ts +3 -0
  172. package/components/tag/useDraggable.js +89 -0
  173. package/components/tag/useNowrap.d.ts +7 -0
  174. package/components/tag/useNowrap.js +115 -0
  175. package/components/timepicker/index.spec.js +1 -1
  176. package/components/tooltip/content.d.ts +3 -2
  177. package/components/tooltip/content.js +18 -1
  178. package/components/tooltip/content.vdt.js +22 -10
  179. package/components/tooltip/index.spec.js +147 -92
  180. package/components/tooltip/styles.d.ts +23 -0
  181. package/components/tooltip/styles.js +2 -2
  182. package/components/tooltip/tooltip.d.ts +1 -1
  183. package/components/tooltip/tooltip.js +11 -11
  184. package/components/upload/index.spec.js +5 -6
  185. package/components/upload/index.vdt.js +3 -1
  186. package/components/utils.d.ts +2 -0
  187. package/components/utils.js +24 -3
  188. package/components/virtual.d.ts +8 -0
  189. package/components/virtual.js +126 -0
  190. package/hooks/useResizeObserver.d.ts +1 -1
  191. package/hooks/useResizeObserver.js +19 -6
  192. package/i18n/en-US.d.ts +4 -1
  193. package/i18n/en-US.js +6 -2
  194. package/index.d.ts +5 -3
  195. package/index.js +5 -3
  196. package/package.json +2 -2
  197. package/styles/fonts/iconfont.js +1 -1
  198. package/styles/fonts/ionicons.js +3 -3
  199. package/styles/global.js +1 -1
  200. package/yarn-error.log +41 -43
  201. package/components/table/useResizeObserver.d.ts +0 -2
  202. package/components/table/useResizeObserver.js +0 -20
@@ -1,6 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
3
3
  import BasicDemo from '~/components/switch/demos/basic';
4
+ import DisabledDemo from '~/components/switch/demos/disabled';
4
5
  import ValueDemo from '~/components/switch/demos/value';
5
6
  import WidthHeightDemo from '~/components/switch/demos/widthHeight';
6
7
  import { mount, unmount, dispatchEvent, wait } from '../../test/utils';
@@ -9,14 +10,14 @@ describe('Switch', function () {
9
10
  unmount();
10
11
  });
11
12
  it('change value by clicking', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
12
- var _mount, instance, element, _element$querySelecto, el, disabledEl, handle;
13
+ var _mount, instance, element, _element$querySelecto, el, handle;
13
14
 
14
15
  return _regeneratorRuntime.wrap(function _callee$(_context) {
15
16
  while (1) {
16
17
  switch (_context.prev = _context.next) {
17
18
  case 0:
18
19
  _mount = mount(BasicDemo), instance = _mount[0], element = _mount[1];
19
- _element$querySelecto = element.querySelectorAll('.k-switch'), el = _element$querySelecto[0], disabledEl = _element$querySelecto[1];
20
+ _element$querySelecto = element.querySelectorAll('.k-switch'), el = _element$querySelecto[0];
20
21
  el.click();
21
22
  _context.next = 5;
22
23
  return wait();
@@ -38,29 +39,61 @@ describe('Switch', function () {
38
39
 
39
40
  case 16:
40
41
  expect(instance.get('value')).to.be.false;
41
- disabledEl.click();
42
- _context.next = 20;
43
- return wait();
44
-
45
- case 20:
46
- expect(element.outerHTML).to.matchSnapshot();
47
42
 
48
- case 21:
43
+ case 17:
49
44
  case "end":
50
45
  return _context.stop();
51
46
  }
52
47
  }
53
48
  }, _callee);
54
49
  })));
55
- it('change value by draging', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
56
- var _mount2, instance, element, _element$querySelecto2, el, disabledEl;
50
+ it('disabled', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
51
+ var _mount2, instance, element, el;
57
52
 
58
53
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
59
54
  while (1) {
60
55
  switch (_context2.prev = _context2.next) {
61
56
  case 0:
62
- _mount2 = mount(BasicDemo), instance = _mount2[0], element = _mount2[1];
63
- _element$querySelecto2 = element.querySelectorAll('.k-switch-handle'), el = _element$querySelecto2[0], disabledEl = _element$querySelecto2[1];
57
+ _mount2 = mount(DisabledDemo), instance = _mount2[0], element = _mount2[1];
58
+ el = element.querySelector('.k-switch');
59
+ el.click();
60
+ _context2.next = 5;
61
+ return wait();
62
+
63
+ case 5:
64
+ expect(element.outerHTML).to.matchSnapshot();
65
+ dispatchEvent(el, 'mousedown', {
66
+ which: 1,
67
+ clientX: 0
68
+ });
69
+ dispatchEvent(document, 'mousemove', {
70
+ clientX: 30
71
+ });
72
+ dispatchEvent(document, 'mouseup', {
73
+ clientX: 30
74
+ });
75
+ _context2.next = 11;
76
+ return wait();
77
+
78
+ case 11:
79
+ expect(element.outerHTML).to.matchSnapshot();
80
+
81
+ case 12:
82
+ case "end":
83
+ return _context2.stop();
84
+ }
85
+ }
86
+ }, _callee2);
87
+ })));
88
+ it('change value by draging', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
89
+ var _mount3, instance, element, _element$querySelecto2, el;
90
+
91
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
92
+ while (1) {
93
+ switch (_context3.prev = _context3.next) {
94
+ case 0:
95
+ _mount3 = mount(BasicDemo), instance = _mount3[0], element = _mount3[1];
96
+ _element$querySelecto2 = element.querySelectorAll('.k-switch-handle'), el = _element$querySelecto2[0];
64
97
  dispatchEvent(el, 'mousedown', {
65
98
  which: 1,
66
99
  clientX: 0
@@ -68,7 +101,7 @@ describe('Switch', function () {
68
101
  dispatchEvent(document, 'mousemove', {
69
102
  clientX: 1
70
103
  });
71
- _context2.next = 6;
104
+ _context3.next = 6;
72
105
  return wait();
73
106
 
74
107
  case 6:
@@ -77,7 +110,7 @@ describe('Switch', function () {
77
110
  dispatchEvent(document, 'mouseup', {
78
111
  clientX: 1
79
112
  });
80
- _context2.next = 10;
113
+ _context3.next = 10;
81
114
  return wait();
82
115
 
83
116
  case 10:
@@ -93,7 +126,7 @@ describe('Switch', function () {
93
126
  dispatchEvent(document, 'mouseup', {
94
127
  clientX: 30
95
128
  });
96
- _context2.next = 17;
129
+ _context3.next = 17;
97
130
  return wait();
98
131
 
99
132
  case 17:
@@ -109,7 +142,7 @@ describe('Switch', function () {
109
142
  dispatchEvent(document, 'mouseup', {
110
143
  clientX: -30
111
144
  });
112
- _context2.next = 24;
145
+ _context3.next = 24;
113
146
  return wait();
114
147
 
115
148
  case 24:
@@ -122,43 +155,27 @@ describe('Switch', function () {
122
155
  dispatchEvent(document, 'mouseup', {
123
156
  clientX: 0
124
157
  });
125
- _context2.next = 29;
158
+ _context3.next = 29;
126
159
  return wait();
127
160
 
128
161
  case 29:
129
- expect(instance.get('value')).to.be.true; // disabled
130
-
131
- dispatchEvent(disabledEl, 'mousedown', {
132
- which: 1,
133
- clientX: 0
134
- });
135
- dispatchEvent(document, 'mousemove', {
136
- clientX: 30
137
- });
138
- dispatchEvent(document, 'mouseup', {
139
- clientX: 30
140
- });
141
- _context2.next = 35;
142
- return wait();
143
-
144
- case 35:
145
- expect(element.outerHTML).to.matchSnapshot();
162
+ expect(instance.get('value')).to.be.true;
146
163
 
147
- case 36:
164
+ case 30:
148
165
  case "end":
149
- return _context2.stop();
166
+ return _context3.stop();
150
167
  }
151
168
  }
152
- }, _callee2);
169
+ }, _callee3);
153
170
  })));
154
- it('drag switch which has custom width and height', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
155
- var _mount3, instance, element, _element$querySelecto3, el;
171
+ it('drag switch which has custom width and height', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
172
+ var _mount4, instance, element, _element$querySelecto3, el;
156
173
 
157
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
174
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
158
175
  while (1) {
159
- switch (_context3.prev = _context3.next) {
176
+ switch (_context4.prev = _context4.next) {
160
177
  case 0:
161
- _mount3 = mount(WidthHeightDemo), instance = _mount3[0], element = _mount3[1];
178
+ _mount4 = mount(WidthHeightDemo), instance = _mount4[0], element = _mount4[1];
162
179
  _element$querySelecto3 = element.querySelectorAll('.k-switch-handle'), el = _element$querySelecto3[2];
163
180
  dispatchEvent(el, 'mousedown', {
164
181
  which: 1,
@@ -170,7 +187,7 @@ describe('Switch', function () {
170
187
  dispatchEvent(document, 'mouseup', {
171
188
  clientX: 50
172
189
  });
173
- _context3.next = 7;
190
+ _context4.next = 7;
174
191
  return wait();
175
192
 
176
193
  case 7:
@@ -185,7 +202,7 @@ describe('Switch', function () {
185
202
  dispatchEvent(document, 'mouseup', {
186
203
  clientX: -50
187
204
  });
188
- _context3.next = 13;
205
+ _context4.next = 13;
189
206
  return wait();
190
207
 
191
208
  case 13:
@@ -193,24 +210,24 @@ describe('Switch', function () {
193
210
 
194
211
  case 14:
195
212
  case "end":
196
- return _context3.stop();
213
+ return _context4.stop();
197
214
  }
198
215
  }
199
- }, _callee3);
216
+ }, _callee4);
200
217
  })));
201
- it('change value by keypress', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
202
- var _mount4, instance, element, el;
218
+ it('change value by keypress', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
219
+ var _mount5, instance, element, el;
203
220
 
204
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
221
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
205
222
  while (1) {
206
- switch (_context4.prev = _context4.next) {
223
+ switch (_context5.prev = _context5.next) {
207
224
  case 0:
208
- _mount4 = mount(BasicDemo), instance = _mount4[0], element = _mount4[1];
225
+ _mount5 = mount(BasicDemo), instance = _mount5[0], element = _mount5[1];
209
226
  el = element.querySelector('.k-switch');
210
227
  dispatchEvent(el, 'keypress', {
211
228
  keyCode: 13
212
229
  });
213
- _context4.next = 5;
230
+ _context5.next = 5;
214
231
  return wait();
215
232
 
216
233
  case 5:
@@ -218,7 +235,7 @@ describe('Switch', function () {
218
235
  dispatchEvent(el, 'keypress', {
219
236
  keyCode: 13
220
237
  });
221
- _context4.next = 9;
238
+ _context5.next = 9;
222
239
  return wait();
223
240
 
224
241
  case 9:
@@ -226,30 +243,30 @@ describe('Switch', function () {
226
243
 
227
244
  case 10:
228
245
  case "end":
229
- return _context4.stop();
246
+ return _context5.stop();
230
247
  }
231
248
  }
232
- }, _callee4);
249
+ }, _callee5);
233
250
  })));
234
- it('custom the value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
235
- var _mount5, instance, element, _element$querySelecto4, el1, el2;
251
+ it('custom the value', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
252
+ var _mount6, instance, element, _element$querySelecto4, el1, el2;
236
253
 
237
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
254
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
238
255
  while (1) {
239
- switch (_context5.prev = _context5.next) {
256
+ switch (_context6.prev = _context6.next) {
240
257
  case 0:
241
- _mount5 = mount(ValueDemo), instance = _mount5[0], element = _mount5[1];
258
+ _mount6 = mount(ValueDemo), instance = _mount6[0], element = _mount6[1];
242
259
  _element$querySelecto4 = element.querySelectorAll('.k-switch'), el1 = _element$querySelecto4[0], el2 = _element$querySelecto4[1];
243
260
  el1.click();
244
261
  el2.click();
245
- _context5.next = 6;
262
+ _context6.next = 6;
246
263
  return wait();
247
264
 
248
265
  case 6:
249
266
  expect(element.outerHTML).to.matchSnapshot();
250
267
  el1.click();
251
268
  el2.click();
252
- _context5.next = 11;
269
+ _context6.next = 11;
253
270
  return wait();
254
271
 
255
272
  case 11:
@@ -257,9 +274,9 @@ describe('Switch', function () {
257
274
 
258
275
  case 12:
259
276
  case "end":
260
- return _context5.stop();
277
+ return _context6.stop();
261
278
  }
262
279
  }
263
- }, _callee5);
280
+ }, _callee6);
264
281
  })));
265
282
  });
@@ -16,12 +16,7 @@ export var TableCell = /*#__PURE__*/function (_Component) {
16
16
  var isSame = true;
17
17
 
18
18
  for (var key in lastProps) {
19
- if (lastProps[key] !== nextProps[key]) {
20
- isSame = false;
21
- break;
22
- }
23
-
24
- if (key === 'props' && nextProps.props.$blocks) {
19
+ if (lastProps[key] !== nextProps[key] || key === 'props' && nextProps.props.$blocks) {
25
20
  isSame = false;
26
21
  break;
27
22
  }
@@ -23,13 +23,14 @@ import { Table, TableColumn } from './';
23
23
  import DraggableTable from '~/components/table/demos/draggable';
24
24
  import MergeCellDemo from '~/components/table/demos/mergeCell';
25
25
  import { AllCheckedStatus } from './useChecked';
26
+ import PaginationDemo from '~/components/table/demos/pagination';
26
27
  describe('Table', function () {
27
28
  afterEach(function () {
28
29
  unmount();
29
30
  localStorage.removeItem('resizableTable');
30
31
  });
31
32
  it('check & uncheck', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
32
- var _mount, instance, element, table, checked, spy, _element$querySelecto, tr1, tr2, all;
33
+ var _mount, instance, element, table, checked, spy, spyCheckRow, spyUncheckRow, spyCheckAll, spyUncheckAll, _element$querySelecto, tr1, tr2, all;
33
34
 
34
35
  return _regeneratorRuntime.wrap(function _callee$(_context) {
35
36
  while (1) {
@@ -42,54 +43,76 @@ describe('Table', function () {
42
43
  spy = sinon.spy(function (v) {
43
44
  return console.log(v);
44
45
  });
45
- table.on('$change:checkedKeys', spy); // click row
46
+ table.on('$change:checkedKeys', spy);
47
+ spyCheckRow = sinon.spy(function (data, index, key) {
48
+ return console.log('checkRow', data, index, key);
49
+ });
50
+ table.on('checkRow', spyCheckRow);
51
+ spyUncheckRow = sinon.spy(function (data, index, key) {
52
+ return console.log('uncheckRow', data, index, key);
53
+ });
54
+ table.on('uncheckRow', spyUncheckRow);
55
+ spyCheckAll = sinon.spy(function () {
56
+ return console.log('checkAll');
57
+ });
58
+ table.on('checkAll', spyCheckAll);
59
+ spyUncheckAll = sinon.spy(function () {
60
+ return console.log('uncheckAll');
61
+ });
62
+ table.on('uncheckAll', spyUncheckAll); // click row
46
63
 
47
64
  _element$querySelecto = element.querySelectorAll('tbody tr'), tr1 = _element$querySelecto[0], tr2 = _element$querySelecto[1];
48
65
  tr1.click();
49
- _context.next = 9;
66
+ _context.next = 17;
50
67
  return wait();
51
68
 
52
- case 9:
69
+ case 17:
53
70
  expect(table.get('checkedKeys')).to.eql([0]);
71
+ expect(spyCheckRow.callCount).to.eql(1);
54
72
  tr2.click();
55
- _context.next = 13;
73
+ _context.next = 22;
56
74
  return wait();
57
75
 
58
- case 13:
76
+ case 22:
59
77
  expect(table.get('checkedKeys')).to.eql([0, 1]);
60
78
  expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.All);
79
+ expect(spyCheckRow.callCount).to.eql(2);
80
+ expect(spyCheckAll.callCount).to.eq(0);
61
81
  tr1.click();
62
- _context.next = 18;
82
+ _context.next = 29;
63
83
  return wait();
64
84
 
65
- case 18:
85
+ case 29:
66
86
  expect(table.get('checkedKeys')).to.eql([1]);
67
87
  expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.Indeterminate);
88
+ expect(spyUncheckRow.callCount).to.eql(1);
68
89
  all = element.querySelector('.k-checkbox');
69
90
  all.click();
70
- _context.next = 24;
91
+ _context.next = 36;
71
92
  return wait();
72
93
 
73
- case 24:
94
+ case 36:
74
95
  expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.All);
96
+ expect(spyCheckAll.callCount).to.eql(1);
75
97
  all.click();
76
- _context.next = 28;
98
+ _context.next = 41;
77
99
  return wait();
78
100
 
79
- case 28:
101
+ case 41:
80
102
  expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.None);
81
103
  expect(table.get('checkedKeys')).to.eql([]);
104
+ expect(spyUncheckAll.callCount).to.eql(1);
82
105
  expect(spy.callCount).to.eql(5); // clear data of table should only trigger $change:checked event once, #407
83
106
 
84
107
  all.click();
85
- table.set('data', []);
86
- _context.next = 35;
108
+ instance.set('data', []);
109
+ _context.next = 49;
87
110
  return wait();
88
111
 
89
- case 35:
112
+ case 49:
90
113
  expect(spy.callCount).to.eql(7);
91
114
 
92
- case 36:
115
+ case 50:
93
116
  case "end":
94
117
  return _context.stop();
95
118
  }
@@ -342,7 +365,7 @@ describe('Table', function () {
342
365
  }, _callee6);
343
366
  })));
344
367
  it('group', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
345
- var _mount7, instance, element, _instance$refs4, __test1, __test2, _element$querySelecto8, table1, table2, icon, dropdown, item, icon2, dropdown2, _dropdown2$querySelec, item1, item2;
368
+ var _mount7, instance, element, _instance$refs4, __test1, __test2, _element$querySelecto8, table1, table2, icon, dropdown, item, icon2, dropdown2, _dropdown2$querySelec, item1, item2, newDropdown;
346
369
 
347
370
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
348
371
  while (1) {
@@ -395,9 +418,21 @@ describe('Table', function () {
395
418
  expect(instance.get('multipleGroup')).to.eql({
396
419
  status: ['active', 'stopped']
397
420
  });
398
- expect(table2.innerHTML).to.matchSnapshot();
421
+ expect(table2.innerHTML).to.matchSnapshot(); // update group
399
422
 
400
- case 32:
423
+ instance.set('statusGroup', [{
424
+ label: 'label',
425
+ value: 'value'
426
+ }]);
427
+ dispatchEvent(icon, 'click');
428
+ _context7.next = 36;
429
+ return wait(500);
430
+
431
+ case 36:
432
+ newDropdown = getElement('.k-table-group-dropdown');
433
+ expect(newDropdown.innerHTML).to.matchSnapshot();
434
+
435
+ case 38:
401
436
  case "end":
402
437
  return _context7.stop();
403
438
  }
@@ -1064,4 +1099,80 @@ describe('Table', function () {
1064
1099
  }
1065
1100
  }, _callee22);
1066
1101
  })));
1102
+ it('pagination', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
1103
+ var _mount25, instance, element, table, pagination, spy;
1104
+
1105
+ return _regeneratorRuntime.wrap(function _callee23$(_context26) {
1106
+ while (1) {
1107
+ switch (_context26.prev = _context26.next) {
1108
+ case 0:
1109
+ _mount25 = mount(PaginationDemo), instance = _mount25[0], element = _mount25[1];
1110
+ table = instance.refs.table;
1111
+ pagination = table.pagination.paginationRef;
1112
+ spy = sinon.spy();
1113
+ table.on('changePage', spy); // check all
1114
+
1115
+ table.checkAll();
1116
+ expect(table.getCheckedData()).to.have.length(10); // next page
1117
+
1118
+ table.set('pagination', {
1119
+ value: 2
1120
+ });
1121
+ table.trigger('$receive:pagination');
1122
+ _context26.next = 11;
1123
+ return wait();
1124
+
1125
+ case 11:
1126
+ expect(table.getCheckedData()).to.have.length(0); // check all again
1127
+
1128
+ table.checkAll();
1129
+ expect(table.getCheckedData()).to.have.length(10); // change limit
1130
+
1131
+ table.set('pagination', {
1132
+ value: 1,
1133
+ limit: 20
1134
+ });
1135
+ table.trigger('$receive:pagination');
1136
+ _context26.next = 18;
1137
+ return wait();
1138
+
1139
+ case 18:
1140
+ expect(table.getCheckedData()).to.have.length(10); // check all again
1141
+
1142
+ table.checkAll();
1143
+ expect(table.getCheckedData()).to.have.length(20); // change limit from pagination
1144
+
1145
+ pagination.value.set('limit', 10);
1146
+ _context26.next = 24;
1147
+ return wait();
1148
+
1149
+ case 24:
1150
+ expect(table.getCheckedData()).to.have.length(10); // FIXME: Pagination component should no trigger change event multiple times
1151
+ // when we set value and limit at the same time
1152
+
1153
+ expect(spy.callCount).to.eql(4);
1154
+ expect(spy.lastCall.lastArg).to.eql({
1155
+ value: 1,
1156
+ limit: 10
1157
+ }); // change page from pagination
1158
+
1159
+ _context26.next = 29;
1160
+ return wait();
1161
+
1162
+ case 29:
1163
+ pagination.value.changePage(2);
1164
+ expect(table.getCheckedData()).to.have.length(0);
1165
+ expect(spy.callCount).to.eql(5);
1166
+ expect(spy.lastCall.lastArg).to.eql({
1167
+ value: 2,
1168
+ limit: 10
1169
+ });
1170
+
1171
+ case 33:
1172
+ case "end":
1173
+ return _context26.stop();
1174
+ }
1175
+ }
1176
+ }, _callee23);
1177
+ })));
1067
1178
  });
@@ -14,7 +14,7 @@ export interface TableRowProps {
14
14
  index: number;
15
15
  disabled: boolean;
16
16
  allDisabled: boolean;
17
- onChangeChecked: (index: number, checked: boolean) => void;
17
+ onChangeChecked: (index: number, checked: boolean, key: TableRowKey) => void;
18
18
  grid: TableGrid;
19
19
  selected: boolean;
20
20
  spreaded: boolean;
@@ -56,9 +56,10 @@ export var TableRow = /*#__PURE__*/function (_Component) {
56
56
  _proto.onChangeChecked = function onChangeChecked(v) {
57
57
  var _this$get2 = this.get(),
58
58
  index = _this$get2.index,
59
+ key = _this$get2.key,
59
60
  onChangeChecked = _this$get2.onChangeChecked;
60
61
 
61
- onChangeChecked(index, v);
62
+ onChangeChecked(index, v, key);
62
63
  };
63
64
 
64
65
  _proto.onClickArrow = function onClickArrow(e) {
@@ -97,7 +97,7 @@ setDefault(function () {
97
97
  export function makeStyles() {
98
98
  return /*#__PURE__*/css("font-size:", table.fontSize, ";color:", table.color, ";position:relative;z-index:0;.k-table-wrapper{border-bottom:", table.border, ";overflow:auto;border-radius:", table.borderRadius, ";}table{width:100%;border-spacing:0;table-layout:fixed;td,th{transition:all ", table.transition, ";}}thead{text-align:", table.thead.textAlign, ";font-size:", table.thead.fontSize, ";font-weight:", table.thead.fontWeight, ";position:sticky;top:0;z-index:2;tr{height:", table.thead.height, ";&:not(:last-of-type) th{border-bottom:", table.border, ";}}}th{padding:", table.thead.padding, ";position:relative;background:", table.thead.bgColor, ";line-height:normal;&:before{content:'';height:", table.thead.delimiterHeight, ";position:absolute;background-color:", table.thead.delimiterColor, ";width:1px;left:1px;top:50%;transform:translateY(-50%);}&:first-of-type:before{display:none;}}.k-table-title{display:inline-flex;align-items:center;max-width:100%;color:", theme.color.lightBlack, ";}.k-table-title-text{flex:1;}tbody{tr{&:hover td{background:", table.tbody.hoverBgcolor, ";}&:last-of-type td{border-bottom-color:transparent;}}}td{padding:", table.tbody.padding, ";border-bottom:", table.border, ";background:", table.bgColor, ";word-wrap:break-word;}.k-fixed-left,.k-fixed-right{position:sticky;z-index:1;&:after{content:'';display:block;transition:box-shadow ", table.transition, ";position:absolute;top:0;bottom:0px;width:10px;pointer-events:none;}}.k-fixed-left:after{right:-11px;}.k-fixed-right:after{left:-11px;}&.k-scroll-left .k-fixed-right:after{box-shadow:", table.fixRightShadow, ";}&.k-scroll-right .k-fixed-left:after{box-shadow:", table.fixLeftShadow, ";}&.k-scroll-middle{.k-fixed-left:after{box-shadow:", table.fixLeftShadow, ";}.k-fixed-right:after{box-shadow:", table.fixRightShadow, ";}}.k-fixed-right+.k-fixed-right:after{display:none;}.k-table-affix-header{position:sticky;top:0;left:0;.k-affix-wrapper{overflow:hidden;}&.k-fixed{position:relative;}}&.k-border,&.k-grid{.k-table-wrapper{border-top:", table.border, ";border-left:", table.border, ";border-right:", table.border, ";}}&.k-grid{td:not(:last-of-type),th:not(:last-of-type){border-right:", table.border, ";}th:before{display:none;}}&.k-stripe{tr:nth-child(even):not(:hover) td{background:", table.stripeBgColor, ";}}.k-table-group{width:", table.group.width, "!important;height:", table.group.width, "!important;margin-left:", table.group.gap, ";position:relative;color:", table.group.color, ";&:hover{color:", theme.color.primary, ";}.k-icon{transition:transform ", table.transition, ";}&.k-dropdown-open .k-icon{transform:rotate(180deg);}}.k-table-check{.k-checkbox,.k-radio{position:relative;top:-1px;}}.k-column-sortable{cursor:pointer;}.k-column-sort{.k-icon{display:block;height:", _sortInstanceProperty(table).iconHeight, ";line-height:", _sortInstanceProperty(table).iconHeight, ";margin-left:", _sortInstanceProperty(table).gap, ";color:", _sortInstanceProperty(table).color, ";}&.k-asc .k-icon.k-desc,&.k-desc .k-icon.k-asc{color:", _sortInstanceProperty(table).disabledColor, ";}}.k-table-spin.k-overlay{z-index:2;}.k-table-empty{text-align:center;}tr.k-expand{td{padding:0;background:#fdfcff;}}&.k-with-expand{tr:not(.k-expand){td{border-bottom:none;}}}.k-table-expand{border-top:", table.border, ";box-sizing:content-box;}tbody tr.k-selected td{background:", table.selectedBgColor, ";}.k-table-arrow{margin-right:", table.arrow.gap, ";transition:transform ", table.transition, ";position:relative;top:-1px;}tr.k-spreaded{.k-table-arrow{transform:rotate(90deg);}}.k-table-resize{height:100%;width:", table.resizeWidth, ";position:absolute;top:0;left:-1px;cursor:ew-resize;}tr.k-dragging{opacity:", table.draggingOpacity, ";}.k-table-scrollbar{overflow-x:auto;overflow-y:hidden;}.k-table-scrollbar-inner{height:1px;}", _mapInstanceProperty(aligns).call(aligns, function (type) {
99
99
  return /*#__PURE__*/css(".k-align-", type, "{text-align:", type, ";}");
100
- }), ";");
100
+ }), ">.k-pagination{margin:16px 0;}");
101
101
  }
102
102
  export function makeGroupMenuStyles() {
103
103
  return /*#__PURE__*/css("max-height:", table.group.menuMaxHeight, ";overflow:auto;.k-dropdown-item.k-active{color:", table.group.activeColor, ";}.k-table-group-header{padding:", table.group.headerPadding, ";border-bottom:", table.group.headerBorder, ";}");
@@ -2,6 +2,7 @@ import { Component, TypeDefs } from 'intact-react';
2
2
  import { TableMerge } from './useMerge';
3
3
  import { TooltipProps } from '../tooltip/tooltip';
4
4
  import type { Events } from '../types';
5
+ import type { PaginationProps, PaginationChangeData } from '../pagination';
5
6
  export interface TableProps<T = any, K extends TableRowKey = TableRowKey, C extends CheckType = CheckType, S extends string = string, G extends TableGroupValue = TableGroupValue> {
6
7
  data?: T[];
7
8
  fixHeader?: boolean | string | number;
@@ -35,6 +36,8 @@ export interface TableProps<T = any, K extends TableRowKey = TableRowKey, C exte
35
36
  widthStoreKey?: string;
36
37
  draggable?: boolean;
37
38
  animation?: boolean | [boolean, boolean];
39
+ hideHeader?: boolean;
40
+ pagination?: boolean | PaginationProps;
38
41
  }
39
42
  export interface TableEvents<T = any, K extends TableRowKey = number> {
40
43
  clickRow: [T, number, K];
@@ -47,6 +50,11 @@ export interface TableEvents<T = any, K extends TableRowKey = number> {
47
50
  from: number;
48
51
  to: number;
49
52
  }];
53
+ checkRow: [T, number, K];
54
+ uncheckRow: [T, number, K];
55
+ checkAll: [];
56
+ uncheckAll: [];
57
+ changePage: [PaginationChangeData];
50
58
  }
51
59
  export interface TableBlocks<T = unknown> {
52
60
  empty: null;
@@ -66,6 +74,13 @@ export declare class Table<T = any, RowKey extends TableRowKey = TableRowKey, Ch
66
74
  static typeDefs: Required<TypeDefs<TableProps<unknown, TableRowKey, CheckType, string, TableGroupValue<string | number | symbol>>>>;
67
75
  static defaults: () => Partial<TableProps<any, TableRowKey, CheckType, string, TableGroupValue<string | number | symbol>>>;
68
76
  static events: Events<TableEvents<any, number>>;
77
+ pagination: {
78
+ data: import("../../hooks/useState").State<any[] | undefined>;
79
+ value: import("../../hooks/useState").State<number>;
80
+ limit: import("../../hooks/useState").State<number>;
81
+ onChange: (data: PaginationChangeData) => void;
82
+ paginationRef: import("intact").RefObject<import("../pagination").Pagination>;
83
+ };
69
84
  private tree;
70
85
  private columns;
71
86
  private scroll;
@@ -25,6 +25,7 @@ import { useDraggable } from './useDraggable';
25
25
  import { useStickyScrollbar } from './useStickyScrollbar';
26
26
  import { useWidth } from './useWidth';
27
27
  import { useScroll } from './useScroll';
28
+ import { usePagination } from './usePagination';
28
29
  var typeDefs = {
29
30
  data: Array,
30
31
  fixHeader: [Boolean, String, Number],
@@ -57,7 +58,9 @@ var typeDefs = {
57
58
  minColWidth: Number,
58
59
  widthStoreKey: String,
59
60
  draggable: Boolean,
60
- animation: [Boolean, Array]
61
+ animation: [Boolean, Array],
62
+ hideHeader: Boolean,
63
+ pagination: [Boolean, Object]
61
64
  };
62
65
 
63
66
  var defaults = function defaults() {
@@ -78,7 +81,12 @@ var defaults = function defaults() {
78
81
  var events = {
79
82
  clickRow: true,
80
83
  dragstart: true,
81
- dragend: true
84
+ dragend: true,
85
+ checkRow: true,
86
+ uncheckRow: true,
87
+ checkAll: true,
88
+ uncheckAll: true,
89
+ changePage: true
82
90
  };
83
91
  export var Table = /*#__PURE__*/function (_Component) {
84
92
  _inheritsLoose(Table, _Component);
@@ -93,21 +101,22 @@ export var Table = /*#__PURE__*/function (_Component) {
93
101
  }
94
102
 
95
103
  _this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
96
- _this.tree = useTree();
104
+ _this.pagination = usePagination();
105
+ _this.tree = useTree(_this.pagination.data);
97
106
  _this.columns = useColumns();
98
107
  _this.scroll = useScroll();
99
108
  _this.stickyHeader = useStickyHeader(_this.scroll.callbacks);
100
109
  _this.width = useWidth(_this.scroll.scrollRef, _this.columns.getColumns);
101
110
  _this.resizable = useResizable(_this.scroll.scrollRef, _this.width.tableRef, _this.width.tableWidth, _this.width.widthMap, _this.width.storeWidth);
102
111
  _this.fixedColumns = useFixedColumns(_this.columns.getColumns, _this.scroll, _this.width.widthMap);
103
- _this.disableRow = useDisableRow(_this.tree.loopData);
104
- _this.merge = useMerge(_this.columns.getCols);
105
- _this.checked = useChecked(_this.disableRow.getEnableKeys, _this.disableRow.getAllKeys, _this.disableRow.isDisabledKey, _this.merge.getGrid, _this.tree.loopData);
112
+ _this.disableRow = useDisableRow(_this.tree.loopData, _this.pagination.data);
113
+ _this.merge = useMerge(_this.columns.getCols, _this.pagination.data);
114
+ _this.checked = useChecked(_this.disableRow.getEnableKeys, _this.disableRow.getAllKeys, _this.disableRow.isDisabledKey, _this.merge.getGrid, _this.tree.loopData, _this.pagination.data);
106
115
  _this.sortable = useSortable();
107
116
  _this.expandable = useExpandable();
108
117
  _this.selected = useSelected();
109
118
  _this.resetRowStatus = useRestRowStatus(_this.disableRow.getAllKeys);
110
- _this.draggable = useDraggable();
119
+ _this.draggable = useDraggable(_this.pagination.data);
111
120
  _this.stickyScrollbar = useStickyScrollbar(_this.stickyHeader.elementRef, _this.scroll, _this.width.tableRef, _this.fixedColumns.setScrollPosition);
112
121
  return _this;
113
122
  }