@majoo-ui/react 2.4.4 → 2.4.5
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.
|
@@ -253,10 +253,16 @@ DropdownMenuContext.propTypes = {
|
|
|
253
253
|
side: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
|
254
254
|
align: PropTypes.oneOf(['start', 'center', 'end'])
|
|
255
255
|
};
|
|
256
|
-
const
|
|
256
|
+
const setRef = (ref, node) => {
|
|
257
|
+
if (typeof ref === 'function') ref(node);else if (ref) ref.current = node;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// forwardRef because DropdownMenuPortal renders its child through Radix's `Portal asChild`,
|
|
261
|
+
// which hands that child a ref; a plain function component would drop it with a warning.
|
|
262
|
+
const DropdownMenuContentContext = /*#__PURE__*/React__default.forwardRef(({
|
|
257
263
|
theme = 'default',
|
|
258
264
|
...props
|
|
259
|
-
}) => {
|
|
265
|
+
}, forwardedRef) => {
|
|
260
266
|
const {
|
|
261
267
|
side,
|
|
262
268
|
align
|
|
@@ -271,7 +277,8 @@ const DropdownMenuContentContext = ({
|
|
|
271
277
|
appElement.classList.remove('noscroll');
|
|
272
278
|
}
|
|
273
279
|
}
|
|
274
|
-
|
|
280
|
+
setRef(forwardedRef, node);
|
|
281
|
+
}, [forwardedRef]);
|
|
275
282
|
return /*#__PURE__*/jsx(StyledContent, {
|
|
276
283
|
className: `dropdown-content ${themeProvider?.theme || ''}`,
|
|
277
284
|
side: side,
|
|
@@ -280,7 +287,7 @@ const DropdownMenuContentContext = ({
|
|
|
280
287
|
...props,
|
|
281
288
|
children: props.children
|
|
282
289
|
});
|
|
283
|
-
};
|
|
290
|
+
});
|
|
284
291
|
DropdownMenuContentContext.propTypes = {
|
|
285
292
|
sideOffset: PropTypes.number,
|
|
286
293
|
alignOffset: PropTypes.number,
|
|
@@ -288,18 +295,19 @@ DropdownMenuContentContext.propTypes = {
|
|
|
288
295
|
};
|
|
289
296
|
|
|
290
297
|
// Radix positions submenus itself, so this only carries the theme class across the portal.
|
|
291
|
-
const DropdownMenuSubContentContext = ({
|
|
298
|
+
const DropdownMenuSubContentContext = /*#__PURE__*/React__default.forwardRef(({
|
|
292
299
|
theme = 'default',
|
|
293
300
|
children,
|
|
294
301
|
...props
|
|
295
|
-
}) => {
|
|
302
|
+
}, ref) => {
|
|
296
303
|
const themeProvider = useThemeProvider(theme);
|
|
297
304
|
return /*#__PURE__*/jsx(StyledSubContent, {
|
|
298
305
|
className: `dropdown-content ${themeProvider?.theme || ''}`,
|
|
306
|
+
ref: ref,
|
|
299
307
|
...props,
|
|
300
308
|
children: children
|
|
301
309
|
});
|
|
302
|
-
};
|
|
310
|
+
});
|
|
303
311
|
DropdownMenuSubContentContext.propTypes = {
|
|
304
312
|
sideOffset: PropTypes.number,
|
|
305
313
|
alignOffset: PropTypes.number,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React__default, { useState, useRef, useLayoutEffect } from 'react';
|
|
1
|
+
import React__default, { useState, useContext, useRef, useLayoutEffect } from 'react';
|
|
2
2
|
import * as TabsPrimitive from '@radix-ui/react-tabs';
|
|
3
3
|
import { colors, styled } from '../../config/stitches.config.esm.js';
|
|
4
|
-
import { addPropsToChildren } from '../../utils/element.esm.js';
|
|
5
4
|
import Box from '../../layout/box/Box.esm.js';
|
|
6
5
|
import Flex from '../../layout/flex/Flex.esm.js';
|
|
7
6
|
import { ConditionalWrapper } from '../../wrapper/ConditionalWrapper.esm.js';
|
|
@@ -154,19 +153,26 @@ const ScrollButtonContainer = styled(Box, {
|
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
});
|
|
156
|
+
|
|
157
|
+
// The active value reaches TabsList and TabsTrigger through context rather than being cloned
|
|
158
|
+
// onto the direct children, so a TabsList may sit inside any wrapper and no element receives
|
|
159
|
+
// an `activeTabs` attribute it does not understand.
|
|
160
|
+
const ActiveTabsContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
157
161
|
const Tabs = ({
|
|
158
162
|
children,
|
|
159
163
|
...props
|
|
160
164
|
}) => {
|
|
161
|
-
const [
|
|
165
|
+
const [uncontrolledActiveTabs, setActiveTabs] = useState(props.defaultValue || '');
|
|
166
|
+
const activeTabs = props.value !== undefined ? props.value : uncontrolledActiveTabs;
|
|
162
167
|
return /*#__PURE__*/jsx(StyledTabs, {
|
|
163
168
|
...props,
|
|
164
169
|
onValueChange: value => {
|
|
165
170
|
setActiveTabs(value);
|
|
166
171
|
if (props.onValueChange) props.onValueChange(value);
|
|
167
172
|
},
|
|
168
|
-
children:
|
|
169
|
-
activeTabs
|
|
173
|
+
children: /*#__PURE__*/jsx(ActiveTabsContext.Provider, {
|
|
174
|
+
value: activeTabs,
|
|
175
|
+
children: children
|
|
170
176
|
})
|
|
171
177
|
});
|
|
172
178
|
};
|
|
@@ -180,9 +186,11 @@ Tabs.propTypes = {
|
|
|
180
186
|
};
|
|
181
187
|
const TabsList = ({
|
|
182
188
|
children,
|
|
183
|
-
activeTabs,
|
|
189
|
+
activeTabs: activeTabsProp,
|
|
184
190
|
...props
|
|
185
191
|
}) => {
|
|
192
|
+
const contextActiveTabs = useContext(ActiveTabsContext);
|
|
193
|
+
const activeTabs = activeTabsProp !== undefined ? activeTabsProp : contextActiveTabs;
|
|
186
194
|
const [listContainerScrollPosition, setlistContainerScrollPosition] = useState(0);
|
|
187
195
|
const [scrollAreaWidth, setScrollAreaWidth] = useState(0);
|
|
188
196
|
const listContainerRef = useRef();
|
|
@@ -199,8 +207,9 @@ const TabsList = ({
|
|
|
199
207
|
...props,
|
|
200
208
|
ref: listContainerRef,
|
|
201
209
|
onScroll: e => setlistContainerScrollPosition(e.target.scrollLeft),
|
|
202
|
-
children:
|
|
203
|
-
activeTabs
|
|
210
|
+
children: /*#__PURE__*/jsx(ActiveTabsContext.Provider, {
|
|
211
|
+
value: activeTabs,
|
|
212
|
+
children: children
|
|
204
213
|
})
|
|
205
214
|
}), listContainerScrollPosition > 10 && /*#__PURE__*/jsx(ScrollButtonContainer, {
|
|
206
215
|
position: "left",
|
|
@@ -234,10 +243,12 @@ const TabsList = ({
|
|
|
234
243
|
const TabsTrigger = ({
|
|
235
244
|
children,
|
|
236
245
|
icon,
|
|
237
|
-
activeTabs,
|
|
246
|
+
activeTabs: activeTabsProp,
|
|
238
247
|
value,
|
|
239
248
|
...props
|
|
240
249
|
}) => {
|
|
250
|
+
const contextActiveTabs = useContext(ActiveTabsContext);
|
|
251
|
+
const activeTabs = activeTabsProp !== undefined ? activeTabsProp : contextActiveTabs;
|
|
241
252
|
const [isIconHovered, setIsIconHovered] = useState(false);
|
|
242
253
|
return /*#__PURE__*/jsx(StyledTrigger, {
|
|
243
254
|
value: value,
|
package/index.esm.css
CHANGED
package/package.json
CHANGED
package/utils/element.esm.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/es.iterator.constructor.js';
|
|
2
|
-
import 'core-js/modules/es.iterator.map.js';
|
|
3
|
-
import React__default from 'react';
|
|
4
|
-
|
|
5
|
-
function addPropsToReactElement(element, props) {
|
|
6
|
-
if (/*#__PURE__*/React__default.isValidElement(element)) {
|
|
7
|
-
return /*#__PURE__*/React__default.cloneElement(element, props);
|
|
8
|
-
}
|
|
9
|
-
return element;
|
|
10
|
-
}
|
|
11
|
-
function addPropsToChildren(children, props) {
|
|
12
|
-
if (!Array.isArray(children)) {
|
|
13
|
-
return addPropsToReactElement(children, props);
|
|
14
|
-
}
|
|
15
|
-
return children.map((childElement, index) => addPropsToReactElement(childElement, {
|
|
16
|
-
key: index,
|
|
17
|
-
...props
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { addPropsToChildren, addPropsToReactElement };
|