@rescui/button 0.24.7-RUI-308-Fix-select-issues-405b9fa40.12 → 0.25.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/button.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use client";
2
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
+ import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
3
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
4
+ import { c } from 'react-compiler-runtime';
3
5
  import React, { useState, useRef, cloneElement } from 'react';
4
6
  import PropTypes from 'prop-types';
5
7
  import cn from 'classnames';
@@ -30,86 +32,207 @@ const ICON_POSITION_STYLES = {
30
32
  'right-edge': styles.alignIconRightEdge
31
33
  };
32
34
  const Button = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
33
- (_ref, forwardedRef) => {
34
- let {
35
- className,
36
- children,
37
- href,
38
- type = 'button',
39
- disabled,
40
- size = 'm',
41
- theme: themeFromProps,
42
- icon,
43
- iconPosition = 'left',
44
- busy = false,
45
- allowMultiline = false,
46
- defaultMultiline = false,
47
- flat,
48
- notFocusable,
49
- highlighted
50
- /* supported only for clear mode */
51
- ,
52
- shifted
53
- /* supported only for clear mode */
54
- ,
55
- mode = 'classic',
56
- ...restProps
57
- } = _ref;
35
+ (t0, forwardedRef) => {
36
+ const $ = c(82);
37
+ let children;
38
+ let className;
39
+ let disabled;
40
+ let flat;
41
+ let highlighted;
42
+ let href;
43
+ let icon;
44
+ let notFocusable;
45
+ let restProps;
46
+ let shifted;
47
+ let t1;
48
+ let t2;
49
+ let t3;
50
+ let t4;
51
+ let t5;
52
+ let t6;
53
+ let t7;
54
+ let themeFromProps;
55
+
56
+ if ($[0] !== t0) {
57
+ ({
58
+ className,
59
+ children,
60
+ href,
61
+ type: t1,
62
+ disabled,
63
+ size: t2,
64
+ theme: themeFromProps,
65
+ icon,
66
+ iconPosition: t3,
67
+ busy: t4,
68
+ allowMultiline: t5,
69
+ defaultMultiline: t6,
70
+ flat,
71
+ notFocusable,
72
+ highlighted,
73
+ shifted,
74
+ mode: t7,
75
+ ...restProps
76
+ } = t0);
77
+ $[0] = t0;
78
+ $[1] = children;
79
+ $[2] = className;
80
+ $[3] = disabled;
81
+ $[4] = flat;
82
+ $[5] = highlighted;
83
+ $[6] = href;
84
+ $[7] = icon;
85
+ $[8] = notFocusable;
86
+ $[9] = restProps;
87
+ $[10] = shifted;
88
+ $[11] = t1;
89
+ $[12] = t2;
90
+ $[13] = t3;
91
+ $[14] = t4;
92
+ $[15] = t5;
93
+ $[16] = t6;
94
+ $[17] = t7;
95
+ $[18] = themeFromProps;
96
+ } else {
97
+ children = $[1];
98
+ className = $[2];
99
+ disabled = $[3];
100
+ flat = $[4];
101
+ highlighted = $[5];
102
+ href = $[6];
103
+ icon = $[7];
104
+ notFocusable = $[8];
105
+ restProps = $[9];
106
+ shifted = $[10];
107
+ t1 = $[11];
108
+ t2 = $[12];
109
+ t3 = $[13];
110
+ t4 = $[14];
111
+ t5 = $[15];
112
+ t6 = $[16];
113
+ t7 = $[17];
114
+ themeFromProps = $[18];
115
+ }
116
+
117
+ const type = t1 === undefined ? "button" : t1;
118
+ const size = t2 === undefined ? "m" : t2;
119
+ const iconPosition = t3 === undefined ? "left" : t3;
120
+ const busy = t4 === undefined ? false : t4;
121
+ const allowMultiline = t5 === undefined ? false : t5;
122
+ const defaultMultiline = t6 === undefined ? false : t6;
123
+ const mode = t7 === undefined ? "classic" : t7;
58
124
  const [multiline, setMultiline] = useState(defaultMultiline);
59
125
  const contentRef = useRef(null);
60
126
  const ref = useRef(null);
127
+ let t8;
61
128
 
62
- const handleRef = el => {
63
- ref.current = el;
129
+ if ($[19] !== forwardedRef) {
130
+ t8 = el => {
131
+ ref.current = el;
64
132
 
65
- if (forwardedRef) {
66
- if (typeof forwardedRef === 'function') {
67
- forwardedRef(el);
68
- } else {
69
- forwardedRef.current = el;
133
+ if (forwardedRef) {
134
+ if (typeof forwardedRef === "function") {
135
+ forwardedRef(el);
136
+ } else {
137
+ forwardedRef.current = el;
138
+ }
70
139
  }
71
- }
72
- };
140
+ };
73
141
 
74
- useResizeObserver(contentRef, entry => {
75
- const target = entry.target;
76
- const {
77
- height
78
- } = entry.contentRect;
79
- const targetStyles = getComputedStyle(target);
80
- const singleLineBlockSize = parseInt(targetStyles.lineHeight, 10);
81
- setMultiline(height > singleLineBlockSize);
82
- });
83
- const theme = useThemeWithUndefined(themeFromProps);
84
- const shiftedLeft = calculateShifted(shifted, 'left');
85
- const shiftedRight = calculateShifted(shifted, 'right');
86
- const shiftedTop = calculateShifted(shifted, 'top');
87
- const shiftedBottom = calculateShifted(shifted, 'bottom'); // check for ignored jsx values and empty string, more info https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored
142
+ $[19] = forwardedRef;
143
+ $[20] = t8;
144
+ } else {
145
+ t8 = $[20];
146
+ }
88
147
 
89
- const isWithoutText = children === null || typeof children === 'undefined' || children === false || children === true || children === '';
90
- let iconSlot;
148
+ const handleRef = t8;
149
+ let t9;
91
150
 
92
- if ( /*#__PURE__*/React.isValidElement(icon) && busy) {
93
- iconSlot = /*#__PURE__*/React.createElement(LoadingOutlineIcon, {
94
- className: styles.icon,
95
- "data-render-all-sizes": true
96
- });
97
- } else if ( /*#__PURE__*/React.isValidElement(icon)) {
98
- iconSlot = /*#__PURE__*/cloneElement(icon, {
99
- className: cn(icon.props?.className, styles.icon),
100
- 'data-render-all-sizes': true
101
- });
151
+ if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
152
+ t9 = entry => {
153
+ const target = entry.target;
154
+ const {
155
+ height
156
+ } = entry.contentRect;
157
+ const targetStyles = getComputedStyle(target);
158
+ const singleLineBlockSize = parseInt(targetStyles.lineHeight, 10);
159
+ setMultiline(height > singleLineBlockSize);
160
+ };
161
+
162
+ $[21] = t9;
163
+ } else {
164
+ t9 = $[21];
102
165
  }
103
166
 
104
- const showBusyOverlay = ! /*#__PURE__*/React.isValidElement(icon) && busy;
105
- const buttonSharedProps = {
106
- href,
107
- disabled: disabled || busy,
108
- ['data-busy']: busy ? 'true' : undefined,
109
- className: cn(styles.main, MODE_STYLES[mode], SIZE_STYLES[size], ICON_POSITION_STYLES[iconPosition] ?? ICON_POSITION_STYLES.left, styles[theme], {
167
+ useResizeObserver(contentRef, t9);
168
+ const theme = useThemeWithUndefined(themeFromProps);
169
+ let iconSlot;
170
+ let isWithoutText;
171
+ let showBusyOverlay;
172
+ let t10;
173
+ let t11;
174
+ let t12;
175
+ let t13;
176
+
177
+ if ($[22] !== allowMultiline || $[23] !== busy || $[24] !== children || $[25] !== className || $[26] !== disabled || $[27] !== flat || $[28] !== highlighted || $[29] !== href || $[30] !== icon || $[31] !== iconPosition || $[32] !== mode || $[33] !== multiline || $[34] !== shifted || $[35] !== size || $[36] !== theme) {
178
+ const shiftedLeft = calculateShifted(shifted, "left");
179
+ const shiftedRight = calculateShifted(shifted, "right");
180
+ const shiftedTop = calculateShifted(shifted, "top");
181
+ const shiftedBottom = calculateShifted(shifted, "bottom");
182
+ isWithoutText = children === null || typeof children === "undefined" || children === false || children === true || children === "";
183
+
184
+ if ( /*#__PURE__*/ /*#__PURE__*/React.isValidElement(icon) && busy) {
185
+ let t14;
186
+
187
+ if ($[44] === Symbol.for("react.memo_cache_sentinel")) {
188
+ t14 = /*#__PURE__*/React.createElement(LoadingOutlineIcon, {
189
+ className: styles.icon,
190
+ "data-render-all-sizes": true
191
+ });
192
+ $[44] = t14;
193
+ } else {
194
+ t14 = $[44];
195
+ }
196
+
197
+ iconSlot = t14;
198
+ } else {
199
+ if ( /*#__PURE__*/React.isValidElement(icon)) {
200
+ let t14;
201
+
202
+ if ($[45] !== icon) {
203
+ t14 = /*#__PURE__*/cloneElement(icon, {
204
+ className: cn(icon.props?.className, styles.icon),
205
+ "data-render-all-sizes": true
206
+ });
207
+ $[45] = icon;
208
+ $[46] = t14;
209
+ } else {
210
+ t14 = $[46];
211
+ }
212
+
213
+ iconSlot = t14;
214
+ }
215
+ }
216
+
217
+ let t14;
218
+
219
+ if ($[47] !== busy || $[48] !== icon) {
220
+ t14 = ! /*#__PURE__*/React.isValidElement(icon) && busy;
221
+ $[47] = busy;
222
+ $[48] = icon;
223
+ $[49] = t14;
224
+ } else {
225
+ t14 = $[49];
226
+ }
227
+
228
+ showBusyOverlay = t14;
229
+ t10 = href;
230
+ t11 = disabled || busy;
231
+ t12 = busy ? "true" : undefined;
232
+ t13 = cn(styles.main, MODE_STYLES[mode], SIZE_STYLES[size], ICON_POSITION_STYLES[iconPosition] ?? ICON_POSITION_STYLES.left, styles[theme], {
110
233
  [styles.disabled]: disabled,
111
- [styles.flatLeft]: flat === 'left',
112
- [styles.flatRight]: flat === 'right',
234
+ [styles.flatLeft]: flat === "left",
235
+ [styles.flatRight]: flat === "right",
113
236
  [styles.highlighted]: highlighted,
114
237
  [styles.withoutText]: isWithoutText,
115
238
  [styles.shiftedLeft]: shiftedLeft,
@@ -120,54 +243,171 @@ const Button = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line comple
120
243
  [styles.allowMultiline]: allowMultiline,
121
244
  [styles.busy]: busy,
122
245
  [styles.busyOverlay]: showBusyOverlay
123
- }, className)
124
- }; // Google Translate replaces TextNodes on page which is leading to a React error on manipulating buttonChildren e.g. when switching to the busy state.
125
- // To prevent this we wrap text node in a span element which itself will not be replaced by Google Translate.
126
- // More info here: https://github.com/facebook/react/issues/11538
127
-
128
- const buttonContent = !isWithoutText && /*#__PURE__*/React.createElement("span", {
129
- className: styles.content,
130
- "data-rs-internal": "button__content",
131
- "data-test": "button__content",
132
- ref: contentRef
133
- }, children);
134
- const buttonChildren = /*#__PURE__*/React.createElement(React.Fragment, null, iconSlot, showBusyOverlay && /*#__PURE__*/React.createElement(LoadingOutlineIcon, {
135
- className: styles.busyIcon,
136
- size: size,
137
- "data-test": "busy-icon"
138
- }), buttonContent);
246
+ }, className);
247
+ $[22] = allowMultiline;
248
+ $[23] = busy;
249
+ $[24] = children;
250
+ $[25] = className;
251
+ $[26] = disabled;
252
+ $[27] = flat;
253
+ $[28] = highlighted;
254
+ $[29] = href;
255
+ $[30] = icon;
256
+ $[31] = iconPosition;
257
+ $[32] = mode;
258
+ $[33] = multiline;
259
+ $[34] = shifted;
260
+ $[35] = size;
261
+ $[36] = theme;
262
+ $[37] = iconSlot;
263
+ $[38] = isWithoutText;
264
+ $[39] = showBusyOverlay;
265
+ $[40] = t10;
266
+ $[41] = t11;
267
+ $[42] = t12;
268
+ $[43] = t13;
269
+ } else {
270
+ iconSlot = $[37];
271
+ isWithoutText = $[38];
272
+ showBusyOverlay = $[39];
273
+ t10 = $[40];
274
+ t11 = $[41];
275
+ t12 = $[42];
276
+ t13 = $[43];
277
+ }
278
+
279
+ let t14;
280
+
281
+ if ($[50] !== t10 || $[51] !== t11 || $[52] !== t12 || $[53] !== t13) {
282
+ t14 = {
283
+ href: t10,
284
+ disabled: t11,
285
+ "data-busy": t12,
286
+ className: t13
287
+ };
288
+ $[50] = t10;
289
+ $[51] = t11;
290
+ $[52] = t12;
291
+ $[53] = t13;
292
+ $[54] = t14;
293
+ } else {
294
+ t14 = $[54];
295
+ }
296
+
297
+ const buttonSharedProps = t14;
298
+ let t15;
299
+
300
+ if ($[55] !== children || $[56] !== isWithoutText) {
301
+ t15 = !isWithoutText && /*#__PURE__*/React.createElement("span", {
302
+ className: styles.content,
303
+ "data-rs-internal": "button__content",
304
+ "data-test": "button__content",
305
+ ref: contentRef
306
+ }, children);
307
+ $[55] = children;
308
+ $[56] = isWithoutText;
309
+ $[57] = t15;
310
+ } else {
311
+ t15 = $[57];
312
+ }
313
+
314
+ const buttonContent = t15;
315
+ let t16;
316
+
317
+ if ($[58] !== showBusyOverlay || $[59] !== size) {
318
+ t16 = showBusyOverlay && /*#__PURE__*/React.createElement(LoadingOutlineIcon, {
319
+ className: styles.busyIcon,
320
+ size: size,
321
+ "data-test": "busy-icon"
322
+ });
323
+ $[58] = showBusyOverlay;
324
+ $[59] = size;
325
+ $[60] = t16;
326
+ } else {
327
+ t16 = $[60];
328
+ }
329
+
330
+ let t17;
331
+
332
+ if ($[61] !== buttonContent || $[62] !== iconSlot || $[63] !== t16) {
333
+ t17 = /*#__PURE__*/React.createElement(React.Fragment, null, iconSlot, t16, buttonContent);
334
+ $[61] = buttonContent;
335
+ $[62] = iconSlot;
336
+ $[63] = t16;
337
+ $[64] = t17;
338
+ } else {
339
+ t17 = $[64];
340
+ }
341
+
342
+ const buttonChildren = t17;
139
343
 
140
344
  if (notFocusable) {
141
345
  if (href) {
142
- console.error('Button with `href` can\'t be completely not focusable. If you want to remove Button with `href` from focus flow, use `tabIndex="-1"` instead of `notFocusable`');
346
+ console.error("Button with `href` can't be completely not focusable. If you want to remove Button with `href` from focus flow, use `tabIndex=\"-1\"` instead of `notFocusable`");
347
+ }
348
+
349
+ let t18;
350
+
351
+ if ($[65] !== buttonChildren || $[66] !== buttonSharedProps || $[67] !== handleRef || $[68] !== restProps) {
352
+ t18 = /*#__PURE__*/React.createElement("div", _extends({
353
+ "data-test": "button"
354
+ }, restProps, {
355
+ ref: handleRef
356
+ }, buttonSharedProps), buttonChildren);
357
+ $[65] = buttonChildren;
358
+ $[66] = buttonSharedProps;
359
+ $[67] = handleRef;
360
+ $[68] = restProps;
361
+ $[69] = t18;
362
+ } else {
363
+ t18 = $[69];
143
364
  }
144
- /** use <div> tag for preventing button controls elements behavior for example 'space' button press support. */
145
-
146
-
147
- return /*#__PURE__*/React.createElement("div", {
148
- "data-test": 'button',
149
- ...restProps,
150
- ref: handleRef,
151
- ...buttonSharedProps
152
- }, buttonChildren);
153
- } else if (href) {
154
- return /*#__PURE__*/React.createElement("a", {
155
- "data-test": 'button',
156
- ...restProps,
157
- ref: handleRef,
158
- type: type,
159
- ...buttonSharedProps
160
- }, buttonChildren);
365
+
366
+ return t18;
161
367
  } else {
162
- return /*#__PURE__*/React.createElement("button", {
163
- "data-test": 'button',
164
- ...restProps,
165
- ref: handleRef,
166
-
167
- /* eslint-disable-next-line react/button-has-type */
168
- type: type,
169
- ...buttonSharedProps
170
- }, buttonChildren);
368
+ if (href) {
369
+ let t18;
370
+
371
+ if ($[70] !== buttonChildren || $[71] !== buttonSharedProps || $[72] !== handleRef || $[73] !== restProps || $[74] !== type) {
372
+ t18 = /*#__PURE__*/React.createElement("a", _extends({
373
+ "data-test": "button"
374
+ }, restProps, {
375
+ ref: handleRef,
376
+ type: type
377
+ }, buttonSharedProps), buttonChildren);
378
+ $[70] = buttonChildren;
379
+ $[71] = buttonSharedProps;
380
+ $[72] = handleRef;
381
+ $[73] = restProps;
382
+ $[74] = type;
383
+ $[75] = t18;
384
+ } else {
385
+ t18 = $[75];
386
+ }
387
+
388
+ return t18;
389
+ } else {
390
+ let t18;
391
+
392
+ if ($[76] !== buttonChildren || $[77] !== buttonSharedProps || $[78] !== handleRef || $[79] !== restProps || $[80] !== type) {
393
+ t18 = /*#__PURE__*/React.createElement("button", _extends({
394
+ "data-test": "button"
395
+ }, restProps, {
396
+ ref: handleRef,
397
+ type: type
398
+ }, buttonSharedProps), buttonChildren);
399
+ $[76] = buttonChildren;
400
+ $[77] = buttonSharedProps;
401
+ $[78] = handleRef;
402
+ $[79] = restProps;
403
+ $[80] = type;
404
+ $[81] = t18;
405
+ } else {
406
+ t18 = $[81];
407
+ }
408
+
409
+ return t18;
410
+ }
171
411
  }
172
412
  });
173
413
  Button.displayName = 'Button';
@@ -1,34 +1,34 @@
1
1
  var styles = {
2
- "light": "_light_2ofd4c_6",
3
- "dark": "_dark_2ofd4c_9",
4
- "flatRight": "_flatRight_2ofd4c_13",
5
- "flatLeft": "_flatLeft_2ofd4c_16",
6
- "sizeXs": "_sizeXs_2ofd4c_20",
7
- "sizeS": "_sizeS_2ofd4c_23",
8
- "sizeM": "_sizeM_2ofd4c_26",
9
- "sizeL": "_sizeL_2ofd4c_29",
10
- "modeClassic": "_modeClassic_2ofd4c_33",
11
- "modeRock": "_modeRock_2ofd4c_36",
12
- "modeTransparent": "_modeTransparent_2ofd4c_39",
13
- "modeOutline": "_modeOutline_2ofd4c_42",
14
- "modeClear": "_modeClear_2ofd4c_45",
15
- "alignIconLeft": "_alignIconLeft_2ofd4c_49",
16
- "alignIconLeftEdge": "_alignIconLeftEdge_2ofd4c_52",
17
- "alignIconRight": "_alignIconRight_2ofd4c_55",
18
- "alignIconRightEdge": "_alignIconRightEdge_2ofd4c_58",
19
- "main": "_main_2ofd4c_62",
20
- "disabled": "_disabled_2ofd4c_139",
21
- "busy": "_busy_2ofd4c_149",
22
- "busyOverlay": "_busyOverlay_2ofd4c_153",
23
- "icon": "_icon_2ofd4c_188",
24
- "allowMultiline": "_allowMultiline_2ofd4c_203",
25
- "content": "_content_2ofd4c_207",
26
- "multiline": "_multiline_2ofd4c_213",
27
- "withoutText": "_withoutText_2ofd4c_217",
28
- "busyIcon": "_busyIcon_2ofd4c_222",
29
- "shiftedLeft": "_shiftedLeft_2ofd4c_243",
30
- "shiftedRight": "_shiftedRight_2ofd4c_246",
31
- "shiftedTop": "_shiftedTop_2ofd4c_249",
32
- "shiftedBottom": "_shiftedBottom_2ofd4c_252"
2
+ "light": "_light_15qumfk_6",
3
+ "dark": "_dark_15qumfk_9",
4
+ "flatRight": "_flatRight_15qumfk_13",
5
+ "flatLeft": "_flatLeft_15qumfk_16",
6
+ "sizeXs": "_sizeXs_15qumfk_20",
7
+ "sizeS": "_sizeS_15qumfk_23",
8
+ "sizeM": "_sizeM_15qumfk_26",
9
+ "sizeL": "_sizeL_15qumfk_29",
10
+ "modeClassic": "_modeClassic_15qumfk_33",
11
+ "modeRock": "_modeRock_15qumfk_36",
12
+ "modeTransparent": "_modeTransparent_15qumfk_39",
13
+ "modeOutline": "_modeOutline_15qumfk_42",
14
+ "modeClear": "_modeClear_15qumfk_45",
15
+ "alignIconLeft": "_alignIconLeft_15qumfk_49",
16
+ "alignIconLeftEdge": "_alignIconLeftEdge_15qumfk_52",
17
+ "alignIconRight": "_alignIconRight_15qumfk_55",
18
+ "alignIconRightEdge": "_alignIconRightEdge_15qumfk_58",
19
+ "main": "_main_15qumfk_62",
20
+ "disabled": "_disabled_15qumfk_139",
21
+ "busy": "_busy_15qumfk_149",
22
+ "busyOverlay": "_busyOverlay_15qumfk_153",
23
+ "icon": "_icon_15qumfk_188",
24
+ "allowMultiline": "_allowMultiline_15qumfk_203",
25
+ "content": "_content_15qumfk_207",
26
+ "multiline": "_multiline_15qumfk_213",
27
+ "withoutText": "_withoutText_15qumfk_217",
28
+ "busyIcon": "_busyIcon_15qumfk_222",
29
+ "shiftedLeft": "_shiftedLeft_15qumfk_243",
30
+ "shiftedRight": "_shiftedRight_15qumfk_246",
31
+ "shiftedTop": "_shiftedTop_15qumfk_249",
32
+ "shiftedBottom": "_shiftedBottom_15qumfk_252"
33
33
  };
34
34
  export { styles as default };