react-science 0.21.2 → 0.22.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,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.AppStateProvider = exports.useAppSettings = exports.useAppView = exports.useAppData = exports.useAppDispatch = exports.useAppState = void 0;
7
4
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- const immer_1 = __importDefault(require("immer"));
5
+ const immer_1 = require("immer");
9
6
  const react_1 = require("react");
10
7
  const index_1 = require("./data/index");
11
8
  const index_2 = require("./producers/index");
@@ -51,7 +48,7 @@ function useAppSettings() {
51
48
  return useAppState().settings;
52
49
  }
53
50
  exports.useAppSettings = useAppSettings;
54
- const appReducer = (0, immer_1.default)(index_2.appStateProducer);
51
+ const appReducer = (0, immer_1.produce)(index_2.appStateProducer);
55
52
  function AppStateProvider(props) {
56
53
  const [appState, appDispatch] = (0, react_1.useReducer)(appReducer, null, getEmptyAppState);
57
54
  return ((0, jsx_runtime_1.jsx)(appDispatchContext.Provider, { value: appDispatch, children: (0, jsx_runtime_1.jsx)(appStateContext.Provider, { value: appState, children: props.children }) }));
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.DropdownMenu = void 0;
7
4
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- const styled_1 = __importDefault(require("@emotion/styled"));
9
5
  const react_1 = require("@headlessui/react");
10
6
  const react_2 = require("react");
11
7
  const useModifiedPopper_1 = require("../hooks/useModifiedPopper");
@@ -17,23 +13,21 @@ const useContextMenuPlacement_1 = require("./useContextMenuPlacement");
17
13
  function DropdownMenu(props) {
18
14
  const { trigger, ...otherProps } = props;
19
15
  if (trigger === 'contextMenu') {
20
- return (0, jsx_runtime_1.jsx)(DropdownContextMenu, { ...otherProps });
16
+ return (0, jsx_runtime_1.jsx)(DropdownContextMenu, { ...props });
21
17
  }
22
18
  return ((0, jsx_runtime_1.jsx)(DropdownClickMenu, { ...otherProps, children: props.children }));
23
19
  }
24
20
  exports.DropdownMenu = DropdownMenu;
25
- const HandleMenuContextDiv = styled_1.default.div `
26
- display: contents;
27
- `;
28
21
  function DropdownContextMenu(props) {
29
- const { children, onSelect, ...otherProps } = props;
30
- const { isPopperElementOpen, closePopperElement, handleContextMenu, setPopperElement, styles, attributes, } = (0, useContextMenuPlacement_1.useContextMenuPlacement)(otherProps.placement || 'right-start');
22
+ const { children, onSelect, as: Wrapper = 'div', placement = 'right-start', options, ...otherProps } = props;
23
+ const { isPopperElementOpen, closePopperElement, handleContextMenu, setPopperElement, styles, attributes, } = (0, useContextMenuPlacement_1.useContextMenuPlacement)(placement);
31
24
  const ref = (0, react_2.useRef)(null);
32
25
  (0, useOnClickOutside_1.useOnClickOutside)(ref, closePopperElement);
33
- return ((0, jsx_runtime_1.jsxs)(HandleMenuContextDiv, { onContextMenu: handleContextMenu, children: [isPopperElementOpen && ((0, jsx_runtime_1.jsx)(Portal_1.Portal, { children: (0, jsx_runtime_1.jsx)("div", { ref: ref, children: (0, jsx_runtime_1.jsx)("div", { ref: setPopperElement, style: styles.popper, ...attributes.popper, children: (0, jsx_runtime_1.jsx)(react_1.Menu, { children: (0, jsx_runtime_1.jsx)(MenuItems_1.MenuItems, { itemsStatic: true, onSelect: (selected) => {
34
- closePopperElement();
35
- onSelect(selected);
36
- }, ...otherProps }) }) }) }) })), children] }));
26
+ const { style = {}, ...otherWrapperProps } = otherProps;
27
+ return ((0, jsx_runtime_1.jsx)(Wrapper, { style: { ...(!props?.as && { display: 'contents' }), ...style }, ...otherWrapperProps, onContextMenu: handleContextMenu, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isPopperElementOpen && ((0, jsx_runtime_1.jsx)(Portal_1.Portal, { children: (0, jsx_runtime_1.jsx)("div", { ref: ref, children: (0, jsx_runtime_1.jsx)("div", { ref: setPopperElement, style: styles.popper, ...attributes.popper, children: (0, jsx_runtime_1.jsx)(react_1.Menu, { children: (0, jsx_runtime_1.jsx)(MenuItems_1.MenuItems, { itemsStatic: true, onSelect: (selected) => {
28
+ closePopperElement();
29
+ onSelect(selected);
30
+ }, options: options }) }) }) }) })), children] }) }));
37
31
  }
38
32
  function DropdownClickMenu(props) {
39
33
  const { placement = 'bottom-start', onSelect, ...otherProps } = props;
@@ -42,7 +42,7 @@ const ConfirmModalFooter = styled_1.default.div `
42
42
  `;
43
43
  function ConfirmModal(props) {
44
44
  const { isOpen, saveText = 'Save', cancelText = 'Cancel', headerColor, maxWidth, onRequestClose, onCancel = onRequestClose, onConfirm, requestCloseOnBackdrop = true, requestCloseOnEsc = true, children, } = props;
45
- const { ref, onClick } = (0, useDialog_1.useDialog)({
45
+ const dialogProps = (0, useDialog_1.useDialog)({
46
46
  isOpen,
47
47
  requestCloseOnEsc,
48
48
  requestCloseOnBackdrop,
@@ -51,7 +51,7 @@ function ConfirmModal(props) {
51
51
  if (!isOpen) {
52
52
  return null;
53
53
  }
54
- return ((0, jsx_runtime_1.jsx)(Portal_1.Portal, { children: (0, jsx_runtime_1.jsx)(ConfirmModalDialog, { ref: ref, onClick: onClick, children: (0, jsx_runtime_1.jsxs)(ConfirmModalContents, { headerColor: headerColor, style: { maxWidth }, children: [(0, jsx_runtime_1.jsx)(ConfirmModalChildrenRoot, { headerColor: headerColor, children: children }), (0, jsx_runtime_1.jsxs)(ConfirmModalFooter, { children: [(0, jsx_runtime_1.jsx)(__1.Button, { onClick: onConfirm, backgroundColor: {
54
+ return ((0, jsx_runtime_1.jsx)(Portal_1.Portal, { children: (0, jsx_runtime_1.jsx)(ConfirmModalDialog, { ...dialogProps, children: (0, jsx_runtime_1.jsxs)(ConfirmModalContents, { headerColor: headerColor, style: { maxWidth }, children: [(0, jsx_runtime_1.jsx)(ConfirmModalChildrenRoot, { headerColor: headerColor, children: children }), (0, jsx_runtime_1.jsxs)(ConfirmModalFooter, { children: [(0, jsx_runtime_1.jsx)(__1.Button, { onClick: onConfirm, backgroundColor: {
55
55
  basic: 'hsla(243deg, 75%, 58%, 1)',
56
56
  hover: 'hsla(245deg, 58%, 50%, 1)',
57
57
  }, color: { basic: 'white' }, children: saveText }), (0, jsx_runtime_1.jsx)(__1.Button, { onClick: onCancel, backgroundColor: {
@@ -44,7 +44,7 @@ const ModalFooterStyled = styled_1.default.div `
44
44
  `;
45
45
  function Modal(props) {
46
46
  const { isOpen, onRequestClose, hasCloseButton = true, requestCloseOnBackdrop = true, requestCloseOnEsc = true, children, width, maxWidth, height, } = props;
47
- const { ref, onClick } = (0, useDialog_1.useDialog)({
47
+ const dialogProps = (0, useDialog_1.useDialog)({
48
48
  isOpen,
49
49
  requestCloseOnEsc,
50
50
  requestCloseOnBackdrop,
@@ -53,7 +53,7 @@ function Modal(props) {
53
53
  if (!isOpen) {
54
54
  return null;
55
55
  }
56
- return ((0, jsx_runtime_1.jsx)(Portal_1.Portal, { children: (0, jsx_runtime_1.jsx)(DialogRoot, { ref: ref, onClick: onClick, children: (0, jsx_runtime_1.jsxs)(DialogContents, { style: {
56
+ return ((0, jsx_runtime_1.jsx)(Portal_1.Portal, { children: (0, jsx_runtime_1.jsx)(DialogRoot, { ...dialogProps, children: (0, jsx_runtime_1.jsxs)(DialogContents, { style: {
57
57
  maxWidth,
58
58
  height: height || 'max-content',
59
59
  width: width || '100%',
@@ -2,28 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDialog = void 0;
4
4
  const react_1 = require("react");
5
+ const react_kbs_1 = require("react-kbs");
5
6
  function useDialog({ isOpen, requestCloseOnEsc, requestCloseOnBackdrop, onRequestClose, }) {
6
- const ref = (0, react_1.useRef)(null);
7
+ (0, react_kbs_1.useKbsDisableGlobal)(isOpen);
8
+ const dialogRef = (0, react_1.useRef)(null);
7
9
  (0, react_1.useEffect)(() => {
8
- function onEsc(event) {
9
- event.preventDefault();
10
- if (requestCloseOnEsc && onRequestClose) {
11
- onRequestClose();
12
- }
13
- }
14
- const dialog = ref.current;
15
- if (dialog) {
16
- dialog.addEventListener('cancel', onEsc);
17
- return () => dialog.removeEventListener('cancel', onEsc);
18
- }
19
- }, [onRequestClose, requestCloseOnEsc]);
20
- (0, react_1.useEffect)(() => {
21
- const dialog = ref.current;
10
+ const dialog = dialogRef.current;
22
11
  if (dialog && isOpen) {
23
12
  dialog.showModal();
24
13
  return () => dialog.close();
25
14
  }
26
15
  }, [isOpen]);
16
+ const onCancel = (0, react_1.useCallback)((event) => {
17
+ event.preventDefault();
18
+ if (requestCloseOnEsc && onRequestClose) {
19
+ onRequestClose();
20
+ }
21
+ }, [onRequestClose, requestCloseOnEsc]);
27
22
  const onClick = (0, react_1.useCallback)((event) => {
28
23
  // Since the dialog has no size of itself, this condition is only
29
24
  // `true` when we click on the backdrop.
@@ -31,6 +26,6 @@ function useDialog({ isOpen, requestCloseOnEsc, requestCloseOnBackdrop, onReques
31
26
  onRequestClose?.();
32
27
  }
33
28
  }, [requestCloseOnBackdrop, onRequestClose]);
34
- return { ref, onClick };
29
+ return { ref: dialogRef, onClick, onCancel };
35
30
  }
36
31
  exports.useDialog = useDialog;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import produce from 'immer';
2
+ import { produce } from 'immer';
3
3
  import { createContext, useContext, useReducer, } from 'react';
4
4
  import { getEmptyAppData } from './data/index';
5
5
  import { appStateProducer } from './producers/index';
@@ -1 +1 @@
1
- {"version":3,"file":"appState.js","sourceRoot":"","sources":["../../../src/app-data/state/appState.tsx"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,OAAO,CAAC;AAC5B,OAAO,EACL,aAAa,EAGb,UAAU,EACV,UAAU,GACX,MAAM,O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AEnE,MAAM,UAAU,cAAc;IAC5B,MAAM,WAAW,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACnD,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,WAAW,EAAE,CAAC,IAAI,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,WAAW,EAAE,CAAC,IAAI,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,EAAE,CAAC,QAAQ,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE7C,MAAM,UAAU,gBAAgB,CAAC,KAA8B;IAC7D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,UAAU,CACxC,UAAU,EACV,IAAI,EACJ,gBAAgB,CACjB,CAAC;IACF,OAAO,CACL,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,WAAW,YAC7C,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,YACtC,KAAK,CAAC,QAAQ,GACU,GACC,CAC/B,CAAC;AACJ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Placement } from '@popperjs/core';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, ElementType, ComponentProps } from 'react';
3
3
  import { MenuOption, MenuOptions } from './MenuItems';
4
4
  interface DropdownMenuBaseProps<T> {
5
5
  /**
@@ -9,6 +9,7 @@ interface DropdownMenuBaseProps<T> {
9
9
  options: MenuOptions<T>;
10
10
  onSelect: (selected: MenuOption<T>) => void;
11
11
  }
12
+ type ElementProps<E = unknown> = E extends ElementType ? ComponentProps<E> : never;
12
13
  interface DropdownMenuClickProps<T> extends DropdownMenuBaseProps<T> {
13
14
  /**
14
15
  * Node to be inside the Button
@@ -16,11 +17,12 @@ interface DropdownMenuClickProps<T> extends DropdownMenuBaseProps<T> {
16
17
  children: ReactNode;
17
18
  trigger: 'click';
18
19
  }
19
- interface DropdownMenuContextProps<T> extends DropdownMenuBaseProps<T> {
20
+ interface DropdownMenuContextProps<T, E> extends DropdownMenuBaseProps<T> {
20
21
  trigger: 'contextMenu';
21
22
  children: ReactNode;
23
+ as?: E;
22
24
  }
23
- export type DropdownMenuProps<T> = DropdownMenuContextProps<T> | DropdownMenuClickProps<T>;
24
- export declare function DropdownMenu<T>(props: DropdownMenuProps<T>): JSX.Element;
25
+ export type DropdownMenuProps<T, E> = DropdownMenuContextProps<T, E> | DropdownMenuClickProps<T>;
26
+ export declare function DropdownMenu<T = unknown, E extends ElementType = 'div'>(props: DropdownMenuProps<T, E> & Omit<ElementProps<E>, keyof DropdownMenuProps<T, E>>): JSX.Element;
25
27
  export {};
26
28
  //# sourceMappingURL=DropdownMenu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownMenu.d.ts","sourceRoot":"","sources":["../../../src/components/dropdown-menu/DropdownMenu.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAU,MAAM,OAAO,CAAC;AAO1C,OAAO,EAAa,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGjE,UAAU,qBAAqB,CAAC,CAAC;IAC/B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,QAAQ,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC7C;AAED,UAAU,sBAAsB,CAAC,CAAC,CAAE,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IAClE;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,OAAO,CAA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,QAAQ,EAAE,SAAS,CAAC;IACpB,EAAE,CAAC,EAAE,CAAC,CAAC;CACR;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAC9B,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC9B,sBAAsB,CAAC,CAAC,CAAC,CAAC;AAE9B,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,WAAW,GAAG,KAAK,EACrE,KAAK,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC5B,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAUvD"}
@@ -1,5 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import styled from '@emotion/styled';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
2
  import { Menu } from '@headlessui/react';
4
3
  import { useRef } from 'react';
5
4
  import { useModifiedPopper } from '../hooks/useModifiedPopper';
@@ -11,22 +10,20 @@ import { useContextMenuPlacement } from './useContextMenuPlacement';
11
10
  export function DropdownMenu(props) {
12
11
  const { trigger, ...otherProps } = props;
13
12
  if (trigger === 'contextMenu') {
14
- return _jsx(DropdownContextMenu, { ...otherProps });
13
+ return _jsx(DropdownContextMenu, { ...props });
15
14
  }
16
15
  return (_jsx(DropdownClickMenu, { ...otherProps, children: props.children }));
17
16
  }
18
- const HandleMenuContextDiv = styled.div `
19
- display: contents;
20
- `;
21
17
  function DropdownContextMenu(props) {
22
- const { children, onSelect, ...otherProps } = props;
23
- const { isPopperElementOpen, closePopperElement, handleContextMenu, setPopperElement, styles, attributes, } = useContextMenuPlacement(otherProps.placement || 'right-start');
18
+ const { children, onSelect, as: Wrapper = 'div', placement = 'right-start', options, ...otherProps } = props;
19
+ const { isPopperElementOpen, closePopperElement, handleContextMenu, setPopperElement, styles, attributes, } = useContextMenuPlacement(placement);
24
20
  const ref = useRef(null);
25
21
  useOnClickOutside(ref, closePopperElement);
26
- return (_jsxs(HandleMenuContextDiv, { onContextMenu: handleContextMenu, children: [isPopperElementOpen && (_jsx(Portal, { children: _jsx("div", { ref: ref, children: _jsx("div", { ref: setPopperElement, style: styles.popper, ...attributes.popper, children: _jsx(Menu, { children: _jsx(MenuItems, { itemsStatic: true, onSelect: (selected) => {
27
- closePopperElement();
28
- onSelect(selected);
29
- }, ...otherProps }) }) }) }) })), children] }));
22
+ const { style = {}, ...otherWrapperProps } = otherProps;
23
+ return (_jsx(Wrapper, { style: { ...(!props?.as && { display: 'contents' }), ...style }, ...otherWrapperProps, onContextMenu: handleContextMenu, children: _jsxs(_Fragment, { children: [isPopperElementOpen && (_jsx(Portal, { children: _jsx("div", { ref: ref, children: _jsx("div", { ref: setPopperElement, style: styles.popper, ...attributes.popper, children: _jsx(Menu, { children: _jsx(MenuItems, { itemsStatic: true, onSelect: (selected) => {
24
+ closePopperElement();
25
+ onSelect(selected);
26
+ }, options: options }) }) }) }) })), children] }) }));
30
27
  }
31
28
  function DropdownClickMenu(props) {
32
29
  const { placement = 'bottom-start', onSelect, ...otherProps } = props;
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownMenu.js","sourceRoot":"","sources":["../../../src/components/dropdown-menu/DropdownMenu.tsx"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAa,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAA2B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ACX,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;gCACrB,UAAU,EAAE,CAAC;gCACb,QAAQ,CAAC,QAAQ,CAAC,CAAC;4BACrB,CAAC,KACG,UAAU,GACd,GACE,GACF,GACC,CACV,IACI,CACR,CAAC;AACJ,CAAC"}
@@ -36,7 +36,7 @@ const ConfirmModalFooter = styled.div `
36
36
  `;
37
37
  export function ConfirmModal(props) {
38
38
  const { isOpen, saveText = 'Save', cancelText = 'Cancel', headerColor, maxWidth, onRequestClose, onCancel = onRequestClose, onConfirm, requestCloseOnBackdrop = true, requestCloseOnEsc = true, children, } = props;
39
- const { ref, onClick } = useDialog({
39
+ const dialogProps = useDialog({
40
40
  isOpen,
41
41
  requestCloseOnEsc,
42
42
  requestCloseOnBackdrop,
@@ -45,7 +45,7 @@ export function ConfirmModal(props) {
45
45
  if (!isOpen) {
46
46
  return null;
47
47
  }
48
- return (_jsx(Portal, { children: _jsx(ConfirmModalDialog, { ref: ref, onClick: onClick, children: _jsxs(ConfirmModalContents, { headerColor: headerColor, style: { maxWidth }, children: [_jsx(ConfirmModalChildrenRoot, { headerColor: headerColor, children: children }), _jsxs(ConfirmModalFooter, { children: [_jsx(Button, { onClick: onConfirm, backgroundColor: {
48
+ return (_jsx(Portal, { children: _jsx(ConfirmModalDialog, { ...dialogProps, children: _jsxs(ConfirmModalContents, { headerColor: headerColor, style: { maxWidth }, children: [_jsx(ConfirmModalChildrenRoot, { headerColor: headerColor, children: children }), _jsxs(ConfirmModalFooter, { children: [_jsx(Button, { onClick: onConfirm, backgroundColor: {
49
49
  basic: 'hsla(243deg, 75%, 58%, 1)',
50
50
  hover: 'hsla(245deg, 58%, 50%, 1)',
51
51
  }, color: { basic: 'white' }, children: saveText }), _jsx(Button, { onClick: onCancel, backgroundColor: {
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmModal.js","sourceRoot":"","sources":["../../../src/components/modal/ConfirmModal.tsx"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,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GAAG,QAAQ,EACrB,WAAW,EACX,QAAQ,EACR,cAAc,EACd,QAAQ,GAAG,cAAc,EACzB,SAAS,EACT,sBAAsB,GAAG,IAAI,EAC7B,iBAAiB,GAAG,IAAI,EACxB,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,WAAW,GAAG,SAAS,CAAC;QAC5B,MAAM;QACN,iBAAiB;QACjB,sBAAsB;QACtB,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,KAAC,MAAM,cACL,KAAC,kBAAkB,OAAK,WAAW,YACjC,MAAC,oBAAoB,IAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,aACjE,KAAC,wBAAwB,IAAC,WAAW,EAAE,WAAW,YAC/C,QAAQ,GACgB,EAE3B,MAAC,kBAAkB,eACjB,KAAC,MAAM,IACL,OAAO,EAAE,SAAS,EAClB,eAAe,EAAE;oCACf,KAAK,EAAE,2BAA2B;oCAClC,KAAK,EAAE,2BAA2B;iCACnC,EACD,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,YAExB,QAAQ,GACF,EACT,KAAC,MAAM,IACL,OAAO,EAAE,QAAQ,EACjB,eAAe,EAAE;oCACf,KAAK,EAAE,yBAAyB;oCAChC,KAAK,EAAE,yBAAyB;iCACjC,EACD,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,YAExB,UAAU,GACJ,IACU,IACA,GACJ,GACd,CACV,CAAC;AACJ,CAAC"}
@@ -38,7 +38,7 @@ const ModalFooterStyled = styled.div `
38
38
  `;
39
39
  export function Modal(props) {
40
40
  const { isOpen, onRequestClose, hasCloseButton = true, requestCloseOnBackdrop = true, requestCloseOnEsc = true, children, width, maxWidth, height, } = props;
41
- const { ref, onClick } = useDialog({
41
+ const dialogProps = useDialog({
42
42
  isOpen,
43
43
  requestCloseOnEsc,
44
44
  requestCloseOnBackdrop,
@@ -47,7 +47,7 @@ export function Modal(props) {
47
47
  if (!isOpen) {
48
48
  return null;
49
49
  }
50
- return (_jsx(Portal, { children: _jsx(DialogRoot, { ref: ref, onClick: onClick, children: _jsxs(DialogContents, { style: {
50
+ return (_jsx(Portal, { children: _jsx(DialogRoot, { ...dialogProps, children: _jsxs(DialogContents, { style: {
51
51
  maxWidth,
52
52
  height: height || 'max-content',
53
53
  width: width || '100%',
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../../src/components/modal/Modal.tsx"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAcxC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAA;;;;;;CAM/B,CAAC;AAEF,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;CAShC,CAAC;AAEF,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;CAMnC,CAAC;AAEF,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAIjC,CAAC;AAEF,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAA;;;CAGnC,CAAC;AAEF,MAAM,UAAU,KAAK,CAAC,KAAiB;IACrC,MAAM,EACJ,MAAM,EACN,cAAc,EACd,cAAc,GAAG,IAAI,EACrB,sBAAsB,GAAG,IAAI,EAC7B,iBAAiB,GAAG,IAAI,EACxB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,GACP,GAAG,KAAK,CAAC;IAEV,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;QACjC,MAAM;QACN,iBAAiB;QACjB,sBAAsB;QACtB,cAAc;KACf,CAAC,CAAC;IAEH,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GAAqB,CAAC;AACjE,CAAC,CAAC"}
@@ -1,11 +1,12 @@
1
- import React from 'react';
1
+ import { MouseEventHandler, ReactEventHandler } from 'react';
2
2
  export declare function useDialog({ isOpen, requestCloseOnEsc, requestCloseOnBackdrop, onRequestClose, }: {
3
3
  isOpen: boolean;
4
4
  requestCloseOnEsc: boolean;
5
5
  requestCloseOnBackdrop: boolean;
6
6
  onRequestClose?: () => void;
7
7
  }): {
8
- ref: React.RefObject<HTMLDialogElement>;
9
- onClick: (event: React.MouseEvent<HTMLDialogElement, MouseEvent>) => void;
8
+ ref: import("react").RefObject<HTMLDialogElement>;
9
+ onClick: MouseEventHandler<HTMLDialogElement>;
10
+ onCancel: ReactEventHandler<HTMLDialogElement>;
10
11
  };
11
12
  //# sourceMappingURL=useDialog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDialog.d.ts","sourceRoot":"","sources":["../../../src/components/modal/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,GACf,EAAE;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sBAAsB,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;;qBA0BW,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,CAAC;EAW1D"}
1
+ {"version":3,"file":"useDialog.d.ts","sourceRoot":"","sources":["../../../src/components/modal/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAIlB,MAAM,OAAO,CAAC;AAGf,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,GACf,EAAE;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sBAAsB,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;;;;EAmCA"}
@@ -1,26 +1,21 @@
1
- import { useCallback, useEffect, useRef } from 'react';
1
+ import { useCallback, useEffect, useRef, } from 'react';
2
+ import { useKbsDisableGlobal } from 'react-kbs';
2
3
  export function useDialog({ isOpen, requestCloseOnEsc, requestCloseOnBackdrop, onRequestClose, }) {
3
- const ref = useRef(null);
4
+ useKbsDisableGlobal(isOpen);
5
+ const dialogRef = useRef(null);
4
6
  useEffect(() => {
5
- function onEsc(event) {
6
- event.preventDefault();
7
- if (requestCloseOnEsc && onRequestClose) {
8
- onRequestClose();
9
- }
10
- }
11
- const dialog = ref.current;
12
- if (dialog) {
13
- dialog.addEventListener('cancel', onEsc);
14
- return () => dialog.removeEventListener('cancel', onEsc);
15
- }
16
- }, [onRequestClose, requestCloseOnEsc]);
17
- useEffect(() => {
18
- const dialog = ref.current;
7
+ const dialog = dialogRef.current;
19
8
  if (dialog && isOpen) {
20
9
  dialog.showModal();
21
10
  return () => dialog.close();
22
11
  }
23
12
  }, [isOpen]);
13
+ const onCancel = useCallback((event) => {
14
+ event.preventDefault();
15
+ if (requestCloseOnEsc && onRequestClose) {
16
+ onRequestClose();
17
+ }
18
+ }, [onRequestClose, requestCloseOnEsc]);
24
19
  const onClick = useCallback((event) => {
25
20
  // Since the dialog has no size of itself, this condition is only
26
21
  // `true` when we click on the backdrop.
@@ -28,6 +23,6 @@ export function useDialog({ isOpen, requestCloseOnEsc, requestCloseOnBackdrop, o
28
23
  onRequestClose?.();
29
24
  }
30
25
  }, [requestCloseOnBackdrop, onRequestClose]);
31
- return { ref, onClick };
26
+ return { ref: dialogRef, onClick, onCancel };
32
27
  }
33
28
  //# sourceMappingURL=useDialog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDialog.js","sourceRoot":"","sources":["../../../src/components/modal/useDialog.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,WAAW,EAAE,S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,CAAC"}
1
+ {"version":3,"file":"useDialog.js","sourceRoot":"","sources":["../../../src/components/modal/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,UAAU,SAAS,CAAC,EACxB,MAAM,EACN,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,GAMf;IACC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE5B,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAElD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;QACjC,IAAI,MAAM,IAAI,MAAM,EAAE;YACpB,MAAM,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;SAC7B;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,KAAK,EAAE,EAAE;QACR,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,IAAI,iBAAiB,IAAI,cAAc,EAAE;YACvC,cAAc,EAAE,CAAC;SAClB;IACH,CAAC,EACD,CAAC,cAAc,EAAE,iBAAiB,CAAC,CACpC,CAAC;IAEF,MAAM,OAAO,GAAG,WAAW,CACzB,CAAC,KAAK,EAAE,EAAE;QACR,iEAAiE;QACjE,wCAAwC;QACxC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,aAAa,IAAI,sBAAsB,EAAE;YAClE,cAAc,EAAE,EAAE,CAAC;SACpB;IACH,CAAC,EACD,CAAC,sBAAsB,EAAE,cAAc,CAAC,CACzC,CAAC;IAEF,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-science",
3
- "version": "0.21.2",
3
+ "version": "0.22.0",
4
4
  "description": "React components to build analysis UI",
5
5
  "exports": {
6
6
  "./app": {
@@ -50,7 +50,7 @@
50
50
  "test-only": "vitest run --coverage "
51
51
  },
52
52
  "volta": {
53
- "node": "18.15.0"
53
+ "node": "18.16.0"
54
54
  },
55
55
  "overrides": {
56
56
  "react": "^18.2.0",
@@ -63,64 +63,64 @@
63
63
  "dependencies": {
64
64
  "@emotion/react": "^11.10.6",
65
65
  "@emotion/styled": "^11.10.6",
66
- "@headlessui/react": "^1.7.13",
67
- "@lukeed/uuid": "^2.0.0",
68
- "@popperjs/core": "^2.11.6",
69
- "@tanstack/react-query": "^4.28.0",
70
- "@tanstack/react-table": "^8.8.0",
66
+ "@headlessui/react": "^1.7.14",
67
+ "@lukeed/uuid": "^2.0.1",
68
+ "@popperjs/core": "^2.11.7",
69
+ "@tanstack/react-query": "^4.29.5",
70
+ "@tanstack/react-table": "^8.8.5",
71
71
  "biologic-converter": "^0.6.0",
72
- "cheminfo-types": "^1.4.0",
72
+ "cheminfo-types": "^1.7.0",
73
73
  "d3-scale-chromatic": "^3.0.0",
74
- "filelist-utils": "^1.8.0",
75
- "immer": "^9.0.21",
74
+ "filelist-utils": "^1.8.1",
75
+ "immer": "^10.0.1",
76
76
  "jcampconverter": "^9.1.0",
77
77
  "lodash": "^4.17.21",
78
- "ml-gsd": "^12.1.2",
78
+ "ml-gsd": "^12.1.3",
79
79
  "ml-peak-shape-generator": "^4.1.2",
80
- "ml-signal-processing": "^1.0.2",
81
- "ml-spectra-processing": "^12.0.0",
82
- "ms-spectrum": "^2.3.0",
80
+ "ml-signal-processing": "^1.0.3",
81
+ "ml-spectra-processing": "^12.3.0",
82
+ "ms-spectrum": "^2.3.1",
83
83
  "netcdfjs": "^2.0.2",
84
84
  "react-d3-utils": "^1.0.0",
85
85
  "react-dropzone": "^14.2.3",
86
- "react-error-boundary": "^4.0.2",
86
+ "react-error-boundary": "^4.0.4",
87
87
  "react-icons": "^4.8.0",
88
88
  "react-inspector": "^6.0.1",
89
89
  "react-kbs": "^2.1.1",
90
90
  "react-plot": "^1.4.2",
91
91
  "react-popper": "^2.3.0",
92
92
  "react-shadow": "^20.0.0",
93
- "spc-parser": "^0.7.1",
93
+ "spc-parser": "^0.7.2",
94
94
  "tinycolor2": "^1.6.0",
95
95
  "use-resize-observer": "^9.1.0",
96
96
  "wdf-parser": "^0.3.0"
97
97
  },
98
98
  "devDependencies": {
99
- "@babel/core": "^7.21.3",
99
+ "@babel/core": "^7.21.4",
100
100
  "@babel/eslint-parser": "^7.21.3",
101
- "@ladle/react": "^2.10.2",
102
- "@playwright/experimental-ct-react": "^1.32.0",
103
- "@playwright/test": "^1.32.0",
101
+ "@ladle/react": "^2.12.3",
102
+ "@playwright/experimental-ct-react": "^1.33.0",
103
+ "@playwright/test": "^1.33.0",
104
104
  "@types/babel__core": "^7.20.0",
105
105
  "@types/d3-scale-chromatic": "^3.0.0",
106
- "@types/lodash": "^4.14.191",
107
- "@types/react": "^18.0.28",
108
- "@types/react-dom": "^18.0.11",
106
+ "@types/lodash": "^4.14.194",
107
+ "@types/react": "^18.2.0",
108
+ "@types/react-dom": "^18.2.1",
109
109
  "@types/react-inspector": "^4.0.2",
110
- "@vitejs/plugin-react": "^3.1.0",
111
- "@vitest/coverage-c8": "^0.29.7",
110
+ "@vitejs/plugin-react": "^4.0.0",
111
+ "@vitest/coverage-c8": "^0.30.1",
112
112
  "cheminfo-font": "^1.9.0",
113
113
  "cross-env": "^7.0.3",
114
- "eslint": "^8.36.0",
115
- "eslint-config-zakodium": "^7.1.0",
116
- "prettier": "^2.8.6",
114
+ "eslint": "^8.39.0",
115
+ "eslint-config-zakodium": "^7.2.0",
116
+ "prettier": "^2.8.8",
117
117
  "react": "^18.2.0",
118
118
  "react-dom": "^18.2.0",
119
119
  "react-ocl": "^5.0.0",
120
- "rimraf": "^4.4.1",
121
- "typescript": "^5.0.2",
122
- "vite": "^4.2.1",
123
- "vitest": "^0.29.7"
120
+ "rimraf": "^5.0.0",
121
+ "typescript": "^5.0.4",
122
+ "vite": "^4.3.3",
123
+ "vitest": "^0.30.1"
124
124
  },
125
125
  "repository": {
126
126
  "type": "git",
@@ -1,4 +1,4 @@
1
- import produce from 'immer';
1
+ import { produce } from 'immer';
2
2
  import {
3
3
  createContext,
4
4
  Dispatch,
@@ -1,7 +1,6 @@
1
- import styled from '@emotion/styled';
2
1
  import { Menu } from '@headlessui/react';
3
2
  import type { Placement } from '@popperjs/core';
4
- import { ReactNode, useRef } from 'react';
3
+ import { ReactNode, useRef, ElementType, ComponentProps } from 'react';
5
4
 
6
5
  import { useModifiedPopper } from '../hooks/useModifiedPopper';
7
6
  import { useOnClickOutside } from '../hooks/useOnClickOutside';
@@ -21,6 +20,10 @@ interface DropdownMenuBaseProps<T> {
21
20
  onSelect: (selected: MenuOption<T>) => void;
22
21
  }
23
22
 
23
+ type ElementProps<E = unknown> = E extends ElementType
24
+ ? ComponentProps<E>
25
+ : never;
26
+
24
27
  interface DropdownMenuClickProps<T> extends DropdownMenuBaseProps<T> {
25
28
  /**
26
29
  * Node to be inside the Button
@@ -29,33 +32,42 @@ interface DropdownMenuClickProps<T> extends DropdownMenuBaseProps<T> {
29
32
  trigger: 'click';
30
33
  }
31
34
 
32
- interface DropdownMenuContextProps<T> extends DropdownMenuBaseProps<T> {
35
+ interface DropdownMenuContextProps<T, E> extends DropdownMenuBaseProps<T> {
33
36
  trigger: 'contextMenu';
34
37
  children: ReactNode;
38
+ as?: E;
35
39
  }
36
40
 
37
- export type DropdownMenuProps<T> =
38
- | DropdownMenuContextProps<T>
41
+ export type DropdownMenuProps<T, E> =
42
+ | DropdownMenuContextProps<T, E>
39
43
  | DropdownMenuClickProps<T>;
40
44
 
41
- export function DropdownMenu<T>(props: DropdownMenuProps<T>) {
45
+ export function DropdownMenu<T = unknown, E extends ElementType = 'div'>(
46
+ props: DropdownMenuProps<T, E> &
47
+ Omit<ElementProps<E>, keyof DropdownMenuProps<T, E>>,
48
+ ) {
42
49
  const { trigger, ...otherProps } = props;
43
50
 
44
51
  if (trigger === 'contextMenu') {
45
- return <DropdownContextMenu {...otherProps} />;
52
+ return <DropdownContextMenu<T, E> {...props} />;
46
53
  }
47
-
48
54
  return (
49
55
  <DropdownClickMenu {...otherProps}>{props.children}</DropdownClickMenu>
50
56
  );
51
57
  }
52
58
 
53
- const HandleMenuContextDiv = styled.div`
54
- display: contents;
55
- `;
56
-
57
- function DropdownContextMenu<T>(props: Omit<DropdownMenuProps<T>, 'trigger'>) {
58
- const { children, onSelect, ...otherProps } = props;
59
+ function DropdownContextMenu<T, E extends ElementType = 'div'>(
60
+ props: Omit<DropdownMenuContextProps<T, E>, 'trigger'> &
61
+ Omit<ElementProps<E>, keyof DropdownMenuProps<T, E>>,
62
+ ) {
63
+ const {
64
+ children,
65
+ onSelect,
66
+ as: Wrapper = 'div',
67
+ placement = 'right-start',
68
+ options,
69
+ ...otherProps
70
+ } = props;
59
71
 
60
72
  const {
61
73
  isPopperElementOpen,
@@ -64,43 +76,51 @@ function DropdownContextMenu<T>(props: Omit<DropdownMenuProps<T>, 'trigger'>) {
64
76
  setPopperElement,
65
77
  styles,
66
78
  attributes,
67
- } = useContextMenuPlacement(otherProps.placement || 'right-start');
79
+ } = useContextMenuPlacement(placement);
68
80
 
69
81
  const ref = useRef<HTMLDivElement>(null);
70
82
  useOnClickOutside(ref, closePopperElement);
71
83
 
84
+ const { style = {}, ...otherWrapperProps } = otherProps as ElementProps<E>;
85
+
72
86
  return (
73
- <HandleMenuContextDiv onContextMenu={handleContextMenu}>
74
- {isPopperElementOpen && (
75
- <Portal>
76
- <div ref={ref}>
77
- <div
78
- ref={setPopperElement}
79
- style={styles.popper}
80
- {...attributes.popper}
81
- >
82
- <Menu>
83
- <MenuItems
84
- itemsStatic
85
- onSelect={(selected) => {
86
- closePopperElement();
87
- onSelect(selected);
88
- }}
89
- {...otherProps}
90
- />
91
- </Menu>
87
+ <Wrapper
88
+ style={{ ...(!props?.as && { display: 'contents' }), ...style }}
89
+ {...otherWrapperProps}
90
+ onContextMenu={handleContextMenu}
91
+ >
92
+ <>
93
+ {isPopperElementOpen && (
94
+ <Portal>
95
+ <div ref={ref}>
96
+ <div
97
+ ref={setPopperElement}
98
+ style={styles.popper}
99
+ {...attributes.popper}
100
+ >
101
+ <Menu>
102
+ <MenuItems
103
+ itemsStatic
104
+ onSelect={(selected) => {
105
+ closePopperElement();
106
+ onSelect(selected);
107
+ }}
108
+ options={options}
109
+ />
110
+ </Menu>
111
+ </div>
92
112
  </div>
93
- </div>
94
- </Portal>
95
- )}
113
+ </Portal>
114
+ )}
96
115
 
97
- {children}
98
- </HandleMenuContextDiv>
116
+ {children}
117
+ </>
118
+ </Wrapper>
99
119
  );
100
120
  }
101
121
 
102
- function DropdownClickMenu<T>(
103
- props: Omit<DropdownMenuProps<T>, 'trigger'> & { children: ReactNode },
122
+ function DropdownClickMenu<T, E>(
123
+ props: Omit<DropdownMenuProps<T, E>, 'trigger'> & { children: ReactNode },
104
124
  ) {
105
125
  const { placement = 'bottom-start', onSelect, ...otherProps } = props;
106
126
 
@@ -72,7 +72,7 @@ export function ConfirmModal(props: ConfirmModalProps) {
72
72
  children,
73
73
  } = props;
74
74
 
75
- const { ref, onClick } = useDialog({
75
+ const dialogProps = useDialog({
76
76
  isOpen,
77
77
  requestCloseOnEsc,
78
78
  requestCloseOnBackdrop,
@@ -85,7 +85,7 @@ export function ConfirmModal(props: ConfirmModalProps) {
85
85
 
86
86
  return (
87
87
  <Portal>
88
- <ConfirmModalDialog ref={ref} onClick={onClick}>
88
+ <ConfirmModalDialog {...dialogProps}>
89
89
  <ConfirmModalContents headerColor={headerColor} style={{ maxWidth }}>
90
90
  <ConfirmModalChildrenRoot headerColor={headerColor}>
91
91
  {children}
@@ -69,7 +69,7 @@ export function Modal(props: ModalProps) {
69
69
  height,
70
70
  } = props;
71
71
 
72
- const { ref, onClick } = useDialog({
72
+ const dialogProps = useDialog({
73
73
  isOpen,
74
74
  requestCloseOnEsc,
75
75
  requestCloseOnBackdrop,
@@ -82,7 +82,7 @@ export function Modal(props: ModalProps) {
82
82
 
83
83
  return (
84
84
  <Portal>
85
- <DialogRoot ref={ref} onClick={onClick}>
85
+ <DialogRoot {...dialogProps}>
86
86
  <DialogContents
87
87
  style={{
88
88
  maxWidth,
@@ -1,4 +1,11 @@
1
- import React, { useCallback, useEffect, useRef } from 'react';
1
+ import {
2
+ MouseEventHandler,
3
+ ReactEventHandler,
4
+ useCallback,
5
+ useEffect,
6
+ useRef,
7
+ } from 'react';
8
+ import { useKbsDisableGlobal } from 'react-kbs';
2
9
 
3
10
  export function useDialog({
4
11
  isOpen,
@@ -11,32 +18,30 @@ export function useDialog({
11
18
  requestCloseOnBackdrop: boolean;
12
19
  onRequestClose?: () => void;
13
20
  }) {
14
- const ref = useRef<HTMLDialogElement>(null);
21
+ useKbsDisableGlobal(isOpen);
15
22
 
16
- useEffect(() => {
17
- function onEsc(event: Event) {
18
- event.preventDefault();
19
- if (requestCloseOnEsc && onRequestClose) {
20
- onRequestClose();
21
- }
22
- }
23
- const dialog = ref.current;
24
- if (dialog) {
25
- dialog.addEventListener('cancel', onEsc);
26
- return () => dialog.removeEventListener('cancel', onEsc);
27
- }
28
- }, [onRequestClose, requestCloseOnEsc]);
23
+ const dialogRef = useRef<HTMLDialogElement>(null);
29
24
 
30
25
  useEffect(() => {
31
- const dialog = ref.current;
26
+ const dialog = dialogRef.current;
32
27
  if (dialog && isOpen) {
33
28
  dialog.showModal();
34
29
  return () => dialog.close();
35
30
  }
36
31
  }, [isOpen]);
37
32
 
38
- const onClick = useCallback(
39
- (event: React.MouseEvent<HTMLDialogElement, MouseEvent>) => {
33
+ const onCancel = useCallback<ReactEventHandler<HTMLDialogElement>>(
34
+ (event) => {
35
+ event.preventDefault();
36
+ if (requestCloseOnEsc && onRequestClose) {
37
+ onRequestClose();
38
+ }
39
+ },
40
+ [onRequestClose, requestCloseOnEsc],
41
+ );
42
+
43
+ const onClick = useCallback<MouseEventHandler<HTMLDialogElement>>(
44
+ (event) => {
40
45
  // Since the dialog has no size of itself, this condition is only
41
46
  // `true` when we click on the backdrop.
42
47
  if (event.target === event.currentTarget && requestCloseOnBackdrop) {
@@ -46,5 +51,5 @@ export function useDialog({
46
51
  [requestCloseOnBackdrop, onRequestClose],
47
52
  );
48
53
 
49
- return { ref, onClick };
54
+ return { ref: dialogRef, onClick, onCancel };
50
55
  }