@synerise/ds-scrollbar 0.4.11 → 0.5.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
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.5.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-scrollbar@0.4.7...@synerise/ds-scrollbar@0.5.0) (2022-08-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * **scrollbar:** creates common interface for old and new scrollbars ([ba9956f](https://github.com/Synerise/synerise-design/commit/ba9956f2a89ff9133da6b4c5a931142865e750e8))
12
+ * **scrollbar:** replace react-perfect-scrollbar by custom ([cd3b312](https://github.com/Synerise/synerise-design/commit/cd3b3121adb3d398f68a48d897db6825ee0cc8c1))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [0.4.7](https://github.com/Synerise/synerise-design/compare/@synerise/ds-scrollbar@0.4.6...@synerise/ds-scrollbar@0.4.7) (2022-03-30)
7
19
 
8
20
  **Note:** Version bump only for package @synerise/ds-scrollbar
package/README.md CHANGED
@@ -28,13 +28,14 @@ import Scrollbar from '@synerise/ds-scrollbar'
28
28
 
29
29
  ## API
30
30
 
31
- | Property | Description | Type | Default |
32
- | --------- | --------------------------------------------------------------------- | ------------------------ | ------- |
33
- | absolute | Whether the scrollbar is over content | boolean | `true` |
34
- | children | Scrolled component | React.ReactNode / string | - |
35
- | classes | String with optional classes | string | - |
31
+ | Property | Description | Type | Default |
32
+ |-----------|----------------------------------------------------------------------|--------------------------|---------|
33
+ | absolute | Whether the scrollbar is over content | boolean | `true` |
34
+ | children | Scrolled component | React.ReactNode / string | - |
35
+ | classes | String with optional classes | string | - |
36
36
  | fetchData | Callback called when scrollbar has been scrolled to the end in Y axis | () => void | - |
37
- | hasMore | Whether the scrollbar can calls fetchData | boolean | - |
38
- | loading | Whether the scrollbar shows loading icon | boolean | - |
39
- | maxHeight | Optional max-height value | string / number | - |
40
- | style | Additional styles for scrollbar wrapper | React.CSSProperties | - |
37
+ | hasMore | Whether the scrollbar can calls fetchData | boolean | - |
38
+ | loading | Whether the scrollbar shows loading icon | boolean | - |
39
+ | maxHeight | Optional max-height value | string / number | - |
40
+ | style | Additional styles for scrollbar wrapper | React.CSSProperties | - |
41
+ | withDnd | Whether use DndScrollbar or VirtualScrollbar component | boolean | false |
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import { ScrollbarProps } from '../Scrollbar.types';
3
+ export declare const DnDScrollbar: React.FC<ScrollbarProps>;
@@ -0,0 +1,187 @@
1
+ var _excluded = ["children", "classes", "maxHeight", "absolute", "loading", "onScroll", "onYReachEnd", "fetchData", "hasMore"];
2
+
3
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
+
5
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
+
7
+ import * as React from 'react';
8
+ import * as S from './DnDScrollbar.styles';
9
+ // eslint-disable-next-line import/prefer-default-export
10
+ export var DnDScrollbar = function DnDScrollbar(_ref) {
11
+ var children = _ref.children,
12
+ classes = _ref.classes,
13
+ maxHeight = _ref.maxHeight,
14
+ absolute = _ref.absolute,
15
+ loading = _ref.loading,
16
+ onScroll = _ref.onScroll,
17
+ onYReachEnd = _ref.onYReachEnd,
18
+ fetchData = _ref.fetchData,
19
+ hasMore = _ref.hasMore,
20
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
21
+
22
+ var contentRef = React.useRef(null);
23
+ var wrapperRef = React.useRef(null);
24
+ var scrollTrackRef = React.useRef(null);
25
+ var scrollThumbRef = React.useRef(null);
26
+ var observer = React.useRef(null);
27
+
28
+ var _React$useState = React.useState(48),
29
+ thumbHeight = _React$useState[0],
30
+ setThumbHeight = _React$useState[1];
31
+
32
+ var _React$useState2 = React.useState(0),
33
+ scrollStartPosition = _React$useState2[0],
34
+ setScrollStartPosition = _React$useState2[1];
35
+
36
+ var _React$useState3 = React.useState(0),
37
+ initialScrollTop = _React$useState3[0],
38
+ setInitialScrollTop = _React$useState3[1];
39
+
40
+ var _React$useState4 = React.useState(false),
41
+ isDragging = _React$useState4[0],
42
+ setIsDragging = _React$useState4[1];
43
+
44
+ var handleTrackClick = React.useCallback(function (e) {
45
+ e.preventDefault();
46
+ e.stopPropagation();
47
+ var trackCurrent = scrollTrackRef.current;
48
+ var contentCurrent = contentRef.current;
49
+
50
+ if (trackCurrent && contentCurrent) {
51
+ var clientY = e.clientY;
52
+ var target = e.target;
53
+ var rect = target.getBoundingClientRect();
54
+ var trackTop = rect.top;
55
+ var thumbOffset = -(thumbHeight / 2);
56
+ var clickRatio = (clientY - trackTop + thumbOffset) / trackCurrent.clientHeight;
57
+ var scrollAmount = Math.floor(clickRatio * contentCurrent.scrollHeight);
58
+ contentCurrent.scrollTo({
59
+ top: scrollAmount,
60
+ behavior: 'smooth'
61
+ });
62
+ }
63
+ }, [thumbHeight]);
64
+ var handleThumbPosition = React.useCallback(function () {
65
+ if (!contentRef.current || !scrollTrackRef.current || !scrollThumbRef.current) {
66
+ return;
67
+ }
68
+
69
+ var _contentRef$current = contentRef.current,
70
+ contentTop = _contentRef$current.scrollTop,
71
+ contentHeight = _contentRef$current.scrollHeight;
72
+ var trackHeight = scrollTrackRef.current.clientHeight;
73
+ var newTop = +contentTop / +contentHeight * trackHeight;
74
+ newTop = Math.min(newTop, trackHeight - thumbHeight);
75
+ var thumb = scrollThumbRef.current;
76
+ thumb.style.top = newTop + "px";
77
+ }, [thumbHeight]);
78
+ var handleThumbMousedown = React.useCallback(function (e) {
79
+ e.stopPropagation();
80
+ setScrollStartPosition(e.clientY);
81
+ if (contentRef.current) setInitialScrollTop(contentRef.current.scrollTop);
82
+ setIsDragging(true);
83
+ }, []);
84
+ var handleThumbMouseup = React.useCallback(function (e) {
85
+ e.stopPropagation();
86
+
87
+ if (isDragging) {
88
+ setIsDragging(false);
89
+ }
90
+ }, [isDragging]);
91
+ var handleThumbMousemove = React.useCallback(function (e) {
92
+ e.stopPropagation();
93
+
94
+ if (isDragging && contentRef.current !== null) {
95
+ var _contentRef$current2 = contentRef.current,
96
+ contentScrollHeight = _contentRef$current2.scrollHeight,
97
+ contentOffsetHeight = _contentRef$current2.offsetHeight;
98
+ var deltaY = (e.clientY - scrollStartPosition) * (contentOffsetHeight / thumbHeight);
99
+ contentRef.current.scrollTop = Math.min(initialScrollTop + deltaY, contentScrollHeight - contentOffsetHeight);
100
+ }
101
+ }, [initialScrollTop, isDragging, scrollStartPosition, thumbHeight]);
102
+ var handleScroll = React.useCallback(function (e) {
103
+ if (contentRef.current !== null) {
104
+ var _contentRef$current3 = contentRef.current,
105
+ scrollHeight = _contentRef$current3.scrollHeight,
106
+ offsetHeight = _contentRef$current3.offsetHeight,
107
+ scrollTop = _contentRef$current3.scrollTop;
108
+ var progress = Math.round((scrollTop + offsetHeight) / scrollHeight * 100) / 100;
109
+
110
+ if (progress === 1 && hasMore) {
111
+ onYReachEnd && onYReachEnd();
112
+ fetchData && fetchData();
113
+ }
114
+ }
115
+
116
+ onScroll && onScroll(e);
117
+ }, [fetchData, hasMore, onScroll, onYReachEnd]);
118
+ var handleResize = React.useCallback(function (trackSize) {
119
+ if (contentRef.current !== null) {
120
+ var _contentRef$current4 = contentRef.current,
121
+ clientHeightContent = _contentRef$current4.clientHeight,
122
+ scrollHeightContent = _contentRef$current4.scrollHeight;
123
+
124
+ if (clientHeightContent === scrollHeightContent) {
125
+ setThumbHeight(0);
126
+ } else {
127
+ setThumbHeight(Math.max(clientHeightContent / scrollHeightContent * trackSize, 48));
128
+ handleThumbPosition();
129
+ }
130
+ }
131
+ }, [handleThumbPosition]);
132
+ React.useEffect(function () {
133
+ if (contentRef.current !== null && scrollTrackRef.current !== null && wrapperRef.current !== null) {
134
+ var ref = wrapperRef.current;
135
+ var content = contentRef.current;
136
+ var trackSize = scrollTrackRef.current.clientHeight; // eslint-disable-next-line no-undef
137
+
138
+ observer.current = new ResizeObserver(function () {
139
+ handleResize(trackSize);
140
+ });
141
+ observer.current.observe(ref);
142
+ content.addEventListener('scroll', handleThumbPosition);
143
+ return function () {
144
+ if (observer.current !== null) {
145
+ observer.current.unobserve(ref);
146
+ }
147
+
148
+ content.removeEventListener('scroll', handleThumbPosition);
149
+ };
150
+ }
151
+
152
+ return undefined;
153
+ }, [handleResize, handleThumbPosition]);
154
+ React.useEffect(function () {
155
+ document.addEventListener('mousemove', handleThumbMousemove);
156
+ document.addEventListener('mouseup', handleThumbMouseup);
157
+ document.addEventListener('mouseleave', handleThumbMouseup);
158
+ return function () {
159
+ document.removeEventListener('mousemove', handleThumbMousemove);
160
+ document.removeEventListener('mouseup', handleThumbMouseup);
161
+ document.removeEventListener('mouseleave', handleThumbMouseup);
162
+ };
163
+ }, [handleThumbMousemove, handleThumbMouseup]);
164
+ return /*#__PURE__*/React.createElement(S.ScrollbarContainer, {
165
+ "data-testid": "dnd-scrollbar"
166
+ }, /*#__PURE__*/React.createElement(S.ScrollbarContent, _extends({
167
+ ref: contentRef
168
+ }, props, {
169
+ style: {
170
+ maxHeight: maxHeight
171
+ },
172
+ onScroll: handleScroll
173
+ }), /*#__PURE__*/React.createElement(S.ScrollbarWrapper, {
174
+ ref: wrapperRef,
175
+ loading: loading,
176
+ absolute: absolute
177
+ }, children)), /*#__PURE__*/React.createElement(S.ScrollbarTrackWrapper, null, /*#__PURE__*/React.createElement(S.TrackVertical, {
178
+ ref: scrollTrackRef,
179
+ onClick: handleTrackClick
180
+ }), /*#__PURE__*/React.createElement(S.ThumbVertical, {
181
+ ref: scrollThumbRef,
182
+ onMouseDown: handleThumbMousedown,
183
+ style: {
184
+ height: thumbHeight + "px"
185
+ }
186
+ })));
187
+ };
@@ -0,0 +1,12 @@
1
+ export declare const ScrollbarContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export declare const ScrollbarContent: import("styled-components").StyledComponent<"div", any, {}, never>;
3
+ export declare const ScrollbarWrapper: import("styled-components").StyledComponent<"div", any, {
4
+ absolute?: boolean | undefined;
5
+ loading?: boolean | undefined;
6
+ }, never>;
7
+ export declare const ScrollbarTrackWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
8
+ export declare const ThumbVertical: import("styled-components").StyledComponent<"div", any, {}, never>;
9
+ export declare const TrackVertical: import("styled-components").StyledComponent<"div", any, {}, never>;
10
+ export declare const Loader: import("styled-components").StyledComponent<"div", any, {
11
+ loading?: boolean | undefined;
12
+ }, never>;
@@ -0,0 +1,40 @@
1
+ import styled, { keyframes } from 'styled-components';
2
+ export var ScrollbarContainer = styled.div.withConfig({
3
+ displayName: "DnDScrollbarstyles__ScrollbarContainer",
4
+ componentId: "sc-12t6y2d-0"
5
+ })(["display:flex;height:100%;overflow:hidden;position:relative;"]);
6
+ export var ScrollbarContent = styled.div.withConfig({
7
+ displayName: "DnDScrollbarstyles__ScrollbarContent",
8
+ componentId: "sc-12t6y2d-1"
9
+ })(["-ms-overflow-style:none;overflow:auto;scrollbar-width:none;width:100%;&::-webkit-scrollbar{display:none;}"]);
10
+ export var ScrollbarWrapper = styled.div.withConfig({
11
+ displayName: "DnDScrollbarstyles__ScrollbarWrapper",
12
+ componentId: "sc-12t6y2d-2"
13
+ })(["padding-right:", ";& > *{opacity:", ";transition:all 0.25s ease-in-out;}"], function (props) {
14
+ return props.absolute ? '' : '11px !important';
15
+ }, function (props) {
16
+ return props.loading ? '0.2' : '1';
17
+ });
18
+ export var ScrollbarTrackWrapper = styled.div.withConfig({
19
+ displayName: "DnDScrollbarstyles__ScrollbarTrackWrapper",
20
+ componentId: "sc-12t6y2d-3"
21
+ })(["display:block;height:100%;position:absolute;width:11px;top:0;right:0;bottom:0;user-select:none;opacity:0.2;&:hover{opacity:0.6;}"]);
22
+ export var ThumbVertical = styled.div.withConfig({
23
+ displayName: "DnDScrollbarstyles__ThumbVertical",
24
+ componentId: "sc-12t6y2d-4"
25
+ })(["width:3px;background-color:#6a7580;border-radius:2px;right:4px;position:absolute;"]);
26
+ export var TrackVertical = styled.div.withConfig({
27
+ displayName: "DnDScrollbarstyles__TrackVertical",
28
+ componentId: "sc-12t6y2d-5"
29
+ })(["opacity:0.2;width:11px;height:calc(100% - 8px);transform:translateY(4px);overflow:hidden;right:0;top:0;bottom:0;position:absolute;&:hover,&:active,&:focus{opacity:0.6;}"]);
30
+ var spinnerAnimation = keyframes(["from{transform:rotateZ(0deg);}to{transform:rotateZ(360deg);}"]);
31
+ export var Loader = styled.div.withConfig({
32
+ displayName: "DnDScrollbarstyles__Loader",
33
+ componentId: "sc-12t6y2d-6"
34
+ })(["width:0;height:0;position:absolute;top:calc(50% - 12px);left:calc(50% - 12px);z-index:99;pointer-events:none;display:flex;opacity:", ";transform-origin:12px 12px;transition:opacity 0.3s ease-in-out;animation:", " 1s forwards linear infinite;svg{color:", ";fill:", ";}"], function (props) {
35
+ return props.loading ? '1' : '0';
36
+ }, spinnerAnimation, function (props) {
37
+ return props.theme.palette['blue-600'];
38
+ }, function (props) {
39
+ return props.theme.palette['blue-600'];
40
+ });
@@ -0,0 +1 @@
1
+ export * from './DnDScrollbar';
@@ -0,0 +1 @@
1
+ export * from './DnDScrollbar';
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import './style/index.less';
3
2
  import { ScrollbarProps } from './Scrollbar.types';
4
3
  declare const Scrollbar: React.ForwardRefExoticComponent<ScrollbarProps & React.RefAttributes<HTMLElement>>;
5
4
  export default Scrollbar;
package/dist/Scrollbar.js CHANGED
@@ -1,75 +1,28 @@
1
+ var _excluded = ["children", "loading", "withDnd", "fetchData"];
2
+
3
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
+
5
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
+
1
7
  import * as React from 'react';
2
- import PerfectScrollbar from 'react-perfect-scrollbar';
3
- import { useCombinedRefs } from '@synerise/ds-utils';
4
- import "./style/index.css";
5
8
  import Icon, { SpinnerM } from '@synerise/ds-icon';
6
9
  import * as S from './Scrollbar.styles';
10
+ import { DnDScrollbar } from './DnDScrollbar';
11
+ import { VirtualScrollbar } from './VirtualScrollbar';
7
12
  var Scrollbar = React.forwardRef(function (_ref, forwardedRef) {
8
- var _ref$absolute = _ref.absolute,
9
- absolute = _ref$absolute === void 0 ? false : _ref$absolute,
10
- children = _ref.children,
11
- classes = _ref.classes,
12
- hasMore = _ref.hasMore,
13
+ var children = _ref.children,
13
14
  loading = _ref.loading,
14
- maxHeight = _ref.maxHeight,
15
- style = _ref.style,
15
+ withDnd = _ref.withDnd,
16
16
  fetchData = _ref.fetchData,
17
- onScroll = _ref.onScroll,
18
- onYReachEnd = _ref.onYReachEnd;
19
- var scrollRef = React.useRef();
20
- var combinedScrollRef = useCombinedRefs(forwardedRef, scrollRef);
21
-
22
- var _React$useState = React.useState(0),
23
- lastScrollTop = _React$useState[0],
24
- setLastScrollTop = _React$useState[1];
25
-
26
- var handleReachEnd = React.useCallback(function (container) {
27
- var _combinedScrollRef$cu;
28
-
29
- if ((combinedScrollRef == null ? void 0 : (_combinedScrollRef$cu = combinedScrollRef.current) == null ? void 0 : _combinedScrollRef$cu.scrollTop) === lastScrollTop) {
30
- return;
31
- }
32
-
33
- combinedScrollRef.current && setLastScrollTop(combinedScrollRef.current.scrollTop);
34
-
35
- if (typeof onYReachEnd === 'function') {
36
- onYReachEnd(container);
37
- }
38
-
39
- if (!loading && hasMore && fetchData) {
40
- fetchData();
41
- }
42
- }, [loading, hasMore, lastScrollTop, fetchData, onYReachEnd, combinedScrollRef]);
43
- var handleScrollUp = React.useCallback(function () {
44
- var _combinedScrollRef$cu2;
17
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
45
18
 
46
- if ((combinedScrollRef == null ? void 0 : (_combinedScrollRef$cu2 = combinedScrollRef.current) == null ? void 0 : _combinedScrollRef$cu2.scrollTop) !== 0) {
47
- setLastScrollTop(0);
48
- }
49
- }, [combinedScrollRef]);
19
+ var Component = withDnd ? DnDScrollbar : VirtualScrollbar;
50
20
  var renderScrollbar = React.useMemo(function () {
51
- return /*#__PURE__*/React.createElement(PerfectScrollbar, {
52
- containerRef: function containerRef(ref) {
53
- combinedScrollRef.current = ref;
54
- } // workaround: https://github.com/goldenyz/react-perfect-scrollbar/issues/94#issuecomment-619131257
55
- ,
56
- onScroll: onScroll,
57
- onScrollUp: handleScrollUp,
58
- options: {
59
- minScrollbarLength: 48
60
- },
61
- onYReachEnd: handleReachEnd
62
- }, /*#__PURE__*/React.createElement(S.ScrollbarContent, {
63
- className: classes,
64
- style: {
65
- maxHeight: maxHeight
66
- }
67
- }, /*#__PURE__*/React.createElement(S.ScrollbarWrapper, {
68
- absolute: absolute,
69
- loading: loading,
70
- style: style
71
- }, children)));
72
- }, [onScroll, handleReachEnd, handleScrollUp, classes, maxHeight, absolute, loading, style, children, combinedScrollRef]);
21
+ return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
22
+ fetchData: fetchData,
23
+ ref: forwardedRef
24
+ }), children);
25
+ }, [children, fetchData, forwardedRef, props]);
73
26
  return fetchData ? /*#__PURE__*/React.createElement(S.ScrollbarContainer, null, renderScrollbar, loading && /*#__PURE__*/React.createElement(S.Loader, {
74
27
  loading: loading
75
28
  }, /*#__PURE__*/React.createElement(Icon, {
@@ -1,9 +1,4 @@
1
- export declare const ScrollbarContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
2
- export declare const ScrollbarContent: import("styled-components").StyledComponent<"div", any, {}, never>;
3
- export declare const ScrollbarWrapper: import("styled-components").StyledComponent<"div", any, {
4
- absolute?: boolean | undefined;
5
- loading?: boolean | undefined;
6
- }, never>;
7
1
  export declare const Loader: import("styled-components").StyledComponent<"div", any, {
8
2
  loading?: boolean | undefined;
9
3
  }, never>;
4
+ export declare const ScrollbarContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -1,28 +1,16 @@
1
1
  import styled, { keyframes } from 'styled-components';
2
- export var ScrollbarContainer = styled.div.withConfig({
3
- displayName: "Scrollbarstyles__ScrollbarContainer",
4
- componentId: "rfwkf7-0"
5
- })(["position:relative;height:100%;"]);
6
- export var ScrollbarContent = styled.div.withConfig({
7
- displayName: "Scrollbarstyles__ScrollbarContent",
8
- componentId: "rfwkf7-1"
9
- })([""]);
10
- export var ScrollbarWrapper = styled.div.withConfig({
11
- displayName: "Scrollbarstyles__ScrollbarWrapper",
12
- componentId: "rfwkf7-2"
13
- })(["padding-right:", ";& > *{opacity:", ";transition:all 0.25s ease-in-out;}"], function (props) {
14
- return props.absolute ? '' : '11px !important';
15
- }, function (props) {
16
- return props.loading ? '0.2' : '1';
17
- });
18
2
  var spinnerAnimation = keyframes(["from{transform:rotateZ(0deg);}to{transform:rotateZ(360deg);}"]);
19
3
  export var Loader = styled.div.withConfig({
20
4
  displayName: "Scrollbarstyles__Loader",
21
- componentId: "rfwkf7-3"
5
+ componentId: "rfwkf7-0"
22
6
  })(["width:0;height:0;position:absolute;top:calc(50% - 12px);left:calc(50% - 12px);z-index:99;pointer-events:none;display:flex;opacity:", ";transform-origin:12px 12px;transition:opacity 0.3s ease-in-out;animation:", " 1s forwards linear infinite;svg{color:", ";fill:", ";}"], function (props) {
23
7
  return props.loading ? '1' : '0';
24
8
  }, spinnerAnimation, function (props) {
25
9
  return props.theme.palette['blue-600'];
26
10
  }, function (props) {
27
11
  return props.theme.palette['blue-600'];
28
- });
12
+ });
13
+ export var ScrollbarContainer = styled.div.withConfig({
14
+ displayName: "Scrollbarstyles__ScrollbarContainer",
15
+ componentId: "rfwkf7-1"
16
+ })(["position:relative;height:100%;"]);
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { ScrollBarProps } from 'react-perfect-scrollbar';
3
2
  export declare type ScrollbarProps = {
4
3
  absolute?: boolean;
5
4
  children: React.ReactNode | string;
@@ -10,5 +9,6 @@ export declare type ScrollbarProps = {
10
9
  style?: React.CSSProperties;
11
10
  fetchData?: () => void;
12
11
  onScroll?: (e: React.UIEvent) => void;
13
- onYReachEnd?: ScrollBarProps['onYReachEnd'];
12
+ onYReachEnd?: () => void;
13
+ withDnd?: boolean;
14
14
  };
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import './style/index.less';
3
+ import { ScrollbarProps } from '../Scrollbar.types';
4
+ export declare const VirtualScrollbar: React.ForwardRefExoticComponent<ScrollbarProps & React.RefAttributes<HTMLElement>>;
@@ -0,0 +1,72 @@
1
+ import * as React from 'react';
2
+ import PerfectScrollbar from 'react-perfect-scrollbar';
3
+ import { useCombinedRefs } from '@synerise/ds-utils';
4
+ import "./style/index.css";
5
+ import * as S from './VirtualScrollbar.styles';
6
+ // eslint-disable-next-line import/prefer-default-export
7
+ export var VirtualScrollbar = React.forwardRef(function (_ref, forwardedRef) {
8
+ var _ref$absolute = _ref.absolute,
9
+ absolute = _ref$absolute === void 0 ? false : _ref$absolute,
10
+ children = _ref.children,
11
+ classes = _ref.classes,
12
+ hasMore = _ref.hasMore,
13
+ loading = _ref.loading,
14
+ maxHeight = _ref.maxHeight,
15
+ style = _ref.style,
16
+ fetchData = _ref.fetchData,
17
+ onScroll = _ref.onScroll,
18
+ onYReachEnd = _ref.onYReachEnd;
19
+ var scrollRef = React.useRef();
20
+ var combinedScrollRef = useCombinedRefs(forwardedRef, scrollRef);
21
+
22
+ var _React$useState = React.useState(0),
23
+ lastScrollTop = _React$useState[0],
24
+ setLastScrollTop = _React$useState[1];
25
+
26
+ var handleReachEnd = React.useCallback(function () {
27
+ var _combinedScrollRef$cu;
28
+
29
+ if ((combinedScrollRef == null ? void 0 : (_combinedScrollRef$cu = combinedScrollRef.current) == null ? void 0 : _combinedScrollRef$cu.scrollTop) === lastScrollTop) {
30
+ return;
31
+ }
32
+
33
+ combinedScrollRef.current && setLastScrollTop(combinedScrollRef.current.scrollTop);
34
+
35
+ if (typeof onYReachEnd === 'function') {
36
+ onYReachEnd();
37
+ }
38
+
39
+ if (!loading && hasMore && fetchData) {
40
+ fetchData();
41
+ }
42
+ }, [loading, hasMore, lastScrollTop, fetchData, onYReachEnd, combinedScrollRef]);
43
+ var handleScrollUp = React.useCallback(function () {
44
+ var _combinedScrollRef$cu2;
45
+
46
+ if ((combinedScrollRef == null ? void 0 : (_combinedScrollRef$cu2 = combinedScrollRef.current) == null ? void 0 : _combinedScrollRef$cu2.scrollTop) !== 0) {
47
+ setLastScrollTop(0);
48
+ }
49
+ }, [combinedScrollRef]);
50
+ return /*#__PURE__*/React.createElement(PerfectScrollbar, {
51
+ containerRef: function containerRef(ref) {
52
+ combinedScrollRef.current = ref;
53
+ } // workaround: https://github.com/goldenyz/react-perfect-scrollbar/issues/94#issuecomment-619131257
54
+ ,
55
+ onScroll: onScroll,
56
+ onScrollUp: handleScrollUp,
57
+ options: {
58
+ minScrollbarLength: 48
59
+ },
60
+ onYReachEnd: handleReachEnd
61
+ }, /*#__PURE__*/React.createElement(S.ScrollbarContent, {
62
+ className: classes,
63
+ style: {
64
+ maxHeight: maxHeight
65
+ },
66
+ "data-testid": "virtual-scrollbar"
67
+ }, /*#__PURE__*/React.createElement(S.ScrollbarWrapper, {
68
+ absolute: absolute,
69
+ loading: loading,
70
+ style: style
71
+ }, children)));
72
+ });
@@ -0,0 +1,5 @@
1
+ export declare const ScrollbarContent: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export declare const ScrollbarWrapper: import("styled-components").StyledComponent<"div", any, {
3
+ absolute?: boolean | undefined;
4
+ loading?: boolean | undefined;
5
+ }, never>;
@@ -0,0 +1,13 @@
1
+ import styled from 'styled-components';
2
+ export var ScrollbarContent = styled.div.withConfig({
3
+ displayName: "VirtualScrollbarstyles__ScrollbarContent",
4
+ componentId: "hoiad9-0"
5
+ })([""]);
6
+ export var ScrollbarWrapper = styled.div.withConfig({
7
+ displayName: "VirtualScrollbarstyles__ScrollbarWrapper",
8
+ componentId: "hoiad9-1"
9
+ })(["padding-right:", ";& > *{opacity:", ";transition:all 0.25s ease-in-out;}"], function (props) {
10
+ return props.absolute ? '' : '11px !important';
11
+ }, function (props) {
12
+ return props.loading ? '0.2' : '1';
13
+ });
@@ -0,0 +1 @@
1
+ export * from './VirtualScrollbar';
@@ -0,0 +1 @@
1
+ export * from './VirtualScrollbar';
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-scrollbar",
3
- "version": "0.4.11",
3
+ "version": "0.5.0",
4
4
  "description": "Scrollbar UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "types": "dist/index.d.ts",
34
34
  "dependencies": {
35
- "@synerise/ds-icon": "^0.49.0",
35
+ "@synerise/ds-icon": "^0.49.5",
36
36
  "react-perfect-scrollbar": "^1.5.8"
37
37
  },
38
38
  "peerDependencies": {
@@ -40,7 +40,8 @@
40
40
  "react": ">=16.9.0 < 17.0.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@synerise/ds-utils": "^0.19.0"
43
+ "@synerise/ds-utils": "^0.19.0",
44
+ "@types/resize-observer-browser": "^0.1.7"
44
45
  },
45
- "gitHead": "1ff23a390382403be15699d1963ad8f6c26e5ba6"
46
+ "gitHead": "a95bdd142863a7e132acf2cc4bf66e247d06a26c"
46
47
  }