@councilbox/councilbox-ui 2.0.55 → 2.0.56

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.
Files changed (48) hide show
  1. package/ScrollbarOld.js +3 -0
  2. package/dist/HOCs/usePopoverPosition.js +2 -0
  3. package/dist/build-index.js +3 -3
  4. package/dist/components/1.Introduction.stories.mdx +1 -1
  5. package/dist/components/2.Changelog.stories.mdx +12 -1
  6. package/dist/components/Button/Button.js +15 -0
  7. package/dist/components/ButtonBasic/ButtonBasic.js +15 -0
  8. package/dist/components/Checkbox/Checkbox.js +2 -2
  9. package/dist/components/DatePicker/DatePicker.js +105 -24
  10. package/dist/components/DatePicker/dateUtils.js +62 -15
  11. package/dist/components/DateRangePicker/DateRangePicker.js +134 -39
  12. package/dist/components/DateTimePicker/DateTimePicker.js +99 -39
  13. package/dist/components/DragDrop/DragDrop.js +17 -4
  14. package/dist/components/Header/Header.js +104 -17
  15. package/dist/components/InputAutocomplete/InputAutocomplete.js +15 -0
  16. package/dist/components/InputPassword/InputPassword.js +14 -1
  17. package/dist/components/InputTextArea/InputTextArea.js +14 -0
  18. package/dist/components/LoadingSection/LoadingSection.js +16 -4
  19. package/dist/components/MenuItem/MenuItem.js +13 -0
  20. package/dist/components/MenuLateralLeft/MenuLateralLeft.js +16 -2
  21. package/dist/components/MenuLateralRight/MenuLateralRight.js +16 -2
  22. package/dist/components/Modal/Modal.js +13 -0
  23. package/dist/components/RadioButton/Radio.js +15 -0
  24. package/dist/components/RichTextInput/DesignRichTextInput.stories.js +2 -2
  25. package/dist/components/RichTextInput/RichTextInput.css +55 -12
  26. package/dist/components/RichTextInput/RichTextInput.js +223 -17
  27. package/dist/components/Scrollbar/Scrollbar.css +60 -19
  28. package/dist/components/Scrollbar/Scrollbar.js +384 -62
  29. package/dist/components/{ScrollbarNew/DesignScrollbarNew.js → ScrollbarOld/DesignScrollbarOld.js} +5 -5
  30. package/dist/components/ScrollbarOld/ScrollbarOld.css +38 -0
  31. package/dist/components/ScrollbarOld/ScrollbarOld.js +104 -0
  32. package/dist/components/{ScrollbarNew/ScrollbarNew.stories.js → ScrollbarOld/ScrollbarOld.stories.js} +13 -13
  33. package/dist/components/SelectInput/SelectInput.js +27 -8
  34. package/dist/components/Slider/Slider.js +15 -0
  35. package/dist/components/Stars/Stars.js +13 -0
  36. package/dist/components/Stepper/Stepper.js +15 -2
  37. package/dist/components/Table/TableSortLabel.js +11 -0
  38. package/dist/components/Tabs/Tabs.js +13 -1
  39. package/dist/components/Tag/Tag.js +16 -0
  40. package/dist/components/TextInput/TextInput.js +13 -0
  41. package/dist/components/TimePicker/TimePicker.js +97 -15
  42. package/dist/components/Toast/Toast.js +15 -2
  43. package/dist/components/Toast/toastStore.js +13 -2
  44. package/dist/components/Tooltip/Tooltip.js +17 -0
  45. package/package.json +2 -2
  46. package/ScrollbarNew.js +0 -3
  47. package/dist/components/ScrollbarNew/ScrollbarNew.css +0 -79
  48. package/dist/components/ScrollbarNew/ScrollbarNew.js +0 -426
@@ -204,6 +204,16 @@ var Tooltip = function Tooltip(_ref) {
204
204
  return document.removeEventListener('keydown', handleKeyDown);
205
205
  };
206
206
  }, [isOpen, closeTooltip]);
207
+ _react["default"].useEffect(function () {
208
+ if (!isOpen) return undefined;
209
+ var handleScroll = function handleScroll() {
210
+ return closeTooltip();
211
+ };
212
+ window.addEventListener('scroll', handleScroll, true);
213
+ return function () {
214
+ return window.removeEventListener('scroll', handleScroll, true);
215
+ };
216
+ }, [isOpen, closeTooltip]);
207
217
  var handleMouseEnter = function handleMouseEnter(event) {
208
218
  if (childElement.props.onMouseEnter) {
209
219
  childElement.props.onMouseEnter(event);
@@ -230,6 +240,12 @@ var Tooltip = function Tooltip(_ref) {
230
240
  }
231
241
  closeTooltip();
232
242
  };
243
+ var handleClick = function handleClick(event) {
244
+ if (childElement.props.onClick) {
245
+ childElement.props.onClick(event);
246
+ }
247
+ closeTooltip();
248
+ };
233
249
  var handleTooltipMouseEnter = function handleTooltipMouseEnter() {
234
250
  if (timeoutRef.current) {
235
251
  clearTimeout(timeoutRef.current);
@@ -247,6 +263,7 @@ var Tooltip = function Tooltip(_ref) {
247
263
  onMouseLeave: handleMouseLeave,
248
264
  onFocus: handleFocus,
249
265
  onBlur: handleBlur,
266
+ onClick: handleClick,
250
267
  ref: containerTooltipRef,
251
268
  'aria-describedby': title && shouldRender ? [existingDescribedBy, tooltipId].filter(Boolean).join(' ') : existingDescribedBy
252
269
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@councilbox/councilbox-ui",
3
- "version": "2.0.55",
3
+ "version": "2.0.56",
4
4
  "main": "dist/build-index.js",
5
5
  "files": [
6
6
  "dist",
@@ -38,7 +38,7 @@
38
38
  "Radio.js",
39
39
  "RichTextInput.js",
40
40
  "Scrollbar.js",
41
- "ScrollbarNew.js",
41
+ "ScrollbarOld.js",
42
42
  "SelectInput.js",
43
43
  "Slider.js",
44
44
  "Spacing.js",
package/ScrollbarNew.js DELETED
@@ -1,3 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = require('./dist/components/ScrollbarNew/ScrollbarNew');
@@ -1,79 +0,0 @@
1
- .Scrollbar>.cbx-scrollbarNew-view {
2
- position: absolute;
3
- top: 0;
4
- left: 0;
5
- right: 0;
6
- bottom: 0;
7
- overflow-y: auto;
8
- overflow-x: hidden;
9
- scroll-behavior: smooth;
10
- -webkit-overflow-scrolling: touch;
11
- scrollbar-width: none;
12
- }
13
-
14
- .Scrollbar.ScrollbarMobile>.cbx-scrollbarNew-view {
15
- scrollbar-width: auto;
16
- }
17
-
18
- .Scrollbar:not(.ScrollbarMobile)>.cbx-scrollbarNew-view::-webkit-scrollbar {
19
- display: none;
20
- }
21
-
22
- .scrollbarBoth>.cbx-scrollbarNew-view {
23
- overflow-x: auto;
24
- }
25
-
26
- .scrollbarOnlyY>.cbx-scrollbarNew-view {
27
- overflow-x: hidden;
28
- }
29
-
30
- .scrollflex>.cbx-scrollbarNew-view {
31
- display: flex;
32
- flex-grow: 1;
33
- min-height: 100%;
34
- }
35
-
36
- .cbx-scrollbarNew-trackVertical,
37
- .cbx-scrollbarNew-trackHorizontal {
38
- position: absolute;
39
- opacity: 1;
40
- transition-property: opacity;
41
- transition-timing-function: ease;
42
- }
43
-
44
- .cbx-scrollbarNew-trackVertical {
45
- top: 2px;
46
- right: 2px;
47
- bottom: 2px;
48
- width: 6px;
49
- border-radius: 3px;
50
- }
51
-
52
- .cbx-scrollbarNew-trackHorizontal {
53
- left: 2px;
54
- right: 2px;
55
- bottom: 2px;
56
- height: 6px;
57
- border-radius: 3px;
58
- }
59
-
60
- .cbx-scrollbarNew-thumbVertical,
61
- .cbx-scrollbarNew-thumbHorizontal {
62
- position: relative;
63
- background-color: rgba(0, 0, 0, .2);
64
- border-radius: inherit;
65
- cursor: pointer;
66
- }
67
-
68
- .cbx-scrollbarNew-thumbVertical {
69
- width: 100%;
70
- }
71
-
72
- .cbx-scrollbarNew-thumbHorizontal {
73
- height: 100%;
74
- }
75
-
76
- .ScrollbarMobile .cbx-scrollbarNew-trackVertical,
77
- .ScrollbarMobile .cbx-scrollbarNew-trackHorizontal {
78
- display: none;
79
- }
@@ -1,426 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
- require("../../styles/main.css");
11
- require("./ScrollbarNew.css");
12
- var _useDynamicStyles2 = _interopRequireDefault(require("../../HOCs/useDynamicStyles"));
13
- var _excluded = ["prefixClass"];
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) { o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } } return i; }
21
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) { if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } } return t; }
22
- var THUMB_MIN_SIZE = 30;
23
- var AUTO_HIDE_TIMEOUT = 1000;
24
- var SCROLL_STOP_DELAY = 100;
25
- var TRACK_FADE_DURATION = 200;
26
- var INTERACTIVE_SELECTOR = ['input', 'select', 'textarea', 'button', '[role="listbox"]', '[role="option"]', '[role="combobox"]', '[role="slider"]', '[role="tablist"]', '[role="tab"]', '[contenteditable="true"]'].join(', ');
27
- var clampThumbSize = function clampThumbSize(trackSize, contentRatio) {
28
- var proportionalSize = Math.ceil(contentRatio * trackSize);
29
- return Math.min(trackSize, Math.max(proportionalSize, THUMB_MIN_SIZE));
30
- };
31
- var EMPTY_AXIS_GEOMETRY = {
32
- size: 0,
33
- offset: 0,
34
- visible: false
35
- };
36
-
37
- // Same measurement react-custom-scrollbars-2 uses: on systems with overlay/0-width
38
- // native scrollbars (macOS trackpad default, some modern Chrome setups), this is 0 -
39
- // and the library shows no custom thumb at all there, relying on the native overlay.
40
- // We replicate that exactly instead of always drawing our own thumb.
41
- var cachedScrollbarWidth = null;
42
- var getScrollbarWidth = function getScrollbarWidth() {
43
- var useCache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
44
- if (useCache && cachedScrollbarWidth !== null) return cachedScrollbarWidth;
45
- if (typeof document === 'undefined') return 0;
46
- var div = document.createElement('div');
47
- div.style.cssText = 'width:100px;height:100px;position:absolute;top:-9999px;overflow:scroll;-ms-overflow-style:scrollbar;';
48
- document.body.appendChild(div);
49
- cachedScrollbarWidth = div.offsetWidth - div.clientWidth;
50
- document.body.removeChild(div);
51
- return cachedScrollbarWidth;
52
- };
53
- var ScrollbarNew = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
54
- var propPrefixClass = _ref.prefixClass,
55
- props = _objectWithoutProperties(_ref, _excluded);
56
- var _useDynamicStyles = (0, _useDynamicStyles2["default"])(props.sx),
57
- stylesInLine = _useDynamicStyles.stylesInLine,
58
- dynamicPrefixClass = _useDynamicStyles.prefixClass;
59
- var prefixClass = propPrefixClass || dynamicPrefixClass;
60
- var style = props.style,
61
- autoHide = props.autoHide,
62
- children = props.children,
63
- showX = props.showX,
64
- onScrollStop = props.onScrollStop,
65
- _props$classFix = props.classFix,
66
- classFix = _props$classFix === void 0 ? '' : _props$classFix,
67
- _props$horizontalScro = props.horizontalScroll,
68
- horizontalScroll = _props$horizontalScro === void 0 ? false : _props$horizontalScro;
69
- var isMobileMode = classFix.split(' ').filter(Boolean).includes('ScrollbarMobile');
70
- var showHorizontalThumb = horizontalScroll && showX && !isMobileMode;
71
- var viewRef = _react["default"].useRef(null);
72
- var trackVerticalRef = _react["default"].useRef(null);
73
- var trackHorizontalRef = _react["default"].useRef(null);
74
- var thumbVerticalRef = _react["default"].useRef(null);
75
- var thumbHorizontalRef = _react["default"].useRef(null);
76
- var dragStateRef = _react["default"].useRef(null);
77
- var trackMouseOverRef = _react["default"].useRef(false);
78
- var scrollStopTimerRef = _react["default"].useRef(null);
79
- var hideTracksTimerRef = _react["default"].useRef(null);
80
- var geometryRef = _react["default"].useRef({
81
- vertical: EMPTY_AXIS_GEOMETRY,
82
- horizontal: EMPTY_AXIS_GEOMETRY
83
- });
84
- var tracksVisibleRef = _react["default"].useRef(true);
85
- var hasNativeScrollbarRef = _react["default"].useRef(getScrollbarWidth() > 0);
86
- var isCustomTrackHidden = _react["default"].useCallback(function () {
87
- return isMobileMode || !hasNativeScrollbarRef.current;
88
- }, [isMobileMode]);
89
-
90
- // Thumb size/offset and track opacity are mutated directly on the DOM (like the
91
- // original library's own dom-css updates) instead of through setState, since this
92
- // runs on every scroll/resize frame and must never trigger a React re-render.
93
- var applyTrackStyles = _react["default"].useCallback(function () {
94
- var _geometryRef$current = geometryRef.current,
95
- vertical = _geometryRef$current.vertical,
96
- horizontal = _geometryRef$current.horizontal;
97
- var showTracks = tracksVisibleRef.current;
98
- var display = isCustomTrackHidden() ? 'none' : '';
99
- if (thumbVerticalRef.current) {
100
- thumbVerticalRef.current.style.height = "".concat(vertical.size, "px");
101
- thumbVerticalRef.current.style.transform = "translateY(".concat(vertical.offset, "px)");
102
- }
103
- if (trackVerticalRef.current) {
104
- trackVerticalRef.current.style.display = display;
105
- trackVerticalRef.current.style.opacity = vertical.visible && showTracks ? '1' : '0';
106
- trackVerticalRef.current.style.pointerEvents = vertical.visible ? 'auto' : 'none';
107
- }
108
- if (thumbHorizontalRef.current) {
109
- thumbHorizontalRef.current.style.width = "".concat(horizontal.size, "px");
110
- thumbHorizontalRef.current.style.transform = "translateX(".concat(horizontal.offset, "px)");
111
- }
112
- if (trackHorizontalRef.current) {
113
- trackHorizontalRef.current.style.display = display;
114
- trackHorizontalRef.current.style.opacity = horizontal.visible && showTracks ? '1' : '0';
115
- trackHorizontalRef.current.style.pointerEvents = horizontal.visible ? 'auto' : 'none';
116
- }
117
- }, [isCustomTrackHidden]);
118
- var setTracksVisibility = _react["default"].useCallback(function (visible) {
119
- tracksVisibleRef.current = visible;
120
- applyTrackStyles();
121
- }, [applyTrackStyles]);
122
- var updateThumbs = _react["default"].useCallback(function () {
123
- var view = viewRef.current;
124
- if (!view || isCustomTrackHidden()) return;
125
- var scrollTop = view.scrollTop,
126
- scrollHeight = view.scrollHeight,
127
- clientHeight = view.clientHeight,
128
- scrollLeft = view.scrollLeft,
129
- scrollWidth = view.scrollWidth,
130
- clientWidth = view.clientWidth;
131
- var trackVerticalSize = trackVerticalRef.current ? trackVerticalRef.current.clientHeight : 0;
132
- var trackHorizontalSize = trackHorizontalRef.current ? trackHorizontalRef.current.clientWidth : 0;
133
- var verticalNeeded = scrollHeight > clientHeight + 1;
134
- var horizontalNeeded = showHorizontalThumb && scrollWidth > clientWidth + 1;
135
- var verticalThumbSize = trackVerticalSize ? clampThumbSize(trackVerticalSize, clientHeight / scrollHeight) : 0;
136
- var verticalOffset = verticalNeeded ? scrollTop / (scrollHeight - clientHeight) * (trackVerticalSize - verticalThumbSize) : 0;
137
- var horizontalThumbSize = trackHorizontalSize ? clampThumbSize(trackHorizontalSize, clientWidth / scrollWidth) : 0;
138
- var horizontalOffset = horizontalNeeded ? scrollLeft / (scrollWidth - clientWidth) * (trackHorizontalSize - horizontalThumbSize) : 0;
139
- geometryRef.current = {
140
- vertical: {
141
- size: verticalThumbSize,
142
- offset: verticalOffset,
143
- visible: verticalNeeded
144
- },
145
- horizontal: {
146
- size: horizontalThumbSize,
147
- offset: horizontalOffset,
148
- visible: horizontalNeeded
149
- }
150
- };
151
- applyTrackStyles();
152
- }, [isCustomTrackHidden, showHorizontalThumb, applyTrackStyles]);
153
- var showTracksNow = _react["default"].useCallback(function () {
154
- clearTimeout(hideTracksTimerRef.current);
155
- setTracksVisibility(true);
156
- }, [setTracksVisibility]);
157
- var scheduleHideTracks = _react["default"].useCallback(function () {
158
- if (!autoHide) return;
159
- if (dragStateRef.current || trackMouseOverRef.current) return;
160
- clearTimeout(hideTracksTimerRef.current);
161
- hideTracksTimerRef.current = setTimeout(function () {
162
- return setTracksVisibility(false);
163
- }, AUTO_HIDE_TIMEOUT);
164
- }, [autoHide, setTracksVisibility]);
165
- var rafIdRef = _react["default"].useRef(null);
166
-
167
- // The library coalesces scroll/resize-driven updates into a single rAF (cancelling
168
- // any pending frame first) so a burst of scroll events only recomputes once per
169
- // paint. Prop/content-driven updates (below, in useLayoutEffect) stay synchronous
170
- // so there's never a stale-thumb flash right after mount or a re-render.
171
- var scheduleUpdateThumbs = _react["default"].useCallback(function () {
172
- if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current);
173
- rafIdRef.current = requestAnimationFrame(function () {
174
- rafIdRef.current = null;
175
- updateThumbs();
176
- });
177
- }, [updateThumbs]);
178
- var handleScroll = _react["default"].useCallback(function () {
179
- scheduleUpdateThumbs();
180
- if (autoHide) showTracksNow();
181
- clearTimeout(scrollStopTimerRef.current);
182
- scrollStopTimerRef.current = setTimeout(function () {
183
- onScrollStop === null || onScrollStop === void 0 ? void 0 : onScrollStop();
184
- scheduleHideTracks();
185
- }, SCROLL_STOP_DELAY);
186
- }, [scheduleUpdateThumbs, autoHide, showTracksNow, onScrollStop, scheduleHideTracks]);
187
- _react["default"].useLayoutEffect(function () {
188
- updateThumbs();
189
- });
190
- _react["default"].useEffect(function () {
191
- if (!autoHide) {
192
- setTracksVisibility(true);
193
- } else {
194
- scheduleHideTracks();
195
- }
196
- }, [autoHide, scheduleHideTracks, setTracksVisibility]);
197
- _react["default"].useEffect(function () {
198
- var view = viewRef.current;
199
- if (!view || typeof ResizeObserver === 'undefined') return undefined;
200
- var observer = new ResizeObserver(function () {
201
- return scheduleUpdateThumbs();
202
- });
203
- observer.observe(view);
204
- if (view.firstElementChild) observer.observe(view.firstElementChild);
205
- var handleWindowResize = function handleWindowResize() {
206
- hasNativeScrollbarRef.current = getScrollbarWidth(false) > 0;
207
- scheduleUpdateThumbs();
208
- applyTrackStyles();
209
- };
210
- window.addEventListener('resize', handleWindowResize);
211
- return function () {
212
- observer.disconnect();
213
- window.removeEventListener('resize', handleWindowResize);
214
- };
215
- }, [scheduleUpdateThumbs, applyTrackStyles]);
216
- _react["default"].useEffect(function () {
217
- return function () {
218
- clearTimeout(scrollStopTimerRef.current);
219
- clearTimeout(hideTracksTimerRef.current);
220
- if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current);
221
- };
222
- }, []);
223
- var startDrag = _react["default"].useCallback(function (axis, event) {
224
- event.preventDefault();
225
- event.stopPropagation();
226
- var view = viewRef.current;
227
- if (!view) return;
228
- dragStateRef.current = {
229
- axis: axis,
230
- startClient: axis === 'vertical' ? event.clientY : event.clientX,
231
- startScroll: axis === 'vertical' ? view.scrollTop : view.scrollLeft,
232
- trackSize: axis === 'vertical' ? trackVerticalRef.current.clientHeight : trackHorizontalRef.current.clientWidth,
233
- thumbSize: axis === 'vertical' ? geometryRef.current.vertical.size : geometryRef.current.horizontal.size
234
- };
235
- document.body.style.userSelect = 'none';
236
- showTracksNow();
237
- var handleMouseMove = function handleMouseMove(moveEvent) {
238
- var drag = dragStateRef.current;
239
- if (!drag) return;
240
- var trackRange = drag.trackSize - drag.thumbSize;
241
- if (trackRange <= 0) return;
242
- var client = drag.axis === 'vertical' ? moveEvent.clientY : moveEvent.clientX;
243
- var delta = client - drag.startClient;
244
- if (drag.axis === 'vertical') {
245
- var scrollable = view.scrollHeight - view.clientHeight;
246
- view.scrollTop = drag.startScroll + delta / trackRange * scrollable;
247
- } else {
248
- var _scrollable = view.scrollWidth - view.clientWidth;
249
- view.scrollLeft = drag.startScroll + delta / trackRange * _scrollable;
250
- }
251
- };
252
- var handleMouseUp = function handleMouseUp() {
253
- dragStateRef.current = null;
254
- document.body.style.userSelect = '';
255
- document.removeEventListener('mousemove', handleMouseMove);
256
- document.removeEventListener('mouseup', handleMouseUp);
257
- scheduleHideTracks();
258
- };
259
- document.addEventListener('mousemove', handleMouseMove);
260
- document.addEventListener('mouseup', handleMouseUp);
261
- }, [showTracksNow, scheduleHideTracks]);
262
- var handleTrackMouseDown = _react["default"].useCallback(function (axis, event) {
263
- var thumbEl = axis === 'vertical' ? thumbVerticalRef.current : thumbHorizontalRef.current;
264
- if (event.target === thumbEl) return;
265
- var view = viewRef.current;
266
- var trackEl = axis === 'vertical' ? trackVerticalRef.current : trackHorizontalRef.current;
267
- if (!view || !trackEl) return;
268
- var rect = trackEl.getBoundingClientRect();
269
- var thumbSize = axis === 'vertical' ? geometryRef.current.vertical.size : geometryRef.current.horizontal.size;
270
- var trackSize = axis === 'vertical' ? trackEl.clientHeight : trackEl.clientWidth;
271
- var trackRange = trackSize - thumbSize;
272
- if (trackRange <= 0) return;
273
- var clickOffset = axis === 'vertical' ? event.clientY - rect.top : event.clientX - rect.left;
274
- var ratio = Math.min(Math.max((clickOffset - thumbSize / 2) / trackRange, 0), 1);
275
- if (axis === 'vertical') {
276
- view.scrollTop = ratio * (view.scrollHeight - view.clientHeight);
277
- } else {
278
- view.scrollLeft = ratio * (view.scrollWidth - view.clientWidth);
279
- }
280
- }, []);
281
- var handleTrackMouseEnter = _react["default"].useCallback(function () {
282
- trackMouseOverRef.current = true;
283
- showTracksNow();
284
- }, [showTracksNow]);
285
- var handleTrackMouseLeave = _react["default"].useCallback(function () {
286
- trackMouseOverRef.current = false;
287
- scheduleHideTracks();
288
- }, [scheduleHideTracks]);
289
- var handleKeyUpToScroll = _react["default"].useCallback(function (e) {
290
- var target = e.target;
291
- if (target.closest(INTERACTIVE_SELECTOR)) return;
292
- if (!viewRef.current) return;
293
- if (e.key === 'ArrowDown') viewRef.current.scrollTop = viewRef.current.scrollHeight;
294
- if (e.key === 'ArrowUp') viewRef.current.scrollTop = 0;
295
- }, []);
296
- _react["default"].useImperativeHandle(ref, function () {
297
- return {
298
- scrollToBottom: function scrollToBottom() {
299
- if (viewRef.current) viewRef.current.scrollTop = viewRef.current.scrollHeight;
300
- },
301
- scrollToTop: function scrollToTop() {
302
- if (viewRef.current) viewRef.current.scrollTop = 0;
303
- },
304
- scrollToLeft: function scrollToLeft() {
305
- if (viewRef.current) viewRef.current.scrollLeft = 0;
306
- },
307
- scrollToRight: function scrollToRight() {
308
- if (viewRef.current) viewRef.current.scrollLeft = viewRef.current.scrollWidth;
309
- },
310
- getScrollHeight: function getScrollHeight() {
311
- return viewRef.current ? viewRef.current.scrollHeight : 0;
312
- },
313
- getScrollTop: function getScrollTop() {
314
- return viewRef.current ? viewRef.current.scrollTop : 0;
315
- },
316
- getScrollLeft: function getScrollLeft() {
317
- return viewRef.current ? viewRef.current.scrollLeft : 0;
318
- },
319
- getScrollWidth: function getScrollWidth() {
320
- return viewRef.current ? viewRef.current.scrollWidth : 0;
321
- },
322
- getClientHeight: function getClientHeight() {
323
- return viewRef.current ? viewRef.current.clientHeight : 0;
324
- },
325
- getClientWidth: function getClientWidth() {
326
- return viewRef.current ? viewRef.current.clientWidth : 0;
327
- },
328
- getValues: function getValues() {
329
- var view = viewRef.current;
330
- if (!view) {
331
- return {
332
- top: 0,
333
- left: 0,
334
- scrollTop: 0,
335
- scrollLeft: 0,
336
- scrollWidth: 0,
337
- scrollHeight: 0,
338
- clientWidth: 0,
339
- clientHeight: 0 // eslint-disable-line max-len
340
- };
341
- }
342
- var scrollTop = view.scrollTop,
343
- scrollLeft = view.scrollLeft,
344
- scrollWidth = view.scrollWidth,
345
- scrollHeight = view.scrollHeight,
346
- clientWidth = view.clientWidth,
347
- clientHeight = view.clientHeight;
348
- return {
349
- left: scrollLeft / (scrollWidth - clientWidth) || 0,
350
- top: scrollTop / (scrollHeight - clientHeight) || 0,
351
- scrollTop: scrollTop,
352
- scrollLeft: scrollLeft,
353
- scrollWidth: scrollWidth,
354
- scrollHeight: scrollHeight,
355
- clientWidth: clientWidth,
356
- clientHeight: clientHeight
357
- };
358
- }
359
- };
360
- }, []);
361
- return (
362
- /*#__PURE__*/
363
- // eslint-disable-next-line jsx-a11y/no-static-element-interactions
364
- _react["default"].createElement("div", {
365
- className: prefixClass("Scrollbar ".concat(classFix, " ").concat(horizontalScroll ? 'scrollbarBoth' : 'scrollbarOnlyY', " scrollbarFixHeight")),
366
- style: _objectSpread(_objectSpread({
367
- position: 'relative',
368
- overflow: 'hidden',
369
- width: '100%',
370
- height: '100%'
371
- }, style), stylesInLine),
372
- onKeyDown: handleKeyUpToScroll
373
- }, /*#__PURE__*/_react["default"].createElement("div", {
374
- ref: viewRef,
375
- className: prefixClass('cbx-scrollbarNew-view'),
376
- onScroll: handleScroll
377
- }, children), /*#__PURE__*/_react["default"].createElement("div", {
378
- ref: trackHorizontalRef,
379
- className: prefixClass('cbx-scrollbarNew-trackHorizontal'),
380
- style: {
381
- transitionDuration: autoHide ? "".concat(TRACK_FADE_DURATION, "ms") : '0ms'
382
- },
383
- onMouseEnter: handleTrackMouseEnter,
384
- onMouseLeave: handleTrackMouseLeave,
385
- onMouseDown: function onMouseDown(e) {
386
- return handleTrackMouseDown('horizontal', e);
387
- }
388
- }, /*#__PURE__*/_react["default"].createElement("div", {
389
- ref: thumbHorizontalRef,
390
- className: prefixClass('cbx-scrollbarNew-thumbHorizontal'),
391
- onMouseDown: function onMouseDown(e) {
392
- return startDrag('horizontal', e);
393
- }
394
- })), /*#__PURE__*/_react["default"].createElement("div", {
395
- ref: trackVerticalRef,
396
- className: prefixClass('cbx-scrollbarNew-trackVertical'),
397
- style: {
398
- transitionDuration: autoHide ? "".concat(TRACK_FADE_DURATION, "ms") : '0ms'
399
- },
400
- onMouseEnter: handleTrackMouseEnter,
401
- onMouseLeave: handleTrackMouseLeave,
402
- onMouseDown: function onMouseDown(e) {
403
- return handleTrackMouseDown('vertical', e);
404
- }
405
- }, /*#__PURE__*/_react["default"].createElement("div", {
406
- ref: thumbVerticalRef,
407
- className: prefixClass('cbx-scrollbarNew-thumbVertical'),
408
- onMouseDown: function onMouseDown(e) {
409
- return startDrag('vertical', e);
410
- }
411
- })))
412
- );
413
- });
414
- ScrollbarNew.propTypes = {
415
- style: _propTypes["default"].object,
416
- sx: _propTypes["default"].object,
417
- autoHide: _propTypes["default"].bool,
418
- showX: _propTypes["default"].bool,
419
- horizontalScroll: _propTypes["default"].bool,
420
- classFix: _propTypes["default"].string,
421
- onScrollStop: _propTypes["default"].func,
422
- prefixClass: _propTypes["default"].func,
423
- children: _propTypes["default"].node
424
- };
425
- var _default = ScrollbarNew;
426
- exports["default"] = _default;