tycho-components 0.7.2 → 0.7.5

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.
@@ -4,9 +4,21 @@ import cx from "classnames";
4
4
  import { useTranslation } from "react-i18next";
5
5
  import { Button, Icon } from "tycho-storybook";
6
6
  import "./style.scss";
7
+ import { useEffect } from "react";
8
+ const attachCloseToEscape = (handleClose) => {
9
+ const closeOnEscape = (e) => {
10
+ if (e.key === 'Escape')
11
+ handleClose();
12
+ };
13
+ window.addEventListener('keydown', closeOnEscape);
14
+ return () => window.removeEventListener('keydown', closeOnEscape);
15
+ };
7
16
  export default function AppModal({ children, title, subtitle, className, close, confirm, disableConfirm, hideFooter, disableClose, disableCancel, confirmLabel, closeLabel, cancel, onEntered, alternativeButton, hideBackdrop, alternativeOptions, }) {
8
17
  const { t } = useTranslation("common");
9
18
  const getClassNames = cx("modal-container", className);
19
+ useEffect(() => {
20
+ return attachCloseToEscape(close);
21
+ }, [close]);
10
22
  return (_jsx(Modal, { open: true, disableEnforceFocus: true, disableAutoFocus: true, disableRestoreFocus: true, hideBackdrop: hideBackdrop, children: _jsx(Fade, { in: true, onEntered: () => onEntered && onEntered(), children: _jsxs(Box, { className: getClassNames, sx: style, children: [_jsxs("div", { className: "header", children: [_jsxs("div", { className: "titles", children: [_jsx("span", { className: "title", children: title }), subtitle && _jsx("span", { className: "subtitle", children: subtitle })] }), !disableClose && (_jsx(Icon, { name: "close", onClick: close, className: "pointer" }))] }), _jsx("div", { className: "body", children: children }), !hideFooter ? (_jsxs("div", { className: "footer", children: [alternativeOptions && alternativeOptions, alternativeButton && (_jsx(Button, { className: "alternative", color: "white", onClick: alternativeButton.action, text: alternativeButton.title })), !disableCancel && (_jsx(Button, { onClick: cancel || close, text: closeLabel || t("button.cancel"), color: "danger" })), confirm && (_jsx(Button, { onClick: confirm, disabled: disableConfirm, text: confirmLabel || t("button.confirm") }))] })) : null] }) }) }));
11
23
  }
12
24
  const style = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.7.2",
4
+ "version": "0.7.5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -51,7 +51,7 @@
51
51
  "react-hook-form": "^7.45.2",
52
52
  "react-i18next": "^13.0.2",
53
53
  "react-router-dom": "^6.14.2",
54
- "tycho-storybook": "0.4.4",
54
+ "tycho-storybook": "0.4.6",
55
55
  "yup": "^1.2.0"
56
56
  },
57
57
  "devDependencies": {
@@ -87,4 +87,4 @@
87
87
  "build-publish": "tsc && npm run copy-css",
88
88
  "copy-css": "node scripts/copy-css.js"
89
89
  }
90
- }
90
+ }