@autobest-ui/components 2.0.3 → 2.0.5-alpha.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/esm/confirm/index.js +5 -0
- package/esm/select/index.d.ts +17 -0
- package/esm/select/index.js +86 -2
- package/esm/style.css +7 -7
- package/esm/table/body/BodyRow.js +1 -2
- package/esm/table/body/CheckIcon.d.ts +1 -1
- package/esm/table/body/CheckIcon.js +12 -2
- package/esm/table/body/index.d.ts +3 -2
- package/esm/table/body/index.js +7 -4
- package/esm/table/header/HeaderCell.js +8 -7
- package/esm/table/index.d.ts +19 -8
- package/esm/table/index.js +82 -21
- package/esm/table/style/index.css +1 -1
- package/esm/table/style/index.scss +11 -20
- package/lib/confirm/index.js +5 -0
- package/lib/select/index.d.ts +17 -0
- package/lib/select/index.js +85 -1
- package/lib/style.css +7 -7
- package/lib/table/body/BodyRow.js +1 -3
- package/lib/table/body/CheckIcon.d.ts +1 -1
- package/lib/table/body/CheckIcon.js +12 -2
- package/lib/table/body/index.d.ts +3 -2
- package/lib/table/body/index.js +8 -4
- package/lib/table/header/HeaderCell.js +9 -7
- package/lib/table/index.d.ts +19 -8
- package/lib/table/index.js +81 -20
- package/lib/table/style/index.css +1 -1
- package/lib/table/style/index.scss +11 -20
- package/package.json +2 -2
|
@@ -39,6 +39,10 @@ var __extends = void 0 && (void 0).__extends || function () {
|
|
|
39
39
|
};
|
|
40
40
|
}();
|
|
41
41
|
|
|
42
|
+
var rotate180Style = {
|
|
43
|
+
transform: 'rotate(180deg)'
|
|
44
|
+
};
|
|
45
|
+
|
|
42
46
|
var HeaderCell =
|
|
43
47
|
/** @class */
|
|
44
48
|
function (_super) {
|
|
@@ -75,9 +79,7 @@ function (_super) {
|
|
|
75
79
|
return /*#__PURE__*/_react.default.createElement("span", {
|
|
76
80
|
className: "".concat(prefixCls, "-arrow")
|
|
77
81
|
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
78
|
-
style: isSortedDescending ?
|
|
79
|
-
transform: 'rotate(180deg)'
|
|
80
|
-
} : null,
|
|
82
|
+
style: isSortedDescending ? rotate180Style : null,
|
|
81
83
|
viewBox: "0 0 1024 1024",
|
|
82
84
|
version: "1.1",
|
|
83
85
|
width: "1em",
|
|
@@ -102,11 +104,11 @@ function (_super) {
|
|
|
102
104
|
sortName = _b.sortName,
|
|
103
105
|
colSpan = _b.colSpan;
|
|
104
106
|
return /*#__PURE__*/_react.default.createElement("th", {
|
|
105
|
-
className: className,
|
|
106
|
-
colSpan: colSpan
|
|
107
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
108
|
-
className: (0, _classnames.default)("".concat(prefixCls, "-title"), (_a = {}, _a["".concat(prefixCls, "-point")] = sortName, _a)),
|
|
107
|
+
className: (0, _classnames.default)(className, (_a = {}, _a["".concat(prefixCls, "-point")] = sortName, _a)),
|
|
108
|
+
colSpan: colSpan,
|
|
109
109
|
onClick: this.onClick
|
|
110
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
111
|
+
className: "".concat(prefixCls, "-title")
|
|
110
112
|
}, title, this.renderArrow()));
|
|
111
113
|
};
|
|
112
114
|
|
package/lib/table/index.d.ts
CHANGED
|
@@ -22,12 +22,9 @@ export interface TableProps<T> extends Pick<HeaderRowProps<T>, 'sortName' | 'sor
|
|
|
22
22
|
* 具体类型见Column
|
|
23
23
|
*/
|
|
24
24
|
columns: TableColumnInfo<T>[];
|
|
25
|
-
/**
|
|
26
|
-
* 获取单条记录的唯一主键; 若是string类型,则取当前行数据中对应名称的属性值; 若是函数,则传入当前行数据,获取rowKey值;这也是勾选功能匹配时所用的key值
|
|
27
|
-
*/
|
|
28
|
-
rowKey?: string | ((rowData: T) => ReactText);
|
|
29
25
|
/**
|
|
30
26
|
* 是否固定表头
|
|
27
|
+
* 固定表头时,建议留一列不设置固定宽度,适应弹性布局
|
|
31
28
|
*/
|
|
32
29
|
fixedHeader?: boolean;
|
|
33
30
|
/**
|
|
@@ -38,6 +35,15 @@ export interface TableProps<T> extends Pick<HeaderRowProps<T>, 'sortName' | 'sor
|
|
|
38
35
|
* 为true时,Table会显示loading样式
|
|
39
36
|
*/
|
|
40
37
|
loading?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 获取单条记录的唯一主键; 若是string类型,则取当前行数据中对应名称的属性值; 若是函数,则传入当前行数据,获取rowKey值;这也是勾选功能匹配时所用的key值
|
|
40
|
+
* 默认取key属性
|
|
41
|
+
*/
|
|
42
|
+
rowKey?: string | BodyProps<T>['getRowKey'];
|
|
43
|
+
/**
|
|
44
|
+
* 获取单行className
|
|
45
|
+
*/
|
|
46
|
+
rowClassName?: (rowData: T, rowIndex: number) => string;
|
|
41
47
|
/**
|
|
42
48
|
* 表格行是否可勾选,详见RowSelection
|
|
43
49
|
*/
|
|
@@ -69,11 +75,14 @@ declare class Table<RowDataType> extends React.Component<TableProps<RowDataType>
|
|
|
69
75
|
headerRef: React.RefObject<HTMLDivElement>;
|
|
70
76
|
bodyRef: React.RefObject<HTMLDivElement>;
|
|
71
77
|
scrollHandler: AddListenerEventHandler;
|
|
72
|
-
getRowKey:
|
|
78
|
+
getRowKey: BodyProps<RowDataType>['getRowKey'];
|
|
79
|
+
resizeObserver: ResizeObserver;
|
|
80
|
+
scrollBarThAdded: boolean;
|
|
73
81
|
static defaultProps: {
|
|
74
82
|
fixedHeader: boolean;
|
|
75
83
|
loading: boolean;
|
|
76
84
|
rowKey: string;
|
|
85
|
+
rowClassName: () => string;
|
|
77
86
|
};
|
|
78
87
|
readonly defaultRowSelection: Pick<StateRowSelectionInfo<RowDataType>, 'selectAllVisible' | 'selectAllChecked' | 'getDisabled'>;
|
|
79
88
|
constructor(props: TableProps<RowDataType>);
|
|
@@ -83,7 +92,8 @@ declare class Table<RowDataType> extends React.Component<TableProps<RowDataType>
|
|
|
83
92
|
clearSelection: () => void;
|
|
84
93
|
componentDidMount(): void;
|
|
85
94
|
componentWillUnmount(): void;
|
|
86
|
-
|
|
95
|
+
headerScroll: (...arg: any[]) => void;
|
|
96
|
+
addListener: () => void;
|
|
87
97
|
getSelectedRows: (selectedKeys: any) => any;
|
|
88
98
|
/**
|
|
89
99
|
* 点击表头的checkbox,全选或全不选
|
|
@@ -93,11 +103,12 @@ declare class Table<RowDataType> extends React.Component<TableProps<RowDataType>
|
|
|
93
103
|
* 点击某一行的checkbook
|
|
94
104
|
* @param visible
|
|
95
105
|
* @param rowData
|
|
106
|
+
* @param rowIndex
|
|
96
107
|
*/
|
|
97
|
-
onSelect: (visible: boolean, rowData: RowDataType) => void;
|
|
108
|
+
onSelect: (visible: boolean, rowData: RowDataType, rowIndex: number) => void;
|
|
98
109
|
getDisabled: (rowData: any) => boolean;
|
|
99
110
|
getRowSelection: () => {
|
|
100
|
-
onSelect: (visible: boolean, rowData: RowDataType) => void;
|
|
111
|
+
onSelect: (visible: boolean, rowData: RowDataType, rowIndex: number) => void;
|
|
101
112
|
onSelectAll: (checked: any) => void;
|
|
102
113
|
getDisabled: (rowData: any) => boolean;
|
|
103
114
|
defaultSelectedRowKeys?: React.ReactText[];
|
package/lib/table/index.js
CHANGED
|
@@ -74,6 +74,7 @@ function (_super) {
|
|
|
74
74
|
_this.prefixCls = 'ab-table';
|
|
75
75
|
_this.headerRef = /*#__PURE__*/_react.default.createRef();
|
|
76
76
|
_this.bodyRef = /*#__PURE__*/_react.default.createRef();
|
|
77
|
+
_this.scrollBarThAdded = false;
|
|
77
78
|
_this.defaultRowSelection = {
|
|
78
79
|
selectAllVisible: true,
|
|
79
80
|
selectAllChecked: false,
|
|
@@ -97,15 +98,59 @@ function (_super) {
|
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
100
|
|
|
100
|
-
_this.
|
|
101
|
+
_this.headerScroll = (0, _utils.throttleWithRAF)(function () {
|
|
102
|
+
_this.headerRef.current.scrollLeft = _this.bodyRef.current.scrollLeft;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
_this.addListener = function () {
|
|
101
106
|
var fixedHeader = _this.props.fixedHeader;
|
|
102
|
-
var headerRef = _this.headerRef.current;
|
|
103
107
|
var bodyRef = _this.bodyRef.current;
|
|
104
108
|
|
|
105
|
-
if (fixedHeader && headerRef && bodyRef) {
|
|
106
|
-
_this.scrollHandler = (0, _utils.addEventListener)(bodyRef, 'scroll',
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
if (fixedHeader && _this.headerRef.current && bodyRef) {
|
|
110
|
+
_this.scrollHandler = (0, _utils.addEventListener)(bodyRef, 'scroll', _this.headerScroll);
|
|
111
|
+
_this.resizeObserver = new ResizeObserver(function (entries) {
|
|
112
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
113
|
+
var entry = entries_1[_i];
|
|
114
|
+
var ele = entry.target;
|
|
115
|
+
|
|
116
|
+
if (entry.contentBoxSize) {
|
|
117
|
+
var headerRef = _this.headerRef.current;
|
|
118
|
+
|
|
119
|
+
if (!headerRef) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (ele.scrollHeight > ele.clientHeight) {
|
|
124
|
+
if (_this.scrollBarThAdded) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var scrollBarTh = document.createElement('th'); // 显示滚动条的情况下,需要在thead追加一个与滚动条等宽的th
|
|
129
|
+
|
|
130
|
+
scrollBarTh.setAttribute('style', "width: ".concat((0, _utils.getScrollBarSize)(), "px; padding: 0"));
|
|
131
|
+
var tHeader = headerRef.querySelector('thead > tr');
|
|
132
|
+
|
|
133
|
+
if (tHeader) {
|
|
134
|
+
tHeader.appendChild(scrollBarTh);
|
|
135
|
+
_this.scrollBarThAdded = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (_this.scrollBarThAdded) {
|
|
142
|
+
// 删除thead追加了的与滚动条等宽的th
|
|
143
|
+
var scrollBarTh = headerRef.querySelector('thead > tr > th:last-child');
|
|
144
|
+
|
|
145
|
+
if (scrollBarTh) {
|
|
146
|
+
scrollBarTh.parentNode.removeChild(scrollBarTh);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
_this.resizeObserver.observe(bodyRef);
|
|
109
154
|
}
|
|
110
155
|
};
|
|
111
156
|
|
|
@@ -117,8 +162,8 @@ function (_super) {
|
|
|
117
162
|
var getRowKey = _this.getRowKey;
|
|
118
163
|
var dataSource = _this.props.dataSource;
|
|
119
164
|
return selectedKeys.map(function (key) {
|
|
120
|
-
return dataSource.find(function (item) {
|
|
121
|
-
return getRowKey(item) === key;
|
|
165
|
+
return dataSource.find(function (item, index) {
|
|
166
|
+
return getRowKey(item, index) === key;
|
|
122
167
|
});
|
|
123
168
|
});
|
|
124
169
|
};
|
|
@@ -177,10 +222,11 @@ function (_super) {
|
|
|
177
222
|
* 点击某一行的checkbook
|
|
178
223
|
* @param visible
|
|
179
224
|
* @param rowData
|
|
225
|
+
* @param rowIndex
|
|
180
226
|
*/
|
|
181
227
|
|
|
182
228
|
|
|
183
|
-
_this.onSelect = function (visible, rowData) {
|
|
229
|
+
_this.onSelect = function (visible, rowData, rowIndex) {
|
|
184
230
|
var getRowKey = _this.getRowKey;
|
|
185
231
|
var _a = _this.props,
|
|
186
232
|
dataSource = _a.dataSource,
|
|
@@ -188,7 +234,7 @@ function (_super) {
|
|
|
188
234
|
var _b = _this.state,
|
|
189
235
|
selectedRowKeys = _b.selectedRowKeys,
|
|
190
236
|
selectedRows = _b.selectedRows;
|
|
191
|
-
var newRowKey = getRowKey(rowData);
|
|
237
|
+
var newRowKey = getRowKey(rowData, rowIndex);
|
|
192
238
|
var newSelectedRowKeys = [];
|
|
193
239
|
var newSelectedRows = [];
|
|
194
240
|
|
|
@@ -203,8 +249,8 @@ function (_super) {
|
|
|
203
249
|
return previousValue;
|
|
204
250
|
}
|
|
205
251
|
|
|
206
|
-
var data = dataSource.find(function (item) {
|
|
207
|
-
return getRowKey(item) === currentValue;
|
|
252
|
+
var data = dataSource.find(function (item, index) {
|
|
253
|
+
return getRowKey(item, index) === currentValue;
|
|
208
254
|
});
|
|
209
255
|
|
|
210
256
|
if (data) {
|
|
@@ -280,7 +326,7 @@ function (_super) {
|
|
|
280
326
|
columns = _a.columns,
|
|
281
327
|
rowSelection = _a.rowSelection;
|
|
282
328
|
return /*#__PURE__*/_react.default.createElement("colgroup", null, rowSelection ? /*#__PURE__*/_react.default.createElement("col", {
|
|
283
|
-
|
|
329
|
+
className: "".concat(_this.prefixCls, "-checkbox-col")
|
|
284
330
|
}) : null, columns.map(function (item) {
|
|
285
331
|
var width = item.width;
|
|
286
332
|
|
|
@@ -327,7 +373,8 @@ function (_super) {
|
|
|
327
373
|
columns = _a.columns,
|
|
328
374
|
dataSource = _a.dataSource,
|
|
329
375
|
expandable = _a.expandable,
|
|
330
|
-
onRowClick = _a.onRowClick
|
|
376
|
+
onRowClick = _a.onRowClick,
|
|
377
|
+
rowClassName = _a.rowClassName;
|
|
331
378
|
var _b = _this.state,
|
|
332
379
|
rowSelection = _b.rowSelection,
|
|
333
380
|
selectedRowKeys = _b.selectedRowKeys;
|
|
@@ -339,7 +386,8 @@ function (_super) {
|
|
|
339
386
|
expandable: expandable,
|
|
340
387
|
rowSelection: rowSelection,
|
|
341
388
|
selectedRowKeys: selectedRowKeys,
|
|
342
|
-
onRowClick: onRowClick
|
|
389
|
+
onRowClick: onRowClick,
|
|
390
|
+
getRowClassName: rowClassName
|
|
343
391
|
}));
|
|
344
392
|
};
|
|
345
393
|
|
|
@@ -358,7 +406,7 @@ function (_super) {
|
|
|
358
406
|
}
|
|
359
407
|
|
|
360
408
|
Table.prototype.componentDidMount = function () {
|
|
361
|
-
this.
|
|
409
|
+
this.addListener();
|
|
362
410
|
};
|
|
363
411
|
|
|
364
412
|
Table.prototype.componentWillUnmount = function () {
|
|
@@ -366,6 +414,10 @@ function (_super) {
|
|
|
366
414
|
this.scrollHandler.remove();
|
|
367
415
|
this.scrollHandler = null;
|
|
368
416
|
}
|
|
417
|
+
|
|
418
|
+
if (this.resizeObserver && this.bodyRef.current) {
|
|
419
|
+
this.resizeObserver.unobserve(this.bodyRef.current);
|
|
420
|
+
}
|
|
369
421
|
};
|
|
370
422
|
|
|
371
423
|
Table.prototype.render = function () {
|
|
@@ -383,25 +435,34 @@ function (_super) {
|
|
|
383
435
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
384
436
|
className: "".concat(cls, "-header"),
|
|
385
437
|
ref: this.headerRef
|
|
386
|
-
}, /*#__PURE__*/_react.default.createElement("table",
|
|
438
|
+
}, /*#__PURE__*/_react.default.createElement("table", {
|
|
439
|
+
className: "".concat(cls, "-table")
|
|
440
|
+
}, this.renderColgroup(), this.renderHeader())), /*#__PURE__*/_react.default.createElement("div", {
|
|
387
441
|
className: "".concat(cls, "-body"),
|
|
388
442
|
style: {
|
|
389
443
|
maxHeight: maxHeight
|
|
390
444
|
},
|
|
391
445
|
ref: this.bodyRef
|
|
392
|
-
}, /*#__PURE__*/_react.default.createElement("table",
|
|
446
|
+
}, /*#__PURE__*/_react.default.createElement("table", {
|
|
447
|
+
className: "".concat(cls, "-table")
|
|
448
|
+
}, this.renderColgroup(), this.renderBody())));
|
|
393
449
|
}
|
|
394
450
|
|
|
395
451
|
return /*#__PURE__*/_react.default.createElement(_loadingContainer.default, {
|
|
396
452
|
loading: loading,
|
|
397
453
|
className: (0, _classnames.default)(className, cls)
|
|
398
|
-
}, /*#__PURE__*/_react.default.createElement("table",
|
|
454
|
+
}, /*#__PURE__*/_react.default.createElement("table", {
|
|
455
|
+
className: "".concat(cls, "-table")
|
|
456
|
+
}, this.renderColgroup(), this.renderHeader(), this.renderBody()));
|
|
399
457
|
};
|
|
400
458
|
|
|
401
459
|
Table.defaultProps = {
|
|
402
460
|
fixedHeader: false,
|
|
403
461
|
loading: false,
|
|
404
|
-
rowKey: 'key'
|
|
462
|
+
rowKey: 'key',
|
|
463
|
+
rowClassName: function rowClassName() {
|
|
464
|
+
return '';
|
|
465
|
+
}
|
|
405
466
|
};
|
|
406
467
|
return Table;
|
|
407
468
|
}(_react.default.Component);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.ab-table{overflow-x:auto}.ab-table
|
|
1
|
+
.ab-table{overflow-x:auto}.ab-table-table{border-spacing:0;width:100%;table-layout:fixed;border-collapse:collapse}.ab-table-header{overflow:hidden}.ab-table-body{overflow:auto}.ab-table-checkbox{width:.32rem;text-align:center}.ab-table-checkbox-col{width:.32rem}.ab-table-point{cursor:pointer}.ab-table-title{display:flex;align-items:center;text-align:left}.ab-table-arrow{font-size:.16rem;color:#fff;padding:0 .05rem}
|
|
@@ -3,22 +3,19 @@ $namespace: ab-table;
|
|
|
3
3
|
.#{$namespace} {
|
|
4
4
|
overflow-x: auto;
|
|
5
5
|
|
|
6
|
-
table {
|
|
6
|
+
&-table {
|
|
7
7
|
border-spacing: 0;
|
|
8
8
|
width: 100%;
|
|
9
9
|
table-layout: fixed;
|
|
10
|
+
border-collapse: collapse;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
&-header {
|
|
13
14
|
overflow: hidden;
|
|
14
|
-
|
|
15
|
-
table {
|
|
16
|
-
width: calc(100% - .17rem);
|
|
17
|
-
}
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
&-body {
|
|
21
|
-
overflow: auto
|
|
18
|
+
overflow: auto;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
&-checkbox {
|
|
@@ -26,14 +23,18 @@ $namespace: ab-table;
|
|
|
26
23
|
text-align: center;
|
|
27
24
|
}
|
|
28
25
|
|
|
26
|
+
&-checkbox-col {
|
|
27
|
+
width: .32rem;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&-point {
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
&-title {
|
|
30
35
|
display: flex;
|
|
31
36
|
align-items: center;
|
|
32
37
|
text-align: left;
|
|
33
|
-
|
|
34
|
-
&.#{$namespace}-point {
|
|
35
|
-
cursor: pointer;
|
|
36
|
-
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
&-arrow {
|
|
@@ -41,14 +42,4 @@ $namespace: ab-table;
|
|
|
41
42
|
color: #fff;
|
|
42
43
|
padding: 0 .05rem;
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@media only screen and (max-width: 767px) {
|
|
47
|
-
.#{$namespace} {
|
|
48
|
-
&-header {
|
|
49
|
-
table {
|
|
50
|
-
width: 100%;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobest-ui/components",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5-alpha.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "components common ui for React",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"react": ">=16.8.6",
|
|
47
47
|
"react-transition-group": ">=4.2.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "441d4fe1f371209bb8d981e5eb1c5e1c52237310"
|
|
50
50
|
}
|