@reykjavik/hanna-react 0.10.154 → 0.10.156

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/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.10.156
8
+
9
+ _2025-06-23_
10
+
11
+ - feat: Allow `MainMenu2` items to be `null` or `false` also
12
+
13
+ ## 0.10.155
14
+
15
+ _2025-06-23_
16
+
17
+ - feat: Allow `MainMenu2` items to be `undefined` for easier conditional item
18
+ array population
19
+
7
20
  ## 0.10.154
8
21
 
9
22
  _2025-06-20_
package/MainMenu2.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Illustration } from '@reykjavik/hanna-utils/assets';
4
4
  import { DefaultTexts } from '@reykjavik/hanna-utils/i18n';
5
5
  import { I18NProps } from './utils/types.js';
6
6
  import { SSRSupportProps, WrapperElmProps } from './utils.js';
7
+ type Falseish = undefined | null | false;
7
8
  export type MainMenu2I18n = {
8
9
  title: string;
9
10
  homeLink: string;
@@ -64,11 +65,11 @@ export type MainMenu2SubMenuItem = MainMenu2Item & {
64
65
  export type MainMenu2SubMenu = {
65
66
  title: string;
66
67
  current?: boolean;
67
- subItems: Array<MainMenu2SubMenuItem | MainMenu2CustomItem>;
68
+ subItems: Array<MainMenu2SubMenuItem | MainMenu2CustomItem | Falseish>;
68
69
  };
69
- export type MainMenu2ItemList = Array<MainMenu2Item | MainMenu2CustomItem>;
70
- export type MainMenu2ButtonItemList = Array<MainMenu2ButtonItem | MainMenu2CustomItem>;
71
- export type MainMenu2SubMenuItemList = Array<MainMenu2SubMenuItem | MainMenu2CustomItem>;
70
+ export type MainMenu2ItemList = Array<MainMenu2Item | MainMenu2CustomItem | Falseish>;
71
+ export type MainMenu2ButtonItemList = Array<MainMenu2ButtonItem | MainMenu2CustomItem | Falseish>;
72
+ export type MainMenu2SubMenuItemList = Array<MainMenu2SubMenuItem | MainMenu2CustomItem | Falseish>;
72
73
  export type MainMenu2Props = {
73
74
  /**
74
75
  * URL for the mandatory (usually screen-reader-only) homepage Link.
@@ -114,3 +115,4 @@ export type MainMenu2Props = {
114
115
  imageUrl?: string;
115
116
  }> & WrapperElmProps & I18NProps<MainMenu2I18n> & SSRSupportProps;
116
117
  export declare const MainMenu2: (props: MainMenu2Props) => JSX.Element;
118
+ export {};
package/MainMenu2.js CHANGED
@@ -64,6 +64,9 @@ const iconMap = {
64
64
  const getRenderers = (props) => {
65
65
  const { onItemClick, closeMenu, openMenu, isBrowser } = props;
66
66
  const renderItem = (classPrefix, item, opts = {}) => {
67
+ if (!item) {
68
+ return;
69
+ }
67
70
  const { key, Tag = 'li', button } = opts;
68
71
  if (typeof item === 'function') {
69
72
  const Item = item;
@@ -109,7 +112,8 @@ const getRenderers = (props) => {
109
112
  if (!items || !items.length) {
110
113
  return null;
111
114
  }
112
- return (react_1.default.createElement("ul", Object.assign({ className: `${classSuffix}items` }, opts.listProps), items.map((listItem, i) => renderItem(classSuffix, listItem, { key: i, button: opts.buttons }))));
115
+ return (react_1.default.createElement("ul", Object.assign({ className: `${classSuffix}items` }, opts.listProps), items.map((listItem, i) => listItem &&
116
+ renderItem(classSuffix, listItem, { key: i, button: opts.buttons }))));
113
117
  };
114
118
  return { renderList, renderItem };
115
119
  };
@@ -163,7 +167,7 @@ const MainMenu2 = (props) => {
163
167
  if (!('title' in item) || 'current' in item) {
164
168
  return item;
165
169
  }
166
- const current = (_a = item.subItems.find((subItem) => 'current' in subItem && !!subItem.current)) === null || _a === void 0 ? void 0 : _a.current;
170
+ const current = (_a = item.subItems.find((subItem) => !!(subItem && 'current' in subItem && !!subItem.current))) === null || _a === void 0 ? void 0 : _a.current;
167
171
  return Object.assign(Object.assign({}, item), { current });
168
172
  });
169
173
  let defaultActive = mainItems.findIndex((item) => 'current' in item && item.current);
@@ -4,6 +4,7 @@ import { Illustration } from '@reykjavik/hanna-utils/assets';
4
4
  import { DefaultTexts } from '@reykjavik/hanna-utils/i18n';
5
5
  import { I18NProps } from './utils/types.js';
6
6
  import { SSRSupportProps, WrapperElmProps } from './utils.js';
7
+ type Falseish = undefined | null | false;
7
8
  export type MainMenu2I18n = {
8
9
  title: string;
9
10
  homeLink: string;
@@ -64,11 +65,11 @@ export type MainMenu2SubMenuItem = MainMenu2Item & {
64
65
  export type MainMenu2SubMenu = {
65
66
  title: string;
66
67
  current?: boolean;
67
- subItems: Array<MainMenu2SubMenuItem | MainMenu2CustomItem>;
68
+ subItems: Array<MainMenu2SubMenuItem | MainMenu2CustomItem | Falseish>;
68
69
  };
69
- export type MainMenu2ItemList = Array<MainMenu2Item | MainMenu2CustomItem>;
70
- export type MainMenu2ButtonItemList = Array<MainMenu2ButtonItem | MainMenu2CustomItem>;
71
- export type MainMenu2SubMenuItemList = Array<MainMenu2SubMenuItem | MainMenu2CustomItem>;
70
+ export type MainMenu2ItemList = Array<MainMenu2Item | MainMenu2CustomItem | Falseish>;
71
+ export type MainMenu2ButtonItemList = Array<MainMenu2ButtonItem | MainMenu2CustomItem | Falseish>;
72
+ export type MainMenu2SubMenuItemList = Array<MainMenu2SubMenuItem | MainMenu2CustomItem | Falseish>;
72
73
  export type MainMenu2Props = {
73
74
  /**
74
75
  * URL for the mandatory (usually screen-reader-only) homepage Link.
@@ -114,3 +115,4 @@ export type MainMenu2Props = {
114
115
  imageUrl?: string;
115
116
  }> & WrapperElmProps & I18NProps<MainMenu2I18n> & SSRSupportProps;
116
117
  export declare const MainMenu2: (props: MainMenu2Props) => JSX.Element;
118
+ export {};
package/esm/MainMenu2.js CHANGED
@@ -60,6 +60,9 @@ const iconMap = {
60
60
  const getRenderers = (props) => {
61
61
  const { onItemClick, closeMenu, openMenu, isBrowser } = props;
62
62
  const renderItem = (classPrefix, item, opts = {}) => {
63
+ if (!item) {
64
+ return;
65
+ }
63
66
  const { key, Tag = 'li', button } = opts;
64
67
  if (typeof item === 'function') {
65
68
  const Item = item;
@@ -105,7 +108,8 @@ const getRenderers = (props) => {
105
108
  if (!items || !items.length) {
106
109
  return null;
107
110
  }
108
- return (React.createElement("ul", Object.assign({ className: `${classSuffix}items` }, opts.listProps), items.map((listItem, i) => renderItem(classSuffix, listItem, { key: i, button: opts.buttons }))));
111
+ return (React.createElement("ul", Object.assign({ className: `${classSuffix}items` }, opts.listProps), items.map((listItem, i) => listItem &&
112
+ renderItem(classSuffix, listItem, { key: i, button: opts.buttons }))));
109
113
  };
110
114
  return { renderList, renderItem };
111
115
  };
@@ -159,7 +163,7 @@ export const MainMenu2 = (props) => {
159
163
  if (!('title' in item) || 'current' in item) {
160
164
  return item;
161
165
  }
162
- const current = (_a = item.subItems.find((subItem) => 'current' in subItem && !!subItem.current)) === null || _a === void 0 ? void 0 : _a.current;
166
+ const current = (_a = item.subItems.find((subItem) => !!(subItem && 'current' in subItem && !!subItem.current))) === null || _a === void 0 ? void 0 : _a.current;
163
167
  return Object.assign(Object.assign({}, item), { current });
164
168
  });
165
169
  let defaultActive = mainItems.findIndex((item) => 'current' in item && item.current);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.154",
3
+ "version": "0.10.156",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",