@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.
package/lib/index.js CHANGED
@@ -6,5 +6,5 @@ export { VerticalSwitcher } from './vertical-switcher.js';
6
6
  * @deprecated use named import instead
7
7
  */
8
8
 
9
- var DefaultSwitcher = Switcher;
9
+ const DefaultSwitcher = Switcher;
10
10
  export { DefaultSwitcher as default };
@@ -10,7 +10,7 @@
10
10
  --_rs-switcher-icon-margin-vertical:2px;
11
11
  }
12
12
  &:not(html) [data-rs-internal='switcher__option']{
13
- --_rs-typography-letter-spacing:0.0045em;
13
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
14
14
  --_rs-typography-text-transform:initial;
15
15
  --_rs-typography-font-variant-numeric:initial;
16
16
  --_rs-typography-font-family:var(
@@ -56,7 +56,7 @@
56
56
  --_rs-switcher-icon-margin-vertical:0px;
57
57
  }
58
58
  &:not(html) [data-rs-internal='switcher__option']{
59
- --_rs-typography-letter-spacing:0.0045em;
59
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
60
60
  --_rs-typography-text-transform:initial;
61
61
  --_rs-typography-font-variant-numeric:initial;
62
62
  --_rs-typography-font-family:var(
@@ -102,7 +102,7 @@
102
102
  --_rs-switcher-icon-margin-vertical:0px;
103
103
  }
104
104
  &:not(html) [data-rs-internal='switcher__option']{
105
- --_rs-typography-letter-spacing:0.0015em;
105
+ --_rs-typography-letter-spacing:var(--rs-text-2-letter-spacing, 0.0015em);
106
106
  --_rs-typography-text-transform:initial;
107
107
  --_rs-typography-font-variant-numeric:initial;
108
108
  --_rs-typography-font-family:var(
@@ -130,14 +130,17 @@
130
130
  --_rs-typography-text-auto-offset:16px;
131
131
  --_rs-typography-ul-list-li-padding-left:22px;
132
132
  --_rs-typography-ol-list-li-padding-left:26px;
133
- --_rs-typography-list-li-margin-top-from-text:16px;
133
+ --_rs-typography-list-li-margin-top-from-text:var(
134
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text,
135
+ 16px
136
+ );
134
137
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
135
138
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
136
139
  --_rs-typography-link-border-bottom-width-from-text:1px;
137
140
  }
138
141
  @media screen and (max-width: 640px){
139
142
  &:not(html) [data-rs-internal='switcher__option']{
140
- --_rs-typography-list-li-margin-top-from-text:12px;
143
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text:12px;
141
144
  }
142
145
  }
143
146
  }
@@ -153,7 +156,7 @@
153
156
  --_rs-switcher-icon-margin-vertical:0px;
154
157
  }
155
158
  &:not(html) [data-rs-internal='switcher__option']{
156
- --_rs-typography-letter-spacing:normal;
159
+ --_rs-typography-letter-spacing:var(--rs-text-1-letter-spacing, normal);
157
160
  --_rs-typography-text-transform:initial;
158
161
  --_rs-typography-font-variant-numeric:initial;
159
162
  --_rs-typography-font-family:var(
@@ -181,14 +184,17 @@
181
184
  --_rs-typography-text-auto-offset:32px;
182
185
  --_rs-typography-ul-list-li-padding-left:26px;
183
186
  --_rs-typography-ol-list-li-padding-left:32px;
184
- --_rs-typography-list-li-margin-top-from-text:24px;
187
+ --_rs-typography-list-li-margin-top-from-text:var(
188
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text,
189
+ 24px
190
+ );
185
191
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
186
192
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
187
193
  --_rs-typography-link-border-bottom-width-from-text:1px;
188
194
  }
189
195
  @media screen and (max-width: 640px){
190
196
  &:not(html) [data-rs-internal='switcher__option']{
191
- --_rs-typography-list-li-margin-top-from-text:16px;
197
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text:16px;
192
198
  }
193
199
  }
194
200
  }
@@ -243,7 +249,7 @@
243
249
  --_rs-switcher-vertical-icon-margin-vertical:2px;
244
250
  }
245
251
  &:not(html) [data-rs-internal='vertical-switcher__option']{
246
- --_rs-typography-letter-spacing:0.0045em;
252
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
247
253
  --_rs-typography-text-transform:initial;
248
254
  --_rs-typography-font-variant-numeric:initial;
249
255
  --_rs-typography-font-family:var(
@@ -287,7 +293,7 @@
287
293
  --_rs-switcher-vertical-icon-margin-vertical:0px;
288
294
  }
289
295
  &:not(html) [data-rs-internal='vertical-switcher__option']{
290
- --_rs-typography-letter-spacing:0.0045em;
296
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
291
297
  --_rs-typography-text-transform:initial;
292
298
  --_rs-typography-font-variant-numeric:initial;
293
299
  --_rs-typography-font-family:var(
@@ -331,7 +337,7 @@
331
337
  --_rs-switcher-vertical-icon-margin-vertical:0px;
332
338
  }
333
339
  &:not(html) [data-rs-internal='vertical-switcher__option']{
334
- --_rs-typography-letter-spacing:0.0015em;
340
+ --_rs-typography-letter-spacing:var(--rs-text-2-letter-spacing, 0.0015em);
335
341
  --_rs-typography-text-transform:initial;
336
342
  --_rs-typography-font-variant-numeric:initial;
337
343
  --_rs-typography-font-family:var(
@@ -359,14 +365,17 @@
359
365
  --_rs-typography-text-auto-offset:16px;
360
366
  --_rs-typography-ul-list-li-padding-left:22px;
361
367
  --_rs-typography-ol-list-li-padding-left:26px;
362
- --_rs-typography-list-li-margin-top-from-text:16px;
368
+ --_rs-typography-list-li-margin-top-from-text:var(
369
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text,
370
+ 16px
371
+ );
363
372
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
364
373
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
365
374
  --_rs-typography-link-border-bottom-width-from-text:1px;
366
375
  }
367
376
  @media screen and (max-width: 640px){
368
377
  &:not(html) [data-rs-internal='vertical-switcher__option']{
369
- --_rs-typography-list-li-margin-top-from-text:12px;
378
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text:12px;
370
379
  }
371
380
  }
372
381
  }
@@ -380,7 +389,7 @@
380
389
  --_rs-switcher-vertical-icon-margin-vertical:0px;
381
390
  }
382
391
  &:not(html) [data-rs-internal='vertical-switcher__option']{
383
- --_rs-typography-letter-spacing:normal;
392
+ --_rs-typography-letter-spacing:var(--rs-text-1-letter-spacing, normal);
384
393
  --_rs-typography-text-transform:initial;
385
394
  --_rs-typography-font-variant-numeric:initial;
386
395
  --_rs-typography-font-family:var(
@@ -408,14 +417,17 @@
408
417
  --_rs-typography-text-auto-offset:32px;
409
418
  --_rs-typography-ul-list-li-padding-left:26px;
410
419
  --_rs-typography-ol-list-li-padding-left:32px;
411
- --_rs-typography-list-li-margin-top-from-text:24px;
420
+ --_rs-typography-list-li-margin-top-from-text:var(
421
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text,
422
+ 24px
423
+ );
412
424
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
413
425
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
414
426
  --_rs-typography-link-border-bottom-width-from-text:1px;
415
427
  }
416
428
  @media screen and (max-width: 640px){
417
429
  &:not(html) [data-rs-internal='vertical-switcher__option']{
418
- --_rs-typography-list-li-margin-top-from-text:16px;
430
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text:16px;
419
431
  }
420
432
  }
421
433
  }
@@ -10,7 +10,7 @@
10
10
  --_rs-switcher-icon-margin-vertical:2px;
11
11
  }
12
12
  &:not(html) [data-rs-internal='switcher__option']{
13
- --_rs-typography-letter-spacing:0.0045em;
13
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
14
14
  --_rs-typography-text-transform:initial;
15
15
  --_rs-typography-font-variant-numeric:initial;
16
16
  --_rs-typography-font-family:var(
@@ -56,7 +56,7 @@
56
56
  --_rs-switcher-icon-margin-vertical:0px;
57
57
  }
58
58
  &:not(html) [data-rs-internal='switcher__option']{
59
- --_rs-typography-letter-spacing:0.0045em;
59
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
60
60
  --_rs-typography-text-transform:initial;
61
61
  --_rs-typography-font-variant-numeric:initial;
62
62
  --_rs-typography-font-family:var(
@@ -102,7 +102,7 @@
102
102
  --_rs-switcher-icon-margin-vertical:0px;
103
103
  }
104
104
  &:not(html) [data-rs-internal='switcher__option']{
105
- --_rs-typography-letter-spacing:0.0015em;
105
+ --_rs-typography-letter-spacing:var(--rs-text-2-letter-spacing, 0.0015em);
106
106
  --_rs-typography-text-transform:initial;
107
107
  --_rs-typography-font-variant-numeric:initial;
108
108
  --_rs-typography-font-family:var(
@@ -130,14 +130,17 @@
130
130
  --_rs-typography-text-auto-offset:16px;
131
131
  --_rs-typography-ul-list-li-padding-left:22px;
132
132
  --_rs-typography-ol-list-li-padding-left:26px;
133
- --_rs-typography-list-li-margin-top-from-text:16px;
133
+ --_rs-typography-list-li-margin-top-from-text:var(
134
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text,
135
+ 16px
136
+ );
134
137
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
135
138
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
136
139
  --_rs-typography-link-border-bottom-width-from-text:1px;
137
140
  }
138
141
  @media screen and (max-width: 640px){
139
142
  &:not(html) [data-rs-internal='switcher__option']{
140
- --_rs-typography-list-li-margin-top-from-text:12px;
143
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text:12px;
141
144
  }
142
145
  }
143
146
  }
@@ -153,7 +156,7 @@
153
156
  --_rs-switcher-icon-margin-vertical:0px;
154
157
  }
155
158
  &:not(html) [data-rs-internal='switcher__option']{
156
- --_rs-typography-letter-spacing:normal;
159
+ --_rs-typography-letter-spacing:var(--rs-text-1-letter-spacing, normal);
157
160
  --_rs-typography-text-transform:initial;
158
161
  --_rs-typography-font-variant-numeric:initial;
159
162
  --_rs-typography-font-family:var(
@@ -181,14 +184,17 @@
181
184
  --_rs-typography-text-auto-offset:32px;
182
185
  --_rs-typography-ul-list-li-padding-left:26px;
183
186
  --_rs-typography-ol-list-li-padding-left:32px;
184
- --_rs-typography-list-li-margin-top-from-text:24px;
187
+ --_rs-typography-list-li-margin-top-from-text:var(
188
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text,
189
+ 24px
190
+ );
185
191
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
186
192
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
187
193
  --_rs-typography-link-border-bottom-width-from-text:1px;
188
194
  }
189
195
  @media screen and (max-width: 640px){
190
196
  &:not(html) [data-rs-internal='switcher__option']{
191
- --_rs-typography-list-li-margin-top-from-text:16px;
197
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text:16px;
192
198
  }
193
199
  }
194
200
  }
@@ -243,7 +249,7 @@
243
249
  --_rs-switcher-vertical-icon-margin-vertical:2px;
244
250
  }
245
251
  &:not(html) [data-rs-internal='vertical-switcher__option']{
246
- --_rs-typography-letter-spacing:0.0045em;
252
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
247
253
  --_rs-typography-text-transform:initial;
248
254
  --_rs-typography-font-variant-numeric:initial;
249
255
  --_rs-typography-font-family:var(
@@ -287,7 +293,7 @@
287
293
  --_rs-switcher-vertical-icon-margin-vertical:0px;
288
294
  }
289
295
  &:not(html) [data-rs-internal='vertical-switcher__option']{
290
- --_rs-typography-letter-spacing:0.0045em;
296
+ --_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
291
297
  --_rs-typography-text-transform:initial;
292
298
  --_rs-typography-font-variant-numeric:initial;
293
299
  --_rs-typography-font-family:var(
@@ -331,7 +337,7 @@
331
337
  --_rs-switcher-vertical-icon-margin-vertical:0px;
332
338
  }
333
339
  &:not(html) [data-rs-internal='vertical-switcher__option']{
334
- --_rs-typography-letter-spacing:0.0015em;
340
+ --_rs-typography-letter-spacing:var(--rs-text-2-letter-spacing, 0.0015em);
335
341
  --_rs-typography-text-transform:initial;
336
342
  --_rs-typography-font-variant-numeric:initial;
337
343
  --_rs-typography-font-family:var(
@@ -359,14 +365,17 @@
359
365
  --_rs-typography-text-auto-offset:16px;
360
366
  --_rs-typography-ul-list-li-padding-left:22px;
361
367
  --_rs-typography-ol-list-li-padding-left:26px;
362
- --_rs-typography-list-li-margin-top-from-text:16px;
368
+ --_rs-typography-list-li-margin-top-from-text:var(
369
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text,
370
+ 16px
371
+ );
363
372
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
364
373
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
365
374
  --_rs-typography-link-border-bottom-width-from-text:1px;
366
375
  }
367
376
  @media screen and (max-width: 640px){
368
377
  &:not(html) [data-rs-internal='vertical-switcher__option']{
369
- --_rs-typography-list-li-margin-top-from-text:12px;
378
+ --_rs-typography-text-2-sm-list-li-margin-top-from-text:12px;
370
379
  }
371
380
  }
372
381
  }
@@ -380,7 +389,7 @@
380
389
  --_rs-switcher-vertical-icon-margin-vertical:0px;
381
390
  }
382
391
  &:not(html) [data-rs-internal='vertical-switcher__option']{
383
- --_rs-typography-letter-spacing:normal;
392
+ --_rs-typography-letter-spacing:var(--rs-text-1-letter-spacing, normal);
384
393
  --_rs-typography-text-transform:initial;
385
394
  --_rs-typography-font-variant-numeric:initial;
386
395
  --_rs-typography-font-family:var(
@@ -408,14 +417,17 @@
408
417
  --_rs-typography-text-auto-offset:32px;
409
418
  --_rs-typography-ul-list-li-padding-left:26px;
410
419
  --_rs-typography-ol-list-li-padding-left:32px;
411
- --_rs-typography-list-li-margin-top-from-text:24px;
420
+ --_rs-typography-list-li-margin-top-from-text:var(
421
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text,
422
+ 24px
423
+ );
412
424
  --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
413
425
  --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
414
426
  --_rs-typography-link-border-bottom-width-from-text:1px;
415
427
  }
416
428
  @media screen and (max-width: 640px){
417
429
  &:not(html) [data-rs-internal='vertical-switcher__option']{
418
- --_rs-typography-list-li-margin-top-from-text:16px;
430
+ --_rs-typography-text-1-sm-list-li-margin-top-from-text:16px;
419
431
  }
420
432
  }
421
433
  }
package/lib/switcher.d.ts CHANGED
@@ -28,8 +28,10 @@ export interface SwitcherProps<ValueType, OptionsValueType extends ValueType> {
28
28
  'data-e2e'?: string;
29
29
  /** **Works only if the `icon` on options is present.** Additional icon position. */
30
30
  iconPosition?: SwitcherOptionIconPosition;
31
+ /** CSS style object */
32
+ style?: React.CSSProperties;
31
33
  }
32
- export declare function Switcher<ValueType, OptionsValueType extends ValueType = ValueType>({ className, theme: themeFromProps, size, disabled, compact, ['data-e2e']: e2eId, options, value: switcherValue, mode, iconPosition, onChange }: SwitcherProps<ValueType, OptionsValueType>): JSX.Element;
34
+ export declare function Switcher<ValueType, OptionsValueType extends ValueType = ValueType>({ className, theme: themeFromProps, size, disabled, compact, ['data-e2e']: e2eId, options, value: switcherValue, mode, iconPosition, onChange, style }: SwitcherProps<ValueType, OptionsValueType>): JSX.Element;
33
35
  export declare namespace Switcher {
34
36
  var propTypes: {};
35
37
  }
package/lib/switcher.js CHANGED
@@ -1,48 +1,43 @@
1
- import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
- import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
3
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
4
1
  import React, { cloneElement, useRef, useCallback, useState, useEffect } from 'react';
5
2
  import PropTypes from 'prop-types';
6
3
  import cn from 'classnames';
7
4
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
8
5
  import { useResizeObserver } from '@rescui/use-resize-observer';
9
6
  import styles from './switcher.p.module.css.js';
10
- var sizeToClass = {
7
+ const MARK_TRANSITION_DURATION = '0.2s';
8
+ const sizeToClass = {
11
9
  l: styles.sizeL,
12
10
  m: styles.sizeM,
13
11
  s: styles.sizeS,
14
12
  xs: styles.sizeXS
15
13
  };
16
- var themeToClass = {
14
+ const themeToClass = {
17
15
  light: styles.themeLight,
18
16
  dark: styles.themeDark
19
17
  };
20
- var modeToClass = {
18
+ const modeToClass = {
21
19
  classic: styles.modeClassic,
22
20
  rock: styles.modeRock
23
21
  };
24
22
 
25
- var findIndexByValue = function findIndexByValue(options, value) {
26
- var index = _findIndexInstanceProperty(options).call(options, function (option) {
27
- return option.value === value;
28
- });
29
-
23
+ const findIndexByValue = (options, value) => {
24
+ const index = options.findIndex(option => option.value === value);
30
25
  return index === -1 ? 0 : index;
31
26
  }; // check for ignored jsx values and empty string, more info https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored
32
27
 
33
28
 
34
- var isNodeEmpty = function isNodeEmpty(node) {
35
- return node === null || typeof node === 'undefined' || node === false || node === true || node === '';
36
- };
29
+ const isNodeEmpty = node => node === null || typeof node === 'undefined' || node === false || node === true || node === '';
37
30
 
38
- var optionRenderer = function optionRenderer(_ref, ref) {
39
- var label = _ref.label,
40
- value = _ref.value,
41
- icon = _ref.icon,
42
- disabled = _ref.disabled,
43
- onClick = _ref.onClick,
44
- selected = _ref.selected;
45
- var isWithoutText = isNodeEmpty(label);
31
+ const optionRenderer = (_ref, ref) => {
32
+ let {
33
+ label,
34
+ value,
35
+ icon,
36
+ disabled,
37
+ onClick,
38
+ selected
39
+ } = _ref;
40
+ const isWithoutText = isNodeEmpty(label);
46
41
  return /*#__PURE__*/React.createElement("button", {
47
42
  key: String(value),
48
43
  ref: ref,
@@ -52,94 +47,101 @@ var optionRenderer = function optionRenderer(_ref, ref) {
52
47
  disabled: disabled,
53
48
  className: cn(styles.option, selected && styles.selected)
54
49
  }, /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/cloneElement(icon, {
55
- className: cn(icon.props.className, styles.icon)
50
+ className: cn(icon.props.className, styles.icon),
51
+ 'data-render-all-sizes': true
56
52
  }), !isWithoutText && /*#__PURE__*/React.createElement("span", null, label));
57
53
  };
58
54
 
59
- var Option = /*#__PURE__*/React.forwardRef(optionRenderer);
55
+ const Option = /*#__PURE__*/React.forwardRef(optionRenderer);
60
56
 
61
57
  function Switcher(_ref2) {
62
- var className = _ref2.className,
63
- themeFromProps = _ref2.theme,
64
- _ref2$size = _ref2.size,
65
- size = _ref2$size === void 0 ? 'm' : _ref2$size,
66
- disabled = _ref2.disabled,
67
- _ref2$compact = _ref2.compact,
68
- compact = _ref2$compact === void 0 ? false : _ref2$compact,
69
- e2eId = _ref2['data-e2e'],
70
- options = _ref2.options,
71
- switcherValue = _ref2.value,
72
- _ref2$mode = _ref2.mode,
73
- mode = _ref2$mode === void 0 ? 'classic' : _ref2$mode,
74
- _ref2$iconPosition = _ref2.iconPosition,
75
- iconPosition = _ref2$iconPosition === void 0 ? 'left' : _ref2$iconPosition,
76
- onChange = _ref2.onChange;
77
- var refsArray = useRef([]);
78
- var containerRef = useRef(null);
79
- var theme = useThemeWithUndefined(themeFromProps);
80
- var handleOptionRef = useCallback(function (index) {
81
- return function (ref) {
82
- if (!ref) {
83
- return;
84
- }
58
+ let {
59
+ className,
60
+ theme: themeFromProps,
61
+ size = 'm',
62
+ disabled,
63
+ compact = false,
64
+ ['data-e2e']: e2eId,
65
+ options,
66
+ value: switcherValue,
67
+ mode = 'classic',
68
+ iconPosition = 'left',
69
+ onChange,
70
+ style
71
+ } = _ref2;
72
+ const refsArray = useRef([]);
73
+ const containerRef = useRef(null);
74
+ const theme = useThemeWithUndefined(themeFromProps);
75
+ const handleOptionRef = useCallback(index => ref => {
76
+ if (!ref) {
77
+ return;
78
+ }
85
79
 
86
- if (refsArray.current[index] !== ref) {
87
- refsArray.current[index] = ref;
88
- }
89
- };
80
+ if (refsArray.current[index] !== ref) {
81
+ refsArray.current[index] = ref;
82
+ }
90
83
  }, []);
91
- var activeIndex = findIndexByValue(options, switcherValue);
92
-
93
- var _useState = useState({
84
+ const activeIndex = findIndexByValue(options, switcherValue);
85
+ const [mark, setMark] = useState({
94
86
  offset: 0,
95
- width: 0
96
- }),
97
- _useState2 = _slicedToArray(_useState, 2),
98
- mark = _useState2[0],
99
- setMark = _useState2[1];
87
+ width: 0,
88
+ hidden: true
89
+ });
90
+ const [isMarkTransitionEnabled, setIsMarkTransitionEnabled] = useState(false);
91
+ const firstMarkUpdate = useRef(true);
100
92
 
101
- var onResize = function onResize() {
102
- var activeEl = refsArray.current[activeIndex];
93
+ const updateMark = function () {
94
+ let isValueChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
95
+ const activeEl = refsArray.current[activeIndex];
103
96
 
104
97
  if (!activeEl) {
105
98
  return;
106
99
  }
107
100
 
108
- var activeElBox = activeEl.getBoundingClientRect();
109
- var parentBox = activeEl.parentElement.getBoundingClientRect();
101
+ const activeElBox = activeEl.getBoundingClientRect();
102
+ const parentBox = activeEl.parentElement.getBoundingClientRect();
110
103
  setMark({
111
104
  // standard activeEl.offsetLeft always return rounded value, so it does not suit us
112
105
  offset: activeElBox.left - parentBox.left,
113
- width: activeElBox.width
106
+ width: activeElBox.width,
107
+ hidden: false
114
108
  });
109
+
110
+ if (firstMarkUpdate.current) {
111
+ firstMarkUpdate.current = false;
112
+ setIsMarkTransitionEnabled(false);
113
+ } else {
114
+ setIsMarkTransitionEnabled(isValueChanged);
115
+ }
115
116
  }; // eslint-disable-next-line react-hooks/exhaustive-deps
116
117
 
117
118
 
118
- useEffect(function () {
119
- return onResize();
120
- }, [activeIndex]);
121
- useResizeObserver(containerRef, onResize);
119
+ useEffect(() => updateMark(true), [activeIndex]);
120
+ useResizeObserver(containerRef, () => updateMark(false));
122
121
  return /*#__PURE__*/React.createElement("span", {
123
- className: cn(className, styles.switcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled, compact && styles.compact, iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft),
122
+ className: cn(className, styles.switcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled, compact && styles.compact, mark.hidden && styles.hiddenMark, iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft),
124
123
  "data-e2e": e2eId,
125
124
  ref: containerRef,
126
125
  "data-rs-internal": 'switcher',
127
- "data-test": cn("switcher", disabled && "switcher-disabled")
128
- }, _mapInstanceProperty(options).call(options, function (_ref3, index) {
126
+ "data-test": cn(`switcher`, disabled && `switcher-disabled`),
127
+ style: { ...style,
128
+ '--_rs-switcher-mark-transition-duration': isMarkTransitionEnabled ? MARK_TRANSITION_DURATION : '0s'
129
+ }
130
+ }, options.map((_ref3, index) => {
129
131
  var _options$activeIndex;
130
132
 
131
- var value = _ref3.value,
132
- label = _ref3.label,
133
- icon = _ref3.icon;
133
+ let {
134
+ value,
135
+ label,
136
+ icon
137
+ } = _ref3;
134
138
  return /*#__PURE__*/React.createElement(Option, {
135
139
  key: String(value),
136
140
  value: value,
137
141
  label: label,
138
142
  icon: icon,
139
143
  disabled: disabled,
140
- onClick: function onClick() {
141
- return onChange(value);
142
- },
144
+ onClick: () => onChange(value),
143
145
  ref: handleOptionRef(index),
144
146
  selected: ((_options$activeIndex = options[activeIndex]) === null || _options$activeIndex === void 0 ? void 0 : _options$activeIndex.value) === value
145
147
  });
@@ -152,7 +154,7 @@ function Switcher(_ref2) {
152
154
  }));
153
155
  }
154
156
 
155
- var optionPropType = PropTypes.shape({
157
+ const optionPropType = PropTypes.shape({
156
158
  label: PropTypes.node,
157
159
  value: PropTypes.any.isRequired,
158
160
  icon: PropTypes.node
@@ -166,6 +168,7 @@ Switcher.propTypes = {
166
168
  theme: PropTypes.oneOf(['light', 'dark']),
167
169
  disabled: PropTypes.bool,
168
170
  iconPosition: PropTypes.oneOf(['left', 'right']),
169
- 'data-e2e': PropTypes.string
171
+ 'data-e2e': PropTypes.string,
172
+ style: PropTypes.object
170
173
  };
171
174
  export { Switcher, Switcher as default };
@@ -1,20 +1,21 @@
1
1
  var styles = {
2
- "themeLight": "_themeLight_1i5u8r0_6",
3
- "themeDark": "_themeDark_1i5u8r0_9",
4
- "sizeXS": "_sizeXS_1i5u8r0_13",
5
- "sizeS": "_sizeS_1i5u8r0_16",
6
- "sizeM": "_sizeM_1i5u8r0_19",
7
- "sizeL": "_sizeL_1i5u8r0_22",
8
- "modeClassic": "_modeClassic_1i5u8r0_26",
9
- "modeRock": "_modeRock_1i5u8r0_29",
10
- "compact": "_compact_1i5u8r0_33",
11
- "switcher": "_switcher_1i5u8r0_37",
12
- "disabled": "_disabled_1i5u8r0_55",
13
- "alignIconLeft": "_alignIconLeft_1i5u8r0_60",
14
- "alignIconRight": "_alignIconRight_1i5u8r0_63",
15
- "option": "_option_1i5u8r0_67",
16
- "selected": "_selected_1i5u8r0_118",
17
- "icon": "_icon_1i5u8r0_137",
18
- "mark": "_mark_1i5u8r0_150"
2
+ "themeLight": "_themeLight_1ehnp4f_6",
3
+ "themeDark": "_themeDark_1ehnp4f_9",
4
+ "sizeXS": "_sizeXS_1ehnp4f_13",
5
+ "sizeS": "_sizeS_1ehnp4f_16",
6
+ "sizeM": "_sizeM_1ehnp4f_19",
7
+ "sizeL": "_sizeL_1ehnp4f_22",
8
+ "modeClassic": "_modeClassic_1ehnp4f_26",
9
+ "modeRock": "_modeRock_1ehnp4f_29",
10
+ "compact": "_compact_1ehnp4f_33",
11
+ "switcher": "_switcher_1ehnp4f_37",
12
+ "disabled": "_disabled_1ehnp4f_55",
13
+ "alignIconLeft": "_alignIconLeft_1ehnp4f_60",
14
+ "alignIconRight": "_alignIconRight_1ehnp4f_63",
15
+ "option": "_option_1ehnp4f_67",
16
+ "selected": "_selected_1ehnp4f_118",
17
+ "hiddenMark": "_hiddenMark_1ehnp4f_127",
18
+ "icon": "_icon_1ehnp4f_158",
19
+ "mark": "_mark_1ehnp4f_171"
19
20
  };
20
21
  export { styles as default };