@rescui/switcher 0.1.2 → 0.1.3

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.css CHANGED
@@ -1,4 +1,4 @@
1
- ._switcher_8dando_4{
1
+ ._switcher_defyb_4{
2
2
 
3
3
  position:relative;
4
4
 
@@ -16,21 +16,21 @@
16
16
 
17
17
  background:transparent;
18
18
  }
19
- ._themeLight_8dando_17{
19
+ ._themeLight_defyb_17{
20
20
  -webkit-box-shadow:inset rgba(25,25,28,0.4) 0 0 0 1px;
21
21
  box-shadow:inset rgba(25,25,28,0.4) 0 0 0 1px;
22
22
  }
23
- ._themeDark_8dando_21{
23
+ ._themeDark_defyb_21{
24
24
  -webkit-box-shadow:inset rgba(255,255,255,0.5) 0 0 0 1px;
25
25
  box-shadow:inset rgba(255,255,255,0.5) 0 0 0 1px;
26
26
  }
27
- ._sizeL_8dando_25{
27
+ ._sizeL_defyb_25{
28
28
  border-radius:36px;
29
29
  }
30
- ._sizeXS_8dando_29{
30
+ ._sizeXS_defyb_29{
31
31
  border-radius:4px;
32
32
  }
33
- ._option_8dando_33{
33
+ ._option_defyb_33{
34
34
  position:relative;
35
35
  -webkit-appearance:none;
36
36
  -moz-appearance:none;
@@ -50,7 +50,7 @@
50
50
 
51
51
  background:transparent;
52
52
  }
53
- ._sizeL_8dando_25 ._option_8dando_33{
53
+ ._sizeL_defyb_25 ._option_defyb_33{
54
54
  padding:12px 32px;
55
55
  color:rgba(25,25,28,0.7);
56
56
  color:var(--rs-typography-color-average, rgba(25,25,28,0.7));
@@ -63,7 +63,7 @@
63
63
  line-height:var(--rs-text-1-line-height, 28px);
64
64
  border-radius:36px;
65
65
  }
66
- ._sizeM_8dando_56 ._option_8dando_33{
66
+ ._sizeM_defyb_56 ._option_defyb_33{
67
67
  padding:8px 24px;
68
68
  letter-spacing:0.0015em;
69
69
  color:rgba(25,25,28,0.7);
@@ -76,10 +76,10 @@
76
76
  line-height:24px;
77
77
  line-height:var(--rs-text-2-line-height, 24px);
78
78
  }
79
- ._rs-reset-letter-spacing_8dando_1 ._sizeM_8dando_56 ._option_8dando_33{
79
+ ._rs-reset-letter-spacing_defyb_1 ._sizeM_defyb_56 ._option_defyb_33{
80
80
  letter-spacing:normal;
81
81
  }
82
- ._sizeS_8dando_61 ._option_8dando_33{
82
+ ._sizeS_defyb_61 ._option_defyb_33{
83
83
  padding:6px 16px;
84
84
  letter-spacing:0.0015em;
85
85
  color:rgba(25,25,28,0.7);
@@ -92,10 +92,10 @@
92
92
  line-height:24px;
93
93
  line-height:var(--rs-text-2-line-height, 24px);
94
94
  }
95
- ._rs-reset-letter-spacing_8dando_1 ._sizeS_8dando_61 ._option_8dando_33{
95
+ ._rs-reset-letter-spacing_defyb_1 ._sizeS_defyb_61 ._option_defyb_33{
96
96
  letter-spacing:normal;
97
97
  }
98
- ._sizeXS_8dando_29 ._option_8dando_33{
98
+ ._sizeXS_defyb_29 ._option_defyb_33{
99
99
  padding:2px 12px;
100
100
  letter-spacing:0.0045em;
101
101
  color:rgba(25,25,28,0.7);
@@ -107,68 +107,68 @@
107
107
  line-height:20px;
108
108
  line-height:var(--rs-text-3-line-height, 20px);
109
109
  }
110
- ._rs-reset-letter-spacing_8dando_1 ._sizeXS_8dando_29 ._option_8dando_33{
110
+ ._rs-reset-letter-spacing_defyb_1 ._sizeXS_defyb_29 ._option_defyb_33{
111
111
  letter-spacing:normal;
112
112
  }
113
- ._sizeXS_8dando_29 ._option_8dando_33 {
113
+ ._sizeXS_defyb_29 ._option_defyb_33 {
114
114
  border-radius:4px;
115
115
  }
116
- ._disabled_8dando_72 ._option_8dando_33{
116
+ ._disabled_defyb_72 ._option_defyb_33{
117
117
  cursor:not-allowed;
118
118
  pointer-events:none;
119
119
  }
120
- ._themeLight_8dando_17 ._option_8dando_33{
120
+ ._themeLight_defyb_17 ._option_defyb_33{
121
121
  color:#19191C;
122
122
  }
123
- ._themeLight_8dando_17 ._option_8dando_33:focus[data-focus-method='key']{
123
+ ._themeLight_defyb_17 ._option_defyb_33:focus[data-focus-method='key']{
124
124
  -webkit-box-shadow:rgba(22,125,255,0.8) 0 0 0 4px;
125
125
  -webkit-box-shadow:var(--rs-color-primary-t-dim-light-theme, rgba(22,125,255,0.8)) 0 0 0 4px;
126
126
  box-shadow:rgba(22,125,255,0.8) 0 0 0 4px;
127
127
  box-shadow:var(--rs-color-primary-t-dim-light-theme, rgba(22,125,255,0.8)) 0 0 0 4px;
128
128
  }
129
- ._themeLight_8dando_17 ._option_8dando_33._selected_8dando_85:hover, ._themeLight_8dando_17 ._option_8dando_33._selected_8dando_85:active{
129
+ ._themeLight_defyb_17 ._option_defyb_33._selected_defyb_85:hover, ._themeLight_defyb_17 ._option_defyb_33._selected_defyb_85:active{
130
130
  background:transparent;
131
131
  cursor:default;
132
132
  }
133
- ._themeLight_8dando_17._modeClassic_8dando_93 ._option_8dando_33:hover{
133
+ ._themeLight_defyb_17._modeClassic_defyb_93 ._option_defyb_33:hover{
134
134
  background:rgba(22,125,255,0.2);
135
135
  background:var(--rs-color-primary-t-fog-light-theme, rgba(22,125,255,0.2));
136
136
  }
137
- ._themeLight_8dando_17._modeRock_8dando_99 ._option_8dando_33:hover{
137
+ ._themeLight_defyb_17._modeRock_defyb_99 ._option_defyb_33:hover{
138
138
  background:rgba(25,25,28,0.1);
139
139
  }
140
- ._disabled_8dando_72._themeLight_8dando_17 ._option_8dando_33,
141
- ._disabled_8dando_72._themeLight_8dando_17 ._option_8dando_33._selected_8dando_85{
140
+ ._disabled_defyb_72._themeLight_defyb_17 ._option_defyb_33,
141
+ ._disabled_defyb_72._themeLight_defyb_17 ._option_defyb_33._selected_defyb_85{
142
142
  color:rgba(25,25,28,0.4);
143
143
  }
144
- ._themeDark_8dando_21 ._option_8dando_33{
144
+ ._themeDark_defyb_21 ._option_defyb_33{
145
145
  color:#FFFFFF;
146
146
  }
147
- ._themeDark_8dando_21 ._option_8dando_33:hover{
147
+ ._themeDark_defyb_21 ._option_defyb_33:hover{
148
148
  background:rgba(255,255,255,0.1);
149
149
  }
150
- ._themeDark_8dando_21 ._option_8dando_33:focus[data-focus-method='key']{
150
+ ._themeDark_defyb_21 ._option_defyb_33:focus[data-focus-method='key']{
151
151
  -webkit-box-shadow:rgba(76,166,255,0.8) 0 0 0 4px;
152
152
  -webkit-box-shadow:var(--rs-color-primary-t-dim-dark-theme, rgba(76,166,255,0.8)) 0 0 0 4px;
153
153
  box-shadow:rgba(76,166,255,0.8) 0 0 0 4px;
154
154
  box-shadow:var(--rs-color-primary-t-dim-dark-theme, rgba(76,166,255,0.8)) 0 0 0 4px;
155
155
  }
156
- ._themeDark_8dando_21 ._option_8dando_33._selected_8dando_85:hover, ._themeDark_8dando_21 ._option_8dando_33._selected_8dando_85:active{
156
+ ._themeDark_defyb_21 ._option_defyb_33._selected_defyb_85:hover, ._themeDark_defyb_21 ._option_defyb_33._selected_defyb_85:active{
157
157
  background:transparent;
158
158
  cursor:default;
159
159
  }
160
- ._themeDark_8dando_21._modeClassic_8dando_93 ._option_8dando_33:hover{
160
+ ._themeDark_defyb_21._modeClassic_defyb_93 ._option_defyb_33:hover{
161
161
  background:rgba(76,166,255,0.3);
162
162
  background:var(--rs-color-primary-t-fog-dark-theme, rgba(76,166,255,0.3));
163
163
  }
164
- ._themeDark_8dando_21._modeRock_8dando_99 ._option_8dando_33:hover{
164
+ ._themeDark_defyb_21._modeRock_defyb_99 ._option_defyb_33:hover{
165
165
  background:rgba(255,255,255,0.1);
166
166
  }
167
- ._disabled_8dando_72._themeDark_8dando_21 ._option_8dando_33,
168
- ._disabled_8dando_72._themeDark_8dando_21 ._option_8dando_33._selected_8dando_85{
167
+ ._disabled_defyb_72._themeDark_defyb_21 ._option_defyb_33,
168
+ ._disabled_defyb_72._themeDark_defyb_21 ._option_defyb_33._selected_defyb_85{
169
169
  color:rgba(255,255,255,0.2);
170
170
  }
171
- ._mark_8dando_146{
171
+ ._mark_defyb_146{
172
172
  position:absolute;
173
173
  top:0;
174
174
  bottom:0;
@@ -176,34 +176,32 @@
176
176
  -webkit-box-sizing:border-box;
177
177
  box-sizing:border-box;
178
178
  border-radius:24px;
179
-
180
179
  -webkit-transition:all 0.3s;
181
-
182
180
  transition:all 0.3s;
183
181
  }
184
- ._themeLight_8dando_17._modeClassic_8dando_93 ._mark_8dando_146{
182
+ ._themeLight_defyb_17._modeClassic_defyb_93 ._mark_defyb_146{
185
183
  border:solid 2px #167DFF;
186
184
  border:solid 2px var(--rs-color-primary-light-theme, #167DFF);
187
185
  }
188
- ._themeDark_8dando_21._modeClassic_8dando_93 ._mark_8dando_146{
186
+ ._themeDark_defyb_21._modeClassic_defyb_93 ._mark_defyb_146{
189
187
  border:solid 2px #4CA6ff;
190
188
  border:solid 2px var(--rs-color-primary-dark-theme, #4CA6ff);
191
189
  }
192
- ._themeLight_8dando_17._modeRock_8dando_99 ._mark_8dando_146{
190
+ ._themeLight_defyb_17._modeRock_defyb_99 ._mark_defyb_146{
193
191
  border:solid 2px #19191C;
194
192
  }
195
- ._themeDark_8dando_21._modeRock_8dando_99 ._mark_8dando_146{
193
+ ._themeDark_defyb_21._modeRock_defyb_99 ._mark_defyb_146{
196
194
  border:solid 2px #FFFFFF;
197
195
  }
198
- ._sizeL_8dando_25 ._mark_8dando_146{
196
+ ._sizeL_defyb_25 ._mark_defyb_146{
199
197
  border-radius:36px;
200
198
  }
201
- ._sizeXS_8dando_29 ._mark_8dando_146{
199
+ ._sizeXS_defyb_29 ._mark_defyb_146{
202
200
  border-radius:4px;
203
201
  }
204
- ._themeLight_8dando_17._disabled_8dando_72 ._mark_8dando_146{
202
+ ._themeLight_defyb_17._disabled_defyb_72 ._mark_defyb_146{
205
203
  border:solid 2px rgba(25,25,28,0.4);
206
204
  }
207
- ._themeDark_8dando_21._disabled_8dando_72 ._mark_8dando_146{
205
+ ._themeDark_defyb_21._disabled_defyb_72 ._mark_defyb_146{
208
206
  border:solid 2px rgba(255,255,255,0.2);
209
207
  }
@@ -1,17 +1,17 @@
1
1
  var styles = {
2
- "switcher": "_switcher_8dando_4",
3
- "themeLight": "_themeLight_8dando_17",
4
- "themeDark": "_themeDark_8dando_21",
5
- "sizeL": "_sizeL_8dando_25",
6
- "sizeXS": "_sizeXS_8dando_29",
7
- "option": "_option_8dando_33",
8
- "sizeM": "_sizeM_8dando_56",
9
- "rs-reset-letter-spacing": "_rs-reset-letter-spacing_8dando_1",
10
- "sizeS": "_sizeS_8dando_61",
11
- "disabled": "_disabled_8dando_72",
12
- "selected": "_selected_8dando_85",
13
- "modeClassic": "_modeClassic_8dando_93",
14
- "modeRock": "_modeRock_8dando_99",
15
- "mark": "_mark_8dando_146"
2
+ "switcher": "_switcher_defyb_4",
3
+ "themeLight": "_themeLight_defyb_17",
4
+ "themeDark": "_themeDark_defyb_21",
5
+ "sizeL": "_sizeL_defyb_25",
6
+ "sizeXS": "_sizeXS_defyb_29",
7
+ "option": "_option_defyb_33",
8
+ "sizeM": "_sizeM_defyb_56",
9
+ "rs-reset-letter-spacing": "_rs-reset-letter-spacing_defyb_1",
10
+ "sizeS": "_sizeS_defyb_61",
11
+ "disabled": "_disabled_defyb_72",
12
+ "selected": "_selected_defyb_85",
13
+ "modeClassic": "_modeClassic_defyb_93",
14
+ "modeRock": "_modeRock_defyb_99",
15
+ "mark": "_mark_defyb_146"
16
16
  };
17
17
  export default styles;
package/lib/switcher.js CHANGED
@@ -1,7 +1,8 @@
1
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
1
2
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
2
3
  import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
3
4
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
4
- import React, { useRef, useMemo, useCallback } from 'react';
5
+ import React, { useState, useRef, useMemo, useCallback } from 'react';
5
6
  import PropTypes from 'prop-types';
6
7
  import { useResizeDetector } from 'react-resize-detector';
7
8
  import cn from 'classnames';
@@ -68,15 +69,18 @@ var Switcher = function Switcher(_ref2) {
68
69
  _ref2$mode = _ref2.mode,
69
70
  mode = _ref2$mode === void 0 ? 'classic' : _ref2$mode,
70
71
  onChange = _ref2.onChange;
72
+
73
+ var _useState = useState(false),
74
+ _useState2 = _slicedToArray(_useState, 2),
75
+ setDummyState = _useState2[1];
76
+
71
77
  var refsArray = useRef([]);
72
78
  var theme = useTheme(themeFromProps);
73
79
 
74
80
  var _useResizeDetector = useResizeDetector({
75
- handleHeight: false,
76
- refreshMode: 'debounce'
81
+ handleHeight: false
77
82
  }),
78
- resizeDetectorRef = _useResizeDetector.ref,
79
- switcherWidth = _useResizeDetector.width;
83
+ resizeDetectorRef = _useResizeDetector.ref;
80
84
 
81
85
  var optionsHash = hashOptions(options);
82
86
  var memoizedOptions = useMemo(function () {
@@ -84,20 +88,29 @@ var Switcher = function Switcher(_ref2) {
84
88
  }, [optionsHash]);
85
89
  var handleOptionRef = useCallback(function (index) {
86
90
  return function (ref) {
87
- refsArray.current[index] = ref;
91
+ if (!ref) {
92
+ return;
93
+ }
94
+
95
+ if (refsArray.current[index] !== ref) {
96
+ refsArray.current[index] = ref; // force rerender
97
+
98
+ setDummyState(function (s) {
99
+ return !s;
100
+ });
101
+ }
88
102
  };
89
103
  }, []);
90
- var offsetAndWidth = useMemo(function () {
91
- if (refsArray.current.length === memoizedOptions.length && refsArray.current.every(Boolean)) {
92
- var activeIndex = findIndexByValue(memoizedOptions, switcherValue);
93
- var activeRef = refsArray.current[activeIndex];
94
- var offset = activeRef.offsetLeft;
95
- var width = activeRef.getBoundingClientRect().width;
96
- return [offset, width];
97
- } else {
98
- return [0, 0];
99
- }
100
- }, [memoizedOptions, switcherValue, switcherWidth]);
104
+ var activeIndex = findIndexByValue(memoizedOptions, switcherValue);
105
+ var activeRef = refsArray.current[activeIndex];
106
+ var markOffset = 0;
107
+ var markWidth = 0;
108
+
109
+ if (activeRef) {
110
+ markOffset = activeRef.offsetLeft;
111
+ markWidth = activeRef.getBoundingClientRect().width;
112
+ }
113
+
101
114
  return /*#__PURE__*/React.createElement("span", {
102
115
  ref: resizeDetectorRef,
103
116
  className: cn(className, styles.switcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled),
@@ -118,10 +131,10 @@ var Switcher = function Switcher(_ref2) {
118
131
  selected: switcherValue === value
119
132
  });
120
133
  }), /*#__PURE__*/React.createElement("span", {
121
- className: styles.mark,
134
+ className: cn(styles.mark),
122
135
  style: {
123
- left: offsetAndWidth[0],
124
- width: offsetAndWidth[1]
136
+ left: markOffset,
137
+ width: markWidth
125
138
  }
126
139
  }));
127
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/switcher",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -26,12 +26,12 @@
26
26
  "react": ">=16.8.0 <18"
27
27
  },
28
28
  "devDependencies": {
29
- "@rescui/colors": "^0.0.5",
30
- "@rescui/scripts": "^0.1.3",
31
- "@rescui/typography": "^0.3.0"
29
+ "@rescui/colors": "^0.0.6",
30
+ "@rescui/scripts": "^0.1.4",
31
+ "@rescui/typography": "^0.4.0"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "rescui-scripts build"
35
35
  },
36
- "gitHead": "11daffddcc420a78b5708443363da65c55f28103"
36
+ "gitHead": "6b1d206de2641861028760d73f33dee214c07911"
37
37
  }