@capillarytech/blaze-ui 0.1.4-alpha.11 → 0.1.4-alpha.12

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * CapTable - Migrated to Ant Design v5
3
3
  */
4
- import React, { useCallback } from 'react';
4
+ import React, { useEffect, useRef, useCallback } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { throttle } from 'lodash';
7
7
  import { Table } from 'antd';
@@ -16,6 +16,22 @@ const StyledTable = styled(Table)`
16
16
  border: 1px solid ${CAP_G07};
17
17
  }
18
18
  }
19
+
20
+ &.show-loader {
21
+ .ant-table-body > table > tbody::after {
22
+ content: '${(props) => props.loadMoreData}';
23
+ display: flex;
24
+ justify-content: center;
25
+ position: absolute;
26
+ width: 100%;
27
+ align-items: center;
28
+ height: 60px;
29
+ text-align: center;
30
+ font-size: 16px;
31
+ color: gray;
32
+ border-top: 1px solid ${CAP_G07};
33
+ }
34
+ }
19
35
  `;
20
36
 
21
37
  const CapTable = ({
@@ -31,34 +47,90 @@ const CapTable = ({
31
47
  showLoader,
32
48
  ...rest
33
49
  }) => {
34
- // Throttled scroll handler using Ant Design's onScroll
35
- const onScroll = useCallback(
36
- throttle(({ target }) => {
37
- if (!infinteScroll || showLoader) return;
50
+ const setPaginationCalled = useRef(false);
51
+ const onScrollThrottle = useRef(
52
+ throttle((event) => {
53
+ const maxScroll = event.target.scrollHeight - event.target.clientHeight;
54
+ const currentScroll = event.target.scrollTop;
38
55
 
39
- const { scrollHeight, scrollTop, clientHeight } = target;
40
- const maxScroll = scrollHeight - clientHeight;
41
-
42
- if (scrollTop >= maxScroll - 10) {
56
+ if (currentScroll >= maxScroll - 10 && !showLoader) {
43
57
  const offsetLimit = { ...offset_limit };
44
58
  offsetLimit.offset += offsetLimit.limit;
45
59
  setPagination?.(offsetLimit);
46
60
  }
47
61
  }, 50),
48
- [infinteScroll, showLoader, offset_limit, setPagination],
49
- );
62
+ ).current;
63
+
64
+ const addScrollEventListener = useCallback(() => {
65
+ const listTable = document.querySelector(`#${id} div.ant-table-body`);
66
+ if (listTable) {
67
+ listTable.addEventListener('scroll', onScrollThrottle);
68
+ }
69
+ }, [id, onScrollThrottle]);
70
+
71
+ const callSetPaginationIfNotOverflow = useCallback(() => {
72
+ const yscrollheight = scroll?.y || 0;
73
+ const listTable = document.querySelector(`#${id} div.ant-table-body`);
74
+ let isOverflow = false;
75
+
76
+ if (yscrollheight && yscrollheight < listTable?.scrollHeight) {
77
+ isOverflow = true;
78
+ }
79
+
80
+ if (!isOverflow && setPagination && dataSource?.length > 0) {
81
+ setPaginationCalled.current = true;
82
+ const offsetLimit = { ...offset_limit };
83
+ offsetLimit.offset += offsetLimit.limit;
84
+ setPagination(offsetLimit);
85
+ }
86
+ }, [id, scroll?.y, setPagination, dataSource, offset_limit]);
87
+
88
+ useEffect(() => {
89
+ const limit = offset_limit?.limit || 10;
90
+ if (infinteScroll) {
91
+ addScrollEventListener();
92
+ if (dataSource?.length >= limit) {
93
+ callSetPaginationIfNotOverflow();
94
+ }
95
+ }
96
+
97
+ return () => {
98
+ const listTable = document.querySelector(`#${id} div.ant-table-body`);
99
+ if (listTable) {
100
+ listTable.removeEventListener('scroll', onScrollThrottle);
101
+ }
102
+ };
103
+ }, [
104
+ infinteScroll,
105
+ dataSource,
106
+ offset_limit,
107
+ addScrollEventListener,
108
+ callSetPaginationIfNotOverflow,
109
+ id,
110
+ onScrollThrottle,
111
+ ]);
112
+
113
+ useEffect(() => {
114
+ const limit = offset_limit?.limit || 10;
115
+ if (
116
+ !setPaginationCalled.current &&
117
+ infinteScroll &&
118
+ dataSource?.length >= limit
119
+ ) {
120
+ callSetPaginationIfNotOverflow();
121
+ }
122
+ }, [infinteScroll, dataSource, offset_limit, callSetPaginationIfNotOverflow]);
50
123
 
51
124
  return (
52
125
  <StyledTable
53
126
  {...rest}
54
127
  id={id}
55
128
  dataSource={dataSource}
56
- scroll={{ ...scroll, y: scroll?.y || 400 }}
129
+ scroll={scroll}
57
130
  pagination={infinteScroll ? false : pagination}
58
- className={classNames('cap-table-v2', className)}
59
- loading={showLoader}
60
- virtual={infinteScroll}
61
- onScroll={onScroll}
131
+ className={classNames('cap-table-v2', className, {
132
+ 'show-loader': showLoader,
133
+ })}
62
134
  />
63
135
  );
64
136
  };
@@ -11,7 +11,7 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
11
11
  /**
12
12
  * CapTable - Migrated to Ant Design v5
13
13
  */
14
- import React, { useCallback } from 'react';
14
+ import React, { useEffect, useRef, useCallback } from 'react';
15
15
  import PropTypes from 'prop-types';
16
16
  import { throttle } from 'lodash';
17
17
  import { Table } from 'antd';
@@ -22,7 +22,9 @@ import LocaleHoc from '../LocaleHoc';
22
22
  var StyledTable = styled(Table).withConfig({
23
23
  displayName: "StyledTable",
24
24
  componentId: "sc-o01z1q-0"
25
- })(["&.cap-table-v2{.ant-table{border:1px solid ", ";}}"], CAP_G07);
25
+ })(["&.cap-table-v2{.ant-table{border:1px solid ", ";}}&.show-loader{.ant-table-body > table > tbody::after{content:'", "';display:flex;justify-content:center;position:absolute;width:100%;align-items:center;height:60px;text-align:center;font-size:16px;color:gray;border-top:1px solid ", ";}}"], CAP_G07, function (props) {
26
+ return props.loadMoreData;
27
+ }, CAP_G07);
26
28
  var CapTable = function CapTable(_ref) {
27
29
  var id = _ref.id,
28
30
  className = _ref.className,
@@ -35,31 +37,65 @@ var CapTable = function CapTable(_ref) {
35
37
  scroll = _ref.scroll,
36
38
  showLoader = _ref.showLoader,
37
39
  rest = _objectWithoutProperties(_ref, _excluded);
38
- // Throttled scroll handler using Ant Design's onScroll
39
- var onScroll = useCallback(throttle(function (_ref2) {
40
- var target = _ref2.target;
41
- if (!infinteScroll || showLoader) return;
42
- var scrollHeight = target.scrollHeight,
43
- scrollTop = target.scrollTop,
44
- clientHeight = target.clientHeight;
45
- var maxScroll = scrollHeight - clientHeight;
46
- if (scrollTop >= maxScroll - 10) {
40
+ var setPaginationCalled = useRef(false);
41
+ var onScrollThrottle = useRef(throttle(function (event) {
42
+ var maxScroll = event.target.scrollHeight - event.target.clientHeight;
43
+ var currentScroll = event.target.scrollTop;
44
+ if (currentScroll >= maxScroll - 10 && !showLoader) {
47
45
  var offsetLimit = _objectSpread({}, offset_limit);
48
46
  offsetLimit.offset += offsetLimit.limit;
49
47
  setPagination === null || setPagination === void 0 ? void 0 : setPagination(offsetLimit);
50
48
  }
51
- }, 50), [infinteScroll, showLoader, offset_limit, setPagination]);
49
+ }, 50)).current;
50
+ var addScrollEventListener = useCallback(function () {
51
+ var listTable = document.querySelector("#".concat(id, " div.ant-table-body"));
52
+ if (listTable) {
53
+ listTable.addEventListener('scroll', onScrollThrottle);
54
+ }
55
+ }, [id, onScrollThrottle]);
56
+ var callSetPaginationIfNotOverflow = useCallback(function () {
57
+ var yscrollheight = (scroll === null || scroll === void 0 ? void 0 : scroll.y) || 0;
58
+ var listTable = document.querySelector("#".concat(id, " div.ant-table-body"));
59
+ var isOverflow = false;
60
+ if (yscrollheight && yscrollheight < (listTable === null || listTable === void 0 ? void 0 : listTable.scrollHeight)) {
61
+ isOverflow = true;
62
+ }
63
+ if (!isOverflow && setPagination && (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) > 0) {
64
+ setPaginationCalled.current = true;
65
+ var offsetLimit = _objectSpread({}, offset_limit);
66
+ offsetLimit.offset += offsetLimit.limit;
67
+ setPagination(offsetLimit);
68
+ }
69
+ }, [id, scroll === null || scroll === void 0 ? void 0 : scroll.y, setPagination, dataSource, offset_limit]);
70
+ useEffect(function () {
71
+ var limit = (offset_limit === null || offset_limit === void 0 ? void 0 : offset_limit.limit) || 10;
72
+ if (infinteScroll) {
73
+ addScrollEventListener();
74
+ if ((dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) >= limit) {
75
+ callSetPaginationIfNotOverflow();
76
+ }
77
+ }
78
+ return function () {
79
+ var listTable = document.querySelector("#".concat(id, " div.ant-table-body"));
80
+ if (listTable) {
81
+ listTable.removeEventListener('scroll', onScrollThrottle);
82
+ }
83
+ };
84
+ }, [infinteScroll, dataSource, offset_limit, addScrollEventListener, callSetPaginationIfNotOverflow, id, onScrollThrottle]);
85
+ useEffect(function () {
86
+ var limit = (offset_limit === null || offset_limit === void 0 ? void 0 : offset_limit.limit) || 10;
87
+ if (!setPaginationCalled.current && infinteScroll && (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) >= limit) {
88
+ callSetPaginationIfNotOverflow();
89
+ }
90
+ }, [infinteScroll, dataSource, offset_limit, callSetPaginationIfNotOverflow]);
52
91
  return /*#__PURE__*/React.createElement(StyledTable, _extends({}, rest, {
53
92
  id: id,
54
93
  dataSource: dataSource,
55
- scroll: _objectSpread(_objectSpread({}, scroll), {}, {
56
- y: (scroll === null || scroll === void 0 ? void 0 : scroll.y) || 400
57
- }),
94
+ scroll: scroll,
58
95
  pagination: infinteScroll ? false : pagination,
59
- className: classNames('cap-table-v2', className),
60
- loading: showLoader,
61
- virtual: infinteScroll,
62
- onScroll: onScroll
96
+ className: classNames('cap-table-v2', className, {
97
+ 'show-loader': showLoader
98
+ })
63
99
  }));
64
100
  };
65
101
  CapTable.propTypes = {