@reykjavik/hanna-react 0.10.131 → 0.10.133

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,13 +4,19 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
- ## 0.10.131
7
+ ## 0.10.133
8
8
 
9
- _2024-07-23_
9
+ _2024-08-08_
10
+
11
+ - feat: `MainMenu`: Pass `closeMenu` function prop to custom item callbacks
12
+
13
+ ## 0.10.132
14
+
15
+ _2024-07-29_
10
16
 
11
- - fix: Typo selector used by `FocusTrap` to find a fallback target
17
+ - fix: `Modal`'s `open` prop not defaulting to `true`
12
18
 
13
- ## 0.10.130
19
+ ## 0.10.130 – 0.10.131
14
20
 
15
21
  _2024-07-23_
16
22
 
@@ -161,7 +167,7 @@ _2023-12-08_
161
167
 
162
168
  _2023-11-17_
163
169
 
164
- - fix: `Modal` not reoppening when `open` prop is toggled
170
+ - fix: `Modal` not reopening when `open` prop is toggled
165
171
 
166
172
  ## 0.10.110 – 0.10.111
167
173
 
package/MainMenu.d.ts CHANGED
@@ -75,7 +75,9 @@ export type MainMenuItem = {
75
75
  * point in the menu item list.
76
76
  */
77
77
  export type MainMenuSeparator = '---';
78
- export type MainMenuItemList = Array<MainMenuItem | MainMenuSeparator | (() => ReactElement)>;
78
+ export type MainMenuItemList = Array<MainMenuItem | MainMenuSeparator | ((props: {
79
+ closeMenu: () => void;
80
+ }) => ReactElement)>;
79
81
  export type MainMenuProps = {
80
82
  /**
81
83
  * Top-level screen-reader headline/label for the whole menu.
package/MainMenu.js CHANGED
@@ -199,7 +199,7 @@ const _MainMenu = (props) => {
199
199
  if (!('label' in item)) {
200
200
  const Item = item;
201
201
  return (react_1.default.createElement("li", { key: i, className: "MainMenu__item" },
202
- react_1.default.createElement(Item, null)));
202
+ react_1.default.createElement(Item, { closeMenu: closeHamburgerMenu })));
203
203
  }
204
204
  const { label, labelLong, lang, controlsId, onClick } = item;
205
205
  const pressed = (activePanel && controlsId === activePanel.id) || undefined;
@@ -16,15 +16,18 @@ export type AbstractModalProps = {
16
16
  */
17
17
  closeDelay?: number;
18
18
  /**
19
- * Indicates if teh Modal should be open or closed. To trigger opening or closing, simply flip this flag.
19
+ * Indicates if the Modal should be open or closed. To trigger opening or
20
+ * closing, simply flip this flag.
20
21
  *
21
22
  * Default: `true`
22
23
  */
23
24
  open?: boolean;
24
25
  /**
25
- * Set this to `true` for Modals that should render as if they always existed and had already been opened.
26
+ * Set this to `true` for Modals that should render as if they always
27
+ * existed and had already been opened.
26
28
  *
27
- * A Modal that "starts open" will not CSS transition in, and will not trigger its `onOpen` callback on mount.
29
+ * A Modal that "starts open" will not CSS transition in, and will not
30
+ * trigger its `onOpen` callback on mount.
28
31
  *
29
32
  * Default: `false`
30
33
  */
@@ -46,7 +49,8 @@ export type AbstractModalProps = {
46
49
  */
47
50
  fickle?: boolean;
48
51
  /**
49
- * Convenience callback that runs as soon as the `open` flag flips to `true` – including on initial opening.
52
+ * Convenience callback that runs as soon as the `open` flag flips to `true`
53
+ * – including on initial opening.
50
54
  *
51
55
  * However, the initial `onOpen` is skipped when `startOpen` is set to `true`.
52
56
  */
@@ -52,11 +52,12 @@ const AbstractModal = (props) => {
52
52
  // eslint-disable-next-line deprecation/deprecation
53
53
  const isFickle = !((_a = props.stable) !== null && _a !== void 0 ? _a : props.fickle === false) || undefined;
54
54
  const txt = (0, i18n_1.getTexts)(props, exports.defaultAbstractModalTexts);
55
+ const openProp = props.open !== false; // defaults to `true`
55
56
  const isBrowser = (0, utils_js_1.useIsBrowserSide)(ssr);
56
57
  const privateDomId = (0, utils_js_1.useDomid)();
57
58
  const domid = wrapperProps.id || privateDomId;
58
59
  const modalElmRef = (0, react_1.useRef)(null);
59
- const [open, setOpen] = (0, react_1.useState)(() => !!props.startOpen && props.open !== false);
60
+ const [open, setOpen] = (0, react_1.useState)(() => !!props.startOpen && openProp);
60
61
  const openModal = () => {
61
62
  if (!open) {
62
63
  addToModalStack(privateDomId);
@@ -77,14 +78,14 @@ const AbstractModal = (props) => {
77
78
  };
78
79
  // ---
79
80
  // Update open state when props.open changes. Icky but simple.
80
- const lastPropsOpen = (0, react_1.useRef)(props.open);
81
- if (props.open !== lastPropsOpen.current && props.open !== open) {
82
- lastPropsOpen.current = props.open;
81
+ const lastPropsOpen = (0, react_1.useRef)(openProp);
82
+ if (openProp !== lastPropsOpen.current && openProp !== open) {
83
+ lastPropsOpen.current = openProp;
83
84
  // these update state during render, which aborts the current render
84
85
  // and triggers an immediate rerender.
85
- props.open ? openModal() : closeModal();
86
+ openProp ? openModal() : closeModal();
86
87
  }
87
- lastPropsOpen.current = props.open;
88
+ lastPropsOpen.current = openProp;
88
89
  // ---
89
90
  const closeOnCurtainClick = isFickle &&
90
91
  ((e) => {
@@ -104,7 +105,7 @@ const AbstractModal = (props) => {
104
105
  // The modal did `startOpen` so we need to add it to the "modal-stack".
105
106
  addToModalStack(privateDomId);
106
107
  }
107
- else if (props.open) {
108
+ else if (openProp) {
108
109
  // The modal should transition to open.
109
110
  openModal();
110
111
  }
package/esm/MainMenu.d.ts CHANGED
@@ -75,7 +75,9 @@ export type MainMenuItem = {
75
75
  * point in the menu item list.
76
76
  */
77
77
  export type MainMenuSeparator = '---';
78
- export type MainMenuItemList = Array<MainMenuItem | MainMenuSeparator | (() => ReactElement)>;
78
+ export type MainMenuItemList = Array<MainMenuItem | MainMenuSeparator | ((props: {
79
+ closeMenu: () => void;
80
+ }) => ReactElement)>;
79
81
  export type MainMenuProps = {
80
82
  /**
81
83
  * Top-level screen-reader headline/label for the whole menu.
package/esm/MainMenu.js CHANGED
@@ -195,7 +195,7 @@ export const _MainMenu = (props) => {
195
195
  if (!('label' in item)) {
196
196
  const Item = item;
197
197
  return (React.createElement("li", { key: i, className: "MainMenu__item" },
198
- React.createElement(Item, null)));
198
+ React.createElement(Item, { closeMenu: closeHamburgerMenu })));
199
199
  }
200
200
  const { label, labelLong, lang, controlsId, onClick } = item;
201
201
  const pressed = (activePanel && controlsId === activePanel.id) || undefined;
@@ -16,15 +16,18 @@ export type AbstractModalProps = {
16
16
  */
17
17
  closeDelay?: number;
18
18
  /**
19
- * Indicates if teh Modal should be open or closed. To trigger opening or closing, simply flip this flag.
19
+ * Indicates if the Modal should be open or closed. To trigger opening or
20
+ * closing, simply flip this flag.
20
21
  *
21
22
  * Default: `true`
22
23
  */
23
24
  open?: boolean;
24
25
  /**
25
- * Set this to `true` for Modals that should render as if they always existed and had already been opened.
26
+ * Set this to `true` for Modals that should render as if they always
27
+ * existed and had already been opened.
26
28
  *
27
- * A Modal that "starts open" will not CSS transition in, and will not trigger its `onOpen` callback on mount.
29
+ * A Modal that "starts open" will not CSS transition in, and will not
30
+ * trigger its `onOpen` callback on mount.
28
31
  *
29
32
  * Default: `false`
30
33
  */
@@ -46,7 +49,8 @@ export type AbstractModalProps = {
46
49
  */
47
50
  fickle?: boolean;
48
51
  /**
49
- * Convenience callback that runs as soon as the `open` flag flips to `true` – including on initial opening.
52
+ * Convenience callback that runs as soon as the `open` flag flips to `true`
53
+ * – including on initial opening.
50
54
  *
51
55
  * However, the initial `onOpen` is skipped when `startOpen` is set to `true`.
52
56
  */
@@ -48,11 +48,12 @@ export const AbstractModal = (props) => {
48
48
  // eslint-disable-next-line deprecation/deprecation
49
49
  const isFickle = !((_a = props.stable) !== null && _a !== void 0 ? _a : props.fickle === false) || undefined;
50
50
  const txt = getTexts(props, defaultAbstractModalTexts);
51
+ const openProp = props.open !== false; // defaults to `true`
51
52
  const isBrowser = useIsBrowserSide(ssr);
52
53
  const privateDomId = useDomid();
53
54
  const domid = wrapperProps.id || privateDomId;
54
55
  const modalElmRef = useRef(null);
55
- const [open, setOpen] = useState(() => !!props.startOpen && props.open !== false);
56
+ const [open, setOpen] = useState(() => !!props.startOpen && openProp);
56
57
  const openModal = () => {
57
58
  if (!open) {
58
59
  addToModalStack(privateDomId);
@@ -73,14 +74,14 @@ export const AbstractModal = (props) => {
73
74
  };
74
75
  // ---
75
76
  // Update open state when props.open changes. Icky but simple.
76
- const lastPropsOpen = useRef(props.open);
77
- if (props.open !== lastPropsOpen.current && props.open !== open) {
78
- lastPropsOpen.current = props.open;
77
+ const lastPropsOpen = useRef(openProp);
78
+ if (openProp !== lastPropsOpen.current && openProp !== open) {
79
+ lastPropsOpen.current = openProp;
79
80
  // these update state during render, which aborts the current render
80
81
  // and triggers an immediate rerender.
81
- props.open ? openModal() : closeModal();
82
+ openProp ? openModal() : closeModal();
82
83
  }
83
- lastPropsOpen.current = props.open;
84
+ lastPropsOpen.current = openProp;
84
85
  // ---
85
86
  const closeOnCurtainClick = isFickle &&
86
87
  ((e) => {
@@ -100,7 +101,7 @@ export const AbstractModal = (props) => {
100
101
  // The modal did `startOpen` so we need to add it to the "modal-stack".
101
102
  addToModalStack(privateDomId);
102
103
  }
103
- else if (props.open) {
104
+ else if (openProp) {
104
105
  // The modal should transition to open.
105
106
  openModal();
106
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.131",
3
+ "version": "0.10.133",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",