@rescui/tab-list 0.18.4 → 0.19.0

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/parts/tab.js CHANGED
@@ -1,76 +1,220 @@
1
1
  "use client";
2
+ import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
3
+ import { c } from 'react-compiler-runtime';
2
4
  import React, { forwardRef, cloneElement } from 'react';
3
5
  import PropTypes from 'prop-types';
4
6
  import cn from 'classnames';
5
7
  import styles from './tab-list.p.module.css.js';
6
8
  import { useTabListContext } from './tab-list-context.js';
7
9
  const TabTag = /*#__PURE__*/forwardRef((props, ref) => {
8
- if (typeof props.href !== 'undefined') {
9
- return /*#__PURE__*/React.createElement("a", {
10
- ref: ref,
11
- ...props
12
- }, props.children);
10
+ const $ = c(6);
11
+
12
+ if (typeof props.href !== "undefined") {
13
+ let t0;
14
+
15
+ if ($[0] !== props || $[1] !== ref) {
16
+ t0 = /*#__PURE__*/React.createElement("a", _extends({
17
+ ref: ref
18
+ }, props), props.children);
19
+ $[0] = props;
20
+ $[1] = ref;
21
+ $[2] = t0;
22
+ } else {
23
+ t0 = $[2];
24
+ }
25
+
26
+ return t0;
13
27
  }
14
28
 
15
- return /*#__PURE__*/React.createElement("button", {
16
- ref: ref,
17
- ...props,
18
- type: "button"
19
- }, props.children);
29
+ let t0;
30
+
31
+ if ($[3] !== props || $[4] !== ref) {
32
+ t0 = /*#__PURE__*/React.createElement("button", _extends({
33
+ ref: ref
34
+ }, props, {
35
+ type: "button"
36
+ }), props.children);
37
+ $[3] = props;
38
+ $[4] = ref;
39
+ $[5] = t0;
40
+ } else {
41
+ t0 = $[5];
42
+ }
43
+
44
+ return t0;
20
45
  });
21
46
  TabTag.displayName = 'TabTag';
22
- const Tab = /*#__PURE__*/forwardRef((_ref, ref) => {
23
- let {
24
- value,
25
- className,
26
- children,
27
- icon,
28
- iconPosition = 'left',
29
- itemId,
30
- onClick,
31
- onKeyDown,
32
- ['data-e2e']: e2eId,
33
- ...restProps
34
- } = _ref;
47
+ const Tab = /*#__PURE__*/forwardRef((t0, ref) => {
48
+ const $ = c(39);
49
+ let children;
50
+ let className;
51
+ let e2eId;
52
+ let icon;
53
+ let itemId;
54
+ let onClick;
55
+ let onKeyDown;
56
+ let restProps;
57
+ let t1;
58
+ let value;
59
+
60
+ if ($[0] !== t0) {
61
+ ({
62
+ value,
63
+ className,
64
+ children,
65
+ icon,
66
+ iconPosition: t1,
67
+ itemId,
68
+ onClick,
69
+ onKeyDown,
70
+ "data-e2e": e2eId,
71
+ ...restProps
72
+ } = t0);
73
+ $[0] = t0;
74
+ $[1] = children;
75
+ $[2] = className;
76
+ $[3] = e2eId;
77
+ $[4] = icon;
78
+ $[5] = itemId;
79
+ $[6] = onClick;
80
+ $[7] = onKeyDown;
81
+ $[8] = restProps;
82
+ $[9] = t1;
83
+ $[10] = value;
84
+ } else {
85
+ children = $[1];
86
+ className = $[2];
87
+ e2eId = $[3];
88
+ icon = $[4];
89
+ itemId = $[5];
90
+ onClick = $[6];
91
+ onKeyDown = $[7];
92
+ restProps = $[8];
93
+ t1 = $[9];
94
+ value = $[10];
95
+ }
96
+
97
+ const iconPosition = t1 === undefined ? "left" : t1;
35
98
  const {
36
99
  onChange,
37
100
  selectedId,
38
101
  rovingTabIndex
39
102
  } = useTabListContext();
40
103
  const selected = itemId === selectedId;
41
- const resolvedTabIndex = typeof itemId === 'undefined' || itemId === rovingTabIndex?.currentTabStopId ? 0 : -1;
42
- return /*#__PURE__*/React.createElement(TabTag, { ...restProps,
43
- className: cn(styles.tab, selected && styles.selected, iconPosition === 'right' ? styles.iconRight : styles.iconLeft, className),
44
- onClick: e => {
104
+ const resolvedTabIndex = typeof itemId === "undefined" || itemId === rovingTabIndex?.currentTabStopId ? 0 : -1;
105
+ const t2 = selected && styles.selected;
106
+ const t3 = iconPosition === "right" ? styles.iconRight : styles.iconLeft;
107
+ let t4;
108
+
109
+ if ($[11] !== className || $[12] !== t2 || $[13] !== t3) {
110
+ t4 = cn(styles.tab, t2, t3, className);
111
+ $[11] = className;
112
+ $[12] = t2;
113
+ $[13] = t3;
114
+ $[14] = t4;
115
+ } else {
116
+ t4 = $[14];
117
+ }
118
+
119
+ let t5;
120
+
121
+ if ($[15] !== onChange || $[16] !== onClick || $[17] !== value) {
122
+ t5 = e => {
45
123
  if (onClick) {
46
124
  onClick(e);
47
125
  }
48
126
 
49
127
  onChange(value);
50
- },
51
- onKeyDown: e => {
52
- if (typeof itemId !== 'undefined') {
53
- rovingTabIndex?.onTabKeyDown(e, itemId);
128
+ };
129
+
130
+ $[15] = onChange;
131
+ $[16] = onClick;
132
+ $[17] = value;
133
+ $[18] = t5;
134
+ } else {
135
+ t5 = $[18];
136
+ }
137
+
138
+ let t6;
139
+
140
+ if ($[19] !== itemId || $[20] !== onKeyDown || $[21] !== rovingTabIndex) {
141
+ t6 = e_0 => {
142
+ if (typeof itemId !== "undefined") {
143
+ rovingTabIndex?.onTabKeyDown(e_0, itemId);
54
144
  }
55
145
 
56
- if (e.key === ' ' || e.key === 'Enter') {
57
- e.currentTarget.click();
58
- e.preventDefault();
146
+ if (e_0.key === " " || e_0.key === "Enter") {
147
+ e_0.currentTarget.click();
148
+ e_0.preventDefault();
59
149
  }
60
150
 
61
- onKeyDown?.(e);
62
- },
63
- role: "tab",
64
- "aria-selected": selected,
65
- tabIndex: resolvedTabIndex,
66
- ref: ref,
67
- "data-e2e": e2eId,
68
- "data-test": `tab${selected ? ' tab-selected' : ''}`,
69
- "data-rs-internal": 'tab-list__tab'
70
- }, icon && /*#__PURE__*/cloneElement(icon, {
71
- className: cn(icon.props.className, styles.icon),
72
- 'data-render-all-sizes': true
73
- }), /*#__PURE__*/React.createElement("div", null, children));
151
+ onKeyDown?.(e_0);
152
+ };
153
+
154
+ $[19] = itemId;
155
+ $[20] = onKeyDown;
156
+ $[21] = rovingTabIndex;
157
+ $[22] = t6;
158
+ } else {
159
+ t6 = $[22];
160
+ }
161
+
162
+ const t7 = `tab${selected ? " tab-selected" : ""}`;
163
+ let t8;
164
+
165
+ if ($[23] !== icon) {
166
+ t8 = icon && /*#__PURE__*/cloneElement(icon, {
167
+ className: cn(icon.props.className, styles.icon),
168
+ "data-render-all-sizes": true
169
+ });
170
+ $[23] = icon;
171
+ $[24] = t8;
172
+ } else {
173
+ t8 = $[24];
174
+ }
175
+
176
+ let t9;
177
+
178
+ if ($[25] !== children) {
179
+ t9 = /*#__PURE__*/React.createElement("div", null, children);
180
+ $[25] = children;
181
+ $[26] = t9;
182
+ } else {
183
+ t9 = $[26];
184
+ }
185
+
186
+ let t10;
187
+
188
+ if ($[27] !== e2eId || $[28] !== ref || $[29] !== resolvedTabIndex || $[30] !== restProps || $[31] !== selected || $[32] !== t4 || $[33] !== t5 || $[34] !== t6 || $[35] !== t7 || $[36] !== t8 || $[37] !== t9) {
189
+ t10 = /*#__PURE__*/React.createElement(TabTag, _extends({}, restProps, {
190
+ className: t4,
191
+ onClick: t5,
192
+ onKeyDown: t6,
193
+ role: "tab",
194
+ "aria-selected": selected,
195
+ tabIndex: resolvedTabIndex,
196
+ ref: ref,
197
+ "data-e2e": e2eId,
198
+ "data-test": t7,
199
+ "data-rs-internal": "tab-list__tab"
200
+ }), t8, t9);
201
+ $[27] = e2eId;
202
+ $[28] = ref;
203
+ $[29] = resolvedTabIndex;
204
+ $[30] = restProps;
205
+ $[31] = selected;
206
+ $[32] = t4;
207
+ $[33] = t5;
208
+ $[34] = t6;
209
+ $[35] = t7;
210
+ $[36] = t8;
211
+ $[37] = t9;
212
+ $[38] = t10;
213
+ } else {
214
+ t10 = $[38];
215
+ }
216
+
217
+ return t10;
74
218
  });
75
219
  Tab.displayName = 'Tab';
76
220
  Tab.propTypes = {
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import { useState, useRef, useCallback, useEffect } from 'react';
2
+ import { c } from 'react-compiler-runtime';
3
+ import { useState, useRef, useEffect } from 'react';
3
4
  import { useResizeObserver } from '@rescui/use-resize-observer';
4
5
 
5
6
  function calculateIndicator(activeNodeRef, parentNode) {
@@ -13,51 +14,136 @@ function calculateIndicator(activeNodeRef, parentNode) {
13
14
  };
14
15
  }
15
16
 
16
- const useIndicator = _ref => {
17
- let {
17
+ const useIndicator = t0 => {
18
+ const $ = c(16);
19
+ const {
18
20
  activeNode,
19
21
  containerRef
20
- } = _ref;
21
- const [indicator, setIndicator] = useState({
22
- left: 0,
23
- width: 0
24
- });
25
- const firstIndicatorUpdate = useRef(true); // Catch the resize of the container which is happening when the fonts downloads for example
26
-
27
- const updateIndicator = useCallback(function () {
28
- let isValueChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
29
-
30
- if (!activeNode || !containerRef.current) {
31
- return;
32
- }
33
-
34
- let isTransitionEnabled;
35
-
36
- if (firstIndicatorUpdate.current) {
37
- firstIndicatorUpdate.current = false;
38
- isTransitionEnabled = false;
39
- } else {
40
- isTransitionEnabled = isValueChanged;
41
- }
42
-
43
- setIndicator({ ...calculateIndicator(activeNode, containerRef.current),
44
- transitionDuration: !isTransitionEnabled ? '0s' : null
45
- });
46
- }, [activeNode, containerRef]); // Trigger it on value change for example
47
-
48
- useEffect(() => updateIndicator(true), [updateIndicator]); // Or changing container size
49
-
50
- useResizeObserver(containerRef, () => updateIndicator(false), {
51
- ignoreFirstCall: true
52
- }); // Or changing active element size
53
-
54
- useResizeObserver(activeNode, () => updateIndicator(false), {
55
- ignoreFirstCall: true
56
- });
57
- return {
58
- indicator,
59
- isIndicatorHidden: typeof indicator.transitionDuration === 'undefined'
60
- };
22
+ } = t0;
23
+ let t1;
24
+
25
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
26
+ t1 = {
27
+ left: 0,
28
+ width: 0
29
+ };
30
+ $[0] = t1;
31
+ } else {
32
+ t1 = $[0];
33
+ }
34
+
35
+ const [indicator, setIndicator] = useState(t1);
36
+ const firstIndicatorUpdate = useRef(true);
37
+ let t2;
38
+
39
+ if ($[1] !== activeNode || $[2] !== containerRef) {
40
+ t2 = t3 => {
41
+ const isValueChanged = t3 === undefined ? false : t3;
42
+
43
+ if (!activeNode || !containerRef.current) {
44
+ return;
45
+ }
46
+
47
+ let isTransitionEnabled;
48
+
49
+ if (firstIndicatorUpdate.current) {
50
+ firstIndicatorUpdate.current = false;
51
+ isTransitionEnabled = false;
52
+ } else {
53
+ isTransitionEnabled = isValueChanged;
54
+ }
55
+
56
+ setIndicator({ ...calculateIndicator(activeNode, containerRef.current),
57
+ transitionDuration: !isTransitionEnabled ? "0s" : null
58
+ });
59
+ };
60
+
61
+ $[1] = activeNode;
62
+ $[2] = containerRef;
63
+ $[3] = t2;
64
+ } else {
65
+ t2 = $[3];
66
+ }
67
+
68
+ const updateIndicator = t2;
69
+ let t3;
70
+ let t4;
71
+
72
+ if ($[4] !== updateIndicator) {
73
+ t3 = () => updateIndicator(true);
74
+
75
+ t4 = [updateIndicator];
76
+ $[4] = updateIndicator;
77
+ $[5] = t3;
78
+ $[6] = t4;
79
+ } else {
80
+ t3 = $[5];
81
+ t4 = $[6];
82
+ }
83
+
84
+ useEffect(t3, t4);
85
+ let t5;
86
+
87
+ if ($[7] !== updateIndicator) {
88
+ t5 = () => updateIndicator(false);
89
+
90
+ $[7] = updateIndicator;
91
+ $[8] = t5;
92
+ } else {
93
+ t5 = $[8];
94
+ }
95
+
96
+ let t6;
97
+
98
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
99
+ t6 = {
100
+ ignoreFirstCall: true
101
+ };
102
+ $[9] = t6;
103
+ } else {
104
+ t6 = $[9];
105
+ }
106
+
107
+ useResizeObserver(containerRef, t5, t6);
108
+ let t7;
109
+
110
+ if ($[10] !== updateIndicator) {
111
+ t7 = () => updateIndicator(false);
112
+
113
+ $[10] = updateIndicator;
114
+ $[11] = t7;
115
+ } else {
116
+ t7 = $[11];
117
+ }
118
+
119
+ let t8;
120
+
121
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
122
+ t8 = {
123
+ ignoreFirstCall: true
124
+ };
125
+ $[12] = t8;
126
+ } else {
127
+ t8 = $[12];
128
+ }
129
+
130
+ useResizeObserver(activeNode, t7, t8);
131
+ const t9 = typeof indicator.transitionDuration === "undefined";
132
+ let t10;
133
+
134
+ if ($[13] !== indicator || $[14] !== t9) {
135
+ t10 = {
136
+ indicator,
137
+ isIndicatorHidden: t9
138
+ };
139
+ $[13] = indicator;
140
+ $[14] = t9;
141
+ $[15] = t10;
142
+ } else {
143
+ t10 = $[15];
144
+ }
145
+
146
+ return t10;
61
147
  };
62
148
 
63
149
  export { useIndicator };
@@ -1,5 +1,6 @@
1
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
- import React from 'react'; // eslint-disable-next-line complexity
1
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
2
+ import { c } from 'react-compiler-runtime';
3
+ import { useState } from 'react';
3
4
 
4
5
  const getNextItemId = _ref => {
5
6
  let {
@@ -31,44 +32,67 @@ const getNextItemId = _ref => {
31
32
  return currentItemId;
32
33
  };
33
34
 
34
- const useRovingTabIndex = _ref2 => {
35
- let {
35
+ const useRovingTabIndex = t0 => {
36
+ const $ = c(5);
37
+ const {
36
38
  selectedId,
37
39
  tabRefs
38
- } = _ref2;
39
- const [currentTabStopId, setCurrentTabStopId] = React.useState(selectedId ?? 0);
40
- const [previousSelectedId, setPreviousSelectedId] = React.useState(selectedId);
40
+ } = t0;
41
+ const [currentTabStopId, setCurrentTabStopId] = useState(selectedId ?? 0);
42
+ const [previousSelectedId, setPreviousSelectedId] = useState(selectedId);
41
43
 
42
44
  if (!Object.is(selectedId, previousSelectedId)) {
43
45
  setPreviousSelectedId(selectedId);
44
46
 
45
- if (typeof selectedId === 'number') {
47
+ if (typeof selectedId === "number") {
46
48
  setCurrentTabStopId(selectedId);
47
49
  }
48
50
  }
49
51
 
50
52
  const currentTabsRefs = tabRefs?.current;
51
- const onTabKeyDown = React.useCallback((e, itemId) => {
52
- var _context;
53
+ let t1;
53
54
 
54
- if (!_includesInstanceProperty(_context = ['ArrowLeft', 'ArrowRight', 'Home', 'End']).call(_context, e.key)) {
55
- return;
56
- }
55
+ if ($[0] !== currentTabsRefs) {
56
+ t1 = (e, itemId) => {
57
+ var _context;
58
+
59
+ if (!_includesInstanceProperty(_context = ["ArrowLeft", "ArrowRight", "Home", "End"]).call(_context, e.key)) {
60
+ return;
61
+ }
62
+
63
+ const itemsCount = currentTabsRefs.size ?? 0;
64
+ const nextItemId = getNextItemId({
65
+ currentItemId: itemId,
66
+ itemsCount,
67
+ key: e.key
68
+ });
69
+ e.preventDefault();
70
+ setCurrentTabStopId(nextItemId);
71
+ currentTabsRefs.get(nextItemId)?.focus();
72
+ };
73
+
74
+ $[0] = currentTabsRefs;
75
+ $[1] = t1;
76
+ } else {
77
+ t1 = $[1];
78
+ }
79
+
80
+ const onTabKeyDown = t1;
81
+ let t2;
82
+
83
+ if ($[2] !== currentTabStopId || $[3] !== onTabKeyDown) {
84
+ t2 = {
85
+ currentTabStopId,
86
+ onTabKeyDown
87
+ };
88
+ $[2] = currentTabStopId;
89
+ $[3] = onTabKeyDown;
90
+ $[4] = t2;
91
+ } else {
92
+ t2 = $[4];
93
+ }
57
94
 
58
- const itemsCount = currentTabsRefs.size ?? 0;
59
- const nextItemId = getNextItemId({
60
- currentItemId: itemId,
61
- itemsCount,
62
- key: e.key
63
- });
64
- e.preventDefault();
65
- setCurrentTabStopId(nextItemId);
66
- currentTabsRefs.get(nextItemId)?.focus();
67
- }, [currentTabsRefs]);
68
- return {
69
- currentTabStopId,
70
- onTabKeyDown
71
- };
95
+ return t2;
72
96
  };
73
97
 
74
98
  export { useRovingTabIndex };