bhd-components 0.2.9 → 0.3.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.
|
@@ -74,6 +74,7 @@ var getParentWidth = function(node) {
|
|
|
74
74
|
};
|
|
75
75
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
76
76
|
//传入的参数为onCell==>需要进行函数合并
|
|
77
|
+
/* 记录的滚动条宽度 */ var recordScrollBarWidth = 0;
|
|
77
78
|
var Table = function(props) {
|
|
78
79
|
var tableRef = useRef(null);
|
|
79
80
|
var timerRef = useRef({
|
|
@@ -90,8 +91,8 @@ var Table = function(props) {
|
|
|
90
91
|
var initColumns = function() {
|
|
91
92
|
var scrollBarDom = tableRef.current.getElementsByClassName("bhd-table-cell-scrollbar")[0];
|
|
92
93
|
var scrollBarWidth = scrollBarDom ? scrollBarDom.clientWidth : 0;
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
recordScrollBarWidth = scrollBarWidth || recordScrollBarWidth;
|
|
95
|
+
var tableWidth = bordered ? tableRef.current.offsetWidth - 2 - recordScrollBarWidth : tableRef.current.offsetWidth - recordScrollBarWidth;
|
|
95
96
|
var _initColumnsWidth = initColumnsWidth(props.columns, tableWidth), selfColumns = _initColumnsWidth.columns;
|
|
96
97
|
setColumns(selfColumns);
|
|
97
98
|
var obj = scrollObject ? scrollObject : {};
|
|
@@ -240,6 +241,11 @@ var Table = function(props) {
|
|
|
240
241
|
}, [
|
|
241
242
|
props.columns
|
|
242
243
|
]);
|
|
244
|
+
useEffect(function() {
|
|
245
|
+
setScrollObject(props.scroll || undefined);
|
|
246
|
+
}, [
|
|
247
|
+
props.scroll
|
|
248
|
+
]);
|
|
243
249
|
var config = _object_spread_props(_object_spread({
|
|
244
250
|
bordered: false
|
|
245
251
|
}, props), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as t,j as e,a as n,b as
|
|
1
|
+
import{_ as t,j as e,a as n,b as i,T as o,c as r}from"./ae211df8.esm.es5.production.js";import{useState as l,useRef as a,useEffect as d}from"react";import"react/jsx-runtime";import"react-dom";var u={Table:"index_module_Table__5278674b",SmallTable:"index_module_SmallTable__5278674b",columnTootipClassName:"index_module_columnTootipClassName__5278674b"},c=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:14,n=0,i=document.createElement("div");return i.style.position="absolute",i.style.whiteSpace="nowrap",i.style.fontSize=e+"px",i.style.opacity="0",i.innerText=t,document.body.append(i),n=i.getBoundingClientRect().width,document.body.removeChild(i),n},s=function(r){var a=r.children,d=r.title,u=r.width,s=t(l(!1),2),m=s[0],h=s[1];return e(o,n(i({},r),{open:m,children:e("span",{onMouseEnter:function(t){var e=0;(e="function"==typeof u?u(t):u)?h(!(c(d)<e)):h(!0)},onMouseLeave:function(){h(!1)},children:a})}))},m=/^\d+%$/,h=/^\d+px$/,w=function(t){var e={};return parseFloat((e=window.getComputedStyle?getComputedStyle(t,null):t.currentStyle)["padding-left"])+parseFloat(e["padding-right"])},f=function(t){try{for(;t&&"TD"!==t.nodeName;)t=t.parentElement;var e=w(t);return t.clientWidth-e}catch(t){return null}},p=0,C=function(o){var c=a(null),w=a({timer:null}),C=o.defaultWidthRang,v=void 0===C?[180,240,320]:C,T=o.isFixedLeft,g=void 0===T||T,E=o.isFixedRight,N=void 0===E||E,_=o.bordered,y=void 0!==_&&_,b=o.kind,L=t(l(o.columns||[]),2),x=L[0],S=L[1],R=t(l(o.scroll||void 0),2),O=R[0],F=R[1],I=o.columnTootipClassName,W=o.columnTootipColor,M=function(){var t=c.current.getElementsByClassName("bhd-table-cell-scrollbar")[0];p=(t?t.clientWidth:0)||p;var e=y?c.current.offsetWidth-2-p:c.current.offsetWidth-p,r=A(o.columns,e).columns;S(r);var l=O||{};l=n(i({},l),{x:e}),F(l)},A=function(t,o){var r=0,l=0,a=0;t=t.map(function(t){return t.width=t.width||"auto",m.test(t.width)?t.width=parseFloat(t.width)>=100?"auto":o*parseFloat(t.width)/100:"number"==typeof t.width?t.width=t.width:h.test(t.width)?t.width=parseFloat(t.width):t.width="auto","auto"===t.width?(r+=1,t.widthRang||(t.widthRang=v),l+=t.widthRang[0],a+=t.widthRang[1]):(l+=t.width,a+=t.width),t.onColumnCell||(t.onColumnCell=t.onCell||function(){return{}}),t.render||(t.ellipsis={showTitle:!1},t.render=function(t){return e(s,{width:function(t){return f(t.target)},title:t,trigger:"hover",overlayClassName:I||u.columnTootipClassName,color:W||"#FFF",children:e("span",{children:t})})}),t});var d=o-l;if(d>0){var c=0;t=(t=t.map(function(t){return"auto"===t.width&&(t.width=t.widthRang[0]+d/r,t.width>t.widthRang[2]&&(c+=t.width-t.widthRang[2],t.width=t.widthRang[2])),t})).map(function(e,n){return c>0&&n!==t.length-1&&(e.width+=c/t.length-1),e})}else t=d<0?t.map(function(e,n){return g&&0===n&&(e.fixed="left"),N&&n===t.length-1&&(e.fixed="right"),"auto"===e.width&&(e.width=e.widthRang[1]),e}):t.map(function(t){return"auto"===t.width&&(t.width=t.widthRang[0]),t});return t.map(function(t){return t.onCell=function(e,o){var r="function"==typeof t.onColumnCell?t.onColumnCell(e,o):{};return r.style=r.style?r.style:{},n(i({},r),{style:i({maxWidth:t.width+"px"},r.style)})},t}),{columns:t,scrollWidth:a}},U=function(){clearTimeout(w.current.timer),w.current.timer=setTimeout(function(){M()},1e3)};d(function(){return M(),window.addEventListener("resize",U),function(){clearTimeout(w.current.timer),window.removeEventListener("resize",U)}},[o.columns]),d(function(){F(o.scroll||void 0)},[o.scroll]);var j=n(i({bordered:!1},o),{columns:x,scroll:O||{x:"auto"}});return e("div",{className:"".concat(u.Table," ").concat("simple"===b?u.SmallTable:""),ref:c,children:e(r,i({},j))})};C.SELECTION_COLUMN=r.SELECTION_COLUMN,C.EXPAND_COLUMN=r.EXPAND_COLUMN,C.SELECTION_ALL=r.SELECTION_ALL,C.SELECTION_INVERT=r.SELECTION_INVERT,C.SELECTION_NONE=r.SELECTION_NONE,C.Column=r.Column,C.ColumnGroup=r.ColumnGroup;export{C as default};
|
package/es2017/table/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const getParentWidth = (node)=>{
|
|
|
31
31
|
};
|
|
32
32
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
33
33
|
//传入的参数为onCell==>需要进行函数合并
|
|
34
|
+
/* 记录的滚动条宽度 */ let recordScrollBarWidth = 0;
|
|
34
35
|
const Table = (props)=>{
|
|
35
36
|
const tableRef = useRef(null);
|
|
36
37
|
const timerRef = useRef({
|
|
@@ -47,8 +48,8 @@ const Table = (props)=>{
|
|
|
47
48
|
const initColumns = ()=>{
|
|
48
49
|
let scrollBarDom = tableRef.current.getElementsByClassName("bhd-table-cell-scrollbar")[0];
|
|
49
50
|
const scrollBarWidth = scrollBarDom ? scrollBarDom.clientWidth : 0;
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
recordScrollBarWidth = scrollBarWidth || recordScrollBarWidth;
|
|
52
|
+
const tableWidth = bordered ? tableRef.current.offsetWidth - 2 - recordScrollBarWidth : tableRef.current.offsetWidth - recordScrollBarWidth;
|
|
52
53
|
let { columns: selfColumns } = initColumnsWidth(props.columns, tableWidth);
|
|
53
54
|
setColumns(selfColumns);
|
|
54
55
|
let obj = scrollObject ? scrollObject : {};
|
|
@@ -193,6 +194,11 @@ const Table = (props)=>{
|
|
|
193
194
|
}, [
|
|
194
195
|
props.columns
|
|
195
196
|
]);
|
|
197
|
+
useEffect(()=>{
|
|
198
|
+
setScrollObject(props.scroll || undefined);
|
|
199
|
+
}, [
|
|
200
|
+
props.scroll
|
|
201
|
+
]);
|
|
196
202
|
let config = _object_spread_props(_object_spread({
|
|
197
203
|
bordered: false
|
|
198
204
|
}, props), {
|
|
@@ -202,7 +208,7 @@ const Table = (props)=>{
|
|
|
202
208
|
}
|
|
203
209
|
});
|
|
204
210
|
return /*#__PURE__*/ _jsx("div", {
|
|
205
|
-
className: `${styles.Table} ${kind === "simple" ? styles.SmallTable :
|
|
211
|
+
className: `${styles.Table} ${kind === "simple" ? styles.SmallTable : ""}`,
|
|
206
212
|
ref: tableRef,
|
|
207
213
|
children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
|
|
208
214
|
});
|
package/esm/table/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var getParentWidth = function(node) {
|
|
|
32
32
|
};
|
|
33
33
|
// const defaultWidthRang: widthRangType = [180, 240, 320]; //默认自适应的值 [最小值,最佳值,最大值]
|
|
34
34
|
//传入的参数为onCell==>需要进行函数合并
|
|
35
|
+
/* 记录的滚动条宽度 */ var recordScrollBarWidth = 0;
|
|
35
36
|
var Table = function(props) {
|
|
36
37
|
var tableRef = useRef(null);
|
|
37
38
|
var timerRef = useRef({
|
|
@@ -48,8 +49,8 @@ var Table = function(props) {
|
|
|
48
49
|
var initColumns = function() {
|
|
49
50
|
var scrollBarDom = tableRef.current.getElementsByClassName("bhd-table-cell-scrollbar")[0];
|
|
50
51
|
var scrollBarWidth = scrollBarDom ? scrollBarDom.clientWidth : 0;
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
recordScrollBarWidth = scrollBarWidth || recordScrollBarWidth;
|
|
53
|
+
var tableWidth = bordered ? tableRef.current.offsetWidth - 2 - recordScrollBarWidth : tableRef.current.offsetWidth - recordScrollBarWidth;
|
|
53
54
|
var _initColumnsWidth = initColumnsWidth(props.columns, tableWidth), selfColumns = _initColumnsWidth.columns;
|
|
54
55
|
setColumns(selfColumns);
|
|
55
56
|
var obj = scrollObject ? scrollObject : {};
|
|
@@ -198,6 +199,11 @@ var Table = function(props) {
|
|
|
198
199
|
}, [
|
|
199
200
|
props.columns
|
|
200
201
|
]);
|
|
202
|
+
useEffect(function() {
|
|
203
|
+
setScrollObject(props.scroll || undefined);
|
|
204
|
+
}, [
|
|
205
|
+
props.scroll
|
|
206
|
+
]);
|
|
201
207
|
var config = _object_spread_props(_object_spread({
|
|
202
208
|
bordered: false
|
|
203
209
|
}, props), {
|