@rescui/tab-list 0.13.4 → 0.13.5

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,12 +1,9 @@
1
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
2
1
  import React, { isValidElement, cloneElement } from 'react';
3
2
 
4
3
  function deepMap(children, fn) {
5
- var _context;
6
-
7
- var processChild = function processChild(child) {
8
- var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
9
- var returnChild = child;
4
+ const processChild = function (child) {
5
+ let i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
6
+ let returnChild = child;
10
7
 
11
8
  if (! /*#__PURE__*/isValidElement(returnChild)) {
12
9
  return returnChild;
@@ -26,7 +23,7 @@ function deepMap(children, fn) {
26
23
  return processChild(children);
27
24
  }
28
25
 
29
- return _mapInstanceProperty(_context = React.Children).call(_context, children, processChild);
26
+ return React.Children.map(children, processChild);
30
27
  }
31
28
 
32
29
  export { deepMap };
@@ -1,6 +1,6 @@
1
1
  var styles = {
2
- "light": "_light_aq3vka_4",
3
- "dark": "_dark_aq3vka_7",
4
- "separator": "_separator_aq3vka_11"
2
+ "light": "_light_q23mtz_4",
3
+ "dark": "_dark_q23mtz_7",
4
+ "separator": "_separator_q23mtz_11"
5
5
  };
6
6
  export { styles as default };
@@ -1,12 +1,10 @@
1
1
  import { createContext, useContext } from 'react';
2
- var TabListContext = /*#__PURE__*/createContext({
2
+ const TabListContext = /*#__PURE__*/createContext({
3
3
  // eslint-disable-next-line @typescript-eslint/no-empty-function
4
- onChange: function onChange() {},
4
+ onChange: () => {},
5
5
  selectedId: 0
6
6
  });
7
7
 
8
- var useTabListContext = function useTabListContext() {
9
- return useContext(TabListContext);
10
- };
8
+ const useTabListContext = () => useContext(TabListContext);
11
9
 
12
10
  export { TabListContext, useTabListContext };
@@ -1,18 +1,18 @@
1
1
  var styles = {
2
- "light": "_light_1kqq769_7",
3
- "dark": "_dark_1kqq769_10",
4
- "sizeM": "_sizeM_1kqq769_14",
5
- "sizeL": "_sizeL_1kqq769_17",
6
- "classic": "_classic_1kqq769_21",
7
- "rock": "_rock_1kqq769_24",
8
- "sparse": "_sparse_1kqq769_28",
9
- "short": "_short_1kqq769_32",
10
- "tabsContainer": "_tabsContainer_1kqq769_36",
11
- "indicator": "_indicator_1kqq769_46",
12
- "iconLeft": "_iconLeft_1kqq769_61",
13
- "iconRight": "_iconRight_1kqq769_64",
14
- "tab": "_tab_1kqq769_36",
15
- "selected": "_selected_1kqq769_154",
16
- "icon": "_icon_1kqq769_61"
2
+ "light": "_light_yqgmx8_7",
3
+ "dark": "_dark_yqgmx8_10",
4
+ "sizeM": "_sizeM_yqgmx8_14",
5
+ "sizeL": "_sizeL_yqgmx8_17",
6
+ "classic": "_classic_yqgmx8_21",
7
+ "rock": "_rock_yqgmx8_24",
8
+ "sparse": "_sparse_yqgmx8_28",
9
+ "short": "_short_yqgmx8_32",
10
+ "tabsContainer": "_tabsContainer_yqgmx8_36",
11
+ "indicator": "_indicator_yqgmx8_46",
12
+ "iconLeft": "_iconLeft_yqgmx8_61",
13
+ "iconRight": "_iconRight_yqgmx8_64",
14
+ "tab": "_tab_yqgmx8_36",
15
+ "selected": "_selected_yqgmx8_154",
16
+ "icon": "_icon_yqgmx8_61"
17
17
  };
18
18
  export { styles as default };
@@ -3,10 +3,12 @@ import cn from 'classnames';
3
3
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
4
4
  import styles from './separator.p.module.css.js';
5
5
 
6
- var TabSeparator = function TabSeparator(_ref) {
7
- var className = _ref.className,
8
- themeFromProps = _ref.theme;
9
- var theme = useThemeWithUndefined(themeFromProps);
6
+ const TabSeparator = _ref => {
7
+ let {
8
+ className,
9
+ theme: themeFromProps
10
+ } = _ref;
11
+ const theme = useThemeWithUndefined(themeFromProps);
10
12
  return /*#__PURE__*/React.createElement("div", {
11
13
  className: cn(styles.separator, styles[theme], className)
12
14
  });
package/lib/parts/tab.js CHANGED
@@ -1,81 +1,67 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/web.dom-collections.for-each.js";
3
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
4
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
5
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
6
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
7
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
8
- import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
9
- import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
10
- var _excluded = ["value", "className", "children", "icon", "iconPosition", "itemId", "onClick", "onKeyDown", "data-e2e"];
11
-
12
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
15
-
16
1
  import React, { forwardRef, cloneElement } from 'react';
17
2
  import PropTypes from 'prop-types';
18
3
  import cn from 'classnames';
19
4
  import styles from './tab-list.p.module.css.js';
20
5
  import { useTabListContext } from './tab-list-context.js';
21
- var TabTag = /*#__PURE__*/forwardRef(function (props, ref) {
6
+ const TabTag = /*#__PURE__*/forwardRef((props, ref) => {
22
7
  if (typeof props.href !== 'undefined') {
23
- return /*#__PURE__*/React.createElement("a", _objectSpread({
24
- ref: ref
25
- }, props), props.children);
8
+ return /*#__PURE__*/React.createElement("a", {
9
+ ref: ref,
10
+ ...props
11
+ }, props.children);
26
12
  }
27
13
 
28
- return /*#__PURE__*/React.createElement("button", _objectSpread(_objectSpread({
29
- ref: ref
30
- }, props), {}, {
14
+ return /*#__PURE__*/React.createElement("button", {
15
+ ref: ref,
16
+ ...props,
31
17
  type: "button"
32
- }), props.children);
18
+ }, props.children);
33
19
  });
34
20
  TabTag.displayName = 'TabTag';
35
- var Tab = /*#__PURE__*/forwardRef(function (_ref, ref) {
36
- var value = _ref.value,
37
- className = _ref.className,
38
- children = _ref.children,
39
- icon = _ref.icon,
40
- _ref$iconPosition = _ref.iconPosition,
41
- iconPosition = _ref$iconPosition === void 0 ? 'left' : _ref$iconPosition,
42
- itemId = _ref.itemId,
43
- _onClick = _ref.onClick,
44
- _onKeyDown = _ref.onKeyDown,
45
- e2eId = _ref['data-e2e'],
46
- restProps = _objectWithoutProperties(_ref, _excluded);
47
-
48
- var _useTabListContext = useTabListContext(),
49
- onChange = _useTabListContext.onChange,
50
- selectedId = _useTabListContext.selectedId;
51
-
52
- var selected = itemId === selectedId;
53
- return /*#__PURE__*/React.createElement(TabTag, _objectSpread(_objectSpread({}, restProps), {}, {
21
+ const Tab = /*#__PURE__*/forwardRef((_ref, ref) => {
22
+ let {
23
+ value,
24
+ className,
25
+ children,
26
+ icon,
27
+ iconPosition = 'left',
28
+ itemId,
29
+ onClick,
30
+ onKeyDown,
31
+ ['data-e2e']: e2eId,
32
+ ...restProps
33
+ } = _ref;
34
+ const {
35
+ onChange,
36
+ selectedId
37
+ } = useTabListContext();
38
+ const selected = itemId === selectedId;
39
+ return /*#__PURE__*/React.createElement(TabTag, { ...restProps,
54
40
  className: cn(styles.tab, selected && styles.selected, iconPosition === 'right' ? styles.iconRight : styles.iconLeft, className),
55
- onClick: function onClick(e) {
56
- if (_onClick) {
57
- _onClick(e);
41
+ onClick: e => {
42
+ if (onClick) {
43
+ onClick(e);
58
44
  }
59
45
 
60
46
  onChange(value);
61
47
  },
62
- onKeyDown: function onKeyDown(e) {
48
+ onKeyDown: e => {
63
49
  if (e.key === ' ') {
64
50
  e.target.click();
65
51
  e.preventDefault();
66
52
  }
67
53
 
68
- if (_onKeyDown) {
69
- _onKeyDown(e);
54
+ if (onKeyDown) {
55
+ onKeyDown(e);
70
56
  }
71
57
  },
72
58
  role: "tab",
73
59
  tabIndex: 0,
74
60
  ref: ref,
75
61
  "data-e2e": e2eId,
76
- "data-test": "tab".concat(selected ? ' tab-selected' : ''),
62
+ "data-test": `tab${selected ? ' tab-selected' : ''}`,
77
63
  "data-rs-internal": 'tab-list__tab'
78
- }), icon && /*#__PURE__*/cloneElement(icon, {
64
+ }, icon && /*#__PURE__*/cloneElement(icon, {
79
65
  className: cn(icon.props.className, styles.icon)
80
66
  }), /*#__PURE__*/React.createElement("div", null, children));
81
67
  });
@@ -1,60 +1,39 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/web.dom-collections.for-each.js";
3
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
4
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
5
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
6
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
7
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
8
- import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
9
- import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
10
-
11
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
-
13
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
14
-
15
1
  import { useState, useEffect } from 'react';
16
2
  import { useResizeObserver } from '@rescui/use-resize-observer';
17
3
 
18
4
  function calculateIndicator(activeNodeRef, parentNode) {
19
- var childPos = activeNodeRef.getBoundingClientRect();
20
- var parentPos = parentNode.getBoundingClientRect();
21
- var left = "".concat(childPos.left - parentPos.left + parentNode.scrollLeft, "px");
22
- var width = "".concat(childPos.width, "px");
5
+ const childPos = activeNodeRef.getBoundingClientRect();
6
+ const parentPos = parentNode.getBoundingClientRect();
7
+ const left = `${childPos.left - parentPos.left + parentNode.scrollLeft}px`;
8
+ const width = `${childPos.width}px`;
23
9
  return {
24
- left: left,
25
- width: width
10
+ left,
11
+ width
26
12
  };
27
13
  }
28
14
 
29
- var useIndicator = function useIndicator(_ref) {
30
- var activeNodeRef = _ref.activeNodeRef,
31
- containerRef = _ref.containerRef,
32
- triggers = _ref.triggers;
33
-
34
- var _useState = useState({
15
+ const useIndicator = _ref => {
16
+ let {
17
+ activeNodeRef,
18
+ containerRef,
19
+ triggers
20
+ } = _ref;
21
+ const [indicator, setIndicator] = useState({
35
22
  left: 0,
36
23
  width: 0
37
- }),
38
- _useState2 = _slicedToArray(_useState, 2),
39
- indicator = _useState2[0],
40
- setIndicator = _useState2[1];
41
-
42
- var _useState3 = useState(true),
43
- _useState4 = _slicedToArray(_useState3, 2),
44
- isSSR = _useState4[0],
45
- setIsSSR = _useState4[1]; // Catch the resize of the container which is happening when the fonts downloads for example
46
-
24
+ });
25
+ const [isSSR, setIsSSR] = useState(true); // Catch the resize of the container which is happening when the fonts downloads for example
47
26
 
48
- var onResize = function onResize() {
27
+ const onResize = () => {
49
28
  if (!activeNodeRef.current || !containerRef.current) {
50
29
  return;
51
30
  }
52
31
 
53
32
  if (isSSR) {
54
33
  setIsSSR(false);
55
- setIndicator(_objectSpread(_objectSpread({}, calculateIndicator(activeNodeRef.current, containerRef.current)), {}, {
34
+ setIndicator({ ...calculateIndicator(activeNodeRef.current, containerRef.current),
56
35
  transitionDuration: '0ms'
57
- }));
36
+ });
58
37
  return;
59
38
  }
60
39
 
@@ -1,53 +1,37 @@
1
- import "core-js/modules/web.dom-collections.for-each.js";
2
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
3
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
4
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
5
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
6
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
- import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
8
- import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
9
- import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
10
- var _excluded = ["child", "itemId", "childValue", "ref"],
11
- _excluded2 = ["value", "onFocus"];
12
- import "core-js/modules/es.object.to-string.js";
13
- import "core-js/modules/es.promise.js";
14
-
15
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
-
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
18
-
19
1
  import React, { useRef, useState, useCallback, useMemo, useEffect, cloneElement } from 'react';
20
2
  import { useResizeObserver } from '@rescui/use-resize-observer';
21
3
  import { deepMap } from './deep-map.js'; // arrow (32) + shadow (10) + shadow blur (~8) + item focus outline (4)
22
4
 
23
- var ARROW_AREA_WIDTH_IN_PX = 54;
5
+ const ARROW_AREA_WIDTH_IN_PX = 54;
24
6
 
25
7
  function patchItemIfNeeded(_ref) {
26
- var child = _ref.child,
27
- itemId = _ref.itemId,
28
- childValue = _ref.childValue,
29
- ref = _ref.ref,
30
- restProps = _objectWithoutProperties(_ref, _excluded);
31
-
32
- return /*#__PURE__*/cloneElement(child, _objectSpread({
33
- itemId: itemId,
8
+ let {
9
+ child,
10
+ itemId,
11
+ childValue,
12
+ ref,
13
+ ...restProps
14
+ } = _ref;
15
+ return /*#__PURE__*/cloneElement(child, {
16
+ itemId,
34
17
  value: childValue,
35
- ref: ref
36
- }, restProps));
18
+ ref,
19
+ ...restProps
20
+ });
37
21
  }
38
22
 
39
23
  function calculateArrowsVisibility(scrollContainerEl) {
40
24
  // doing this because scrollContainerEl.scrollWidth returns a rounded value
41
- var scrollLeft = Math.round(scrollContainerEl.scrollLeft);
42
- var shouldShowAnyArrow = scrollContainerEl.offsetWidth < scrollContainerEl.scrollWidth; // in some browsers, fully scrolled element has `scrollLeft + offsetWidth === scrollWidth - 1`
25
+ const scrollLeft = Math.round(scrollContainerEl.scrollLeft);
26
+ const shouldShowAnyArrow = scrollContainerEl.offsetWidth < scrollContainerEl.scrollWidth; // in some browsers, fully scrolled element has `scrollLeft + offsetWidth === scrollWidth - 1`
43
27
  // so we take this measurement error into account
44
28
 
45
- var delta = 1;
46
- var showLeftArrow = shouldShowAnyArrow && scrollLeft > 0;
47
- var showRightArrow = shouldShowAnyArrow && scrollLeft + scrollContainerEl.offsetWidth < scrollContainerEl.scrollWidth - delta;
29
+ const delta = 1;
30
+ const showLeftArrow = shouldShowAnyArrow && scrollLeft > 0;
31
+ const showRightArrow = shouldShowAnyArrow && scrollLeft + scrollContainerEl.offsetWidth < scrollContainerEl.scrollWidth - delta;
48
32
  return {
49
- showLeftArrow: showLeftArrow,
50
- showRightArrow: showRightArrow
33
+ showLeftArrow,
34
+ showRightArrow
51
35
  };
52
36
  }
53
37
 
@@ -76,30 +60,30 @@ function scrollElementLeft(element, to) {
76
60
  }
77
61
 
78
62
  function scrollIntoView(activeNode, parentNode) {
79
- var childWidth = activeNode.offsetWidth;
80
- var parentWidth = parentNode.offsetWidth;
81
- var parentStyles = getComputedStyle(parentNode);
82
- var parentMarginsOffset = parseInt(parentStyles.marginLeft, 10) + parseInt(parentStyles.marginRight, 10);
83
- var parentScrollLeft = parentNode.scrollLeft;
84
- var parentScrollWidth = parentNode.scrollWidth; // position of the left border in the container
63
+ const childWidth = activeNode.offsetWidth;
64
+ const parentWidth = parentNode.offsetWidth;
65
+ const parentStyles = getComputedStyle(parentNode);
66
+ const parentMarginsOffset = parseInt(parentStyles.marginLeft, 10) + parseInt(parentStyles.marginRight, 10);
67
+ const parentScrollLeft = parentNode.scrollLeft;
68
+ const parentScrollWidth = parentNode.scrollWidth; // position of the left border in the container
85
69
 
86
- var activeNodeLeft = parentNode.offsetLeft + activeNode.offsetLeft; // position of the right border in the container
70
+ const activeNodeLeft = parentNode.offsetLeft + activeNode.offsetLeft; // position of the right border in the container
87
71
 
88
- var activeNodeRight = activeNodeLeft + childWidth; // position of the left border in relation to the viewport
72
+ const activeNodeRight = activeNodeLeft + childWidth; // position of the left border in relation to the viewport
89
73
 
90
- var activeNodeLeftOffset = activeNodeLeft - parentScrollLeft; // position of the right border in relation to the viewport
74
+ const activeNodeLeftOffset = activeNodeLeft - parentScrollLeft; // position of the right border in relation to the viewport
91
75
 
92
- var activeNodeRightOffset = parentWidth - (activeNodeLeftOffset + childWidth); // by default, don't scroll at all
76
+ const activeNodeRightOffset = parentWidth - (activeNodeLeftOffset + childWidth); // by default, don't scroll at all
93
77
 
94
- var scrollTo = -1; // if before the element there is a space larger than arrow area
78
+ let scrollTo = -1; // if before the element there is a space larger than arrow area
95
79
 
96
- var isElHasWorkSpaceLeft = activeNodeLeft > ARROW_AREA_WIDTH_IN_PX; // if after the element there is a space larger than arrow area
80
+ const isElHasWorkSpaceLeft = activeNodeLeft > ARROW_AREA_WIDTH_IN_PX; // if after the element there is a space larger than arrow area
97
81
 
98
- var isElHasWorkSpaceRight = activeNodeRight < parentScrollWidth - ARROW_AREA_WIDTH_IN_PX;
82
+ const isElHasWorkSpaceRight = activeNodeRight < parentScrollWidth - ARROW_AREA_WIDTH_IN_PX;
99
83
 
100
84
  if (activeNodeRightOffset <= ARROW_AREA_WIDTH_IN_PX) {
101
85
  if (isElHasWorkSpaceRight) {
102
- var sideOffset = parentWidth - childWidth + parentMarginsOffset;
86
+ const sideOffset = parentWidth - childWidth + parentMarginsOffset;
103
87
  scrollTo = activeNodeLeft + ARROW_AREA_WIDTH_IN_PX - sideOffset;
104
88
  } else {
105
89
  scrollTo = parentScrollWidth - parentWidth; // right edge
@@ -120,67 +104,60 @@ function scrollIntoView(activeNode, parentNode) {
120
104
  }
121
105
  }
122
106
 
123
- var useScrollableList = function useScrollableList(_ref2) {
124
- var children = _ref2.children,
125
- compareValues = _ref2.compareValues,
126
- value = _ref2.value,
127
- CompareItem = _ref2.CompareItem;
128
- var activeNodeRef = useRef(null);
129
- var scrollableRef = useRef(null);
130
- var containerRef = useRef(null); // reset targeted element on scrolling by arrows
107
+ const useScrollableList = _ref2 => {
108
+ let {
109
+ children,
110
+ compareValues,
111
+ value,
112
+ CompareItem
113
+ } = _ref2;
114
+ const activeNodeRef = useRef(null);
115
+ const scrollableRef = useRef(null);
116
+ const containerRef = useRef(null); // reset targeted element on scrolling by arrows
131
117
  // so on window resize there wouldn't scroll to it
132
118
 
133
- var _useState = useState(null),
134
- _useState2 = _slicedToArray(_useState, 2),
135
- targetedEl = _useState2[0],
136
- setTargetedEl = _useState2[1];
137
-
138
- var _useState3 = useState({
119
+ const [targetedEl, setTargetedEl] = useState(null);
120
+ const [{
121
+ showLeftArrow,
122
+ showRightArrow
123
+ }, setShowArrows] = useState({
139
124
  showLeftArrow: false,
140
125
  showRightArrow: false
141
- }),
142
- _useState4 = _slicedToArray(_useState3, 2),
143
- _useState4$ = _useState4[0],
144
- showLeftArrow = _useState4$.showLeftArrow,
145
- showRightArrow = _useState4$.showRightArrow,
146
- setShowArrows = _useState4[1];
147
-
148
- var _onFocus = useCallback(function (e) {
126
+ });
127
+ const onFocus = useCallback(e => {
149
128
  setTargetedEl(e.target);
150
129
  }, []);
151
-
152
- var _useMemo = useMemo(function () {
153
- var counter = 0;
154
- var currentSelectedItemId = null;
155
- var items = deepMap(children, function (child) {
130
+ const [childrenWithValues, selectedId] = useMemo(() => {
131
+ let counter = 0;
132
+ let currentSelectedItemId = null;
133
+ const items = deepMap(children, child => {
156
134
  if (child.type === CompareItem) {
157
- var _child$props = child.props,
158
- _child$props$value = _child$props.value,
159
- childValue = _child$props$value === void 0 ? counter : _child$props$value,
160
- onFocusFromProps = _child$props.onFocus,
161
- restProps = _objectWithoutProperties(_child$props, _excluded2);
162
-
163
- var hasAlreadySelectedItem = currentSelectedItemId === null;
164
- var isSelectedItem = hasAlreadySelectedItem && compareValues(value, childValue);
135
+ const {
136
+ value: childValue = counter,
137
+ onFocus: onFocusFromProps,
138
+ ...restProps
139
+ } = child.props;
140
+ const hasAlreadySelectedItem = currentSelectedItemId === null;
141
+ const isSelectedItem = hasAlreadySelectedItem && compareValues(value, childValue);
165
142
 
166
143
  if (isSelectedItem) {
167
144
  currentSelectedItemId = counter;
168
145
  }
169
146
 
170
- var patchedItem = patchItemIfNeeded(_objectSpread(_objectSpread({
171
- child: child,
147
+ const patchedItem = patchItemIfNeeded({
148
+ child,
172
149
  itemId: counter,
173
- childValue: childValue
174
- }, restProps), {}, {
175
- onFocus: function onFocus(e) {
150
+ childValue,
151
+ ...restProps,
152
+ onFocus: e => {
176
153
  if (onFocusFromProps) {
177
154
  onFocusFromProps(e);
178
155
  }
179
156
 
180
- _onFocus(e);
157
+ onFocus(e);
181
158
  },
182
159
  ref: isSelectedItem ? activeNodeRef : null
183
- }));
160
+ });
184
161
  counter += 1;
185
162
  return patchedItem;
186
163
  } else {
@@ -188,28 +165,25 @@ var useScrollableList = function useScrollableList(_ref2) {
188
165
  }
189
166
  });
190
167
  return [React.Children.toArray(items), currentSelectedItemId];
191
- }, [children, value, compareValues, _onFocus, CompareItem]),
192
- _useMemo2 = _slicedToArray(_useMemo, 2),
193
- childrenWithValues = _useMemo2[0],
194
- selectedId = _useMemo2[1];
195
-
196
- var prepareDirectionScroller = function prepareDirectionScroller(direction) {
197
- return function () {
198
- var current = scrollableRef.current;
199
- var left = Math.max(current.clientWidth - 2 * ARROW_AREA_WIDTH_IN_PX, 30) * (direction === 'right' ? 1 : -1);
200
- setTargetedEl(null);
201
- scrollElementBy(current, left);
202
- };
168
+ }, [children, value, compareValues, onFocus, CompareItem]);
169
+
170
+ const prepareDirectionScroller = direction => () => {
171
+ const {
172
+ current
173
+ } = scrollableRef;
174
+ const left = Math.max(current.clientWidth - 2 * ARROW_AREA_WIDTH_IN_PX, 30) * (direction === 'right' ? 1 : -1);
175
+ setTargetedEl(null);
176
+ scrollElementBy(current, left);
203
177
  };
204
178
 
205
- useEffect(function () {
179
+ useEffect(() => {
206
180
  if (!activeNodeRef.current) {
207
181
  return;
208
182
  }
209
183
 
210
184
  setTargetedEl(activeNodeRef.current);
211
185
  }, [value, childrenWithValues]);
212
- var setArrowsVisibility = useCallback(function () {
186
+ const setArrowsVisibility = useCallback(() => {
213
187
  if (!scrollableRef.current) {
214
188
  return;
215
189
  }
@@ -217,8 +191,8 @@ var useScrollableList = function useScrollableList(_ref2) {
217
191
  setShowArrows(calculateArrowsVisibility(scrollableRef.current));
218
192
  }, []); // update arrows while smooth scrolling
219
193
 
220
- useEffect(function () {
221
- var scrollContainer = scrollableRef.current;
194
+ useEffect(() => {
195
+ const scrollContainer = scrollableRef.current;
222
196
 
223
197
  if (!scrollContainer) {
224
198
  return null;
@@ -227,13 +201,11 @@ var useScrollableList = function useScrollableList(_ref2) {
227
201
  scrollContainer.addEventListener('scroll', setArrowsVisibility, {
228
202
  passive: true
229
203
  });
230
- return function () {
231
- return scrollContainer.removeEventListener('scroll', setArrowsVisibility);
232
- };
204
+ return () => scrollContainer.removeEventListener('scroll', setArrowsVisibility);
233
205
  }, [setArrowsVisibility]); // scrollIntoView active element when it changes or the component resizes
234
206
 
235
- var updateScrollState = function updateScrollState() {
236
- var scrollableEl = scrollableRef.current;
207
+ const updateScrollState = () => {
208
+ const scrollableEl = scrollableRef.current;
237
209
 
238
210
  if (!scrollableEl) {
239
211
  return;
@@ -255,14 +227,14 @@ var useScrollableList = function useScrollableList(_ref2) {
255
227
  });
256
228
  useEffect(updateScrollState, [targetedEl, setArrowsVisibility]);
257
229
  return {
258
- selectedId: selectedId,
259
- prepareDirectionScroller: prepareDirectionScroller,
260
- activeNodeRef: activeNodeRef,
261
- scrollableRef: scrollableRef,
262
- containerRef: containerRef,
263
- childrenWithValues: childrenWithValues,
264
- showLeftArrow: showLeftArrow,
265
- showRightArrow: showRightArrow
230
+ selectedId,
231
+ prepareDirectionScroller,
232
+ activeNodeRef,
233
+ scrollableRef,
234
+ containerRef,
235
+ childrenWithValues,
236
+ showLeftArrow,
237
+ showRightArrow
266
238
  };
267
239
  };
268
240