@homebound/beam 2.98.2 → 2.99.0

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.
@@ -1,4 +1,4 @@
1
- import { ReactNode } from "react";
1
+ import { MutableRefObject, ReactNode } from "react";
2
2
  import { Only, Xss } from "../../Css";
3
3
  import { Callback } from "../../types";
4
4
  export declare type ModalSize = "sm" | "md" | "lg" | "xl";
@@ -19,7 +19,12 @@ export interface ModalProps {
19
19
  forceScrolling?: boolean;
20
20
  /** Adds a callback that is called _after_ close has definitely happened. */
21
21
  onClose?: Callback;
22
+ /** Imperative API for interacting with the Modal */
23
+ api?: MutableRefObject<ModalApi | undefined>;
22
24
  }
25
+ export declare type ModalApi = {
26
+ setSize: (size: ModalProps["size"]) => void;
27
+ };
23
28
  /**
24
29
  * Internal component for displaying a Modal; see `useModal` for the public API.
25
30
  *
@@ -20,7 +20,7 @@ const utils_1 = require("../../utils");
20
20
  * Provides underlay, modal container, and header. Will disable scrolling of page under the modal.
21
21
  */
22
22
  function Modal(props) {
23
- const { size = "md", content, forceScrolling } = props;
23
+ const { size = "md", content, forceScrolling, api } = props;
24
24
  const isFixedHeight = typeof size !== "string";
25
25
  const ref = (0, react_1.useRef)(null);
26
26
  const { modalBodyDiv, modalFooterDiv, modalHeaderDiv, drawerContentStack } = (0, BeamContext_1.useBeamContext)();
@@ -37,13 +37,16 @@ function Modal(props) {
37
37
  }, ref);
38
38
  const { modalProps } = (0, react_aria_1.useModal)();
39
39
  const { dialogProps, titleProps } = (0, react_aria_1.useDialog)({ role: "dialog" }, ref);
40
- const [width, height] = getSize(size);
40
+ const [[width, height], setSize] = (0, react_1.useState)(getSize(size));
41
41
  const contentRef = (0, react_1.useRef)(null);
42
42
  const modalBodyRef = (0, react_1.useRef)(null);
43
43
  const modalFooterRef = (0, react_1.useRef)(null);
44
44
  const modalHeaderRef = (0, react_1.useRef)(null);
45
45
  const testId = (0, utils_1.useTestIds)({}, testIdPrefix);
46
46
  (0, react_aria_1.usePreventScroll)();
47
+ if (api) {
48
+ api.current = { setSize: (size = "md") => setSize(getSize(size)) };
49
+ }
47
50
  const [hasScroll, setHasScroll] = (0, react_1.useState)(forceScrolling !== null && forceScrolling !== void 0 ? forceScrolling : false);
48
51
  (0, resize_observer_1.default)(contentRef, ({ target }) => {
49
52
  if (forceScrolling === undefined && !isFixedHeight) {
@@ -4,5 +4,6 @@ export interface UseModalHook {
4
4
  openModal: (props: ModalProps) => void;
5
5
  closeModal: Callback;
6
6
  addCanClose: (canClose: CheckFn) => void;
7
+ setSize: (size: ModalProps["size"]) => void;
7
8
  }
8
9
  export declare function useModal(): UseModalHook;
@@ -7,6 +7,7 @@ const utils_1 = require("../../utils");
7
7
  function useModal() {
8
8
  const { modalState, modalCanCloseChecks } = (0, BeamContext_1.useBeamContext)();
9
9
  const lastCanClose = (0, react_1.useRef)();
10
+ const api = (0, react_1.useRef)();
10
11
  (0, react_1.useEffect)(() => {
11
12
  return () => {
12
13
  modalCanCloseChecks.current = modalCanCloseChecks.current.filter((c) => c !== lastCanClose.current);
@@ -16,7 +17,7 @@ function useModal() {
16
17
  openModal(props) {
17
18
  // TODO Check already open?
18
19
  // TODO Check can leave?
19
- modalState.current = props;
20
+ modalState.current = { ...props, api };
20
21
  },
21
22
  closeModal() {
22
23
  var _a;
@@ -38,6 +39,12 @@ function useModal() {
38
39
  ];
39
40
  lastCanClose.current = canClose;
40
41
  },
42
+ setSize(size) {
43
+ var _a;
44
+ if (modalState.current && ((_a = modalState.current.api) === null || _a === void 0 ? void 0 : _a.current)) {
45
+ modalState.current.api.current.setSize(size);
46
+ }
47
+ },
41
48
  }), [modalState, modalCanCloseChecks]);
42
49
  }
43
50
  exports.useModal = useModal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.98.2",
3
+ "version": "2.99.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",