@longline/aqua-ui 1.0.220 → 1.0.221

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.
@@ -6,9 +6,15 @@ interface IMainMenuProps {
6
6
  children?: React.ReactNode;
7
7
  }
8
8
  /**
9
- * A `MainMenu` is always positioned on the left side of its container, and fills it
10
- * vertically.
9
+ * A `MainMenu` is always positioned on the left side of its container, and
10
+ * fills it vertically.
11
11
  * It requires react-spring/web to work.
12
+ *
13
+ * A `MainMenu` contains `MainMenu.Item` components as children. Each child
14
+ * can have a `secondary` prop, which will place it in the secondary section
15
+ * of the main menu. It is possible to wrap the `MainMenu.Item` components
16
+ * in other components (for example, a component that conditionally renders
17
+ * the menu item), and the secondary prop will still be detected.
12
18
  */
13
19
  declare const MainMenu: {
14
20
  (props: IMainMenuProps): React.JSX.Element;
@@ -16,24 +16,67 @@ var __assign = (this && this.__assign) || function () {
16
16
  import * as React from 'react';
17
17
  import styled from 'styled-components';
18
18
  import { Item } from './Item';
19
+ function containsSecondaryMenuItem(child) {
20
+ var found = false;
21
+ React.Children.forEach(child, function (c) {
22
+ if (!React.isValidElement(c))
23
+ return;
24
+ if (c.type === MainMenu.Item && c.props.secondary) {
25
+ found = true;
26
+ }
27
+ else if (c.props.children) {
28
+ if (containsSecondaryMenuItem(c.props.children)) {
29
+ found = true;
30
+ }
31
+ }
32
+ });
33
+ return found;
34
+ }
19
35
  var MainMenuBase = function (props) {
36
+ var directChildren = React.Children.toArray(props.children);
37
+ var primaryItems = [];
38
+ var secondaryItems = [];
39
+ // Go through all direct children, and determine whether they go in
40
+ // the primary or secondary menu section. This is done by checking if the
41
+ // child contains a MainMenu.Item, and if that item is secondary. Items
42
+ // are detected at any depth.
43
+ directChildren.forEach(function (child) {
44
+ if (containsSecondaryMenuItem(child)) {
45
+ secondaryItems.push(child);
46
+ }
47
+ else {
48
+ primaryItems.push(child);
49
+ }
50
+ });
20
51
  return (React.createElement("div", { className: props.className },
21
- React.createElement(Top, null, React.Children.toArray(props.children).filter(function (c) { return !c.props.secondary; })),
22
- React.createElement(Bottom, null, React.Children.toArray(props.children).filter(function (c) { return c.props.secondary; }))));
52
+ React.createElement(Top, null, primaryItems),
53
+ React.createElement(Bottom, null, secondaryItems)));
23
54
  };
24
55
  var Top = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 16px;\n"], ["\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 16px;\n"])));
25
56
  var Bottom = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: end;\n gap: 16px;\n"], ["\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: end;\n gap: 16px;\n"])));
26
57
  var MainMenuStyled = styled(MainMenuBase)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n // Position and size:\n position: relative;\n box-sizing: border-box;\n z-index: 1;\n height: 100%;\n width: 80px;\n\n // Appearance:\n padding-bottom: 32px;\n background-image: linear-gradient(#457298, #2C4253);\n\n // Content:\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n pointer-events: auto;\n"], ["\n // Position and size:\n position: relative;\n box-sizing: border-box;\n z-index: 1;\n height: 100%;\n width: 80px;\n\n // Appearance:\n padding-bottom: 32px;\n background-image: linear-gradient(#457298, #2C4253);\n\n // Content:\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n pointer-events: auto;\n"
27
58
  /**
28
- * A `MainMenu` is always positioned on the left side of its container, and fills it
29
- * vertically.
59
+ * A `MainMenu` is always positioned on the left side of its container, and
60
+ * fills it vertically.
30
61
  * It requires react-spring/web to work.
62
+ *
63
+ * A `MainMenu` contains `MainMenu.Item` components as children. Each child
64
+ * can have a `secondary` prop, which will place it in the secondary section
65
+ * of the main menu. It is possible to wrap the `MainMenu.Item` components
66
+ * in other components (for example, a component that conditionally renders
67
+ * the menu item), and the secondary prop will still be detected.
31
68
  */
32
69
  ])));
33
70
  /**
34
- * A `MainMenu` is always positioned on the left side of its container, and fills it
35
- * vertically.
71
+ * A `MainMenu` is always positioned on the left side of its container, and
72
+ * fills it vertically.
36
73
  * It requires react-spring/web to work.
74
+ *
75
+ * A `MainMenu` contains `MainMenu.Item` components as children. Each child
76
+ * can have a `secondary` prop, which will place it in the secondary section
77
+ * of the main menu. It is possible to wrap the `MainMenu.Item` components
78
+ * in other components (for example, a component that conditionally renders
79
+ * the menu item), and the secondary prop will still be detected.
37
80
  */
38
81
  var MainMenu = function (props) { return React.createElement(MainMenuStyled, __assign({}, props)); };
39
82
  MainMenu.displayName = 'MainMenu';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.220",
3
+ "version": "1.0.221",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",