@reykjavik/hanna-react 0.10.93 → 0.10.95

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.
Files changed (184) hide show
  1. package/AccordionList.d.ts +2 -3
  2. package/AccordionList.js +3 -3
  3. package/Alert.d.ts +2 -3
  4. package/Alert.js +2 -2
  5. package/ArticleCarousel/_ArticleCarouselCard.js +2 -2
  6. package/ArticleCarousel.d.ts +2 -3
  7. package/ArticleMeta.js +2 -2
  8. package/Attention.js +2 -2
  9. package/BasicTable.js +2 -2
  10. package/BgBox.js +2 -2
  11. package/Bling.js +2 -2
  12. package/ButtonBar.js +2 -2
  13. package/CHANGELOG.md +14 -1
  14. package/ContactBubble.d.ts +2 -3
  15. package/ContactBubble.js +2 -2
  16. package/Datepicker.js +2 -2
  17. package/ExtraLinks.js +3 -3
  18. package/FieldGroup.js +2 -2
  19. package/FileInput.js +3 -3
  20. package/FooterInfo.d.ts +2 -2
  21. package/FooterInfo.js +3 -3
  22. package/Form.js +2 -2
  23. package/FormField.d.ts +2 -3
  24. package/FormField.js +2 -2
  25. package/Gallery.d.ts +2 -3
  26. package/GridBlocks.js +2 -2
  27. package/Heading.js +2 -2
  28. package/IframeBlock.js +2 -2
  29. package/ImageCards.js +2 -2
  30. package/InfoHero.js +2 -2
  31. package/LabeledTextBlock.js +2 -2
  32. package/Layout.d.ts +3 -6
  33. package/Layout.js +7 -13
  34. package/MainMenu/_PrimaryPanel.js +2 -2
  35. package/MainMenu.d.ts +2 -3
  36. package/MainMenu.js +3 -3
  37. package/Multiselect.js +5 -5
  38. package/NameCard.js +2 -2
  39. package/NewsHero.js +2 -2
  40. package/PageFilter.js +2 -2
  41. package/PageHeading.js +2 -2
  42. package/Picture.js +2 -2
  43. package/ProcessOverview.js +2 -2
  44. package/ReadSpeakerPlayer.js +2 -2
  45. package/RowBlock.d.ts +2 -2
  46. package/RowBlock.js +2 -2
  47. package/RowBlockColumn.js +2 -2
  48. package/SearchInput.js +2 -2
  49. package/SearchResults.js +2 -2
  50. package/Selectbox.js +2 -2
  51. package/ShareButtons.d.ts +2 -3
  52. package/Sharpie.js +2 -2
  53. package/SiteSearchAutocomplete.d.ts +1 -1
  54. package/SiteSearchCurtain.js +2 -2
  55. package/SiteSearchInput.d.ts +2 -3
  56. package/Skeleton.js +2 -2
  57. package/SubHeading.js +2 -2
  58. package/Tabs.d.ts +2 -3
  59. package/Tabs.js +2 -2
  60. package/TagPill.js +3 -3
  61. package/TextBlock.js +2 -2
  62. package/TextInput.js +2 -2
  63. package/Tooltip.js +2 -2
  64. package/VSpacer.js +2 -2
  65. package/WizardLayout.d.ts +2 -3
  66. package/WizardLayout.js +2 -2
  67. package/WizardStepper.js +3 -3
  68. package/_abstract/_AbstractCarousel.d.ts +3 -4
  69. package/_abstract/_AbstractCarousel.js +2 -2
  70. package/_abstract/_Block.d.ts +2 -2
  71. package/_abstract/_Block.js +2 -2
  72. package/_abstract/_Button.d.ts +3 -3
  73. package/_abstract/_Button.js +2 -2
  74. package/_abstract/_Image.js +3 -3
  75. package/_abstract/_TogglerGroup.js +2 -2
  76. package/_abstract/_TogglerGroupField.d.ts +2 -2
  77. package/_abstract/_TogglerGroupField.js +2 -2
  78. package/_abstract/_TogglerInput.d.ts +2 -2
  79. package/_abstract/_TogglerInput.js +2 -2
  80. package/_mixed_export_resolution_/ReactDropzone.d.ts +3 -3
  81. package/_mixed_export_resolution_/ReactDropzone.js +3 -3
  82. package/esm/AccordionList.d.ts +2 -3
  83. package/esm/AccordionList.js +3 -3
  84. package/esm/Alert.d.ts +2 -3
  85. package/esm/Alert.js +2 -2
  86. package/esm/ArticleCarousel/_ArticleCarouselCard.js +2 -2
  87. package/esm/ArticleCarousel.d.ts +2 -3
  88. package/esm/ArticleMeta.js +2 -2
  89. package/esm/Attention.js +2 -2
  90. package/esm/BasicTable.js +2 -2
  91. package/esm/BgBox.js +2 -2
  92. package/esm/Bling.js +2 -2
  93. package/esm/ButtonBar.js +2 -2
  94. package/esm/ContactBubble.d.ts +2 -3
  95. package/esm/ContactBubble.js +2 -2
  96. package/esm/Datepicker.js +2 -2
  97. package/esm/ExtraLinks.js +3 -3
  98. package/esm/FieldGroup.js +2 -2
  99. package/esm/FileInput.js +3 -3
  100. package/esm/FooterInfo.d.ts +2 -2
  101. package/esm/FooterInfo.js +3 -3
  102. package/esm/Form.js +2 -2
  103. package/esm/FormField.d.ts +2 -3
  104. package/esm/FormField.js +2 -2
  105. package/esm/Gallery.d.ts +2 -3
  106. package/esm/GridBlocks.js +2 -2
  107. package/esm/Heading.js +2 -2
  108. package/esm/IframeBlock.js +2 -2
  109. package/esm/ImageCards.js +2 -2
  110. package/esm/InfoHero.js +2 -2
  111. package/esm/LabeledTextBlock.js +2 -2
  112. package/esm/Layout.d.ts +3 -6
  113. package/esm/Layout.js +7 -13
  114. package/esm/MainMenu/_PrimaryPanel.js +2 -2
  115. package/esm/MainMenu.d.ts +2 -3
  116. package/esm/MainMenu.js +3 -3
  117. package/esm/Multiselect.js +5 -5
  118. package/esm/NameCard.js +2 -2
  119. package/esm/NewsHero.js +2 -2
  120. package/esm/PageFilter.js +2 -2
  121. package/esm/PageHeading.js +2 -2
  122. package/esm/Picture.js +2 -2
  123. package/esm/ProcessOverview.js +2 -2
  124. package/esm/ReadSpeakerPlayer.js +2 -2
  125. package/esm/RowBlock.d.ts +2 -2
  126. package/esm/RowBlock.js +2 -2
  127. package/esm/RowBlockColumn.js +2 -2
  128. package/esm/SearchInput.js +2 -2
  129. package/esm/SearchResults.js +2 -2
  130. package/esm/Selectbox.js +2 -2
  131. package/esm/ShareButtons.d.ts +2 -3
  132. package/esm/Sharpie.js +2 -2
  133. package/esm/SiteSearchAutocomplete.d.ts +1 -1
  134. package/esm/SiteSearchCurtain.js +2 -2
  135. package/esm/SiteSearchInput.d.ts +2 -3
  136. package/esm/Skeleton.js +2 -2
  137. package/esm/SubHeading.js +2 -2
  138. package/esm/Tabs.d.ts +2 -3
  139. package/esm/Tabs.js +2 -2
  140. package/esm/TagPill.js +3 -3
  141. package/esm/TextBlock.js +2 -2
  142. package/esm/TextInput.js +2 -2
  143. package/esm/Tooltip.js +2 -2
  144. package/esm/VSpacer.js +2 -2
  145. package/esm/WizardLayout.d.ts +2 -3
  146. package/esm/WizardLayout.js +2 -2
  147. package/esm/WizardStepper.js +3 -3
  148. package/esm/_abstract/_AbstractCarousel.d.ts +3 -4
  149. package/esm/_abstract/_AbstractCarousel.js +2 -2
  150. package/esm/_abstract/_Block.d.ts +2 -2
  151. package/esm/_abstract/_Block.js +2 -2
  152. package/esm/_abstract/_Button.d.ts +3 -3
  153. package/esm/_abstract/_Button.js +2 -2
  154. package/esm/_abstract/_Image.js +3 -3
  155. package/esm/_abstract/_TogglerGroup.js +2 -2
  156. package/esm/_abstract/_TogglerGroupField.d.ts +2 -2
  157. package/esm/_abstract/_TogglerGroupField.js +2 -2
  158. package/esm/_abstract/_TogglerInput.d.ts +2 -2
  159. package/esm/_abstract/_TogglerInput.js +2 -2
  160. package/esm/_mixed_export_resolution_/ReactDropzone.d.ts +3 -3
  161. package/esm/_mixed_export_resolution_/ReactDropzone.js +3 -3
  162. package/esm/utils/HannaUIState.d.ts +3 -4
  163. package/esm/utils/config.d.ts +11 -1
  164. package/esm/utils/config.js +1 -0
  165. package/esm/utils/types.d.ts +12 -0
  166. package/esm/utils/types.js +1 -0
  167. package/esm/utils/useGetSVGtext.d.ts +1 -1
  168. package/esm/utils/useGetSVGtext.js +2 -2
  169. package/esm/utils/useMenuToggling.d.ts +2 -0
  170. package/esm/utils/useMenuToggling.js +31 -21
  171. package/esm/utils.d.ts +2 -1
  172. package/esm/utils.js +2 -1
  173. package/package.json +5 -4
  174. package/utils/HannaUIState.d.ts +3 -4
  175. package/utils/config.d.ts +11 -1
  176. package/utils/config.js +1 -0
  177. package/utils/types.d.ts +12 -0
  178. package/utils/types.js +2 -0
  179. package/utils/useGetSVGtext.d.ts +1 -1
  180. package/utils/useGetSVGtext.js +2 -2
  181. package/utils/useMenuToggling.d.ts +2 -0
  182. package/utils/useMenuToggling.js +31 -21
  183. package/utils.d.ts +2 -1
  184. package/utils.js +5 -1
@@ -1,7 +1,7 @@
1
1
  import { __rest } from "tslib";
2
2
  import React from 'react';
3
+ import { modifiedClass } from '@hugsmidjan/qj/classUtils';
3
4
  import { useDomid } from '@hugsmidjan/react/hooks';
4
- import getBemClass from '@hugsmidjan/react/utils/getBemClass';
5
5
  export const TogglerInput = (props) => {
6
6
  const { bem, modifier, className, label, invalid, errorMessage, Wrapper = 'div', required, reqText, type, id, innerWrap, wrapperProps, inputProps } = props, restInputProps = __rest(props, ["bem", "modifier", "className", "label", "invalid", "errorMessage", "Wrapper", "required", "reqText", "type", "id", "innerWrap", "wrapperProps", "inputProps"]);
7
7
  const domid = useDomid(id);
@@ -16,7 +16,7 @@ export const TogglerInput = (props) => {
16
16
  " ",
17
17
  label,
18
18
  ' '));
19
- return (React.createElement(Wrapper, Object.assign({}, wrapperProps, { className: getBemClass(bem, modifier, className) }),
19
+ return (React.createElement(Wrapper, Object.assign({}, wrapperProps, { className: modifiedClass(bem, modifier, className) }),
20
20
  React.createElement("input", Object.assign({ className: bem + '__input', type: type, id: domid, "aria-invalid": invalid || !!errorMessage || undefined, "aria-describedby": errorId }, restInputProps, inputProps, (readOnly && { disabled: true }))),
21
21
  ' ',
22
22
  React.createElement("label", { className: bem + '__label', htmlFor: domid },
@@ -1,3 +1,3 @@
1
- import * as reactDropzonePkg from 'react-dropzone';
2
- export declare const ReactDropzone: typeof reactDropzonePkg.default;
3
- export declare const useDropzone: typeof reactDropzonePkg.useDropzone;
1
+ import * as _pkg from 'react-dropzone';
2
+ export declare const ReactDropzone: typeof _pkg.default;
3
+ export declare const useDropzone: typeof _pkg.useDropzone;
@@ -1,10 +1,10 @@
1
1
  // See <file://./_WAT.md> for info on why this file exists
2
- import * as reactDropzonePkg from 'react-dropzone';
3
- const _default = reactDropzonePkg.default;
2
+ import * as _pkg from 'react-dropzone';
4
3
  // This defensive code is required to get around the fact that react-dropzone
5
4
  // mixes default and named exports.
6
5
  // Depending whether this module is run as ESM or CJS, then `_default` may be
7
6
  // either the actual default export or an object with a default property.
8
7
  // Rejoice in the woeful borderlands of modern ESM and legacy CJS interop.
9
- export const ReactDropzone = 'default' in _default ? _default.default : _default;
8
+ const reactDropzonePkg = 'default' in _pkg.default ? _pkg.default : _pkg;
9
+ export const ReactDropzone = reactDropzonePkg.default;
10
10
  export const useDropzone = reactDropzonePkg.useDropzone;
@@ -1,8 +1,7 @@
1
1
  /// <reference types="react" />
2
- type HannaUIStateProps = {
2
+ export type HannaUIStateState = {
3
3
  closeHamburgerMenu: () => void;
4
4
  isHamburgerMenuOpen: boolean | undefined;
5
5
  };
6
- export declare const HannaUIState: import("react").Provider<HannaUIStateProps>;
7
- export declare const useHannaUIState: () => HannaUIStateProps;
8
- export {};
6
+ export declare const HannaUIState: import("react").Provider<HannaUIStateState>;
7
+ export declare const useHannaUIState: () => HannaUIStateState;
@@ -1,4 +1,14 @@
1
+ import { SSRSupport } from '@hugsmidjan/react/hooks';
1
2
  export type { LinkRenderer } from '../_abstract/_Link.js';
2
3
  export { setLinkRenderer } from '../_abstract/_Link.js';
3
- export type { SSRSupport } from '@hugsmidjan/react/hooks';
4
4
  export { setDefaultSSR } from '@hugsmidjan/react/hooks';
5
+ export type SSRSupportProps = {
6
+ /**
7
+ * Indicates whether server-side rendering is supported or not.
8
+ *
9
+ * The `ssr-only` value is useful for cases where you need
10
+ * to demo the server-rendered version in a browser.
11
+ */
12
+ ssr?: SSRSupport;
13
+ };
14
+ export type { SSRSupport };
@@ -1,2 +1,3 @@
1
1
  export { setLinkRenderer } from '../_abstract/_Link.js';
2
+ // ---------------------------------------------------------------------------
2
3
  export { setDefaultSSR } from '@hugsmidjan/react/hooks';
@@ -0,0 +1,12 @@
1
+ import { Modifiers } from '@hugsmidjan/qj/classUtils';
2
+ export type BemModifierProps = {
3
+ /** List of CSS BEM --modifier's to add to the component's main wrapper.
4
+ *
5
+ * All falsy values are neatly skipped.
6
+ */
7
+ modifier?: Modifiers;
8
+ };
9
+ export type BemProps = {
10
+ /** CSS BEM class-name prefix to be used for this component. Defaults to the same as the original component's displayName */
11
+ bem?: string;
12
+ } & BemModifierProps;
@@ -0,0 +1 @@
1
+ export {};
@@ -6,5 +6,5 @@ type SVGMeta = {
6
6
  * Fetches a remote SVG image and returns its XML/source
7
7
  * string for inlining, or further processing
8
8
  */
9
- export declare const useGetSVGtext: (imageSrc: string | undefined) => SVGMeta | undefined;
9
+ export declare const useGetSVGtext: (imageSrc: string | undefined, altText?: string) => SVGMeta | undefined;
10
10
  export {};
@@ -4,12 +4,12 @@ import { getSVGtext } from '@reykjavik/hanna-utils';
4
4
  * Fetches a remote SVG image and returns its XML/source
5
5
  * string for inlining, or further processing
6
6
  */
7
- export const useGetSVGtext = (imageSrc) => {
7
+ export const useGetSVGtext = (imageSrc, altText) => {
8
8
  const [inlineSvg, setInlineSvg] = useState();
9
9
  const srcRef = useRef(imageSrc);
10
10
  useEffect(() => {
11
11
  if (imageSrc) {
12
- getSVGtext(imageSrc).then((code) => {
12
+ getSVGtext(imageSrc, altText).then((code) => {
13
13
  if (imageSrc === srcRef.current) {
14
14
  setInlineSvg({ imageSrc, code });
15
15
  }
@@ -1,8 +1,10 @@
1
+ import { HannaUIStateState } from './HannaUIState.js';
1
2
  type MenuTogglingState = {
2
3
  isMenuActive: true | undefined;
3
4
  isMenuOpen: boolean;
4
5
  toggleMenu: () => void;
5
6
  closeMenu: () => void;
7
+ uiState: HannaUIStateState;
6
8
  };
7
9
  export declare const useMenuToggling: (doInitialize?: boolean) => MenuTogglingState;
8
10
  export {};
@@ -7,14 +7,33 @@ const htmlClass = (className, add) => {
7
7
  const noop = () => undefined;
8
8
  // ---------------------------------------------------------------------------
9
9
  export const useMenuToggling = (doInitialize = true) => {
10
- const [isMenuOpen, setIsMenuOpen] = useState(false);
11
- const [isMenuActive, setIsMenuActive] = useState();
12
- const _state = { isMenuOpen, isMenuActive };
13
- const stateRef = useRef(_state);
14
- stateRef.current = _state;
10
+ const stateRef = useRef({
11
+ isMenuOpen: false,
12
+ isMenuActive: undefined,
13
+ toggleMenu: doInitialize
14
+ ? () => {
15
+ if (stateRef.current.isMenuActive) {
16
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
17
+ stateRef.current.isMenuOpen ? _closeMenu() : _openMenu();
18
+ }
19
+ }
20
+ : noop,
21
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
22
+ closeMenu: () => doInitialize && _closeMenu(),
23
+ });
24
+ const [{ isMenuOpen, isMenuActive, uiState }, setMenuState] = useState({
25
+ isMenuOpen: false,
26
+ isMenuActive: undefined,
27
+ uiState: {
28
+ closeHamburgerMenu: () => stateRef.current.closeMenu(),
29
+ isHamburgerMenuOpen: false,
30
+ },
31
+ });
32
+ stateRef.current.isMenuOpen = isMenuOpen;
33
+ stateRef.current.isMenuActive = isMenuActive;
15
34
  const _openMenu = () => {
16
35
  if (!stateRef.current.isMenuOpen) {
17
- setIsMenuOpen(true);
36
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuOpen: true, uiState: Object.assign(Object.assign({}, state.uiState), { isHamburgerMenuOpen: true }) })));
18
37
  htmlClass('menu-is-open', true);
19
38
  htmlClass('menu-is-closed', false);
20
39
  focusElement('#pagenav');
@@ -22,7 +41,7 @@ export const useMenuToggling = (doInitialize = true) => {
22
41
  };
23
42
  const _closeMenu = () => {
24
43
  if (stateRef.current.isMenuOpen) {
25
- setIsMenuOpen(false);
44
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuOpen: false, uiState: Object.assign(Object.assign({}, state.uiState), { isHamburgerMenuOpen: false }) })));
26
45
  htmlClass('menu-is-closed', true);
27
46
  htmlClass('menu-is-open', false);
28
47
  focusElement('.Layout__header__skiplink');
@@ -31,32 +50,23 @@ export const useMenuToggling = (doInitialize = true) => {
31
50
  useFormatMonitor(doInitialize
32
51
  ? (media) => {
33
52
  if (media.becameHamburger) {
34
- setIsMenuActive(true);
53
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuActive: true })));
35
54
  htmlClass('menu-is-active', true);
36
55
  htmlClass('menu-is-closed', true);
37
56
  }
38
57
  if (media.leftHamburger) {
39
58
  _closeMenu();
40
- setIsMenuActive(undefined);
59
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuActive: undefined })));
41
60
  htmlClass('menu-is-active', false);
42
61
  htmlClass('menu-is-closed', false);
43
62
  }
44
63
  }
45
64
  : noop);
46
- const { toggleMenu, closeMenu } = useRef(doInitialize
47
- ? {
48
- toggleMenu: () => {
49
- if (stateRef.current.isMenuActive) {
50
- stateRef.current.isMenuOpen ? _closeMenu() : _openMenu();
51
- }
52
- },
53
- closeMenu: _closeMenu,
54
- }
55
- : { toggleMenu: noop, closeMenu: noop }).current;
56
65
  return {
57
66
  isMenuActive,
58
67
  isMenuOpen,
59
- toggleMenu,
60
- closeMenu,
68
+ toggleMenu: stateRef.current.toggleMenu,
69
+ closeMenu: stateRef.current.closeMenu,
70
+ uiState,
61
71
  };
62
72
  };
package/esm/utils.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export * from './utils/browserSide.js';
2
2
  export * from './utils/config.js';
3
- export * from './utils/HannaUIState.js';
3
+ export { HannaUIState, useHannaUIState } from './utils/HannaUIState.js';
4
4
  export * from './utils/useDidChange.js';
5
5
  export * from './utils/useFormatMonitor.js';
6
6
  export * from './utils/useGetSVGtext.js';
7
+ export * from './utils/useMenuToggling.js';
7
8
  export * from './utils/useMixedControlState.js';
8
9
  export * from './utils/useScrollbarWidthCSSVar.js';
9
10
  /**
package/esm/utils.js CHANGED
@@ -1,8 +1,9 @@
1
1
  export * from './utils/browserSide.js';
2
2
  export * from './utils/config.js';
3
- export * from './utils/HannaUIState.js';
3
+ export { HannaUIState, useHannaUIState } from './utils/HannaUIState.js';
4
4
  export * from './utils/useDidChange.js';
5
5
  export * from './utils/useFormatMonitor.js';
6
6
  export * from './utils/useGetSVGtext.js';
7
+ export * from './utils/useMenuToggling.js';
7
8
  export * from './utils/useMixedControlState.js';
8
9
  export * from './utils/useScrollbarWidthCSSVar.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.93",
3
+ "version": "0.10.95",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",
@@ -14,10 +14,10 @@
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
16
  "@floating-ui/react": "^0.19.2",
17
- "@hugsmidjan/qj": "^4.20.0",
17
+ "@hugsmidjan/qj": "^4.21.0",
18
18
  "@hugsmidjan/react": "^0.4.32",
19
19
  "@reykjavik/hanna-css": "^0.4.3",
20
- "@reykjavik/hanna-utils": "^0.2.7",
20
+ "@reykjavik/hanna-utils": "^0.2.8",
21
21
  "@types/react": "^17.0.24",
22
22
  "@types/react-autosuggest": "^10.1.0",
23
23
  "@types/react-datepicker": "^4.8.0",
@@ -28,7 +28,8 @@
28
28
  "react-datepicker": "4.11.0",
29
29
  "react-dropzone": "^10.2.2",
30
30
  "react-intersection-observer": "^8.30.1",
31
- "react-transition-group": "^4.4.1"
31
+ "react-transition-group": "^4.4.1",
32
+ "tslib": "^2.4.0"
32
33
  },
33
34
  "engines": {
34
35
  "node": ">=16"
@@ -1,8 +1,7 @@
1
1
  /// <reference types="react" />
2
- type HannaUIStateProps = {
2
+ export type HannaUIStateState = {
3
3
  closeHamburgerMenu: () => void;
4
4
  isHamburgerMenuOpen: boolean | undefined;
5
5
  };
6
- export declare const HannaUIState: import("react").Provider<HannaUIStateProps>;
7
- export declare const useHannaUIState: () => HannaUIStateProps;
8
- export {};
6
+ export declare const HannaUIState: import("react").Provider<HannaUIStateState>;
7
+ export declare const useHannaUIState: () => HannaUIStateState;
package/utils/config.d.ts CHANGED
@@ -1,4 +1,14 @@
1
+ import { SSRSupport } from '@hugsmidjan/react/hooks';
1
2
  export type { LinkRenderer } from '../_abstract/_Link.js';
2
3
  export { setLinkRenderer } from '../_abstract/_Link.js';
3
- export type { SSRSupport } from '@hugsmidjan/react/hooks';
4
4
  export { setDefaultSSR } from '@hugsmidjan/react/hooks';
5
+ export type SSRSupportProps = {
6
+ /**
7
+ * Indicates whether server-side rendering is supported or not.
8
+ *
9
+ * The `ssr-only` value is useful for cases where you need
10
+ * to demo the server-rendered version in a browser.
11
+ */
12
+ ssr?: SSRSupport;
13
+ };
14
+ export type { SSRSupport };
package/utils/config.js CHANGED
@@ -3,5 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setDefaultSSR = exports.setLinkRenderer = void 0;
4
4
  var _Link_js_1 = require("../_abstract/_Link.js");
5
5
  Object.defineProperty(exports, "setLinkRenderer", { enumerable: true, get: function () { return _Link_js_1.setLinkRenderer; } });
6
+ // ---------------------------------------------------------------------------
6
7
  var hooks_1 = require("@hugsmidjan/react/hooks");
7
8
  Object.defineProperty(exports, "setDefaultSSR", { enumerable: true, get: function () { return hooks_1.setDefaultSSR; } });
@@ -0,0 +1,12 @@
1
+ import { Modifiers } from '@hugsmidjan/qj/classUtils';
2
+ export type BemModifierProps = {
3
+ /** List of CSS BEM --modifier's to add to the component's main wrapper.
4
+ *
5
+ * All falsy values are neatly skipped.
6
+ */
7
+ modifier?: Modifiers;
8
+ };
9
+ export type BemProps = {
10
+ /** CSS BEM class-name prefix to be used for this component. Defaults to the same as the original component's displayName */
11
+ bem?: string;
12
+ } & BemModifierProps;
package/utils/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -6,5 +6,5 @@ type SVGMeta = {
6
6
  * Fetches a remote SVG image and returns its XML/source
7
7
  * string for inlining, or further processing
8
8
  */
9
- export declare const useGetSVGtext: (imageSrc: string | undefined) => SVGMeta | undefined;
9
+ export declare const useGetSVGtext: (imageSrc: string | undefined, altText?: string) => SVGMeta | undefined;
10
10
  export {};
@@ -7,12 +7,12 @@ const hanna_utils_1 = require("@reykjavik/hanna-utils");
7
7
  * Fetches a remote SVG image and returns its XML/source
8
8
  * string for inlining, or further processing
9
9
  */
10
- const useGetSVGtext = (imageSrc) => {
10
+ const useGetSVGtext = (imageSrc, altText) => {
11
11
  const [inlineSvg, setInlineSvg] = (0, react_1.useState)();
12
12
  const srcRef = (0, react_1.useRef)(imageSrc);
13
13
  (0, react_1.useEffect)(() => {
14
14
  if (imageSrc) {
15
- (0, hanna_utils_1.getSVGtext)(imageSrc).then((code) => {
15
+ (0, hanna_utils_1.getSVGtext)(imageSrc, altText).then((code) => {
16
16
  if (imageSrc === srcRef.current) {
17
17
  setInlineSvg({ imageSrc, code });
18
18
  }
@@ -1,8 +1,10 @@
1
+ import { HannaUIStateState } from './HannaUIState.js';
1
2
  type MenuTogglingState = {
2
3
  isMenuActive: true | undefined;
3
4
  isMenuOpen: boolean;
4
5
  toggleMenu: () => void;
5
6
  closeMenu: () => void;
7
+ uiState: HannaUIStateState;
6
8
  };
7
9
  export declare const useMenuToggling: (doInitialize?: boolean) => MenuTogglingState;
8
10
  export {};
@@ -10,14 +10,33 @@ const htmlClass = (className, add) => {
10
10
  const noop = () => undefined;
11
11
  // ---------------------------------------------------------------------------
12
12
  const useMenuToggling = (doInitialize = true) => {
13
- const [isMenuOpen, setIsMenuOpen] = (0, react_1.useState)(false);
14
- const [isMenuActive, setIsMenuActive] = (0, react_1.useState)();
15
- const _state = { isMenuOpen, isMenuActive };
16
- const stateRef = (0, react_1.useRef)(_state);
17
- stateRef.current = _state;
13
+ const stateRef = (0, react_1.useRef)({
14
+ isMenuOpen: false,
15
+ isMenuActive: undefined,
16
+ toggleMenu: doInitialize
17
+ ? () => {
18
+ if (stateRef.current.isMenuActive) {
19
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
20
+ stateRef.current.isMenuOpen ? _closeMenu() : _openMenu();
21
+ }
22
+ }
23
+ : noop,
24
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
25
+ closeMenu: () => doInitialize && _closeMenu(),
26
+ });
27
+ const [{ isMenuOpen, isMenuActive, uiState }, setMenuState] = (0, react_1.useState)({
28
+ isMenuOpen: false,
29
+ isMenuActive: undefined,
30
+ uiState: {
31
+ closeHamburgerMenu: () => stateRef.current.closeMenu(),
32
+ isHamburgerMenuOpen: false,
33
+ },
34
+ });
35
+ stateRef.current.isMenuOpen = isMenuOpen;
36
+ stateRef.current.isMenuActive = isMenuActive;
18
37
  const _openMenu = () => {
19
38
  if (!stateRef.current.isMenuOpen) {
20
- setIsMenuOpen(true);
39
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuOpen: true, uiState: Object.assign(Object.assign({}, state.uiState), { isHamburgerMenuOpen: true }) })));
21
40
  htmlClass('menu-is-open', true);
22
41
  htmlClass('menu-is-closed', false);
23
42
  (0, hanna_utils_1.focusElement)('#pagenav');
@@ -25,7 +44,7 @@ const useMenuToggling = (doInitialize = true) => {
25
44
  };
26
45
  const _closeMenu = () => {
27
46
  if (stateRef.current.isMenuOpen) {
28
- setIsMenuOpen(false);
47
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuOpen: false, uiState: Object.assign(Object.assign({}, state.uiState), { isHamburgerMenuOpen: false }) })));
29
48
  htmlClass('menu-is-closed', true);
30
49
  htmlClass('menu-is-open', false);
31
50
  (0, hanna_utils_1.focusElement)('.Layout__header__skiplink');
@@ -34,33 +53,24 @@ const useMenuToggling = (doInitialize = true) => {
34
53
  (0, useFormatMonitor_js_1.useFormatMonitor)(doInitialize
35
54
  ? (media) => {
36
55
  if (media.becameHamburger) {
37
- setIsMenuActive(true);
56
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuActive: true })));
38
57
  htmlClass('menu-is-active', true);
39
58
  htmlClass('menu-is-closed', true);
40
59
  }
41
60
  if (media.leftHamburger) {
42
61
  _closeMenu();
43
- setIsMenuActive(undefined);
62
+ setMenuState((state) => (Object.assign(Object.assign({}, state), { isMenuActive: undefined })));
44
63
  htmlClass('menu-is-active', false);
45
64
  htmlClass('menu-is-closed', false);
46
65
  }
47
66
  }
48
67
  : noop);
49
- const { toggleMenu, closeMenu } = (0, react_1.useRef)(doInitialize
50
- ? {
51
- toggleMenu: () => {
52
- if (stateRef.current.isMenuActive) {
53
- stateRef.current.isMenuOpen ? _closeMenu() : _openMenu();
54
- }
55
- },
56
- closeMenu: _closeMenu,
57
- }
58
- : { toggleMenu: noop, closeMenu: noop }).current;
59
68
  return {
60
69
  isMenuActive,
61
70
  isMenuOpen,
62
- toggleMenu,
63
- closeMenu,
71
+ toggleMenu: stateRef.current.toggleMenu,
72
+ closeMenu: stateRef.current.closeMenu,
73
+ uiState,
64
74
  };
65
75
  };
66
76
  exports.useMenuToggling = useMenuToggling;
package/utils.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export * from './utils/browserSide.js';
2
2
  export * from './utils/config.js';
3
- export * from './utils/HannaUIState.js';
3
+ export { HannaUIState, useHannaUIState } from './utils/HannaUIState.js';
4
4
  export * from './utils/useDidChange.js';
5
5
  export * from './utils/useFormatMonitor.js';
6
6
  export * from './utils/useGetSVGtext.js';
7
+ export * from './utils/useMenuToggling.js';
7
8
  export * from './utils/useMixedControlState.js';
8
9
  export * from './utils/useScrollbarWidthCSSVar.js';
9
10
  /**
package/utils.js CHANGED
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useHannaUIState = exports.HannaUIState = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./utils/browserSide.js"), exports);
5
6
  tslib_1.__exportStar(require("./utils/config.js"), exports);
6
- tslib_1.__exportStar(require("./utils/HannaUIState.js"), exports);
7
+ var HannaUIState_js_1 = require("./utils/HannaUIState.js");
8
+ Object.defineProperty(exports, "HannaUIState", { enumerable: true, get: function () { return HannaUIState_js_1.HannaUIState; } });
9
+ Object.defineProperty(exports, "useHannaUIState", { enumerable: true, get: function () { return HannaUIState_js_1.useHannaUIState; } });
7
10
  tslib_1.__exportStar(require("./utils/useDidChange.js"), exports);
8
11
  tslib_1.__exportStar(require("./utils/useFormatMonitor.js"), exports);
9
12
  tslib_1.__exportStar(require("./utils/useGetSVGtext.js"), exports);
13
+ tslib_1.__exportStar(require("./utils/useMenuToggling.js"), exports);
10
14
  tslib_1.__exportStar(require("./utils/useMixedControlState.js"), exports);
11
15
  tslib_1.__exportStar(require("./utils/useScrollbarWidthCSSVar.js"), exports);