@cypress-design/react-modal 0.2.0 → 0.3.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.
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
2
2
  $ rollup -c ./rollup.config.mjs
3
3
  
4
4
  ./index.ts → ./dist/index.umd.js, ./dist/index.es.mjs...
5
- created ./dist/index.umd.js, ./dist/index.es.mjs in 16.7s
5
+ created ./dist/index.umd.js, ./dist/index.es.mjs in 16.2s
6
6
  $ tsc --project ./tsconfig.build.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @cypress-design/react-modal
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#351](https://github.com/cypress-io/cypress-design/pull/351) [`98322c8`](https://github.com/cypress-io/cypress-design/commit/98322c8ca62a62f3462457704a0d3a06beb84be2) Thanks [@elevatebart](https://github.com/elevatebart)! - refactor: build dialog using dialog html
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`98322c8`](https://github.com/cypress-io/cypress-design/commit/98322c8ca62a62f3462457704a0d3a06beb84be2)]:
12
+ - @cypress-design/constants-modal@0.3.0
13
+
14
+ ## 0.2.1
15
+
16
+ ### Patch Changes
17
+
18
+ - [#288](https://github.com/cypress-io/cypress-design/pull/288) [`2c53ea8`](https://github.com/cypress-io/cypress-design/commit/2c53ea8ffa13baaf299bd3168de819166ad071ce) Thanks [@elevatebart](https://github.com/elevatebart)! - fix accessibility
19
+
3
20
  ## 0.2.0
4
21
 
5
22
  ### Minor Changes
package/Modal.tsx CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  IconActionDelete,
7
7
  } from '@cypress-design/react-icon'
8
8
  import {
9
- ClassBackDrop,
10
9
  ClassCloseButton,
11
10
  ClassContent,
12
11
  ClassHelpLink,
@@ -14,7 +13,6 @@ import {
14
13
  ClassModal,
15
14
  ClassModalFullscreenDimensions,
16
15
  ClassModalStandardDimensions,
17
- ClassModalContainer,
18
16
  ClassTitle,
19
17
  ClassTitleBox,
20
18
  disableBodyScroll,
@@ -38,74 +36,89 @@ export const Modal: React.FC<ModalProps> = ({
38
36
  children,
39
37
  fullscreen = false,
40
38
  }) => {
39
+ const dialogRef = React.useRef<HTMLDialogElement>(null)
40
+
41
41
  React.useEffect(() => {
42
42
  if (show) {
43
43
  disableBodyScroll()
44
+ dialogRef.current?.showModal()
44
45
  } else {
46
+ dialogRef.current?.close()
45
47
  freeBodyScroll()
46
48
  }
47
- }, [show])
49
+ }, [show, onClose])
48
50
 
49
51
  React.useEffect(
50
52
  () => () => {
51
53
  freeBodyScroll()
52
54
  },
53
- []
55
+ [],
56
+ )
57
+
58
+ const closeOnClickBackdrop = React.useCallback<
59
+ React.MouseEventHandler<HTMLDialogElement>
60
+ >(
61
+ (event) => {
62
+ const rect = dialogRef.current?.getBoundingClientRect()
63
+ if (!rect) return
64
+ const isInDialog =
65
+ rect.top <= event.clientY &&
66
+ event.clientY <= rect.top + rect.height &&
67
+ rect.left <= event.clientX &&
68
+ event.clientX <= rect.left + rect.width
69
+ if (!isInDialog) {
70
+ onClose?.()
71
+ }
72
+ },
73
+ [onClose],
54
74
  )
55
75
 
56
76
  return (
57
77
  show &&
58
78
  createPortal(
59
- <div>
60
- <div className={ClassBackDrop} onClick={() => onClose?.()}></div>
79
+ <dialog
80
+ ref={dialogRef}
81
+ className={clsx(
82
+ show ? ClassModal : null,
83
+ fullscreen
84
+ ? ClassModalFullscreenDimensions
85
+ : ClassModalStandardDimensions,
86
+ )}
87
+ onClick={closeOnClickBackdrop}
88
+ >
89
+ <div className={ClassTitleBox}>
90
+ <div id="cy_modal_label" className={ClassTitle}>
91
+ {title}
92
+ </div>
93
+ {helpLink ? <div className={ClassHelpLinkDash} /> : null}
94
+ {helpLink ? (
95
+ <a href={helpLink} className={ClassHelpLink}>
96
+ Need help
97
+ <IconActionQuestionMarkCircle
98
+ className="ml-[4px]"
99
+ stroke-color="indigo-500"
100
+ fill-color="indigo-100"
101
+ />
102
+ </a>
103
+ ) : null}
61
104
 
62
- <div
63
- className={ClassModalContainer}
64
- tabIndex={-1}
65
- aria-modal="true"
66
- role="modal"
67
- >
68
- <div
69
- className={clsx(
70
- ClassModal,
71
- fullscreen
72
- ? ClassModalFullscreenDimensions
73
- : ClassModalStandardDimensions
74
- )}
105
+ <div className="grow" />
106
+ <button
107
+ aria-label="Close"
108
+ className={ClassCloseButton}
109
+ onClick={() => onClose?.()}
75
110
  >
76
- <div className={ClassTitleBox}>
77
- <div className={ClassTitle}>{title}</div>
78
- {helpLink ? <div className={ClassHelpLinkDash} /> : null}
79
- {helpLink ? (
80
- <a href={helpLink} className={ClassHelpLink}>
81
- Need help
82
- <IconActionQuestionMarkCircle
83
- className="ml-[4px]"
84
- stroke-color="indigo-500"
85
- fill-color="indigo-100"
86
- />
87
- </a>
88
- ) : null}
89
-
90
- <div className="grow" />
91
- <button
92
- aria-label="Close"
93
- className={ClassCloseButton}
94
- onClick={() => onClose?.()}
95
- >
96
- <IconActionDelete
97
- className="children:transition-all"
98
- stroke-color="gray-400"
99
- hover-stroke-color="gray-700"
100
- interactiveColorsOnGroup
101
- />
102
- </button>
103
- </div>
104
- <div className={ClassContent}>{children}</div>
105
- </div>
111
+ <IconActionDelete
112
+ className="children:transition-all"
113
+ stroke-color="gray-400"
114
+ hover-stroke-color="gray-700"
115
+ interactiveColorsOnGroup
116
+ />
117
+ </button>
106
118
  </div>
107
- </div>,
108
- document.body
119
+ <div className={ClassContent}>{children}</div>
120
+ </dialog>,
121
+ document.body,
109
122
  )
110
123
  )
111
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.d.ts","sourceRoot":"./","sources":["Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAuB9B,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA8EtC,CAAA;AAED,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"Modal.d.ts","sourceRoot":"./","sources":["Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAqB9B,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA6FtC,CAAA;AAED,eAAe,KAAK,CAAA"}