@simplybusiness/mobius 10.3.3 → 10.4.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.
@@ -4,6 +4,7 @@ export interface ModalProps extends RefAttributes<ModalElementType> {
4
4
  isOpen: boolean;
5
5
  onOpen?: () => void;
6
6
  onClose?: () => void;
7
+ preventEscapeKey?: boolean;
7
8
  children?: ReactNode;
8
9
  className?: string;
9
10
  closeLabel?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simplybusiness/mobius",
3
3
  "license": "UNLICENSED",
4
- "version": "10.3.3",
4
+ "version": "10.4.0",
5
5
  "description": "Core library of Mobius react components",
6
6
  "repository": {
7
7
  "type": "git",
@@ -98,7 +98,7 @@
98
98
  "dependencies": {
99
99
  "@floating-ui/react": "^0.27.19",
100
100
  "@loadable/component": "^5.16.7",
101
- "@simplybusiness/icons": "^5.0.4",
101
+ "@simplybusiness/icons": "^5.1.0",
102
102
  "@simplybusiness/mobius-hooks": "^0.1.1",
103
103
  "classnames": "^2.5.1",
104
104
  "dialog-polyfill": "^0.5.6",
@@ -17,6 +17,7 @@ const Modal = ({ ref, ...props }: ModalProps) => {
17
17
  const {
18
18
  isOpen,
19
19
  onClose,
20
+ preventEscapeKey = false,
20
21
  onOpen,
21
22
  children,
22
23
  className,
@@ -76,6 +77,11 @@ const Modal = ({ ref, ...props }: ModalProps) => {
76
77
  <dialog
77
78
  ref={mergeRefs([dialogRef, ref])}
78
79
  onCancel={close}
80
+ onKeyDown={event => {
81
+ if (preventEscapeKey && event.key === "Escape") {
82
+ event.preventDefault();
83
+ }
84
+ }}
79
85
  className={modalClasses}
80
86
  aria-labelledby={titleId}
81
87
  {...rest}
@@ -5,6 +5,7 @@ export interface ModalProps extends RefAttributes<ModalElementType> {
5
5
  isOpen: boolean;
6
6
  onOpen?: () => void;
7
7
  onClose?: () => void;
8
+ preventEscapeKey?: boolean;
8
9
  children?: ReactNode;
9
10
  className?: string;
10
11
  closeLabel?: string;
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/components/Modal/Modal.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useDialog } from \"../../hooks\";\nimport { mergeRefs } from \"../../utils\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalContext } from \"./ModalContext\";\nimport type { ModalProps } from \"./types\";\nimport \"./Modal.css\";\n\nexport type ModalElementType = HTMLDialogElement;\n\nconst TRANSITION_CSS_VARIABLE = \"--modal-transition-duration\";\n\nconst Modal = ({ ref, ...props }: ModalProps) => {\n const {\n isOpen,\n onClose,\n onOpen,\n children,\n className,\n closeLabel,\n isFullScreen,\n animation,\n ...rest\n } = props;\n const [shouldTransition, setShouldTransition] = useState(false);\n\n useEffect(() => {\n setShouldTransition(supportsDialog());\n }, []);\n\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const { close } = useDialog({\n ref: dialogRef,\n isOpen,\n onOpen,\n onClose,\n transition: {\n isEnabled: !!animation,\n CSSVariable: TRANSITION_CSS_VARIABLE,\n },\n });\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius-modal\",\n {\n \"--no-dialog-support\": !shouldTransition, // This class is used to correctly position modal in x/y middle on iOS <= 15.2\n \"--should-transition\": shouldTransition && animation,\n \"--slide-up\": animation === \"slideUp\",\n \"--fade\": animation === \"fade\",\n \"--is-fullscreen\": isFullScreen,\n },\n className,\n );\n\n const [titleId, setTitleId] = useState<string | undefined>(undefined);\n\n const handleSetTitleId = useCallback((id: string) => {\n setTitleId(id);\n }, []);\n\n const contextValue = useMemo(\n () => ({\n onClose: close,\n closeLabel,\n titleId,\n setTitleId: handleSetTitleId,\n }),\n [close, closeLabel, titleId, handleSetTitleId],\n );\n\n return (\n <dialog\n ref={mergeRefs([dialogRef, ref])}\n onCancel={close}\n className={modalClasses}\n aria-labelledby={titleId}\n {...rest}\n >\n <ModalContext.Provider value={contextValue}>\n {children}\n </ModalContext.Provider>\n </dialog>\n );\n};\n\nModal.displayName = \"Modal\";\nexport { Modal };\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAEA,OAAO,gBAAgB;AACvB,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAMlE,OAAO;AAyED;AArEN,IAAM,0BAA0B;AAEhC,IAAM,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,MAAkB;AAC/C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,KAAK;AAE9D,YAAU,MAAM;AACd,wBAAoB,eAAe,CAAC;AAAA,EACtC,GAAG,CAAC,CAAC;AAEL,QAAM,YAAY,OAAiC,IAAI;AACvD,QAAM,EAAE,MAAM,IAAI,UAAU;AAAA,IAC1B,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,MACV,WAAW,CAAC,CAAC;AAAA,MACb,aAAa;AAAA,IACf;AAAA,EACF,CAAC;AAED,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,MACE,uBAAuB,CAAC;AAAA;AAAA,MACxB,uBAAuB,oBAAoB;AAAA,MAC3C,cAAc,cAAc;AAAA,MAC5B,UAAU,cAAc;AAAA,MACxB,mBAAmB;AAAA,IACrB;AAAA,IACA;AAAA,EACF;AAEA,QAAM,CAAC,SAAS,UAAU,IAAI,SAA6B,MAAS;AAEpE,QAAM,mBAAmB,YAAY,CAAC,OAAe;AACnD,eAAW,EAAE;AAAA,EACf,GAAG,CAAC,CAAC;AAEL,QAAM,eAAe;AAAA,IACnB,OAAO;AAAA,MACL,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA,YAAY;AAAA,IACd;AAAA,IACA,CAAC,OAAO,YAAY,SAAS,gBAAgB;AAAA,EAC/C;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK,UAAU,CAAC,WAAW,GAAG,CAAC;AAAA,MAC/B,UAAU;AAAA,MACV,WAAW;AAAA,MACX,mBAAiB;AAAA,MAChB,GAAG;AAAA,MAEJ,8BAAC,aAAa,UAAb,EAAsB,OAAO,cAC3B,UACH;AAAA;AAAA,EACF;AAEJ;AAEA,MAAM,cAAc;",
6
- "names": []
7
- }