@mezzanine-ui/react 0.11.0 → 0.11.2
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/Navigation/Navigation.d.ts +1 -1
- package/Navigation/Navigation.js +40 -33
- package/package.json +4 -4
|
@@ -3,7 +3,7 @@ import { NavigationOrientation } from '@mezzanine-ui/core/navigation';
|
|
|
3
3
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
4
|
import { NavigationItemProps } from './NavigationItem';
|
|
5
5
|
import { NavigationSubMenuProps } from './NavigationSubMenu';
|
|
6
|
-
export declare type NavigationChild = ReactElement<NavigationItemProps | NavigationSubMenuProps
|
|
6
|
+
export declare type NavigationChild = ReactElement<NavigationItemProps | NavigationSubMenuProps> | null;
|
|
7
7
|
export declare type NavigationChildren = NavigationChild | NavigationChild[];
|
|
8
8
|
export interface NavigationProps extends Omit<NativeElementPropsWithoutKeyAndRef<'ul'>, 'onClick'> {
|
|
9
9
|
/**
|
package/Navigation/Navigation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, Children, cloneElement } from 'react';
|
|
2
|
+
import { forwardRef, useCallback, Children, cloneElement, useMemo } from 'react';
|
|
3
3
|
import { navigationClasses } from '@mezzanine-ui/core/navigation';
|
|
4
4
|
import NavigationItem from './NavigationItem.js';
|
|
5
5
|
import NavigationSubMenu from './NavigationSubMenu.js';
|
|
@@ -8,41 +8,48 @@ import cx from 'clsx';
|
|
|
8
8
|
|
|
9
9
|
const Navigation = forwardRef((props, ref) => {
|
|
10
10
|
const { activeKey, children = [], className, onClick, orientation = 'horizontal', ...rest } = props;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
const renderItemChildren = useCallback((parsedChildren) => (Children.map(parsedChildren, (child) => {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
if (child) {
|
|
14
|
+
switch (child.type) {
|
|
15
|
+
case NavigationItem: {
|
|
16
|
+
const itemChild = child;
|
|
17
|
+
return cloneElement(itemChild, {
|
|
18
|
+
active: itemChild.props.active || activeKey === itemChild.key,
|
|
19
|
+
eventKey: itemChild.key,
|
|
20
|
+
onClick: itemChild.props.onClick || onClick,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
case NavigationSubMenu: {
|
|
24
|
+
const subMenuChild = child;
|
|
25
|
+
const subMenuChildren = child.props.children;
|
|
26
|
+
let subMenuActive = false;
|
|
27
|
+
const groupChildren = Children
|
|
28
|
+
.map(subMenuChildren, (groupChild) => {
|
|
29
|
+
const active = activeKey === groupChild.key || groupChild.props.active;
|
|
30
|
+
if (active) {
|
|
31
|
+
subMenuActive = true;
|
|
32
|
+
}
|
|
33
|
+
return cloneElement(groupChild, {
|
|
34
|
+
active,
|
|
35
|
+
eventKey: groupChild.key,
|
|
36
|
+
onClick: groupChild.props.onClick || onClick,
|
|
37
|
+
});
|
|
35
38
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
39
|
+
return cloneElement(subMenuChild, {
|
|
40
|
+
active: subMenuChild.props.active || subMenuActive,
|
|
41
|
+
}, groupChildren);
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return renderItemChildren(((_b = (_a = child.props) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : []));
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
return null;
|
|
48
|
+
})), [activeKey, onClick]);
|
|
49
|
+
const context = useMemo(() => ({
|
|
50
|
+
orientation,
|
|
51
|
+
}), [orientation]);
|
|
52
|
+
return (jsx("ul", { ...rest, ref: ref, className: cx(navigationClasses.host, navigationClasses[orientation], className), children: jsx(NavigationContext.Provider, { value: context, children: renderItemChildren(children) }) }));
|
|
46
53
|
});
|
|
47
54
|
var Navigation$1 = Navigation;
|
|
48
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"react-dom": "^18.2.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mezzanine-ui/core": "^0.
|
|
35
|
-
"@mezzanine-ui/icons": "^0.
|
|
36
|
-
"@mezzanine-ui/system": "^0.
|
|
34
|
+
"@mezzanine-ui/core": "^0.11.2",
|
|
35
|
+
"@mezzanine-ui/icons": "^0.11.2",
|
|
36
|
+
"@mezzanine-ui/system": "^0.11.2",
|
|
37
37
|
"@popperjs/core": "^2.11.5",
|
|
38
38
|
"@types/react-transition-group": "^4.4.5",
|
|
39
39
|
"clsx": "^1.1.1",
|