@rescui/switcher 0.3.6 → 0.4.1
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 +46 -47
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/index.p.module.css.js +14 -14
- package/lib/switcher.d.ts +13 -7
- package/lib/switcher.js +40 -37
- package/package.json +4 -4
package/lib/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.
|
|
1
|
+
._switcher_idwmbk_4{
|
|
2
2
|
position:relative;
|
|
3
3
|
|
|
4
4
|
display:-webkit-inline-box;
|
|
@@ -15,21 +15,21 @@
|
|
|
15
15
|
|
|
16
16
|
background:transparent;
|
|
17
17
|
}
|
|
18
|
-
.
|
|
18
|
+
._themeLight_idwmbk_16{
|
|
19
19
|
-webkit-box-shadow:inset rgba(25,25,28,0.4) 0 0 0 1px;
|
|
20
20
|
box-shadow:inset rgba(25,25,28,0.4) 0 0 0 1px;
|
|
21
21
|
}
|
|
22
|
-
.
|
|
22
|
+
._themeDark_idwmbk_20{
|
|
23
23
|
-webkit-box-shadow:inset rgba(255,255,255,0.5) 0 0 0 1px;
|
|
24
24
|
box-shadow:inset rgba(255,255,255,0.5) 0 0 0 1px;
|
|
25
25
|
}
|
|
26
|
-
.
|
|
26
|
+
._sizeL_idwmbk_24{
|
|
27
27
|
border-radius:36px;
|
|
28
28
|
}
|
|
29
|
-
.
|
|
29
|
+
._sizeXS_idwmbk_28{
|
|
30
30
|
border-radius:4px;
|
|
31
31
|
}
|
|
32
|
-
.
|
|
32
|
+
._option_idwmbk_32{
|
|
33
33
|
position:relative;
|
|
34
34
|
-webkit-appearance:none;
|
|
35
35
|
-moz-appearance:none;
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
background:transparent;
|
|
51
51
|
}
|
|
52
|
-
.
|
|
52
|
+
._sizeL_idwmbk_24 ._option_idwmbk_32{
|
|
53
53
|
padding:12px 32px;
|
|
54
54
|
font-family:'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
|
|
55
55
|
font-family:var(--rs-font-family-ui, var(--rs-font-family-jb-sans, 'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif));
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
line-height:var(--rs-text-1-line-height, 28px);
|
|
63
63
|
border-radius:36px;
|
|
64
64
|
}
|
|
65
|
-
.
|
|
65
|
+
._sizeM_idwmbk_55 ._option_idwmbk_32{
|
|
66
66
|
padding:8px 24px;
|
|
67
67
|
letter-spacing:0.0015em;
|
|
68
68
|
font-family:'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
|
|
@@ -75,26 +75,25 @@
|
|
|
75
75
|
line-height:24px;
|
|
76
76
|
line-height:var(--rs-text-2-line-height, 24px);
|
|
77
77
|
}
|
|
78
|
-
._rs-reset-letter-
|
|
78
|
+
._rs-reset-letter-spacing_idwmbk_1 ._sizeM_idwmbk_55 ._option_idwmbk_32{
|
|
79
79
|
letter-spacing:normal;
|
|
80
80
|
}
|
|
81
|
-
.
|
|
81
|
+
._sizeS_idwmbk_60 ._option_idwmbk_32{
|
|
82
82
|
padding:6px 16px;
|
|
83
|
-
letter-spacing:0.
|
|
83
|
+
letter-spacing:0.0045em;
|
|
84
84
|
font-family:'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
|
|
85
85
|
font-family:var(--rs-font-family-ui, var(--rs-font-family-jb-sans, 'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif));
|
|
86
86
|
-webkit-font-feature-settings:"kern", "liga", "calt";
|
|
87
87
|
font-feature-settings:"kern", "liga", "calt";
|
|
88
|
-
font-size:
|
|
89
|
-
font-size:var(--rs-text-
|
|
90
|
-
|
|
91
|
-
line-height:
|
|
92
|
-
line-height:var(--rs-text-2-line-height, 24px);
|
|
88
|
+
font-size:13px;
|
|
89
|
+
font-size:var(--rs-text-3-font-size, 13px);
|
|
90
|
+
line-height:20px;
|
|
91
|
+
line-height:var(--rs-text-3-line-height, 20px);
|
|
93
92
|
}
|
|
94
|
-
._rs-reset-letter-
|
|
93
|
+
._rs-reset-letter-spacing_idwmbk_1 ._sizeS_idwmbk_60 ._option_idwmbk_32{
|
|
95
94
|
letter-spacing:normal;
|
|
96
95
|
}
|
|
97
|
-
.
|
|
96
|
+
._sizeXS_idwmbk_28 ._option_idwmbk_32{
|
|
98
97
|
padding:2px 12px;
|
|
99
98
|
letter-spacing:0.0045em;
|
|
100
99
|
font-family:'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
|
|
@@ -106,68 +105,68 @@
|
|
|
106
105
|
line-height:20px;
|
|
107
106
|
line-height:var(--rs-text-3-line-height, 20px);
|
|
108
107
|
}
|
|
109
|
-
._rs-reset-letter-
|
|
108
|
+
._rs-reset-letter-spacing_idwmbk_1 ._sizeXS_idwmbk_28 ._option_idwmbk_32{
|
|
110
109
|
letter-spacing:normal;
|
|
111
110
|
}
|
|
112
|
-
.
|
|
111
|
+
._sizeXS_idwmbk_28 ._option_idwmbk_32 {
|
|
113
112
|
border-radius:4px;
|
|
114
113
|
}
|
|
115
|
-
.
|
|
114
|
+
._disabled_idwmbk_71 ._option_idwmbk_32{
|
|
116
115
|
cursor:not-allowed;
|
|
117
116
|
pointer-events:none;
|
|
118
117
|
}
|
|
119
|
-
.
|
|
118
|
+
._themeLight_idwmbk_16 ._option_idwmbk_32{
|
|
120
119
|
color:#19191C;
|
|
121
120
|
}
|
|
122
|
-
.
|
|
121
|
+
._themeLight_idwmbk_16 ._option_idwmbk_32:focus[data-focus-method='key']{
|
|
123
122
|
-webkit-box-shadow:rgba(107, 87, 255, 0.8) 0 0 0 4px;
|
|
124
123
|
-webkit-box-shadow:var(--rs-color-primary-t-dim-light-theme, rgba(107, 87, 255, 0.8)) 0 0 0 4px;
|
|
125
124
|
box-shadow:rgba(107, 87, 255, 0.8) 0 0 0 4px;
|
|
126
125
|
box-shadow:var(--rs-color-primary-t-dim-light-theme, rgba(107, 87, 255, 0.8)) 0 0 0 4px;
|
|
127
126
|
}
|
|
128
|
-
.
|
|
127
|
+
._themeLight_idwmbk_16 ._option_idwmbk_32._selected_idwmbk_84:hover, ._themeLight_idwmbk_16 ._option_idwmbk_32._selected_idwmbk_84:active{
|
|
129
128
|
background:transparent;
|
|
130
129
|
cursor:default;
|
|
131
130
|
}
|
|
132
|
-
.
|
|
131
|
+
._themeLight_idwmbk_16._modeClassic_idwmbk_92 ._option_idwmbk_32:hover{
|
|
133
132
|
background:rgba(107, 87, 255,0.2);
|
|
134
133
|
background:var(--rs-color-primary-t-fog-light-theme, rgba(107, 87, 255,0.2));
|
|
135
134
|
}
|
|
136
|
-
.
|
|
135
|
+
._themeLight_idwmbk_16._modeRock_idwmbk_98 ._option_idwmbk_32:hover{
|
|
137
136
|
background:rgba(25,25,28,0.1);
|
|
138
137
|
}
|
|
139
|
-
.
|
|
140
|
-
.
|
|
138
|
+
._disabled_idwmbk_71._themeLight_idwmbk_16 ._option_idwmbk_32,
|
|
139
|
+
._disabled_idwmbk_71._themeLight_idwmbk_16 ._option_idwmbk_32._selected_idwmbk_84{
|
|
141
140
|
color:rgba(25,25,28,0.4);
|
|
142
141
|
}
|
|
143
|
-
.
|
|
142
|
+
._themeDark_idwmbk_20 ._option_idwmbk_32{
|
|
144
143
|
color:#FFFFFF;
|
|
145
144
|
}
|
|
146
|
-
.
|
|
145
|
+
._themeDark_idwmbk_20 ._option_idwmbk_32:hover{
|
|
147
146
|
background:rgba(255,255,255,0.1);
|
|
148
147
|
}
|
|
149
|
-
.
|
|
148
|
+
._themeDark_idwmbk_20 ._option_idwmbk_32:focus[data-focus-method='key']{
|
|
150
149
|
-webkit-box-shadow:rgba(132, 115, 255,0.8) 0 0 0 4px;
|
|
151
150
|
-webkit-box-shadow:var(--rs-color-primary-t-dim-dark-theme, rgba(132, 115, 255,0.8)) 0 0 0 4px;
|
|
152
151
|
box-shadow:rgba(132, 115, 255,0.8) 0 0 0 4px;
|
|
153
152
|
box-shadow:var(--rs-color-primary-t-dim-dark-theme, rgba(132, 115, 255,0.8)) 0 0 0 4px;
|
|
154
153
|
}
|
|
155
|
-
.
|
|
154
|
+
._themeDark_idwmbk_20 ._option_idwmbk_32._selected_idwmbk_84:hover, ._themeDark_idwmbk_20 ._option_idwmbk_32._selected_idwmbk_84:active{
|
|
156
155
|
background:transparent;
|
|
157
156
|
cursor:default;
|
|
158
157
|
}
|
|
159
|
-
.
|
|
158
|
+
._themeDark_idwmbk_20._modeClassic_idwmbk_92 ._option_idwmbk_32:hover{
|
|
160
159
|
background:rgba(132, 115, 255,0.3);
|
|
161
160
|
background:var(--rs-color-primary-t-fog-dark-theme, rgba(132, 115, 255,0.3));
|
|
162
161
|
}
|
|
163
|
-
.
|
|
162
|
+
._themeDark_idwmbk_20._modeRock_idwmbk_98 ._option_idwmbk_32:hover{
|
|
164
163
|
background:rgba(255,255,255,0.1);
|
|
165
164
|
}
|
|
166
|
-
.
|
|
167
|
-
.
|
|
165
|
+
._disabled_idwmbk_71._themeDark_idwmbk_20 ._option_idwmbk_32,
|
|
166
|
+
._disabled_idwmbk_71._themeDark_idwmbk_20 ._option_idwmbk_32._selected_idwmbk_84{
|
|
168
167
|
color:rgba(255,255,255,0.2);
|
|
169
168
|
}
|
|
170
|
-
.
|
|
169
|
+
._mark_idwmbk_145{
|
|
171
170
|
position:absolute;
|
|
172
171
|
top:0;
|
|
173
172
|
bottom:0;
|
|
@@ -175,32 +174,32 @@
|
|
|
175
174
|
-webkit-box-sizing:border-box;
|
|
176
175
|
box-sizing:border-box;
|
|
177
176
|
border-radius:24px;
|
|
178
|
-
-webkit-transition:all 0.
|
|
179
|
-
transition:all 0.
|
|
177
|
+
-webkit-transition:all 0.2s;
|
|
178
|
+
transition:all 0.2s;
|
|
180
179
|
}
|
|
181
|
-
.
|
|
180
|
+
._themeLight_idwmbk_16._modeClassic_idwmbk_92 ._mark_idwmbk_145{
|
|
182
181
|
border:solid 2px #6B57FF;
|
|
183
182
|
border:solid 2px var(--rs-color-primary-light-theme, #6B57FF);
|
|
184
183
|
}
|
|
185
|
-
.
|
|
184
|
+
._themeDark_idwmbk_20._modeClassic_idwmbk_92 ._mark_idwmbk_145{
|
|
186
185
|
border:solid 2px #8473FF;
|
|
187
186
|
border:solid 2px var(--rs-color-primary-dark-theme, #8473FF);
|
|
188
187
|
}
|
|
189
|
-
.
|
|
188
|
+
._themeLight_idwmbk_16._modeRock_idwmbk_98 ._mark_idwmbk_145{
|
|
190
189
|
border:solid 2px #19191C;
|
|
191
190
|
}
|
|
192
|
-
.
|
|
191
|
+
._themeDark_idwmbk_20._modeRock_idwmbk_98 ._mark_idwmbk_145{
|
|
193
192
|
border:solid 2px #FFFFFF;
|
|
194
193
|
}
|
|
195
|
-
.
|
|
194
|
+
._sizeL_idwmbk_24 ._mark_idwmbk_145{
|
|
196
195
|
border-radius:36px;
|
|
197
196
|
}
|
|
198
|
-
.
|
|
197
|
+
._sizeXS_idwmbk_28 ._mark_idwmbk_145{
|
|
199
198
|
border-radius:4px;
|
|
200
199
|
}
|
|
201
|
-
.
|
|
200
|
+
._themeLight_idwmbk_16._disabled_idwmbk_71 ._mark_idwmbk_145{
|
|
202
201
|
border:solid 2px rgba(25,25,28,0.4);
|
|
203
202
|
}
|
|
204
|
-
.
|
|
203
|
+
._themeDark_idwmbk_20._disabled_idwmbk_71 ._mark_idwmbk_145{
|
|
205
204
|
border:solid 2px rgba(255,255,255,0.2);
|
|
206
205
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from './switcher';
|
|
1
|
+
export { default, Switcher } from './switcher';
|
|
2
|
+
export type { SwitcherProps } from './switcher';
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './index.css';
|
|
2
|
-
export { Switcher as default } from './switcher.js';
|
|
2
|
+
export { Switcher, Switcher as default } from './switcher.js';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"switcher": "
|
|
3
|
-
"themeLight": "
|
|
4
|
-
"themeDark": "
|
|
5
|
-
"sizeL": "
|
|
6
|
-
"sizeXS": "
|
|
7
|
-
"option": "
|
|
8
|
-
"sizeM": "
|
|
9
|
-
"rs-reset-letter-spacing": "_rs-reset-letter-
|
|
10
|
-
"sizeS": "
|
|
11
|
-
"disabled": "
|
|
12
|
-
"selected": "
|
|
13
|
-
"modeClassic": "
|
|
14
|
-
"modeRock": "
|
|
15
|
-
"mark": "
|
|
2
|
+
"switcher": "_switcher_idwmbk_4",
|
|
3
|
+
"themeLight": "_themeLight_idwmbk_16",
|
|
4
|
+
"themeDark": "_themeDark_idwmbk_20",
|
|
5
|
+
"sizeL": "_sizeL_idwmbk_24",
|
|
6
|
+
"sizeXS": "_sizeXS_idwmbk_28",
|
|
7
|
+
"option": "_option_idwmbk_32",
|
|
8
|
+
"sizeM": "_sizeM_idwmbk_55",
|
|
9
|
+
"rs-reset-letter-spacing": "_rs-reset-letter-spacing_idwmbk_1",
|
|
10
|
+
"sizeS": "_sizeS_idwmbk_60",
|
|
11
|
+
"disabled": "_disabled_idwmbk_71",
|
|
12
|
+
"selected": "_selected_idwmbk_84",
|
|
13
|
+
"modeClassic": "_modeClassic_idwmbk_92",
|
|
14
|
+
"modeRock": "_modeRock_idwmbk_98",
|
|
15
|
+
"mark": "_mark_idwmbk_145"
|
|
16
16
|
};
|
|
17
17
|
export { styles as default };
|
package/lib/switcher.d.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export
|
|
3
|
-
export interface SwitcherOption<ValueType extends SwitcherValue> {
|
|
2
|
+
export interface SwitcherOption<OptionsValueType> {
|
|
4
3
|
label: React.ReactNode;
|
|
5
|
-
value:
|
|
4
|
+
value: OptionsValueType;
|
|
6
5
|
}
|
|
7
6
|
export declare type SwitcherSize = 'l' | 'm' | 's' | 'xs';
|
|
8
7
|
export declare type SwitcherTheme = 'light' | 'dark';
|
|
9
8
|
export declare type SwitcherMode = 'rock' | 'classic';
|
|
10
|
-
export interface SwitcherProps<ValueType extends
|
|
11
|
-
|
|
9
|
+
export interface SwitcherProps<ValueType, OptionsValueType extends ValueType> {
|
|
10
|
+
/** Current selected value */
|
|
12
11
|
value: ValueType;
|
|
13
|
-
|
|
12
|
+
/** Array of options */
|
|
13
|
+
options?: SwitcherOption<OptionsValueType>[];
|
|
14
|
+
onChange: (value: OptionsValueType) => void;
|
|
14
15
|
className?: string;
|
|
15
16
|
theme?: SwitcherTheme;
|
|
16
17
|
size?: SwitcherSize;
|
|
18
|
+
/** Appearance mode */
|
|
17
19
|
mode?: SwitcherMode;
|
|
18
20
|
disabled?: boolean;
|
|
21
|
+
/** Identifier for e2e tests */
|
|
19
22
|
'data-e2e'?: string;
|
|
20
23
|
}
|
|
21
|
-
export declare
|
|
24
|
+
export declare function Switcher<ValueType, OptionsValueType extends ValueType = ValueType>({ className, theme: themeFromProps, size, disabled, ['data-e2e']: e2eId, options, value: switcherValue, mode, onChange }: SwitcherProps<ValueType, OptionsValueType>): JSX.Element;
|
|
25
|
+
export declare namespace Switcher {
|
|
26
|
+
var propTypes: {};
|
|
27
|
+
}
|
|
22
28
|
export default Switcher;
|
package/lib/switcher.js
CHANGED
|
@@ -3,11 +3,11 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
|
|
|
3
3
|
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
|
|
4
4
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
5
5
|
import "core-js/modules/es.object.to-string.js";
|
|
6
|
-
import React, {
|
|
6
|
+
import React, { useRef, useMemo, useCallback, useState, useEffect } from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
|
-
import { useResizeDetector } from 'react-resize-detector';
|
|
9
8
|
import cn from 'classnames';
|
|
10
9
|
import { useTheme } from '@rescui/ui-contexts';
|
|
10
|
+
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
11
11
|
import styles from './index.p.module.css.js';
|
|
12
12
|
var sizeToClass = {
|
|
13
13
|
l: styles.sizeL,
|
|
@@ -58,7 +58,7 @@ var optionRenderer = function optionRenderer(_ref, ref) {
|
|
|
58
58
|
|
|
59
59
|
var Option = /*#__PURE__*/React.forwardRef(optionRenderer);
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
function Switcher(_ref2) {
|
|
62
62
|
var className = _ref2.className,
|
|
63
63
|
themeFromProps = _ref2.theme,
|
|
64
64
|
_ref2$size = _ref2.size,
|
|
@@ -70,20 +70,11 @@ var Switcher = function Switcher(_ref2) {
|
|
|
70
70
|
_ref2$mode = _ref2.mode,
|
|
71
71
|
mode = _ref2$mode === void 0 ? 'classic' : _ref2$mode,
|
|
72
72
|
onChange = _ref2.onChange;
|
|
73
|
-
|
|
74
|
-
var _useState = useState(false),
|
|
75
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
76
|
-
setDummyState = _useState2[1];
|
|
77
|
-
|
|
78
73
|
var refsArray = useRef([]);
|
|
74
|
+
var containerRef = useRef(null);
|
|
79
75
|
var theme = useTheme(themeFromProps);
|
|
76
|
+
var optionsHash = hashOptions(options); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
77
|
|
|
81
|
-
var _useResizeDetector = useResizeDetector({
|
|
82
|
-
handleHeight: false
|
|
83
|
-
}),
|
|
84
|
-
resizeDetectorRef = _useResizeDetector.ref;
|
|
85
|
-
|
|
86
|
-
var optionsHash = hashOptions(options);
|
|
87
78
|
var memoizedOptions = useMemo(function () {
|
|
88
79
|
return options;
|
|
89
80
|
}, [optionsHash]);
|
|
@@ -94,28 +85,45 @@ var Switcher = function Switcher(_ref2) {
|
|
|
94
85
|
}
|
|
95
86
|
|
|
96
87
|
if (refsArray.current[index] !== ref) {
|
|
97
|
-
refsArray.current[index] = ref;
|
|
98
|
-
|
|
99
|
-
setDummyState(function (s) {
|
|
100
|
-
return !s;
|
|
101
|
-
});
|
|
88
|
+
refsArray.current[index] = ref;
|
|
102
89
|
}
|
|
103
90
|
};
|
|
104
91
|
}, []);
|
|
105
92
|
var activeIndex = findIndexByValue(memoizedOptions, switcherValue);
|
|
106
|
-
var activeRef = refsArray.current[activeIndex];
|
|
107
|
-
var markOffset = 0;
|
|
108
|
-
var markWidth = 0;
|
|
109
93
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
94
|
+
var _useState = useState({
|
|
95
|
+
offset: 0,
|
|
96
|
+
width: 0
|
|
97
|
+
}),
|
|
98
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
99
|
+
mark = _useState2[0],
|
|
100
|
+
setMark = _useState2[1];
|
|
101
|
+
|
|
102
|
+
var onResize = function onResize() {
|
|
103
|
+
var activeEl = refsArray.current[activeIndex];
|
|
104
|
+
|
|
105
|
+
if (!activeEl) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var activeElBox = activeEl.getBoundingClientRect();
|
|
110
|
+
var parentBox = activeEl.parentElement.getBoundingClientRect();
|
|
111
|
+
setMark({
|
|
112
|
+
// standard activeEl.offsetLeft always return rounded value, so it does not suit us
|
|
113
|
+
offset: activeElBox.left - parentBox.left,
|
|
114
|
+
width: activeElBox.width
|
|
115
|
+
});
|
|
116
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
+
|
|
114
118
|
|
|
119
|
+
useEffect(function () {
|
|
120
|
+
return onResize();
|
|
121
|
+
}, [activeIndex]);
|
|
122
|
+
useResizeObserver(containerRef, onResize);
|
|
115
123
|
return /*#__PURE__*/React.createElement("span", {
|
|
116
|
-
ref: resizeDetectorRef,
|
|
117
124
|
className: cn(className, styles.switcher, sizeToClass[size], themeToClass[theme], modeToClass[mode], disabled && styles.disabled),
|
|
118
125
|
"data-e2e": e2eId,
|
|
126
|
+
ref: containerRef,
|
|
119
127
|
"data-test": "switcher".concat(disabled ? '-disabled' : '')
|
|
120
128
|
}, _mapInstanceProperty(memoizedOptions).call(memoizedOptions, function (_ref3, index) {
|
|
121
129
|
var value = _ref3.value,
|
|
@@ -134,29 +142,24 @@ var Switcher = function Switcher(_ref2) {
|
|
|
134
142
|
}), /*#__PURE__*/React.createElement("span", {
|
|
135
143
|
className: cn(styles.mark),
|
|
136
144
|
style: {
|
|
137
|
-
left:
|
|
138
|
-
width:
|
|
145
|
+
left: mark.offset,
|
|
146
|
+
width: mark.width
|
|
139
147
|
}
|
|
140
148
|
}));
|
|
141
|
-
}
|
|
149
|
+
}
|
|
142
150
|
|
|
143
|
-
var switcherValuePropType = PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.symbol, PropTypes.bool]);
|
|
144
151
|
var optionPropType = PropTypes.shape({
|
|
145
152
|
label: PropTypes.node.isRequired,
|
|
146
|
-
value:
|
|
153
|
+
value: PropTypes.any.isRequired
|
|
147
154
|
});
|
|
148
155
|
Switcher.propTypes = {
|
|
149
156
|
options: PropTypes.arrayOf(optionPropType).isRequired,
|
|
150
|
-
value: switcherValuePropType.isRequired,
|
|
151
157
|
onChange: PropTypes.func.isRequired,
|
|
158
|
+
value: PropTypes.any.isRequired,
|
|
152
159
|
className: PropTypes.string,
|
|
153
160
|
size: PropTypes.oneOf(['l', 'm', 's', 'xs']),
|
|
154
161
|
theme: PropTypes.oneOf(['light', 'dark']),
|
|
155
162
|
disabled: PropTypes.bool,
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Identifier for e2e tests
|
|
159
|
-
* */
|
|
160
163
|
'data-e2e': PropTypes.string
|
|
161
164
|
};
|
|
162
165
|
export { Switcher, Switcher as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/switcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime-corejs3": "^7.14.0",
|
|
19
|
+
"@rescui/use-resize-observer": "^0.1.1",
|
|
19
20
|
"classnames": "^2.2.6",
|
|
20
|
-
"core-js": "^3.9.1"
|
|
21
|
-
"react-resize-detector": "^6.7.3"
|
|
21
|
+
"core-js": "^3.9.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@rescui/ui-contexts": "<0.4.0",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rescui-scripts build"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "40e998f9a619c95fe39dc88c3f1ddb824cf7b37a"
|
|
37
37
|
}
|