@rescui/switcher 0.10.3 → 0.10.5-RUI-226-Update-card-cn-6e43cc89.60

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,93 +1,66 @@
1
- import "core-js/modules/es.function.name.js";
2
- import "core-js/modules/es.regexp.exec.js";
3
- import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
4
- import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
5
- import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
6
- import _getIteratorMethod from "@babel/runtime-corejs3/core-js/get-iterator-method";
7
- import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
8
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
9
- import "core-js/modules/es.object.to-string.js";
10
-
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
12
-
13
- function _unsupportedIterableToArray(o, minLen) { var _context; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context = Object.prototype.toString.call(o)).call(_context, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
-
15
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
16
-
17
1
  import React, { createContext, useRef, useCallback, useState, useEffect, useContext, cloneElement } from 'react';
18
2
  import PropTypes from 'prop-types';
19
3
  import cn from 'classnames';
20
4
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
21
5
  import { useResizeObserver } from '@rescui/use-resize-observer';
22
- import styles from './vertical-switcher.p.module.css.js'; // eslint-disable-next-line @typescript-eslint/no-empty-function
6
+ import styles from './vertical-switcher.p.module.css.js';
7
+ const MARK_TRANSITION_DURATION = '0.2s'; // eslint-disable-next-line @typescript-eslint/no-empty-function
23
8
 
24
- var noop = function noop() {};
9
+ const noop = () => {};
25
10
 
26
- var verticalSwitcherContext = /*#__PURE__*/createContext({
11
+ const verticalSwitcherContext = /*#__PURE__*/createContext({
27
12
  switcherValue: null,
28
13
  onChange: noop,
29
- handleOptionRef: function handleOptionRef() {
30
- return noop;
31
- },
14
+ handleOptionRef: () => noop,
32
15
  disabled: null
33
16
  });
34
- var sizeToClass = {
17
+ const sizeToClass = {
35
18
  l: styles.sizeL,
36
19
  m: styles.sizeM,
37
20
  s: styles.sizeS,
38
21
  xs: styles.sizeXS
39
22
  };
40
- var themeToClass = {
23
+ const themeToClass = {
41
24
  light: styles.themeLight,
42
25
  dark: styles.themeDark
43
26
  };
44
- var modeToClass = {
27
+ const modeToClass = {
45
28
  classic: styles.modeClassic,
46
29
  rock: styles.modeRock
47
30
  }; // eslint-disable-next-line complexity
48
31
 
49
- var processOptions = function processOptions(_ref) {
50
- var _foundIndexByValue;
51
-
52
- var rawOptions = _ref.rawOptions,
53
- value = _ref.value,
54
- iconPosition = _ref.iconPosition;
55
- var options = [];
56
- var foundIndexByValue = null;
57
- var currentIndex = 0;
58
- var withLeftIcons = false;
59
-
60
- var _iterator = _createForOfIteratorHelper(rawOptions),
61
- _step;
62
-
63
- try {
64
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
65
- var option = _step.value;
66
- options.push({
67
- label: option.label,
68
- value: option.value,
69
- icon: option.icon
70
- });
32
+ const processOptions = _ref => {
33
+ let {
34
+ rawOptions,
35
+ value,
36
+ iconPosition
37
+ } = _ref;
38
+ const options = [];
39
+ let foundIndexByValue = null;
40
+ let currentIndex = 0;
41
+ let withLeftIcons = false;
42
+
43
+ for (const option of rawOptions) {
44
+ options.push({
45
+ label: option.label,
46
+ value: option.value,
47
+ icon: option.icon
48
+ });
71
49
 
72
- if ( /*#__PURE__*/React.isValidElement(option.icon) && iconPosition === 'left') {
73
- withLeftIcons = true;
74
- }
50
+ if ( /*#__PURE__*/React.isValidElement(option.icon) && iconPosition === 'left') {
51
+ withLeftIcons = true;
52
+ }
75
53
 
76
- if (option.value === value && foundIndexByValue === null) {
77
- foundIndexByValue = currentIndex;
78
- }
54
+ if (option.value === value && foundIndexByValue === null) {
55
+ foundIndexByValue = currentIndex;
56
+ }
79
57
 
80
- currentIndex++;
81
- } // If some options on the first depth level have icons, we should align all other options accordingly
58
+ currentIndex++;
59
+ } // If some options on the first depth level have icons, we should align all other options accordingly
82
60
 
83
- } catch (err) {
84
- _iterator.e(err);
85
- } finally {
86
- _iterator.f();
87
- }
88
61
 
89
62
  if (withLeftIcons) {
90
- options.forEach(function (option) {
63
+ options.forEach(option => {
91
64
  if (! /*#__PURE__*/React.isValidElement(option.icon)) {
92
65
  option.icon = /*#__PURE__*/React.createElement("span", {
93
66
  className: styles.fakeIcon
@@ -97,43 +70,41 @@ var processOptions = function processOptions(_ref) {
97
70
  }
98
71
 
99
72
  return {
100
- options: options,
101
- activeIndex: (_foundIndexByValue = foundIndexByValue) !== null && _foundIndexByValue !== void 0 ? _foundIndexByValue : 0
73
+ options,
74
+ activeIndex: foundIndexByValue ?? 0
102
75
  };
103
76
  }; // check for ignored jsx values and empty string, more info https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored
104
77
 
105
78
 
106
- var isNodeEmpty = function isNodeEmpty(node) {
107
- return node === null || typeof node === 'undefined' || node === false || node === true || node === '';
108
- };
79
+ const isNodeEmpty = node => node === null || typeof node === 'undefined' || node === false || node === true || node === '';
109
80
 
110
81
  function Option(_ref2) {
111
- var label = _ref2.label,
112
- value = _ref2.value,
113
- icon = _ref2.icon,
114
- index = _ref2.index;
115
-
116
- var _useContext = useContext(verticalSwitcherContext),
117
- switcherValue = _useContext.switcherValue,
118
- onChange = _useContext.onChange,
119
- handleOptionRef = _useContext.handleOptionRef,
120
- disabled = _useContext.disabled;
121
-
122
- var selected = switcherValue === value;
123
- var isWithoutText = isNodeEmpty(label);
82
+ let {
83
+ label,
84
+ value,
85
+ icon,
86
+ index
87
+ } = _ref2;
88
+ const {
89
+ switcherValue,
90
+ onChange,
91
+ handleOptionRef,
92
+ disabled
93
+ } = useContext(verticalSwitcherContext);
94
+ const selected = switcherValue === value;
95
+ const isWithoutText = isNodeEmpty(label);
124
96
  return /*#__PURE__*/React.createElement("button", {
125
97
  key: String(value),
126
98
  ref: handleOptionRef(index),
127
- onClick: function onClick() {
128
- return onChange(value);
129
- },
99
+ onClick: () => onChange(value),
130
100
  type: "button",
131
101
  "data-rs-internal": 'vertical-switcher__option',
132
102
  disabled: disabled,
133
103
  className: cn(styles.option, selected && styles.selected),
134
- "data-test": cn("vertical-switcher-option", selected && ' vertical-switcher-option-selected')
104
+ "data-test": cn(`vertical-switcher-option`, selected && ' vertical-switcher-option-selected')
135
105
  }, /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/cloneElement(icon, {
136
- className: cn(icon.props.className, styles.icon)
106
+ className: cn(icon.props.className, styles.icon),
107
+ 'data-render-all-sizes': true
137
108
  }), !isWithoutText && /*#__PURE__*/React.createElement("span", {
138
109
  className: styles.optionLabel
139
110
  }, label));
@@ -142,92 +113,100 @@ function Option(_ref2) {
142
113
  function VerticalSwitcher(_ref3) {
143
114
  var _options$activeIndex;
144
115
 
145
- var className = _ref3.className,
146
- themeFromProps = _ref3.theme,
147
- _ref3$size = _ref3.size,
148
- size = _ref3$size === void 0 ? 'm' : _ref3$size,
149
- disabled = _ref3.disabled,
150
- e2eId = _ref3['data-e2e'],
151
- rawOptions = _ref3.options,
152
- switcherValue = _ref3.value,
153
- _ref3$mode = _ref3.mode,
154
- mode = _ref3$mode === void 0 ? 'classic' : _ref3$mode,
155
- _ref3$iconPosition = _ref3.iconPosition,
156
- iconPosition = _ref3$iconPosition === void 0 ? 'left' : _ref3$iconPosition,
157
- onChange = _ref3.onChange,
158
- style = _ref3.style;
159
- var refsArray = useRef([]);
160
- var containerRef = useRef(null);
161
- var theme = useThemeWithUndefined(themeFromProps);
162
-
163
- var _processOptions = processOptions({
164
- rawOptions: rawOptions,
116
+ let {
117
+ className,
118
+ theme: themeFromProps,
119
+ size = 'm',
120
+ disabled,
121
+ ['data-e2e']: e2eId,
122
+ options: rawOptions,
165
123
  value: switcherValue,
166
- iconPosition: iconPosition
167
- }),
168
- options = _processOptions.options,
169
- activeIndex = _processOptions.activeIndex;
170
-
171
- var handleOptionRef = useCallback(function (index) {
172
- return function (ref) {
173
- if (!ref) {
174
- return;
175
- }
124
+ mode = 'classic',
125
+ iconPosition = 'left',
126
+ onChange,
127
+ style
128
+ } = _ref3;
129
+ const refsArray = useRef([]);
130
+ const containerRef = useRef(null);
131
+ const theme = useThemeWithUndefined(themeFromProps);
132
+ const {
133
+ options,
134
+ activeIndex
135
+ } = processOptions({
136
+ rawOptions,
137
+ value: switcherValue,
138
+ iconPosition
139
+ });
140
+ const handleOptionRef = useCallback(index => ref => {
141
+ if (!ref) {
142
+ return;
143
+ }
176
144
 
177
- if (refsArray.current[index] !== ref) {
178
- refsArray.current[index] = ref;
179
- }
180
- };
145
+ if (refsArray.current[index] !== ref) {
146
+ refsArray.current[index] = ref;
147
+ }
181
148
  }, []);
182
-
183
- var _useState = useState({
149
+ const [mark, setMark] = useState({
184
150
  offset: 0,
185
- height: 0
186
- }),
187
- _useState2 = _slicedToArray(_useState, 2),
188
- mark = _useState2[0],
189
- setMark = _useState2[1];
151
+ height: 0,
152
+ hidden: true
153
+ });
154
+ const [isMarkTransitionEnabled, setIsMarkTransitionEnabled] = useState(false);
155
+ const firstMarkUpdate = useRef(true);
190
156
 
191
- var onResize = function onResize() {
192
- var activeEl = refsArray.current[activeIndex];
157
+ const updateMark = function () {
158
+ let isValueChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
159
+ const activeEl = refsArray.current[activeIndex];
193
160
 
194
161
  if (!activeEl) {
195
162
  return;
196
163
  }
197
164
 
198
- var parentEl = activeEl.parentElement;
199
- var activeElBox = activeEl.getBoundingClientRect();
200
- var parentBox = parentEl.getBoundingClientRect();
165
+ const parentEl = activeEl.parentElement;
166
+ const activeElBox = activeEl.getBoundingClientRect();
167
+ const parentBox = parentEl.getBoundingClientRect();
201
168
  setMark({
202
169
  // standard activeEl.offsetTop always return rounded value, so it does not suit us
203
170
  offset: activeElBox.top - parentBox.top + parentEl.scrollTop,
204
- height: activeElBox.height
171
+ height: activeElBox.height,
172
+ hidden: false
205
173
  });
174
+
175
+ if (firstMarkUpdate.current) {
176
+ firstMarkUpdate.current = false;
177
+ setIsMarkTransitionEnabled(false);
178
+ } else {
179
+ setIsMarkTransitionEnabled(isValueChanged);
180
+ }
206
181
  }; // eslint-disable-next-line react-hooks/exhaustive-deps
207
182
 
208
183
 
209
- useEffect(function () {
210
- return onResize();
211
- }, [activeIndex]);
212
- useResizeObserver(containerRef, onResize);
184
+ useEffect(() => updateMark(true), [activeIndex]);
185
+ useResizeObserver(containerRef, () => updateMark(false), {
186
+ ignoreFirstCall: true
187
+ });
213
188
  return /*#__PURE__*/React.createElement("span", {
214
- className: cn(className, styles.verticalSwitcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled, iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft),
189
+ className: cn(className, styles.verticalSwitcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled, mark.hidden && styles.hiddenMark, iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft),
215
190
  "data-e2e": e2eId,
216
191
  ref: containerRef,
217
192
  "data-rs-internal": 'vertical-switcher',
218
- "data-test": cn("vertical-switcher", disabled && "vertical-switcher-disabled"),
219
- style: style
193
+ "data-test": cn(`vertical-switcher`, disabled && `vertical-switcher-disabled`),
194
+ style: { ...style,
195
+ '--_rs-switcher-vertical-mark-transition-duration': isMarkTransitionEnabled ? MARK_TRANSITION_DURATION : '0s'
196
+ }
220
197
  }, /*#__PURE__*/React.createElement(verticalSwitcherContext.Provider, {
221
198
  value: {
222
199
  switcherValue: (_options$activeIndex = options[activeIndex]) === null || _options$activeIndex === void 0 ? void 0 : _options$activeIndex.value,
223
- onChange: onChange,
224
- handleOptionRef: handleOptionRef,
225
- disabled: disabled
200
+ onChange,
201
+ handleOptionRef,
202
+ disabled
226
203
  }
227
- }, _mapInstanceProperty(options).call(options, function (_ref4, index) {
228
- var value = _ref4.value,
229
- label = _ref4.label,
230
- icon = _ref4.icon;
204
+ }, options.map((_ref4, index) => {
205
+ let {
206
+ value,
207
+ label,
208
+ icon
209
+ } = _ref4;
231
210
  return /*#__PURE__*/React.createElement(Option, {
232
211
  key: String(value),
233
212
  value: value,
@@ -244,7 +223,7 @@ function VerticalSwitcher(_ref3) {
244
223
  })));
245
224
  }
246
225
 
247
- var optionPropType = PropTypes.shape({
226
+ const optionPropType = PropTypes.shape({
248
227
  label: PropTypes.node,
249
228
  value: PropTypes.any.isRequired,
250
229
  icon: PropTypes.node
@@ -1,21 +1,22 @@
1
1
  var styles = {
2
- "themeLight": "_themeLight_el1i9h_6",
3
- "themeDark": "_themeDark_el1i9h_9",
4
- "sizeXS": "_sizeXS_el1i9h_13",
5
- "sizeS": "_sizeS_el1i9h_16",
6
- "sizeM": "_sizeM_el1i9h_19",
7
- "sizeL": "_sizeL_el1i9h_22",
8
- "modeClassic": "_modeClassic_el1i9h_26",
9
- "modeRock": "_modeRock_el1i9h_29",
10
- "verticalSwitcher": "_verticalSwitcher_el1i9h_33",
11
- "disabled": "_disabled_el1i9h_50",
12
- "alignIconLeft": "_alignIconLeft_el1i9h_55",
13
- "alignIconRight": "_alignIconRight_el1i9h_58",
14
- "option": "_option_el1i9h_62",
15
- "selected": "_selected_el1i9h_107",
16
- "optionLabel": "_optionLabel_el1i9h_126",
17
- "icon": "_icon_el1i9h_132",
18
- "fakeIcon": "_fakeIcon_el1i9h_143",
19
- "mark": "_mark_el1i9h_150"
2
+ "themeLight": "_themeLight_1gqbuza_6",
3
+ "themeDark": "_themeDark_1gqbuza_9",
4
+ "sizeXS": "_sizeXS_1gqbuza_13",
5
+ "sizeS": "_sizeS_1gqbuza_16",
6
+ "sizeM": "_sizeM_1gqbuza_19",
7
+ "sizeL": "_sizeL_1gqbuza_22",
8
+ "modeClassic": "_modeClassic_1gqbuza_26",
9
+ "modeRock": "_modeRock_1gqbuza_29",
10
+ "verticalSwitcher": "_verticalSwitcher_1gqbuza_33",
11
+ "disabled": "_disabled_1gqbuza_50",
12
+ "alignIconLeft": "_alignIconLeft_1gqbuza_55",
13
+ "alignIconRight": "_alignIconRight_1gqbuza_58",
14
+ "option": "_option_1gqbuza_62",
15
+ "selected": "_selected_1gqbuza_107",
16
+ "hiddenMark": "_hiddenMark_1gqbuza_116",
17
+ "optionLabel": "_optionLabel_1gqbuza_147",
18
+ "icon": "_icon_1gqbuza_153",
19
+ "fakeIcon": "_fakeIcon_1gqbuza_164",
20
+ "mark": "_mark_1gqbuza_171"
20
21
  };
21
22
  export { styles as default };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@rescui/switcher",
3
- "version": "0.10.3",
3
+ "version": "0.10.5-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
7
7
  "main": "lib/index.js",
8
+ "module": "lib/index.js",
8
9
  "src:main": "src/index.ts",
9
10
  "files": [
10
11
  "lib",
@@ -15,10 +16,9 @@
15
16
  "access": "public"
16
17
  },
17
18
  "dependencies": {
18
- "@babel/runtime-corejs3": "^7.14.0",
19
- "@rescui/use-resize-observer": "^0.2.4",
20
- "classnames": "^2.2.6",
21
- "core-js": "^3.9.1"
19
+ "@babel/runtime-corejs3": "^7.26.0",
20
+ "@rescui/use-resize-observer": "0.2.6-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
21
+ "classnames": "^2.2.6"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@rescui/ui-contexts": "^0.5.0",
@@ -26,15 +26,15 @@
26
26
  "react": ">=16.8.0 <19"
27
27
  },
28
28
  "devDependencies": {
29
- "@rescui/colors": "^0.2.5",
30
- "@rescui/icons": "^0.16.11",
31
- "@rescui/scripts": "^0.3.4",
32
- "@rescui/typography": "^0.19.0"
29
+ "@rescui/colors": "0.2.7-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
30
+ "@rescui/icons": "0.16.13-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
31
+ "@rescui/scripts": "0.4.0",
32
+ "@rescui/typography": "0.19.2-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rescui-scripts build && yarn run build-pcss-api",
36
36
  "build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
37
37
  },
38
38
  "nx": {},
39
- "gitHead": "3ef429c66a082b71861a814ba508693c68a94842"
39
+ "gitHead": "6e43cc893fafb22b990273901bc0a070fb15761f"
40
40
  }