@hi-ui/table 4.10.0 → 4.11.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @hi-ui/table
2
2
 
3
+ ## 4.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#3219](https://github.com/XiaoMi/hiui/pull/3219) [`ca7a945fe`](https://github.com/XiaoMi/hiui/commit/ca7a945fe1eeaf14b3ffb34375ff613781d7bebd) Thanks [@zyprepare](https://github.com/zyprepare)! - feat(table): TableColumnItem 类型增加 minWidth 参数 (#3216)
8
+
9
+ ### Patch Changes
10
+
11
+ - [#3254](https://github.com/XiaoMi/hiui/pull/3254) [`fc1360986`](https://github.com/XiaoMi/hiui/commit/fc136098659d111d5df8a369a5b305e4be71d46e) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(table): 更新 useTable 逻辑以确保滚动位置不超出表格宽度,并添加 @hi-ui/radio 依赖
12
+
3
13
  ## 4.10.0
4
14
 
5
15
  ### Minor Changes
package/lib/cjs/Table.js CHANGED
@@ -25,7 +25,7 @@ var reactUtils = require('@hi-ui/react-utils');
25
25
  var TableSettingMenu = require('./TableSettingMenu.js');
26
26
  var Loading = require('@hi-ui/loading');
27
27
  var Checkbox = require('@hi-ui/checkbox');
28
- var index$1 = require('./packages/ui/radio/lib/esm/index.js');
28
+ var Radio = require('@hi-ui/radio');
29
29
  var useCheck = require('./hooks/use-check.js');
30
30
  var typeAssertion = require('@hi-ui/type-assertion');
31
31
  var treeUtils = require('@hi-ui/tree-utils');
@@ -41,6 +41,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
41
41
  var Pagination__default = /*#__PURE__*/_interopDefaultCompat(Pagination);
42
42
  var Loading__default = /*#__PURE__*/_interopDefaultCompat(Loading);
43
43
  var Checkbox__default = /*#__PURE__*/_interopDefaultCompat(Checkbox);
44
+ var Radio__default = /*#__PURE__*/_interopDefaultCompat(Radio);
44
45
  var _prefix = classname.getPrefixCls('table');
45
46
  /**
46
47
  * 需要使用双表格的场景对应的 API
@@ -215,7 +216,7 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
215
216
  onClick: function onClick(evt) {
216
217
  evt.stopPropagation();
217
218
  }
218
- })) : ( /*#__PURE__*/React__default["default"].createElement(index$1["default"], {
219
+ })) : ( /*#__PURE__*/React__default["default"].createElement(Radio__default["default"], {
219
220
  checked: checked,
220
221
  disabled: disabledCheckbox,
221
222
  onChange: function onChange(evt) {
@@ -31,7 +31,7 @@ var useColWidth = function useColWidth(_ref) {
31
31
  // 是否重新设置过表格每列宽度
32
32
  var hasResetWidths = React__default["default"].useRef(false);
33
33
  var _React$useState = React__default["default"].useState(function () {
34
- return index.getGroupItemWidth(columns);
34
+ return index.getGroupItemWidth(columns).colWidths;
35
35
  }),
36
36
  colWidths = _React$useState[0],
37
37
  setColWidths = _React$useState[1];
@@ -39,12 +39,12 @@ var useColWidth = function useColWidth(_ref) {
39
39
  if (measureRowElement && measureRowElement.childNodes) {
40
40
  // 超出的宽度,即每列真实的宽度超出设置的宽度的总和
41
41
  var exceedWidth = 0;
42
- var _realColumnsWidth = Array.from(measureRowElement.childNodes).map(function (node, index) {
42
+ var _realColumnsWidth = Array.from(measureRowElement.childNodes).map(function (node, index$1) {
43
43
  var _a;
44
- var realWidth = node.getBoundingClientRect().width || 0;
45
- var _ref2 = (_a = columns[index]) !== null && _a !== void 0 ? _a : {},
46
- width = _ref2.width,
44
+ var realWidth = node.getBoundingClientRect().width || 60;
45
+ var _ref2 = (_a = columns[index$1]) !== null && _a !== void 0 ? _a : {},
47
46
  fixed = _ref2.fixed;
47
+ var width = index.getGroupItemWidth(columns).colWidths[index$1];
48
48
  // 如果该列设置了 fixed 并且真实宽度大于设置的 width 则设置为 width
49
49
  if (fixed && width && width < realWidth) {
50
50
  exceedWidth += realWidth - width;
@@ -71,12 +71,12 @@ var useColWidth = function useColWidth(_ref) {
71
71
  return _realColumnsWidth;
72
72
  }
73
73
  }
74
- return index.getGroupItemWidth(columns);
74
+ return index.getGroupItemWidth(columns).colWidths;
75
75
  }, [columns]);
76
76
  var getVirtualWidths = React.useCallback(function () {
77
77
  var measureRowElement = measureRowElementRef.current;
78
78
  if (!measureRowElement) {
79
- return index.getGroupItemWidth(columns);
79
+ return index.getGroupItemWidth(columns).colWidths;
80
80
  }
81
81
  /** 虚拟滚动时,内容宽度不能用以前table自动渲染的方式获取,需要手动计算 */
82
82
  var columnDefaultWidth = 200;
@@ -105,7 +105,7 @@ var useColWidth = function useColWidth(_ref) {
105
105
  }
106
106
  }, [getVirtualWidths, virtual]);
107
107
  useUpdateEffect.useUpdateEffect(function () {
108
- setColWidths(index.getGroupItemWidth(columns));
108
+ setColWidths(index.getGroupItemWidth(columns).colWidths);
109
109
  // setColWidths((prev) => {
110
110
  // // resizable 模式下通过 measureRowElementRef.current 去更新列宽,防止拖拽后宽度被重置
111
111
  // // 例如同时设置了 resizable 和 rowSelection,当拖拽某列宽度后再选中某行时,该列宽度会被重置
@@ -147,33 +147,35 @@ var useColWidth = function useColWidth(_ref) {
147
147
  setHeaderTableElement = _React$useState2[1];
148
148
  // 控制列最小可调整宽度
149
149
  var _React$useState3 = React__default["default"].useState([]),
150
- minColWidth = _React$useState3[0],
151
- setMinColWidth = _React$useState3[1];
152
- // 当列变化时同步更新 minColWidth
150
+ minColWidths = _React$useState3[0],
151
+ setMinColWidths = _React$useState3[1];
152
+ // 当列变化时同步更新 minColWidths
153
153
  React__default["default"].useEffect(function () {
154
154
  var resizeObserver;
155
155
  if (headerTableElement) {
156
156
  resizeObserver = new ResizeObserver(function () {
157
157
  var resizableHandlerWidth = 4;
158
- var _minColWidth = Array.from(headerTableElement.childNodes).map(function (th) {
158
+ var calcMinColWidths = Array.from(headerTableElement.childNodes).map(function (th, index$1) {
159
+ var minColWidth = index.getGroupItemWidth(columns).minColWidths[index$1];
159
160
  var thPaddingLeft = parseFloat(window.getComputedStyle(th).getPropertyValue('padding-left'));
160
161
  var childNodes = Array.from(th.childNodes);
161
- return childNodes.map(function (child) {
162
+ var childNodesWidth = childNodes.map(function (child) {
162
163
  return child.offsetWidth;
163
164
  }).reduce(function (prev, next) {
164
165
  return prev + next;
165
166
  }, 0) + thPaddingLeft * 2 + resizableHandlerWidth;
167
+ return childNodesWidth > minColWidth ? minColWidth : childNodesWidth;
166
168
  });
167
- setMinColWidth(_minColWidth);
169
+ setMinColWidths(calcMinColWidths);
168
170
  });
169
171
  resizeObserver.observe(headerTableElement);
170
172
  } else {
171
- setMinColWidth(Array(columns.length).fill(0));
173
+ setMinColWidths(Array(columns.length).fill(0));
172
174
  }
173
175
  return function () {
174
176
  resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
175
177
  };
176
- }, [columns.length, headerTableElement, resizable]);
178
+ }, [columns, columns.length, headerTableElement, resizable]);
177
179
  /**
178
180
  * 控制列最小可调整宽度
179
181
  */
@@ -198,8 +200,8 @@ var useColWidth = function useColWidth(_ref) {
198
200
  */
199
201
  var onColumnResizable = React__default["default"].useCallback(function (evt, _ref3, index) {
200
202
  var size = _ref3.size;
201
- var minWidth = minColWidth[index];
202
- var anotherMinWidth = minColWidth[index + 1];
203
+ var minWidth = minColWidths[index];
204
+ var anotherMinWidth = minColWidths[index + 1];
203
205
  var nextWidth = size.width > minWidth ? size.width : minWidth;
204
206
  setColWidths(function (prev) {
205
207
  var nextColWidths = [].concat(prev);
@@ -216,18 +218,18 @@ var useColWidth = function useColWidth(_ref) {
216
218
  nextColWidths[index + 1] = anotherWidth;
217
219
  return nextColWidths;
218
220
  });
219
- }, [minColWidth, tableWidthAdjustOnResize]);
221
+ }, [minColWidths, tableWidthAdjustOnResize]);
220
222
  var getColgroupProps = React__default["default"].useCallback(function (column, index) {
221
223
  var width = colWidths[index] || undefined;
224
+ var minWidth = minColWidths[index] || undefined;
222
225
  return {
223
226
  style: {
224
227
  width: width,
225
- // TODO(疑惑): minWidth 所要解决的问题
226
- minWidth: width
228
+ minWidth: minWidth || width
227
229
  }
228
230
  // 'data-hover-highlight': setAttrStatus(isHoveredCol(column.dataKey)),
229
231
  };
230
- }, [colWidths]);
232
+ }, [colWidths, minColWidths]);
231
233
  return {
232
234
  measureRowElementRef: measureRowElementRef,
233
235
  onColumnResizable: onColumnResizable,
@@ -402,8 +402,18 @@ var useTable = function useTable(_a) {
402
402
  right = _scrollBodyElementRef.right;
403
403
  scrollRight = tableTefRight - right;
404
404
  }
405
+ var _scrollLeft = scrollLeft;
406
+ if (bodyTableRef.current && scrollBodyElementRef.current) {
407
+ var _bodyTableRef$current2 = bodyTableRef.current.getBoundingClientRect(),
408
+ tableWidth = _bodyTableRef$current2.width;
409
+ var _scrollBodyElementRef2 = scrollBodyElementRef.current.getBoundingClientRect(),
410
+ scrollBodyWidth = _scrollBodyElementRef2.width;
411
+ if (scrollLeft + scrollBodyWidth > tableWidth) {
412
+ _scrollLeft = tableWidth - scrollBodyWidth;
413
+ }
414
+ }
405
415
  setScrollSize({
406
- scrollLeft: scrollLeft,
416
+ scrollLeft: _scrollLeft,
407
417
  scrollRight: scrollRight
408
418
  });
409
419
  }, [rightFrozenColKeys, scrollSize]);
@@ -66,22 +66,29 @@ var setColumnsDefaultWidth = function setColumnsDefaultWidth(columns, defaultWid
66
66
  * 如果是多级表头,将会递归 children 得到叶子结点层每项的宽度
67
67
  */
68
68
  var getGroupItemWidth = function getGroupItemWidth(columns) {
69
- var baseColWidths = [];
69
+ var colWidths = [];
70
+ var minColWidths = [];
70
71
  var dig = function dig(column) {
71
72
  column.forEach(function (_ref) {
72
73
  var children = _ref.children,
73
- width = _ref.width;
74
+ width = _ref.width,
75
+ minWidth = _ref.minWidth;
74
76
  if (Array.isArray(children)) {
75
77
  dig(children);
76
78
  return;
77
79
  }
78
80
  // 如果没有设置列宽度,css 宽度默认是 `auto`,这里对于非数字 width 均设置为 0
79
81
  var colWidth = typeAssertion.isNumeric(width) ? Number(width) : 0;
80
- baseColWidths.push(colWidth);
82
+ var minColWidth = typeAssertion.isNumeric(minWidth) ? Number(minWidth) : colWidth || 60;
83
+ colWidths.push(colWidth < minColWidth ? minColWidth : colWidth);
84
+ minColWidths.push(minColWidth);
81
85
  });
82
86
  };
83
87
  dig(columns);
84
- return baseColWidths;
88
+ return {
89
+ colWidths: colWidths,
90
+ minColWidths: minColWidths
91
+ };
85
92
  };
86
93
  var parseFixedColumns = function parseFixedColumns(item, index, columns, arr, key, parentStickyWidth) {
87
94
  if (parentStickyWidth === void 0) {
package/lib/esm/Table.js CHANGED
@@ -20,7 +20,7 @@ import { withDefaultProps } from '@hi-ui/react-utils';
20
20
  import { TableSettingMenu } from './TableSettingMenu.js';
21
21
  import Loading from '@hi-ui/loading';
22
22
  import Checkbox from '@hi-ui/checkbox';
23
- import Radio from './packages/ui/radio/lib/esm/index.js';
23
+ import Radio from '@hi-ui/radio';
24
24
  import { useTableCheck } from './hooks/use-check.js';
25
25
  import { isNullish } from '@hi-ui/type-assertion';
26
26
  import { cloneTree, flattenTree } from '@hi-ui/tree-utils';
@@ -19,7 +19,7 @@ var useColWidth = function useColWidth(_ref) {
19
19
  // 是否重新设置过表格每列宽度
20
20
  var hasResetWidths = React__default.useRef(false);
21
21
  var _React$useState = React__default.useState(function () {
22
- return getGroupItemWidth(columns);
22
+ return getGroupItemWidth(columns).colWidths;
23
23
  }),
24
24
  colWidths = _React$useState[0],
25
25
  setColWidths = _React$useState[1];
@@ -29,10 +29,10 @@ var useColWidth = function useColWidth(_ref) {
29
29
  var exceedWidth = 0;
30
30
  var _realColumnsWidth = Array.from(measureRowElement.childNodes).map(function (node, index) {
31
31
  var _a;
32
- var realWidth = node.getBoundingClientRect().width || 0;
32
+ var realWidth = node.getBoundingClientRect().width || 60;
33
33
  var _ref2 = (_a = columns[index]) !== null && _a !== void 0 ? _a : {},
34
- width = _ref2.width,
35
34
  fixed = _ref2.fixed;
35
+ var width = getGroupItemWidth(columns).colWidths[index];
36
36
  // 如果该列设置了 fixed 并且真实宽度大于设置的 width 则设置为 width
37
37
  if (fixed && width && width < realWidth) {
38
38
  exceedWidth += realWidth - width;
@@ -59,12 +59,12 @@ var useColWidth = function useColWidth(_ref) {
59
59
  return _realColumnsWidth;
60
60
  }
61
61
  }
62
- return getGroupItemWidth(columns);
62
+ return getGroupItemWidth(columns).colWidths;
63
63
  }, [columns]);
64
64
  var getVirtualWidths = useCallback(function () {
65
65
  var measureRowElement = measureRowElementRef.current;
66
66
  if (!measureRowElement) {
67
- return getGroupItemWidth(columns);
67
+ return getGroupItemWidth(columns).colWidths;
68
68
  }
69
69
  /** 虚拟滚动时,内容宽度不能用以前table自动渲染的方式获取,需要手动计算 */
70
70
  var columnDefaultWidth = 200;
@@ -93,7 +93,7 @@ var useColWidth = function useColWidth(_ref) {
93
93
  }
94
94
  }, [getVirtualWidths, virtual]);
95
95
  useUpdateEffect(function () {
96
- setColWidths(getGroupItemWidth(columns));
96
+ setColWidths(getGroupItemWidth(columns).colWidths);
97
97
  // setColWidths((prev) => {
98
98
  // // resizable 模式下通过 measureRowElementRef.current 去更新列宽,防止拖拽后宽度被重置
99
99
  // // 例如同时设置了 resizable 和 rowSelection,当拖拽某列宽度后再选中某行时,该列宽度会被重置
@@ -135,33 +135,35 @@ var useColWidth = function useColWidth(_ref) {
135
135
  setHeaderTableElement = _React$useState2[1];
136
136
  // 控制列最小可调整宽度
137
137
  var _React$useState3 = React__default.useState([]),
138
- minColWidth = _React$useState3[0],
139
- setMinColWidth = _React$useState3[1];
140
- // 当列变化时同步更新 minColWidth
138
+ minColWidths = _React$useState3[0],
139
+ setMinColWidths = _React$useState3[1];
140
+ // 当列变化时同步更新 minColWidths
141
141
  React__default.useEffect(function () {
142
142
  var resizeObserver;
143
143
  if (headerTableElement) {
144
144
  resizeObserver = new ResizeObserver(function () {
145
145
  var resizableHandlerWidth = 4;
146
- var _minColWidth = Array.from(headerTableElement.childNodes).map(function (th) {
146
+ var calcMinColWidths = Array.from(headerTableElement.childNodes).map(function (th, index) {
147
+ var minColWidth = getGroupItemWidth(columns).minColWidths[index];
147
148
  var thPaddingLeft = parseFloat(window.getComputedStyle(th).getPropertyValue('padding-left'));
148
149
  var childNodes = Array.from(th.childNodes);
149
- return childNodes.map(function (child) {
150
+ var childNodesWidth = childNodes.map(function (child) {
150
151
  return child.offsetWidth;
151
152
  }).reduce(function (prev, next) {
152
153
  return prev + next;
153
154
  }, 0) + thPaddingLeft * 2 + resizableHandlerWidth;
155
+ return childNodesWidth > minColWidth ? minColWidth : childNodesWidth;
154
156
  });
155
- setMinColWidth(_minColWidth);
157
+ setMinColWidths(calcMinColWidths);
156
158
  });
157
159
  resizeObserver.observe(headerTableElement);
158
160
  } else {
159
- setMinColWidth(Array(columns.length).fill(0));
161
+ setMinColWidths(Array(columns.length).fill(0));
160
162
  }
161
163
  return function () {
162
164
  resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
163
165
  };
164
- }, [columns.length, headerTableElement, resizable]);
166
+ }, [columns, columns.length, headerTableElement, resizable]);
165
167
  /**
166
168
  * 控制列最小可调整宽度
167
169
  */
@@ -186,8 +188,8 @@ var useColWidth = function useColWidth(_ref) {
186
188
  */
187
189
  var onColumnResizable = React__default.useCallback(function (evt, _ref3, index) {
188
190
  var size = _ref3.size;
189
- var minWidth = minColWidth[index];
190
- var anotherMinWidth = minColWidth[index + 1];
191
+ var minWidth = minColWidths[index];
192
+ var anotherMinWidth = minColWidths[index + 1];
191
193
  var nextWidth = size.width > minWidth ? size.width : minWidth;
192
194
  setColWidths(function (prev) {
193
195
  var nextColWidths = [].concat(prev);
@@ -204,18 +206,18 @@ var useColWidth = function useColWidth(_ref) {
204
206
  nextColWidths[index + 1] = anotherWidth;
205
207
  return nextColWidths;
206
208
  });
207
- }, [minColWidth, tableWidthAdjustOnResize]);
209
+ }, [minColWidths, tableWidthAdjustOnResize]);
208
210
  var getColgroupProps = React__default.useCallback(function (column, index) {
209
211
  var width = colWidths[index] || undefined;
212
+ var minWidth = minColWidths[index] || undefined;
210
213
  return {
211
214
  style: {
212
215
  width: width,
213
- // TODO(疑惑): minWidth 所要解决的问题
214
- minWidth: width
216
+ minWidth: minWidth || width
215
217
  }
216
218
  // 'data-hover-highlight': setAttrStatus(isHoveredCol(column.dataKey)),
217
219
  };
218
- }, [colWidths]);
220
+ }, [colWidths, minColWidths]);
219
221
  return {
220
222
  measureRowElementRef: measureRowElementRef,
221
223
  onColumnResizable: onColumnResizable,
@@ -390,8 +390,18 @@ var useTable = function useTable(_a) {
390
390
  right = _scrollBodyElementRef.right;
391
391
  scrollRight = tableTefRight - right;
392
392
  }
393
+ var _scrollLeft = scrollLeft;
394
+ if (bodyTableRef.current && scrollBodyElementRef.current) {
395
+ var _bodyTableRef$current2 = bodyTableRef.current.getBoundingClientRect(),
396
+ tableWidth = _bodyTableRef$current2.width;
397
+ var _scrollBodyElementRef2 = scrollBodyElementRef.current.getBoundingClientRect(),
398
+ scrollBodyWidth = _scrollBodyElementRef2.width;
399
+ if (scrollLeft + scrollBodyWidth > tableWidth) {
400
+ _scrollLeft = tableWidth - scrollBodyWidth;
401
+ }
402
+ }
393
403
  setScrollSize({
394
- scrollLeft: scrollLeft,
404
+ scrollLeft: _scrollLeft,
395
405
  scrollRight: scrollRight
396
406
  });
397
407
  }, [rightFrozenColKeys, scrollSize]);
@@ -61,22 +61,29 @@ var setColumnsDefaultWidth = function setColumnsDefaultWidth(columns, defaultWid
61
61
  * 如果是多级表头,将会递归 children 得到叶子结点层每项的宽度
62
62
  */
63
63
  var getGroupItemWidth = function getGroupItemWidth(columns) {
64
- var baseColWidths = [];
64
+ var colWidths = [];
65
+ var minColWidths = [];
65
66
  var dig = function dig(column) {
66
67
  column.forEach(function (_ref) {
67
68
  var children = _ref.children,
68
- width = _ref.width;
69
+ width = _ref.width,
70
+ minWidth = _ref.minWidth;
69
71
  if (Array.isArray(children)) {
70
72
  dig(children);
71
73
  return;
72
74
  }
73
75
  // 如果没有设置列宽度,css 宽度默认是 `auto`,这里对于非数字 width 均设置为 0
74
76
  var colWidth = isNumeric(width) ? Number(width) : 0;
75
- baseColWidths.push(colWidth);
77
+ var minColWidth = isNumeric(minWidth) ? Number(minWidth) : colWidth || 60;
78
+ colWidths.push(colWidth < minColWidth ? minColWidth : colWidth);
79
+ minColWidths.push(minColWidth);
76
80
  });
77
81
  };
78
82
  dig(columns);
79
- return baseColWidths;
83
+ return {
84
+ colWidths: colWidths,
85
+ minColWidths: minColWidths
86
+ };
80
87
  };
81
88
  var parseFixedColumns = function parseFixedColumns(item, index, columns, arr, key, parentStickyWidth) {
82
89
  if (parentStickyWidth === void 0) {
@@ -95,7 +95,11 @@ export declare type TableColumnItem = {
95
95
  */
96
96
  width?: number;
97
97
  /**
98
- * 是否固定列宽,使用场景:设置 width 后,当所有列宽总和小于表格宽度时,多的宽度会分摊到每一列上,设置 fixed 后该列不会参与多余宽度均分。
98
+ * 该列最小宽度
99
+ */
100
+ minWidth?: number;
101
+ /**
102
+ * 是否固定列宽,使用场景:设置 width 后,当所有列宽总和小于表格宽度时,多的宽度会分摊到每一列上,设置 fixed 后该列不会参与多余宽度分摊。
99
103
  */
100
104
  fixed?: boolean;
101
105
  /**
@@ -6,7 +6,10 @@ export declare const setColumnsDefaultWidth: (columns: any, defaultWidth: any) =
6
6
  * 获取每个 Column 的真实列宽度(排除合并列头)
7
7
  * 如果是多级表头,将会递归 children 得到叶子结点层每项的宽度
8
8
  */
9
- export declare const getGroupItemWidth: (columns: TableColumnItem[]) => number[];
9
+ export declare const getGroupItemWidth: (columns: TableColumnItem[]) => {
10
+ colWidths: number[];
11
+ minColWidths: number[];
12
+ };
10
13
  export declare const getMaskItemsWIdth: (columns: TableColumnItem[]) => number;
11
14
  export declare const parseFixedColumns: (item: any, index: number, columns: any[], arr: any[], key: string, parentStickyWidth?: number) => any;
12
15
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/table",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -58,6 +58,7 @@
58
58
  "@hi-ui/object-utils": "^4.0.4",
59
59
  "@hi-ui/pagination": "^4.2.0",
60
60
  "@hi-ui/popper": "^4.1.5",
61
+ "@hi-ui/radio": "^4.1.4",
61
62
  "@hi-ui/react-utils": "^4.0.4",
62
63
  "@hi-ui/scrollbar": "^4.2.0",
63
64
  "@hi-ui/select": "^4.6.0",
@@ -1,100 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- var _typeof = require("@babel/runtime/helpers/typeof");
13
- Object.defineProperty(exports, '__esModule', {
14
- value: true
15
- });
16
- var tslib = require('tslib');
17
- var React = require('react');
18
- var classname = require('@hi-ui/classname');
19
- var env = require('@hi-ui/env');
20
- var useRadio = require('./use-radio.js');
21
- var context = require('./context.js');
22
- var typeAssertion = require('@hi-ui/type-assertion');
23
- var funcUtils = require('@hi-ui/func-utils');
24
- function _interopDefaultCompat(e) {
25
- return e && _typeof(e) === 'object' && 'default' in e ? e : {
26
- 'default': e
27
- };
28
- }
29
- var React__default = /*#__PURE__*/_interopDefaultCompat(React);
30
-
31
- /** @LICENSE
32
- * @hi-ui/radio
33
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
34
- *
35
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
36
- *
37
- * This source code is licensed under the MIT license found in the
38
- * LICENSE file in the root directory of this source tree.
39
- */
40
- var RADIO_PREFIX = classname.getPrefixCls('radio');
41
- /**
42
- * 单选
43
- */
44
- var Radio = /*#__PURE__*/React.forwardRef(function (_a, ref) {
45
- var _a$prefixCls = _a.prefixCls,
46
- prefixCls = _a$prefixCls === void 0 ? RADIO_PREFIX : _a$prefixCls,
47
- _a$role = _a.role,
48
- role = _a$role === void 0 ? 'radio' : _a$role,
49
- className = _a.className,
50
- children = _a.children,
51
- rest = tslib.__rest(_a, ["prefixCls", "role", "className", "children"]);
52
- var groupContext = context.useRadioGroupContext();
53
- var _ref = groupContext || {},
54
- disabledContext = _ref.disabled,
55
- isCheckedContext = _ref.isChecked,
56
- nameContext = _ref.name,
57
- onChangeContext = _ref.onChange,
58
- _ref$type = _ref.type,
59
- type = _ref$type === void 0 ? 'default' : _ref$type;
60
- var checkedProp = rest.checked,
61
- valueProp = rest.value,
62
- _rest$disabled = rest.disabled,
63
- disabled = _rest$disabled === void 0 ? disabledContext : _rest$disabled,
64
- _rest$name = rest.name,
65
- name = _rest$name === void 0 ? nameContext : _rest$name,
66
- onChangeProp = rest.onChange;
67
- // Group's priority is higher than its own.
68
- var checked = isCheckedContext && !typeAssertion.isNullish(valueProp) ? isCheckedContext(valueProp) : checkedProp;
69
- var onChange = onChangeContext && !typeAssertion.isNullish(valueProp) ? funcUtils.callAllFuncs(function (evt) {
70
- if (evt.target.checked) {
71
- onChangeContext(valueProp);
72
- }
73
- }, onChangeProp) : onChangeProp;
74
- var _useRadio = useRadio.useRadio(Object.assign(Object.assign({}, rest), {
75
- disabled: disabled,
76
- name: name,
77
- checked: checked,
78
- onChange: onChange
79
- })),
80
- rootProps = _useRadio.rootProps,
81
- getInputProps = _useRadio.getInputProps;
82
- var inputProps = getInputProps();
83
- var cls = classname.cx(prefixCls, className, prefixCls + "--type-" + type);
84
- return /*#__PURE__*/React__default["default"].createElement("label", Object.assign({
85
- ref: ref,
86
- role: role,
87
- className: cls
88
- }, rootProps), /*#__PURE__*/React__default["default"].createElement("input", Object.assign({}, inputProps, {
89
- tabIndex: 0,
90
- className: prefixCls + "__input"
91
- })), /*#__PURE__*/React__default["default"].createElement("span", {
92
- className: prefixCls + "__controller"
93
- }), children ? /*#__PURE__*/React__default["default"].createElement("span", {
94
- className: prefixCls + "__label"
95
- }, children) : null);
96
- });
97
- if (env.__DEV__) {
98
- Radio.displayName = 'Radio';
99
- }
100
- exports.Radio = Radio;
@@ -1,104 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- var _typeof = require("@babel/runtime/helpers/typeof");
13
- Object.defineProperty(exports, '__esModule', {
14
- value: true
15
- });
16
- var tslib = require('tslib');
17
- var React = require('react');
18
- var classname = require('@hi-ui/classname');
19
- var env = require('@hi-ui/env');
20
- var useRadioGroup = require('./use-radio-group.js');
21
- var context = require('./context.js');
22
- var types = require('./types.js');
23
- var typeAssertion = require('@hi-ui/type-assertion');
24
- var Radio = require('./Radio.js');
25
- function _interopDefaultCompat(e) {
26
- return e && _typeof(e) === 'object' && 'default' in e ? e : {
27
- 'default': e
28
- };
29
- }
30
- var React__default = /*#__PURE__*/_interopDefaultCompat(React);
31
-
32
- /** @LICENSE
33
- * @hi-ui/radio
34
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
35
- *
36
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
37
- *
38
- * This source code is licensed under the MIT license found in the
39
- * LICENSE file in the root directory of this source tree.
40
- */
41
- var RADIO_GROUP_PREFIX = classname.getPrefixCls('radio-group');
42
- /**
43
- * 单选组合器
44
- */
45
- var RadioGroup = /*#__PURE__*/React.forwardRef(function (_a, ref) {
46
- var _a$prefixCls = _a.prefixCls,
47
- prefixCls = _a$prefixCls === void 0 ? RADIO_GROUP_PREFIX : _a$prefixCls,
48
- className = _a.className,
49
- children = _a.children,
50
- data = _a.data,
51
- _a$type = _a.type,
52
- type = _a$type === void 0 ? types.RadioGroupTypeEnum.DEFAULT : _a$type,
53
- _a$placement = _a.placement,
54
- placement = _a$placement === void 0 ? types.RadioGroupPlacementEnum.HORIZONTAL : _a$placement,
55
- _a$autoWidth = _a.autoWidth,
56
- autoWidth = _a$autoWidth === void 0 ? false : _a$autoWidth,
57
- rest = tslib.__rest(_a, ["prefixCls", "className", "children", "data", "type", "placement", "autoWidth"]);
58
- var _useRadioGroup = useRadioGroup.useRadioGroup(rest),
59
- rootProps = _useRadioGroup.rootProps,
60
- name = _useRadioGroup.name,
61
- value = _useRadioGroup.value,
62
- onChange = _useRadioGroup.onChange,
63
- isChecked = _useRadioGroup.isChecked,
64
- disabled = _useRadioGroup.disabled;
65
- var providedValue = React.useMemo(function () {
66
- return {
67
- name: name,
68
- onChange: onChange,
69
- value: value,
70
- isChecked: isChecked,
71
- disabled: disabled,
72
- type: type,
73
- placement: placement
74
- };
75
- }, [name, onChange, value, isChecked, disabled, type, placement]);
76
- var hasData = typeAssertion.isArrayNonEmpty(data);
77
- // data 优先级大于内嵌式组合
78
- if (hasData) {
79
- children = data.map(function (_ref) {
80
- var id = _ref.id,
81
- disabled = _ref.disabled,
82
- title = _ref.title;
83
- return /*#__PURE__*/React__default["default"].createElement(Radio.Radio, {
84
- key: id,
85
- value: id,
86
- name: name,
87
- disabled: disabled,
88
- checked: isChecked(id),
89
- className: prefixCls + "__item"
90
- }, title);
91
- });
92
- }
93
- var cls = classname.cx(prefixCls, className, prefixCls + "--placement-" + placement, autoWidth && type === types.RadioGroupTypeEnum.BUTTON && prefixCls + "--auto-width", prefixCls + "--type-" + type, hasData && prefixCls + "--data-wrap");
94
- return /*#__PURE__*/React__default["default"].createElement(context.RadioGroupProvider, {
95
- value: providedValue
96
- }, /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
97
- ref: ref,
98
- className: cls
99
- }, rootProps), children));
100
- });
101
- if (env.__DEV__) {
102
- RadioGroup.displayName = 'RadioGroup';
103
- }
104
- exports.RadioGroup = RadioGroup;