@reykjavik/hanna-react 0.10.116 → 0.10.117

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,14 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.10.117
8
+
9
+ _2024-01-26_
10
+
11
+ - feat: Add compnent `IframeedLayout`
12
+ - feat: Default to auto-activating the first `MainMenu2__main__item`
13
+ - fix: Remove leftover `data-icon` attribute off `MainMenu2`'s SSR toggler
14
+
7
15
  ## 0.10.116
8
16
 
9
17
  _2024-01-10_
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ import type { HannaColorTheme } from '@reykjavik/hanna-css';
3
+ import { HannaLang } from '@reykjavik/hanna-utils/i18n';
4
+ import { BemModifierProps } from './utils/types.js';
5
+ import { WrapperElmProps } from './utils.js';
6
+ export type IframedLayoutProps = {
7
+ children: ReactNode;
8
+ colorTheme?: HannaColorTheme;
9
+ lang?: HannaLang;
10
+ } & WrapperElmProps<'div', 'data-color-theme'> & BemModifierProps;
11
+ export declare const IframedLayout: (props: IframedLayoutProps) => JSX.Element;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IframedLayout = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const classUtils_1 = require("@hugsmidjan/qj/classUtils");
7
+ const utils_js_1 = require("./utils.js");
8
+ const IframedLayout = (props) => {
9
+ (0, utils_js_1.useScrollbarWidthCSSVar)();
10
+ const { colorTheme, children, wrapperProps } = props;
11
+ return (react_1.default.createElement("div", Object.assign({}, wrapperProps, { className: (0, classUtils_1.modifiedClass)('IframedLayout', props.modifier, (wrapperProps || {}).className), "data-color-theme": colorTheme }), children));
12
+ };
13
+ exports.IframedLayout = IframedLayout;
package/Layout.d.ts CHANGED
@@ -14,7 +14,7 @@ export type LayoutI18n = {
14
14
  lang?: string;
15
15
  };
16
16
  export declare const defaultLayoutTexts: DefaultTexts<LayoutI18n>;
17
- type LayoutProps = {
17
+ export type LayoutProps = {
18
18
  globalAlerts?: ReactNode;
19
19
  navChildren?: ReactNode;
20
20
  footerChildren?: ReactNode;
@@ -25,7 +25,7 @@ type LayoutProps = {
25
25
  lang?: HannaLang;
26
26
  /** @deprecated Not used (Will be removed in v0.11) */
27
27
  ssr?: SSRSupport;
28
- } & WrapperElmProps & BemModifierProps & EitherObj<{
28
+ } & WrapperElmProps<'div', 'data-color-theme'> & BemModifierProps & EitherObj<{
29
29
  mainChildren: ReactNode;
30
30
  }, {
31
31
  children: ReactNode;
package/MainMenu2.js CHANGED
@@ -45,14 +45,6 @@ exports.defaultMainMenu2Texts = {
45
45
  closeMenu: 'Zamknij',
46
46
  closeMenuLong: 'Zamknij menu główne',
47
47
  },
48
- se: {
49
- title: 'Huvudmeny',
50
- homeLink: 'Förstasida',
51
- openMenu: 'Meny',
52
- openMenuLong: 'Öppna huvudmenyn',
53
- closeMenu: 'Stäng',
54
- closeMenuLong: 'Stäng huvudmenyn',
55
- },
56
48
  };
57
49
  // ---------------------------------------------------------------------------
58
50
  const iconMap = {
@@ -165,7 +157,13 @@ const MainMenu2 = (props) => {
165
157
  const current = (_a = item.subItems.find((subItem) => 'current' in subItem && !!subItem.current)) === null || _a === void 0 ? void 0 : _a.current;
166
158
  return Object.assign(Object.assign({}, item), { current });
167
159
  });
168
- const defaultActive = mainItems.findIndex((item) => 'current' in item && item.current);
160
+ let defaultActive = mainItems.findIndex((item) => 'current' in item && item.current);
161
+ // Fall back to setting the first item as active, if the first item
162
+ // has subItems. If the first item is just a link/button, then we
163
+ // just render everything equally not active.
164
+ if (defaultActive < 0 && 'subItems' in (mainItems[0] || {})) {
165
+ defaultActive = 0;
166
+ }
169
167
  return { mainItems, defaultActive };
170
168
  }, [items.main]);
171
169
  const [activeSubmenu, setActiveSubmenu] = (0, react_1.useState)(defaultActive);
@@ -206,7 +204,7 @@ const MainMenu2 = (props) => {
206
204
  'aria-label': txt.openMenuLong,
207
205
  title: txt.openMenuLong,
208
206
  children: txt.openMenu,
209
- })))) : (react_1.default.createElement(ButtonPrimary_js_1.default, { className: "MainMenu2__toggler", size: "small", href: `#${menuId}`, onClick: a11yHelpers_js_1.handleAnchorLinkClick, "aria-hidden": "true", "data-icon": "text" }, txt.title)),
207
+ })))) : (react_1.default.createElement(ButtonPrimary_js_1.default, { className: "MainMenu2__toggler", size: "small", href: `#${menuId}`, onClick: a11yHelpers_js_1.handleAnchorLinkClick, "aria-hidden": "true" }, txt.title)),
210
208
  mainItems && (react_1.default.createElement("div", { className: (0, classUtils_1.modifiedClass)('MainMenu2__main', activeSubmenu < 0 && 'noneActive') },
211
209
  renderItem('MainMenu2__main__', homeLinkItem, { Tag: 'div' }),
212
210
  mainItems.map((mainItem, i) => {
package/Tooltip.js CHANGED
@@ -19,7 +19,6 @@ const Tooltip = (props) => {
19
19
  });
20
20
  const { arrow } = middlewareData;
21
21
  const arrowX = arrow === null || arrow === void 0 ? void 0 : arrow.x;
22
- const arrowY = arrow === null || arrow === void 0 ? void 0 : arrow.y;
23
22
  (0, useCallbackOnEsc_js_1.useCallbackOnEsc)(() => {
24
23
  setIsOpen(false);
25
24
  });
@@ -67,7 +66,7 @@ const Tooltip = (props) => {
67
66
  (_a = wrapperProps.onContextMenu) === null || _a === void 0 ? void 0 : _a.call(wrapperProps, e);
68
67
  }, style: x == null
69
68
  ? wrapperProps.style
70
- : Object.assign(Object.assign({}, wrapperProps.style), { '--tooltip-content-pos-y': `${y}px`, '--tooltip-content-pos-x': `${x}px`, '--tooltip-arrow-pos-x': `${arrowX}px`, '--tooltip-arrow-pos-y': `${arrowY}px` }) }),
69
+ : Object.assign(Object.assign({}, wrapperProps.style), { '--tooltip-content-pos-y': `${y}px`, '--tooltip-content-pos-x': `${x}px`, '--tooltip-arrow-pos-x': `${arrowX}px` }) }),
71
70
  react_1.default.createElement("summary", { className: (0, classUtils_1.modifiedClass)('Tooltip__trigger', iconOnly && 'icononly'), ref: refs.setReference }, label),
72
71
  react_1.default.createElement("div", { className: "Tooltip__content", onClick: (e) => e.stopPropagation(), ref: refs.setFloating },
73
72
  x !== null && (react_1.default.createElement("div", { "data-floating-ui-hack-plz-ignore": "", style: { position: 'absolute', display: 'none' }, ref: arrowRef })),
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ import type { HannaColorTheme } from '@reykjavik/hanna-css';
3
+ import { HannaLang } from '@reykjavik/hanna-utils/i18n';
4
+ import { BemModifierProps } from './utils/types.js';
5
+ import { WrapperElmProps } from './utils.js';
6
+ export type IframedLayoutProps = {
7
+ children: ReactNode;
8
+ colorTheme?: HannaColorTheme;
9
+ lang?: HannaLang;
10
+ } & WrapperElmProps<'div', 'data-color-theme'> & BemModifierProps;
11
+ export declare const IframedLayout: (props: IframedLayoutProps) => JSX.Element;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { modifiedClass } from '@hugsmidjan/qj/classUtils';
3
+ import { useScrollbarWidthCSSVar } from './utils.js';
4
+ export const IframedLayout = (props) => {
5
+ useScrollbarWidthCSSVar();
6
+ const { colorTheme, children, wrapperProps } = props;
7
+ return (React.createElement("div", Object.assign({}, wrapperProps, { className: modifiedClass('IframedLayout', props.modifier, (wrapperProps || {}).className), "data-color-theme": colorTheme }), children));
8
+ };
package/esm/Layout.d.ts CHANGED
@@ -14,7 +14,7 @@ export type LayoutI18n = {
14
14
  lang?: string;
15
15
  };
16
16
  export declare const defaultLayoutTexts: DefaultTexts<LayoutI18n>;
17
- type LayoutProps = {
17
+ export type LayoutProps = {
18
18
  globalAlerts?: ReactNode;
19
19
  navChildren?: ReactNode;
20
20
  footerChildren?: ReactNode;
@@ -25,7 +25,7 @@ type LayoutProps = {
25
25
  lang?: HannaLang;
26
26
  /** @deprecated Not used (Will be removed in v0.11) */
27
27
  ssr?: SSRSupport;
28
- } & WrapperElmProps & BemModifierProps & EitherObj<{
28
+ } & WrapperElmProps<'div', 'data-color-theme'> & BemModifierProps & EitherObj<{
29
29
  mainChildren: ReactNode;
30
30
  }, {
31
31
  children: ReactNode;
package/esm/MainMenu2.js CHANGED
@@ -41,14 +41,6 @@ export const defaultMainMenu2Texts = {
41
41
  closeMenu: 'Zamknij',
42
42
  closeMenuLong: 'Zamknij menu główne',
43
43
  },
44
- se: {
45
- title: 'Huvudmeny',
46
- homeLink: 'Förstasida',
47
- openMenu: 'Meny',
48
- openMenuLong: 'Öppna huvudmenyn',
49
- closeMenu: 'Stäng',
50
- closeMenuLong: 'Stäng huvudmenyn',
51
- },
52
44
  };
53
45
  // ---------------------------------------------------------------------------
54
46
  const iconMap = {
@@ -161,7 +153,13 @@ export const MainMenu2 = (props) => {
161
153
  const current = (_a = item.subItems.find((subItem) => 'current' in subItem && !!subItem.current)) === null || _a === void 0 ? void 0 : _a.current;
162
154
  return Object.assign(Object.assign({}, item), { current });
163
155
  });
164
- const defaultActive = mainItems.findIndex((item) => 'current' in item && item.current);
156
+ let defaultActive = mainItems.findIndex((item) => 'current' in item && item.current);
157
+ // Fall back to setting the first item as active, if the first item
158
+ // has subItems. If the first item is just a link/button, then we
159
+ // just render everything equally not active.
160
+ if (defaultActive < 0 && 'subItems' in (mainItems[0] || {})) {
161
+ defaultActive = 0;
162
+ }
165
163
  return { mainItems, defaultActive };
166
164
  }, [items.main]);
167
165
  const [activeSubmenu, setActiveSubmenu] = useState(defaultActive);
@@ -202,7 +200,7 @@ export const MainMenu2 = (props) => {
202
200
  'aria-label': txt.openMenuLong,
203
201
  title: txt.openMenuLong,
204
202
  children: txt.openMenu,
205
- })))) : (React.createElement(ButtonPrimary, { className: "MainMenu2__toggler", size: "small", href: `#${menuId}`, onClick: handleAnchorLinkClick, "aria-hidden": "true", "data-icon": "text" }, txt.title)),
203
+ })))) : (React.createElement(ButtonPrimary, { className: "MainMenu2__toggler", size: "small", href: `#${menuId}`, onClick: handleAnchorLinkClick, "aria-hidden": "true" }, txt.title)),
206
204
  mainItems && (React.createElement("div", { className: modifiedClass('MainMenu2__main', activeSubmenu < 0 && 'noneActive') },
207
205
  renderItem('MainMenu2__main__', homeLinkItem, { Tag: 'div' }),
208
206
  mainItems.map((mainItem, i) => {
package/esm/Tooltip.js CHANGED
@@ -15,7 +15,6 @@ export const Tooltip = (props) => {
15
15
  });
16
16
  const { arrow } = middlewareData;
17
17
  const arrowX = arrow === null || arrow === void 0 ? void 0 : arrow.x;
18
- const arrowY = arrow === null || arrow === void 0 ? void 0 : arrow.y;
19
18
  useCallbackOnEsc(() => {
20
19
  setIsOpen(false);
21
20
  });
@@ -63,7 +62,7 @@ export const Tooltip = (props) => {
63
62
  (_a = wrapperProps.onContextMenu) === null || _a === void 0 ? void 0 : _a.call(wrapperProps, e);
64
63
  }, style: x == null
65
64
  ? wrapperProps.style
66
- : Object.assign(Object.assign({}, wrapperProps.style), { '--tooltip-content-pos-y': `${y}px`, '--tooltip-content-pos-x': `${x}px`, '--tooltip-arrow-pos-x': `${arrowX}px`, '--tooltip-arrow-pos-y': `${arrowY}px` }) }),
65
+ : Object.assign(Object.assign({}, wrapperProps.style), { '--tooltip-content-pos-y': `${y}px`, '--tooltip-content-pos-x': `${x}px`, '--tooltip-arrow-pos-x': `${arrowX}px` }) }),
67
66
  React.createElement("summary", { className: modifiedClass('Tooltip__trigger', iconOnly && 'icononly'), ref: refs.setReference }, label),
68
67
  React.createElement("div", { className: "Tooltip__content", onClick: (e) => e.stopPropagation(), ref: refs.setFloating },
69
68
  x !== null && (React.createElement("div", { "data-floating-ui-hack-plz-ignore": "", style: { position: 'absolute', display: 'none' }, ref: arrowRef })),
package/esm/index.d.ts CHANGED
@@ -54,6 +54,7 @@
54
54
  /// <reference path="./InfoBlock.d.tsx" />
55
55
  /// <reference path="./ImageCards.d.tsx" />
56
56
  /// <reference path="./Illustration.d.tsx" />
57
+ /// <reference path="./IframedLayout.d.tsx" />
57
58
  /// <reference path="./IframeBlock.d.tsx" />
58
59
  /// <reference path="./HeroBlock.d.tsx" />
59
60
  /// <reference path="./Heading.d.tsx" />
package/index.d.ts CHANGED
@@ -54,6 +54,7 @@
54
54
  /// <reference path="./InfoBlock.d.tsx" />
55
55
  /// <reference path="./ImageCards.d.tsx" />
56
56
  /// <reference path="./Illustration.d.tsx" />
57
+ /// <reference path="./IframedLayout.d.tsx" />
57
58
  /// <reference path="./IframeBlock.d.tsx" />
58
59
  /// <reference path="./HeroBlock.d.tsx" />
59
60
  /// <reference path="./Heading.d.tsx" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.116",
3
+ "version": "0.10.117",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",
@@ -17,8 +17,8 @@
17
17
  "@floating-ui/react": "^0.19.2",
18
18
  "@hugsmidjan/qj": "^4.22.1",
19
19
  "@hugsmidjan/react": "^0.4.32",
20
- "@reykjavik/hanna-css": "^0.4.12",
21
- "@reykjavik/hanna-utils": "^0.2.13",
20
+ "@reykjavik/hanna-css": "^0.4.14",
21
+ "@reykjavik/hanna-utils": "^0.2.14",
22
22
  "@types/react-autosuggest": "^10.1.0",
23
23
  "@types/react-datepicker": "^4.8.0",
24
24
  "@types/react-transition-group": "^4.4.0",
@@ -269,6 +269,10 @@
269
269
  "import": "./esm/Illustration.js",
270
270
  "require": "./Illustration.js"
271
271
  },
272
+ "./IframedLayout": {
273
+ "import": "./esm/IframedLayout.js",
274
+ "require": "./IframedLayout.js"
275
+ },
272
276
  "./IframeBlock": {
273
277
  "import": "./esm/IframeBlock.js",
274
278
  "require": "./IframeBlock.js"