@atlaskit/modal-dialog 12.0.2

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +2111 -0
  2. package/LICENSE +13 -0
  3. package/README.md +13 -0
  4. package/__perf__/default.tsx +42 -0
  5. package/__perf__/interactions.tsx +136 -0
  6. package/__perf__/scroll.tsx +98 -0
  7. package/codemods/12.0.0-lite-mode.ts +51 -0
  8. package/codemods/__tests__/12.0.0-lite-mode.test.ts +493 -0
  9. package/codemods/__tests__/handle-prop-spread.tsx +276 -0
  10. package/codemods/__tests__/inline-WidthNames-declaration.test.ts +260 -0
  11. package/codemods/__tests__/map-actions-prop.tsx +436 -0
  12. package/codemods/__tests__/map-body-from-props.test.ts +645 -0
  13. package/codemods/__tests__/map-container-from-props.test.ts +323 -0
  14. package/codemods/__tests__/map-footer-from-props.test.ts +544 -0
  15. package/codemods/__tests__/map-header-from-props.test.ts +559 -0
  16. package/codemods/__tests__/map-heading-prop.tsx +438 -0
  17. package/codemods/__tests__/remove-appearance-prop.test.ts +79 -0
  18. package/codemods/__tests__/remove-component-override-props.test.ts +153 -0
  19. package/codemods/__tests__/remove-is-chromeless.tsx +182 -0
  20. package/codemods/__tests__/rename-appearance-type.test.ts +52 -0
  21. package/codemods/__tests__/rename-inner-component-prop-types.test.ts +82 -0
  22. package/codemods/__tests__/rename-scrollBehavior-to-shouldScrollInViewport.test.ts +237 -0
  23. package/codemods/internal/constants.tsx +41 -0
  24. package/codemods/internal/utils.tsx +223 -0
  25. package/codemods/migrations/handle-prop-spread.tsx +51 -0
  26. package/codemods/migrations/inline-WidthNames-declaration.ts +92 -0
  27. package/codemods/migrations/map-actions-prop.tsx +430 -0
  28. package/codemods/migrations/map-body-from-props.ts +147 -0
  29. package/codemods/migrations/map-container-from-props.ts +72 -0
  30. package/codemods/migrations/map-footer-from-props.ts +107 -0
  31. package/codemods/migrations/map-header-from-props.ts +101 -0
  32. package/codemods/migrations/map-heading-prop.tsx +193 -0
  33. package/codemods/migrations/remove-appearance-prop.ts +27 -0
  34. package/codemods/migrations/remove-component-override-props.ts +84 -0
  35. package/codemods/migrations/remove-is-chromeless.tsx +42 -0
  36. package/codemods/migrations/rename-appearance-type.ts +9 -0
  37. package/codemods/migrations/rename-inner-component-prop-types.ts +28 -0
  38. package/codemods/migrations/rename-scrollBehavior-to-shouldScrollInViewport.ts +82 -0
  39. package/dist/cjs/hooks.js +22 -0
  40. package/dist/cjs/index.js +63 -0
  41. package/dist/cjs/internal/components/modal-dialog.js +155 -0
  42. package/dist/cjs/internal/components/positioner.js +89 -0
  43. package/dist/cjs/internal/components/scroll-container.js +138 -0
  44. package/dist/cjs/internal/constants.js +48 -0
  45. package/dist/cjs/internal/context.js +13 -0
  46. package/dist/cjs/internal/hooks/use-modal-stack.js +110 -0
  47. package/dist/cjs/internal/hooks/use-on-motion-finish.js +24 -0
  48. package/dist/cjs/internal/hooks/use-prevent-programmatic-scroll.js +55 -0
  49. package/dist/cjs/internal/hooks/use-scroll.js +20 -0
  50. package/dist/cjs/internal/utils.js +35 -0
  51. package/dist/cjs/modal-body.js +66 -0
  52. package/dist/cjs/modal-footer.js +40 -0
  53. package/dist/cjs/modal-header.js +43 -0
  54. package/dist/cjs/modal-title.js +108 -0
  55. package/dist/cjs/modal-transition.js +21 -0
  56. package/dist/cjs/modal-wrapper.js +126 -0
  57. package/dist/cjs/types.js +5 -0
  58. package/dist/cjs/version.json +5 -0
  59. package/dist/es2019/hooks.js +11 -0
  60. package/dist/es2019/index.js +7 -0
  61. package/dist/es2019/internal/components/modal-dialog.js +120 -0
  62. package/dist/es2019/internal/components/positioner.js +78 -0
  63. package/dist/es2019/internal/components/scroll-container.js +97 -0
  64. package/dist/es2019/internal/constants.js +27 -0
  65. package/dist/es2019/internal/context.js +3 -0
  66. package/dist/es2019/internal/hooks/use-modal-stack.js +85 -0
  67. package/dist/es2019/internal/hooks/use-on-motion-finish.js +17 -0
  68. package/dist/es2019/internal/hooks/use-prevent-programmatic-scroll.js +39 -0
  69. package/dist/es2019/internal/hooks/use-scroll.js +11 -0
  70. package/dist/es2019/internal/utils.js +22 -0
  71. package/dist/es2019/modal-body.js +50 -0
  72. package/dist/es2019/modal-footer.js +30 -0
  73. package/dist/es2019/modal-header.js +30 -0
  74. package/dist/es2019/modal-title.js +94 -0
  75. package/dist/es2019/modal-transition.js +10 -0
  76. package/dist/es2019/modal-wrapper.js +88 -0
  77. package/dist/es2019/types.js +1 -0
  78. package/dist/es2019/version.json +5 -0
  79. package/dist/esm/hooks.js +11 -0
  80. package/dist/esm/index.js +7 -0
  81. package/dist/esm/internal/components/modal-dialog.js +131 -0
  82. package/dist/esm/internal/components/positioner.js +76 -0
  83. package/dist/esm/internal/components/scroll-container.js +114 -0
  84. package/dist/esm/internal/constants.js +27 -0
  85. package/dist/esm/internal/context.js +3 -0
  86. package/dist/esm/internal/hooks/use-modal-stack.js +96 -0
  87. package/dist/esm/internal/hooks/use-on-motion-finish.js +16 -0
  88. package/dist/esm/internal/hooks/use-prevent-programmatic-scroll.js +44 -0
  89. package/dist/esm/internal/hooks/use-scroll.js +11 -0
  90. package/dist/esm/internal/utils.js +22 -0
  91. package/dist/esm/modal-body.js +49 -0
  92. package/dist/esm/modal-footer.js +29 -0
  93. package/dist/esm/modal-header.js +29 -0
  94. package/dist/esm/modal-title.js +93 -0
  95. package/dist/esm/modal-transition.js +10 -0
  96. package/dist/esm/modal-wrapper.js +96 -0
  97. package/dist/esm/types.js +1 -0
  98. package/dist/esm/version.json +5 -0
  99. package/dist/types/hooks.d.ts +1 -0
  100. package/dist/types/index.d.ts +8 -0
  101. package/dist/types/internal/components/modal-dialog.d.ts +3 -0
  102. package/dist/types/internal/components/positioner.d.ts +10 -0
  103. package/dist/types/internal/components/scroll-container.d.ts +20 -0
  104. package/dist/types/internal/constants.d.ts +25 -0
  105. package/dist/types/internal/context.d.ts +20 -0
  106. package/dist/types/internal/hooks/use-modal-stack.d.ts +13 -0
  107. package/dist/types/internal/hooks/use-on-motion-finish.d.ts +4 -0
  108. package/dist/types/internal/hooks/use-prevent-programmatic-scroll.d.ts +7 -0
  109. package/dist/types/internal/hooks/use-scroll.d.ts +1 -0
  110. package/dist/types/internal/utils.d.ts +3 -0
  111. package/dist/types/modal-body.d.ts +16 -0
  112. package/dist/types/modal-footer.d.ts +16 -0
  113. package/dist/types/modal-header.d.ts +16 -0
  114. package/dist/types/modal-title.d.ts +26 -0
  115. package/dist/types/modal-transition.d.ts +3 -0
  116. package/dist/types/modal-wrapper.d.ts +5 -0
  117. package/dist/types/types.d.ts +90 -0
  118. package/extract-react-types/modal-attributes.tsx +5 -0
  119. package/hooks/package.json +7 -0
  120. package/modal-body/package.json +7 -0
  121. package/modal-dialog/package.json +7 -0
  122. package/modal-footer/package.json +7 -0
  123. package/modal-header/package.json +7 -0
  124. package/modal-title/package.json +7 -0
  125. package/modal-transition/package.json +7 -0
  126. package/package.json +113 -0
  127. package/types/package.json +7 -0
@@ -0,0 +1,27 @@
1
+ import core, { ASTPath, Collection, JSXAttribute } from 'jscodeshift/src/core';
2
+
3
+ import {
4
+ getDefaultSpecifier,
5
+ getJSXAttributesByName,
6
+ } from '@atlaskit/codemod-utils';
7
+
8
+ import { APPEARANCE_PROP_NAME, PACKAGE_NAME } from '../internal/constants';
9
+
10
+ export const removeAppearanceProp = (
11
+ j: core.JSCodeshift,
12
+ source: Collection<Node>,
13
+ ) => {
14
+ const defaultSpecifier = getDefaultSpecifier(j, source, PACKAGE_NAME);
15
+
16
+ if (!defaultSpecifier) {
17
+ return;
18
+ }
19
+
20
+ source.findJSXElements(defaultSpecifier).forEach((element) => {
21
+ getJSXAttributesByName(j, element, APPEARANCE_PROP_NAME).forEach(
22
+ (attribute: ASTPath<JSXAttribute>) => {
23
+ j(attribute).remove();
24
+ },
25
+ );
26
+ });
27
+ };
@@ -0,0 +1,84 @@
1
+ import core, { ASTPath, JSXElement } from 'jscodeshift';
2
+ import { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import {
5
+ addCommentToStartOfFile,
6
+ getDefaultSpecifier,
7
+ getJSXAttributesByName,
8
+ hasJSXAttributesByName,
9
+ } from '@atlaskit/codemod-utils';
10
+
11
+ import {
12
+ BODY_PROP_NAME,
13
+ COMPONENTS_PROP_NAME,
14
+ FOOTER_PROP_NAME,
15
+ HEADER_PROP_NAME,
16
+ PACKAGE_NAME,
17
+ } from '../internal/constants';
18
+
19
+ // TODO: Double-check the link to the customization docs after DSP-536 is completed.
20
+ const comment = `
21
+ We have converted this file as best we could but you might still need
22
+ to manually complete migrating this usage of ModalDialog.
23
+
24
+ This file uses one or more of the following ModalDialog props: 'components', 'header',
25
+ 'footer', 'body'. These props have been removed as part of moving to
26
+ a compositional API.
27
+
28
+ The render props that used to be exposed by the custom component APIs are
29
+ now accessible using the 'useModal' hook instead: 'testId', 'titleId', and 'onClose'.
30
+
31
+ We are also no longer exposing 'appearance' as render prop, so this needs to be
32
+ manually passed to your custom components.
33
+
34
+ If you are using the 'container' value of 'components' to wrap ModalDialog in something
35
+ other than a 'form', you'll need to add the style 'all: inherit;' for scrolling to function.
36
+
37
+ For a complete guide on customization using the new compositional API, refer to the docs at
38
+ https://atlassian.design/components/modal-dialog/examples.
39
+ `;
40
+
41
+ export const removeComponentOverrideProps = (
42
+ j: core.JSCodeshift,
43
+ source: Collection<Node>,
44
+ ) => {
45
+ const defaultSpecifier = getDefaultSpecifier(j, source, PACKAGE_NAME);
46
+
47
+ if (!defaultSpecifier) {
48
+ return;
49
+ }
50
+
51
+ let hasAttributesToRemove;
52
+ const attributeNames = [
53
+ BODY_PROP_NAME,
54
+ COMPONENTS_PROP_NAME,
55
+ FOOTER_PROP_NAME,
56
+ HEADER_PROP_NAME,
57
+ ];
58
+
59
+ source.findJSXElements(defaultSpecifier).forEach((element) => {
60
+ hasAttributesToRemove = attributeNames.find((attributeName) =>
61
+ hasJSXAttributesByName(j, element, attributeName),
62
+ );
63
+
64
+ attributeNames.forEach((attributeName) =>
65
+ removeAttribute(j, element, attributeName),
66
+ );
67
+ });
68
+
69
+ if (hasAttributesToRemove) {
70
+ addCommentToStartOfFile({ j, base: source, message: comment });
71
+ }
72
+ };
73
+
74
+ const removeAttribute = (
75
+ j: core.JSCodeshift,
76
+ element: ASTPath<JSXElement>,
77
+ attributeName: string,
78
+ ) => {
79
+ getJSXAttributesByName(j, element, attributeName).forEach(
80
+ (attribute: any) => {
81
+ j(attribute).remove();
82
+ },
83
+ );
84
+ };
@@ -0,0 +1,42 @@
1
+ import core, { Collection } from 'jscodeshift/src/core';
2
+
3
+ import {
4
+ addCommentBefore,
5
+ getDefaultSpecifier,
6
+ getJSXAttributesByName,
7
+ } from '@atlaskit/codemod-utils';
8
+
9
+ import { IS_CHROMELESS_PROP_NAME, PACKAGE_NAME } from '../internal/constants';
10
+
11
+ const comment = `
12
+ ModalDialog has a new compositional API and the 'isChromeless' prop is no longer supported.
13
+ To have the functionality of the 'isChromeless' prop, you can choose to not use any of the default exports (ModalBody, ModalHeader and ModalFooter).
14
+ The only other change is that ModalDialog's children should have a border radius of 3px to match the box shadow.
15
+ For more information, check the documentation at https://atlassian.design/components/modal-dialog/examples`;
16
+
17
+ export const removeIsChromeless = (
18
+ j: core.JSCodeshift,
19
+ source: Collection<Node>,
20
+ ) => {
21
+ const defaultSpecifier = getDefaultSpecifier(j, source, PACKAGE_NAME);
22
+
23
+ if (!defaultSpecifier) {
24
+ return;
25
+ }
26
+
27
+ source.findJSXElements(defaultSpecifier).forEach((element) => {
28
+ getJSXAttributesByName(j, element, IS_CHROMELESS_PROP_NAME).forEach(
29
+ (attribute: any) => {
30
+ // if values is true then add comment before removing
31
+ if (
32
+ attribute.node.value === null ||
33
+ (attribute.node.value.expression &&
34
+ attribute.node.value.expression.value !== false)
35
+ ) {
36
+ addCommentBefore(j, j(element), comment);
37
+ }
38
+ j(attribute).remove();
39
+ },
40
+ );
41
+ });
42
+ };
@@ -0,0 +1,9 @@
1
+ import { renameNamedImportWithAliasName } from '@atlaskit/codemod-utils';
2
+
3
+ import { PACKAGE_NAME } from '../internal/constants';
4
+
5
+ export const renameAppearanceType = renameNamedImportWithAliasName(
6
+ PACKAGE_NAME,
7
+ 'AppearanceType',
8
+ 'Appearance',
9
+ );
@@ -0,0 +1,28 @@
1
+ import core from 'jscodeshift';
2
+ import { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { renameNamedImportWithAliasName as createAliasImportFor } from '@atlaskit/codemod-utils';
5
+
6
+ import {
7
+ MODAL_BODY_TYPE_NAME,
8
+ MODAL_FOOTER_TYPE_NAME,
9
+ MODAL_HEADER_TYPE_NAME,
10
+ MODAL_TITLE_TYPE_NAME,
11
+ PACKAGE_NAME,
12
+ } from '../internal/constants';
13
+
14
+ export const renameInnerComponentPropTypes = (
15
+ j: core.JSCodeshift,
16
+ source: Collection<Node>,
17
+ ) => {
18
+ const aliases = [
19
+ { name: 'HeaderComponentProps', as: MODAL_HEADER_TYPE_NAME },
20
+ { name: 'TitleComponentProps', as: MODAL_TITLE_TYPE_NAME },
21
+ { name: 'BodyComponentProps', as: MODAL_BODY_TYPE_NAME },
22
+ { name: 'FooterComponentProps', as: MODAL_FOOTER_TYPE_NAME },
23
+ ];
24
+
25
+ aliases
26
+ .map(({ name, as }) => createAliasImportFor(PACKAGE_NAME, name, as))
27
+ .forEach((createAlias) => createAlias(j, source));
28
+ };
@@ -0,0 +1,82 @@
1
+ import core, {
2
+ ASTPath,
3
+ JSXAttribute,
4
+ JSXElement,
5
+ JSXExpressionContainer,
6
+ StringLiteral,
7
+ } from 'jscodeshift';
8
+ import { Collection } from 'jscodeshift/src/Collection';
9
+
10
+ import {
11
+ getDefaultSpecifier,
12
+ getJSXAttributesByName,
13
+ } from '@atlaskit/codemod-utils';
14
+
15
+ import { PACKAGE_NAME } from '../internal/constants';
16
+
17
+ const fromProp = 'scrollBehavior';
18
+ const toProp = 'shouldScrollInViewport';
19
+
20
+ export const renameScrollBehaviorToShouldScrollInViewport = (
21
+ j: core.JSCodeshift,
22
+ source: Collection<Node>,
23
+ ) => {
24
+ const defaultSpecifier = getDefaultSpecifier(j, source, PACKAGE_NAME);
25
+
26
+ if (!defaultSpecifier) {
27
+ return;
28
+ }
29
+
30
+ const convertToBooleanProp = (
31
+ attribute: ASTPath<JSXAttribute>,
32
+ value: StringLiteral,
33
+ ) => {
34
+ if (value.value === 'outside') {
35
+ // scrollBehavior="outside" -> shouldScrollInViewport
36
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(toProp), null));
37
+ } else {
38
+ // scrollBehavior="inside" and scrollBehavior="inside-wide" -> removed
39
+ j(attribute).remove();
40
+ }
41
+ };
42
+
43
+ source
44
+ .findJSXElements(defaultSpecifier)
45
+ .forEach((element: ASTPath<JSXElement>) => {
46
+ getJSXAttributesByName(j, element, fromProp).forEach(
47
+ (attribute: ASTPath<JSXAttribute>) => {
48
+ const { value } = attribute.node;
49
+
50
+ if (!value) {
51
+ return;
52
+ }
53
+
54
+ if (value.type === 'StringLiteral') {
55
+ convertToBooleanProp(attribute, value);
56
+ } else if (value.type === 'JSXExpressionContainer') {
57
+ const expContainer = value as JSXExpressionContainer;
58
+ if (expContainer.expression.type === 'StringLiteral') {
59
+ convertToBooleanProp(
60
+ attribute,
61
+ value.expression as StringLiteral,
62
+ );
63
+ } else if (expContainer.expression.type !== 'JSXEmptyExpression') {
64
+ // scrollBehavior={scrollBehavior} -> shouldScrollInViewport={scrollBehavior === 'outside'}
65
+ j(attribute).replaceWith(
66
+ j.jsxAttribute(
67
+ j.jsxIdentifier(toProp),
68
+ j.jsxExpressionContainer(
69
+ j.binaryExpression(
70
+ '===',
71
+ expContainer.expression,
72
+ j.stringLiteral('outside'),
73
+ ),
74
+ ),
75
+ ),
76
+ );
77
+ }
78
+ }
79
+ },
80
+ );
81
+ });
82
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useModal = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _context = require("./internal/context");
11
+
12
+ var useModal = function useModal() {
13
+ var modalContext = (0, _react.useContext)(_context.ModalContext);
14
+
15
+ if (modalContext == null) {
16
+ throw Error('@atlaskit/modal-dialog: Modal context unavailable – this component needs to be a child of ModalDialog.');
17
+ }
18
+
19
+ return modalContext;
20
+ };
21
+
22
+ exports.useModal = useModal;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "default", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _modalWrapper.default;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "ModalTransition", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _modalTransition.default;
18
+ }
19
+ });
20
+ Object.defineProperty(exports, "ModalHeader", {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _modalHeader.default;
24
+ }
25
+ });
26
+ Object.defineProperty(exports, "ModalTitle", {
27
+ enumerable: true,
28
+ get: function get() {
29
+ return _modalTitle.default;
30
+ }
31
+ });
32
+ Object.defineProperty(exports, "ModalBody", {
33
+ enumerable: true,
34
+ get: function get() {
35
+ return _modalBody.default;
36
+ }
37
+ });
38
+ Object.defineProperty(exports, "ModalFooter", {
39
+ enumerable: true,
40
+ get: function get() {
41
+ return _modalFooter.default;
42
+ }
43
+ });
44
+ Object.defineProperty(exports, "useModal", {
45
+ enumerable: true,
46
+ get: function get() {
47
+ return _hooks.useModal;
48
+ }
49
+ });
50
+
51
+ var _modalWrapper = _interopRequireDefault(require("./modal-wrapper"));
52
+
53
+ var _modalTransition = _interopRequireDefault(require("./modal-transition"));
54
+
55
+ var _modalHeader = _interopRequireDefault(require("./modal-header"));
56
+
57
+ var _modalTitle = _interopRequireDefault(require("./modal-title"));
58
+
59
+ var _modalBody = _interopRequireDefault(require("./modal-body"));
60
+
61
+ var _modalFooter = _interopRequireDefault(require("./modal-footer"));
62
+
63
+ var _hooks = require("./hooks");
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
14
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
+
16
+ var _react = require("react");
17
+
18
+ var _core = require("@emotion/core");
19
+
20
+ var _reactUid = require("react-uid");
21
+
22
+ var _mergeRefs = _interopRequireDefault(require("@atlaskit/ds-lib/merge-refs"));
23
+
24
+ var _useAutoFocus = _interopRequireDefault(require("@atlaskit/ds-lib/use-auto-focus"));
25
+
26
+ var _fadeIn = _interopRequireDefault(require("@atlaskit/motion/fade-in"));
27
+
28
+ var _colors = require("@atlaskit/theme/colors");
29
+
30
+ var _constants = require("../constants");
31
+
32
+ var _context = require("../context");
33
+
34
+ var _useOnMotionFinish3 = _interopRequireDefault(require("../hooks/use-on-motion-finish"));
35
+
36
+ var _utils = require("../utils");
37
+
38
+ var _positioner = _interopRequireDefault(require("./positioner"));
39
+
40
+ /** @jsx jsx */
41
+ var dialogStyles = (0, _core.css)({
42
+ display: 'flex',
43
+ width: '100%',
44
+ maxWidth: '100vw',
45
+ height: '100%',
46
+ minHeight: 0,
47
+ maxHeight: '100vh',
48
+ flex: '1 1 auto',
49
+ flexDirection: 'column',
50
+ backgroundColor: _colors.N0,
51
+ color: _constants.textColor,
52
+ pointerEvents: 'auto',
53
+ '@media (min-width: 480px)': {
54
+ width: 'var(--modal-dialog-width)',
55
+ maxWidth: 'inherit',
56
+ marginRight: 'inherit',
57
+ marginLeft: 'inherit',
58
+ borderRadius: _constants.borderRadius,
59
+ boxShadow: "0 0 0 1px ".concat(_colors.N30A, ", 0 2px 1px ").concat(_colors.N30A, ", 0 0 20px -6px ").concat(_colors.N60A)
60
+ },
61
+
62
+ /**
63
+ * This is to support scrolling if the modal's children are wrapped in
64
+ * a form.
65
+ */
66
+ // eslint-disable-next-line @repo/internal/styles/no-nested-styles
67
+ '& > form:only-child': {
68
+ display: 'inherit',
69
+ maxHeight: 'inherit',
70
+ flexDirection: 'inherit'
71
+ }
72
+ });
73
+ var viewportScrollStyles = (0, _core.css)({
74
+ /**
75
+ * This ensures that the element fills the viewport on mobile
76
+ * while also allowing it to overflow if its height is larger than
77
+ * the viewport.
78
+ */
79
+ minHeight: '100vh',
80
+ maxHeight: 'none',
81
+ '@media (min-width: 480px)': {
82
+ minHeight: 'var(--modal-dialog-height)'
83
+ }
84
+ });
85
+ var bodyScrollStyles = (0, _core.css)({
86
+ '@media (min-width: 480px)': {
87
+ height: 'var(--modal-dialog-height)',
88
+ maxHeight: 'inherit'
89
+ }
90
+ });
91
+
92
+ var ModalDialog = function ModalDialog(props) {
93
+ var _props$width = props.width,
94
+ width = _props$width === void 0 ? 'medium' : _props$width,
95
+ _props$shouldScrollIn = props.shouldScrollInViewport,
96
+ shouldScrollInViewport = _props$shouldScrollIn === void 0 ? false : _props$shouldScrollIn,
97
+ autoFocus = props.autoFocus,
98
+ stackIndex = props.stackIndex,
99
+ onClose = props.onClose,
100
+ onCloseComplete = props.onCloseComplete,
101
+ onOpenComplete = props.onOpenComplete,
102
+ height = props.height,
103
+ children = props.children,
104
+ testId = props.testId;
105
+ var id = (0, _reactUid.useUID)();
106
+ var titleId = "modal-dialog-title-".concat(id);
107
+ (0, _useAutoFocus.default)((0, _typeof2.default)(autoFocus) === 'object' ? autoFocus : undefined, // When a user supplies a ref to focus we enable this hook
108
+ (0, _typeof2.default)(autoFocus) === 'object');
109
+
110
+ var _useOnMotionFinish = (0, _useOnMotionFinish3.default)({
111
+ onOpenComplete: onOpenComplete,
112
+ onCloseComplete: onCloseComplete
113
+ }),
114
+ _useOnMotionFinish2 = (0, _slicedToArray2.default)(_useOnMotionFinish, 2),
115
+ motionRef = _useOnMotionFinish2[0],
116
+ onMotionFinish = _useOnMotionFinish2[1];
117
+
118
+ var modalDialogContext = (0, _react.useMemo)(function () {
119
+ return {
120
+ testId: testId,
121
+ titleId: titleId,
122
+ onClose: onClose
123
+ };
124
+ }, [testId, titleId, onClose]);
125
+ return (0, _core.jsx)(_positioner.default, {
126
+ stackIndex: stackIndex,
127
+ shouldScrollInViewport: shouldScrollInViewport,
128
+ testId: testId
129
+ }, (0, _core.jsx)(_context.ModalContext.Provider, {
130
+ value: modalDialogContext
131
+ }, (0, _core.jsx)(_context.ScrollContext.Provider, {
132
+ value: shouldScrollInViewport
133
+ }, (0, _core.jsx)(_fadeIn.default, {
134
+ entranceDirection: "bottom",
135
+ onFinish: onMotionFinish
136
+ }, function (bottomFadeInProps) {
137
+ return (0, _core.jsx)("section", (0, _extends2.default)({}, bottomFadeInProps, {
138
+ ref: (0, _mergeRefs.default)([bottomFadeInProps.ref, motionRef]),
139
+ style: {
140
+ '--modal-dialog-width': (0, _utils.dialogWidth)(width),
141
+ '--modal-dialog-height': (0, _utils.dialogHeight)(height)
142
+ },
143
+ css: [dialogStyles, shouldScrollInViewport ? viewportScrollStyles : bodyScrollStyles],
144
+ role: "dialog",
145
+ "aria-labelledby": titleId,
146
+ "data-testid": testId,
147
+ "data-modal-stack": stackIndex,
148
+ tabIndex: -1,
149
+ "aria-modal": true
150
+ }), children);
151
+ }))));
152
+ };
153
+
154
+ var _default = ModalDialog;
155
+ exports.default = _default;