@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.
@@ -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
  /**
@@ -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 ItemChildren = Children.map(children, (child) => {
12
- switch (child.type) {
13
- case NavigationItem: {
14
- const itemChild = child;
15
- return cloneElement(itemChild, {
16
- active: itemChild.props.active || activeKey === itemChild.key,
17
- eventKey: itemChild.key,
18
- onClick: itemChild.props.onClick || onClick,
19
- });
20
- }
21
- case NavigationSubMenu: {
22
- const subMenuChild = child;
23
- const subMenuChildren = child.props.children;
24
- let subMenuActive = false;
25
- const groupChildren = Children
26
- .map(subMenuChildren, (groupChild) => {
27
- const active = activeKey === groupChild.key || groupChild.props.active;
28
- if (active) {
29
- subMenuActive = true;
30
- }
31
- return cloneElement(groupChild, {
32
- active,
33
- eventKey: groupChild.key,
34
- onClick: groupChild.props.onClick || onClick,
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
- return cloneElement(subMenuChild, {
38
- active: subMenuChild.props.active || subMenuActive,
39
- }, groupChildren);
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
- return (jsx("ul", { ...rest, ref: ref, className: cx(navigationClasses.host, navigationClasses[orientation], className), children: jsx(NavigationContext.Provider, { value: {
44
- orientation,
45
- }, children: ItemChildren }) }));
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.0",
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.10.5",
35
- "@mezzanine-ui/icons": "^0.10.2",
36
- "@mezzanine-ui/system": "^0.7.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",