no-frills-ui 0.0.14-alpha.1 → 0.0.14-alpha.10

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 (222) hide show
  1. package/README.md +28 -22
  2. package/dist/index.js +3419 -2768
  3. package/dist/index.js.map +1 -1
  4. package/lib-esm/components/Accordion/Accordion.d.ts +11 -16
  5. package/lib-esm/components/Accordion/Accordion.js +25 -29
  6. package/lib-esm/components/Accordion/Accordion.js.map +1 -1
  7. package/lib-esm/components/Accordion/AccordionStep.d.ts +22 -22
  8. package/lib-esm/components/Accordion/AccordionStep.js +111 -109
  9. package/lib-esm/components/Accordion/AccordionStep.js.map +1 -1
  10. package/lib-esm/components/Badge/Badge.d.ts +13 -16
  11. package/lib-esm/components/Badge/Badge.js +31 -51
  12. package/lib-esm/components/Badge/Badge.js.map +1 -1
  13. package/lib-esm/components/Button/ActionButton.d.ts +9 -5
  14. package/lib-esm/components/Button/ActionButton.js +18 -38
  15. package/lib-esm/components/Button/ActionButton.js.map +1 -1
  16. package/lib-esm/components/Button/Button.d.ts +9 -5
  17. package/lib-esm/components/Button/Button.js +18 -40
  18. package/lib-esm/components/Button/Button.js.map +1 -1
  19. package/lib-esm/components/Button/IconButton.d.ts +9 -5
  20. package/lib-esm/components/Button/IconButton.js +18 -42
  21. package/lib-esm/components/Button/IconButton.js.map +1 -1
  22. package/lib-esm/components/Button/LinkButton.d.ts +9 -5
  23. package/lib-esm/components/Button/LinkButton.js +18 -32
  24. package/lib-esm/components/Button/LinkButton.js.map +1 -1
  25. package/lib-esm/components/Button/RaisedButton.d.ts +9 -5
  26. package/lib-esm/components/Button/RaisedButton.js +18 -46
  27. package/lib-esm/components/Button/RaisedButton.js.map +1 -1
  28. package/lib-esm/components/Card/Card.d.ts +4 -6
  29. package/lib-esm/components/Card/Card.js +18 -13
  30. package/lib-esm/components/Card/Card.js.map +1 -1
  31. package/lib-esm/components/Chip/Chip.d.ts +6 -3
  32. package/lib-esm/components/Chip/Chip.js +44 -43
  33. package/lib-esm/components/Chip/Chip.js.map +1 -1
  34. package/lib-esm/components/ChipInput/ChipInput.d.ts +28 -30
  35. package/lib-esm/components/ChipInput/ChipInput.js +121 -139
  36. package/lib-esm/components/ChipInput/ChipInput.js.map +1 -1
  37. package/lib-esm/components/Dialog/AlertDialog.d.ts +11 -12
  38. package/lib-esm/components/Dialog/AlertDialog.js +44 -28
  39. package/lib-esm/components/Dialog/AlertDialog.js.map +1 -1
  40. package/lib-esm/components/Dialog/ConfirmDialog.d.ts +13 -14
  41. package/lib-esm/components/Dialog/ConfirmDialog.js +49 -33
  42. package/lib-esm/components/Dialog/ConfirmDialog.js.map +1 -1
  43. package/lib-esm/components/Dialog/Dialog.d.ts +40 -18
  44. package/lib-esm/components/Dialog/Dialog.js +125 -70
  45. package/lib-esm/components/Dialog/Dialog.js.map +1 -1
  46. package/lib-esm/components/Dialog/PromptDialog.d.ts +18 -19
  47. package/lib-esm/components/Dialog/PromptDialog.js +78 -49
  48. package/lib-esm/components/Dialog/PromptDialog.js.map +1 -1
  49. package/lib-esm/components/DragAndDrop/DragAndDrop.d.ts +43 -41
  50. package/lib-esm/components/DragAndDrop/DragAndDrop.js +104 -31
  51. package/lib-esm/components/DragAndDrop/DragAndDrop.js.map +1 -1
  52. package/lib-esm/components/DragAndDrop/DragItem.d.ts +5 -1
  53. package/lib-esm/components/DragAndDrop/DragItem.js +171 -92
  54. package/lib-esm/components/DragAndDrop/DragItem.js.map +1 -1
  55. package/lib-esm/components/DragAndDrop/types.d.ts +22 -3
  56. package/lib-esm/components/DragAndDrop/types.js +9 -6
  57. package/lib-esm/components/DragAndDrop/types.js.map +1 -1
  58. package/lib-esm/components/Drawer/Drawer.d.ts +86 -22
  59. package/lib-esm/components/Drawer/Drawer.js +176 -97
  60. package/lib-esm/components/Drawer/Drawer.js.map +1 -1
  61. package/lib-esm/components/Drawer/index.d.ts +1 -1
  62. package/lib-esm/components/Groups/Group.d.ts +5 -8
  63. package/lib-esm/components/Groups/Group.js +34 -79
  64. package/lib-esm/components/Groups/Group.js.map +1 -1
  65. package/lib-esm/components/Groups/GroupLabel.js +8 -17
  66. package/lib-esm/components/Groups/GroupLabel.js.map +1 -1
  67. package/lib-esm/components/Input/Checkbox.d.ts +12 -15
  68. package/lib-esm/components/Input/Checkbox.js +51 -118
  69. package/lib-esm/components/Input/Checkbox.js.map +1 -1
  70. package/lib-esm/components/Input/Dropdown.d.ts +11 -12
  71. package/lib-esm/components/Input/Dropdown.js +133 -52
  72. package/lib-esm/components/Input/Dropdown.js.map +1 -1
  73. package/lib-esm/components/Input/Input.d.ts +3 -3
  74. package/lib-esm/components/Input/Input.js +61 -109
  75. package/lib-esm/components/Input/Input.js.map +1 -1
  76. package/lib-esm/components/Input/Radio.d.ts +4 -8
  77. package/lib-esm/components/Input/Radio.js +35 -79
  78. package/lib-esm/components/Input/Radio.js.map +1 -1
  79. package/lib-esm/components/Input/RadioButton.d.ts +4 -8
  80. package/lib-esm/components/Input/RadioButton.js +34 -71
  81. package/lib-esm/components/Input/RadioButton.js.map +1 -1
  82. package/lib-esm/components/Input/Select.d.ts +6 -13
  83. package/lib-esm/components/Input/Select.js +75 -122
  84. package/lib-esm/components/Input/Select.js.map +1 -1
  85. package/lib-esm/components/Input/TextArea.d.ts +6 -13
  86. package/lib-esm/components/Input/TextArea.js +64 -108
  87. package/lib-esm/components/Input/TextArea.js.map +1 -1
  88. package/lib-esm/components/Input/Toggle.d.ts +4 -9
  89. package/lib-esm/components/Input/Toggle.js +31 -80
  90. package/lib-esm/components/Input/Toggle.js.map +1 -1
  91. package/lib-esm/components/Menu/Menu.d.ts +8 -6
  92. package/lib-esm/components/Menu/Menu.js +116 -31
  93. package/lib-esm/components/Menu/Menu.js.map +1 -1
  94. package/lib-esm/components/Menu/MenuContext.d.ts +11 -5
  95. package/lib-esm/components/Menu/MenuContext.js +6 -2
  96. package/lib-esm/components/Menu/MenuContext.js.map +1 -1
  97. package/lib-esm/components/Menu/MenuItem.d.ts +7 -4
  98. package/lib-esm/components/Menu/MenuItem.js +46 -47
  99. package/lib-esm/components/Menu/MenuItem.js.map +1 -1
  100. package/lib-esm/components/Modal/Modal.d.ts +75 -16
  101. package/lib-esm/components/Modal/Modal.js +150 -51
  102. package/lib-esm/components/Modal/Modal.js.map +1 -1
  103. package/lib-esm/components/Notification/Notification.d.ts +46 -39
  104. package/lib-esm/components/Notification/Notification.js +80 -87
  105. package/lib-esm/components/Notification/Notification.js.map +1 -1
  106. package/lib-esm/components/Notification/NotificationManager.d.ts +19 -5
  107. package/lib-esm/components/Notification/NotificationManager.js +177 -79
  108. package/lib-esm/components/Notification/NotificationManager.js.map +1 -1
  109. package/lib-esm/components/Notification/style.d.ts +6 -3
  110. package/lib-esm/components/Notification/style.js +64 -140
  111. package/lib-esm/components/Notification/style.js.map +1 -1
  112. package/lib-esm/components/Notification/types.d.ts +2 -0
  113. package/lib-esm/components/Notification/types.js +9 -10
  114. package/lib-esm/components/Notification/types.js.map +1 -1
  115. package/lib-esm/components/Popover/Popover.d.ts +21 -20
  116. package/lib-esm/components/Popover/Popover.js +159 -126
  117. package/lib-esm/components/Popover/Popover.js.map +1 -1
  118. package/lib-esm/components/Spinner/Spinner.d.ts +14 -12
  119. package/lib-esm/components/Spinner/Spinner.js +22 -27
  120. package/lib-esm/components/Spinner/Spinner.js.map +1 -1
  121. package/lib-esm/components/Stepper/Step.d.ts +15 -12
  122. package/lib-esm/components/Stepper/Step.js +18 -25
  123. package/lib-esm/components/Stepper/Step.js.map +1 -1
  124. package/lib-esm/components/Stepper/Stepper.d.ts +11 -17
  125. package/lib-esm/components/Stepper/Stepper.js +104 -102
  126. package/lib-esm/components/Stepper/Stepper.js.map +1 -1
  127. package/lib-esm/components/Tabs/Tab.d.ts +10 -16
  128. package/lib-esm/components/Tabs/Tab.js +9 -15
  129. package/lib-esm/components/Tabs/Tab.js.map +1 -1
  130. package/lib-esm/components/Tabs/Tabs.d.ts +11 -22
  131. package/lib-esm/components/Tabs/Tabs.js +97 -55
  132. package/lib-esm/components/Tabs/Tabs.js.map +1 -1
  133. package/lib-esm/components/Toast/Toast.d.ts +34 -7
  134. package/lib-esm/components/Toast/Toast.js +200 -109
  135. package/lib-esm/components/Toast/Toast.js.map +1 -1
  136. package/lib-esm/components/Toast/ToastStory.d.ts +21 -24
  137. package/lib-esm/components/Tooltip/Tooltip.d.ts +11 -14
  138. package/lib-esm/components/Tooltip/Tooltip.js +52 -67
  139. package/lib-esm/components/Tooltip/Tooltip.js.map +1 -1
  140. package/lib-esm/components/index.d.ts +1 -0
  141. package/lib-esm/components/index.js +43 -20
  142. package/lib-esm/components/index.js.map +1 -1
  143. package/lib-esm/icons/CheckCircle.d.ts +1 -1
  144. package/lib-esm/icons/CheckCircle.js +22 -4
  145. package/lib-esm/icons/CheckCircle.js.map +1 -1
  146. package/lib-esm/icons/Close.d.ts +1 -1
  147. package/lib-esm/icons/Close.js +22 -4
  148. package/lib-esm/icons/Close.js.map +1 -1
  149. package/lib-esm/icons/DragIndicator.d.ts +1 -1
  150. package/lib-esm/icons/DragIndicator.js +22 -4
  151. package/lib-esm/icons/DragIndicator.js.map +1 -1
  152. package/lib-esm/icons/ErrorOutline.d.ts +1 -1
  153. package/lib-esm/icons/ErrorOutline.js +16 -4
  154. package/lib-esm/icons/ErrorOutline.js.map +1 -1
  155. package/lib-esm/icons/ExpandMore.d.ts +1 -1
  156. package/lib-esm/icons/ExpandMore.js +22 -4
  157. package/lib-esm/icons/ExpandMore.js.map +1 -1
  158. package/lib-esm/icons/FiberManualRecord.d.ts +1 -1
  159. package/lib-esm/icons/FiberManualRecord.js +24 -4
  160. package/lib-esm/icons/FiberManualRecord.js.map +1 -1
  161. package/lib-esm/icons/Info.d.ts +1 -1
  162. package/lib-esm/icons/Info.js +22 -4
  163. package/lib-esm/icons/Info.js.map +1 -1
  164. package/lib-esm/icons/ReportProblem.d.ts +1 -1
  165. package/lib-esm/icons/ReportProblem.js +22 -4
  166. package/lib-esm/icons/ReportProblem.js.map +1 -1
  167. package/lib-esm/shared/LayerManager.d.ts +34 -4
  168. package/lib-esm/shared/LayerManager.js +248 -114
  169. package/lib-esm/shared/LayerManager.js.map +1 -1
  170. package/lib-esm/shared/constants.d.ts +58 -27
  171. package/lib-esm/shared/constants.js +62 -26
  172. package/lib-esm/shared/constants.js.map +1 -1
  173. package/lib-esm/shared/styles.d.ts +1 -1
  174. package/lib-esm/shared/styles.js +21 -24
  175. package/lib-esm/shared/styles.js.map +1 -1
  176. package/package.json +130 -74
  177. package/lib-esm/components/Accordion/index.js +0 -3
  178. package/lib-esm/components/Accordion/index.js.map +0 -1
  179. package/lib-esm/components/Badge/index.js +0 -2
  180. package/lib-esm/components/Badge/index.js.map +0 -1
  181. package/lib-esm/components/Button/index.js +0 -6
  182. package/lib-esm/components/Button/index.js.map +0 -1
  183. package/lib-esm/components/Card/index.js +0 -3
  184. package/lib-esm/components/Card/index.js.map +0 -1
  185. package/lib-esm/components/Chip/index.js +0 -2
  186. package/lib-esm/components/Chip/index.js.map +0 -1
  187. package/lib-esm/components/ChipInput/index.js +0 -2
  188. package/lib-esm/components/ChipInput/index.js.map +0 -1
  189. package/lib-esm/components/Dialog/index.js +0 -5
  190. package/lib-esm/components/Dialog/index.js.map +0 -1
  191. package/lib-esm/components/DragAndDrop/index.js +0 -3
  192. package/lib-esm/components/DragAndDrop/index.js.map +0 -1
  193. package/lib-esm/components/Drawer/index.js +0 -2
  194. package/lib-esm/components/Drawer/index.js.map +0 -1
  195. package/lib-esm/components/Groups/index.js +0 -3
  196. package/lib-esm/components/Groups/index.js.map +0 -1
  197. package/lib-esm/components/Input/index.js +0 -9
  198. package/lib-esm/components/Input/index.js.map +0 -1
  199. package/lib-esm/components/Menu/index.js +0 -3
  200. package/lib-esm/components/Menu/index.js.map +0 -1
  201. package/lib-esm/components/Modal/index.js +0 -2
  202. package/lib-esm/components/Modal/index.js.map +0 -1
  203. package/lib-esm/components/Notification/index.js +0 -3
  204. package/lib-esm/components/Notification/index.js.map +0 -1
  205. package/lib-esm/components/Popover/index.js +0 -2
  206. package/lib-esm/components/Popover/index.js.map +0 -1
  207. package/lib-esm/components/Spinner/index.js +0 -2
  208. package/lib-esm/components/Spinner/index.js.map +0 -1
  209. package/lib-esm/components/Stepper/index.js +0 -4
  210. package/lib-esm/components/Stepper/index.js.map +0 -1
  211. package/lib-esm/components/Tabs/index.js +0 -3
  212. package/lib-esm/components/Tabs/index.js.map +0 -1
  213. package/lib-esm/components/Toast/ToastStory.js +0 -35
  214. package/lib-esm/components/Toast/ToastStory.js.map +0 -1
  215. package/lib-esm/components/Toast/index.js +0 -2
  216. package/lib-esm/components/Toast/index.js.map +0 -1
  217. package/lib-esm/components/Tooltip/index.js +0 -2
  218. package/lib-esm/components/Tooltip/index.js.map +0 -1
  219. package/lib-esm/icons/index.js +0 -9
  220. package/lib-esm/icons/index.js.map +0 -1
  221. package/lib-esm/index.js +0 -2
  222. package/lib-esm/index.js.map +0 -1
@@ -1,34 +1,93 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  export { Header as ModalHeader, Body as ModalBody, Footer as ModalFooter, } from '../../shared/styles';
4
- type ModalProps = PropTypes.InferProps<typeof Modal.propTypes>;
3
+ type ModalProps = {
4
+ /** Opens the modal */
5
+ open: boolean;
6
+ /** Closes the modal on esc */
7
+ closeOnEsc?: boolean;
8
+ /** Closes the modal on overlay click */
9
+ closeOnOverlayClick?: boolean;
10
+ /** Call back function called when the modal closes. */
11
+ onClose?: () => void;
12
+ /** Ref forwarded to the modal container */
13
+ forwardRef?: React.Ref<HTMLDivElement>;
14
+ } & React.HTMLAttributes<HTMLDivElement>;
5
15
  interface ModalState {
6
16
  open: boolean;
7
17
  }
18
+ /**
19
+ * Modal component
20
+ *
21
+ * A dialog window that sits on top of the main application content.
22
+ * It disrupts the user's workflow to demand attention for a critical task or decision.
23
+ *
24
+ * Accessibility:
25
+ * - Implements ARIA `role="dialog"` and `aria-modal="true"`.
26
+ * - Traps focus effectively within the modal while open.
27
+ * - Restores focus to the triggering element upon closure.
28
+ * - Supports closing via ESC key and overlay click.
29
+ */
8
30
  export default class Modal extends React.Component<React.PropsWithChildren<ModalProps>, ModalState> {
9
31
  state: {
10
32
  open: boolean;
11
33
  };
12
- static propTypes: {
13
- /** Opens the modal */
14
- open: PropTypes.Validator<boolean>;
15
- /** Closes the modal on esc */
16
- closeOnEsc: PropTypes.Requireable<boolean>;
17
- /** Closes the modal on overlay click */
18
- closeOnOverlayClick: PropTypes.Requireable<boolean>;
19
- /** Call back function called when the modal closes. */
20
- onClose: PropTypes.Requireable<(...args: any[]) => any>;
21
- };
22
34
  static defaultProps: {
23
35
  closeOnEsc: boolean;
24
36
  closeOnOverlayClick: boolean;
25
37
  };
38
+ /**
39
+ * Syncs state with props.
40
+ */
26
41
  static getDerivedStateFromProps(props: ModalProps): {
27
42
  open: boolean;
28
- };
29
- private layer;
30
- private closeCallback;
43
+ } | null;
44
+ private layer?;
45
+ private closeCallback?;
46
+ /**
47
+ * Internal close handler.
48
+ * Restores focus and calls the external onClose callback.
49
+ */
31
50
  private onClose;
51
+ private lastFocusedElement;
52
+ private modalRef;
53
+ /**
54
+ * Retrieves all focusable elements within the modal.
55
+ */
56
+ private getFocusableElements;
57
+ /**
58
+ * Handles keydown events to implement the focus trap.
59
+ * Traps Tab and Shift+Tab within the modal.
60
+ */
61
+ private handleKeyDown;
62
+ /**
63
+ * Lifecycle method to save the currently focused element when the modal mounts while open.
64
+ */
65
+ componentDidMount(): void;
66
+ /**
67
+ * Lifecycle method to restore focus when the modal unmounts.
68
+ */
69
+ componentWillUnmount(): void;
70
+ /**
71
+ * Restores focus to the element that was focused before the modal opened.
72
+ */
73
+ private restoreFocus;
74
+ /**
75
+ * Callback ref to capture the Modal DOM element.
76
+ * Triggers initial focus setting when the element mounts.
77
+ */
78
+ private setModalRef;
79
+ /**
80
+ * Sets initial focus within the modal.
81
+ * Tries to focus the header (first child) first, then the first interactive element, or falls back to the container.
82
+ */
83
+ private setInitialFocus;
84
+ /**
85
+ * Lifecycle method to handle Modal updates.
86
+ * Manages opening/closing logic via LayerManager and focus preservation.
87
+ */
32
88
  getSnapshotBeforeUpdate(prevProps: ModalProps): void;
33
- render(): import("@emotion/react/jsx-runtime").JSX.Element;
89
+ /**
90
+ * Renders the Modal component via the LayerManager portal.
91
+ */
92
+ render(): import("@emotion/react/jsx-runtime").JSX.Element | null;
34
93
  }
@@ -1,49 +1,51 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
1
+ import { jsx } from '@emotion/react/jsx-runtime';
13
2
  import React from 'react';
14
- import PropTypes from 'prop-types';
15
- import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';
16
- export { Header as ModalHeader, Body as ModalBody, Footer as ModalFooter, } from '../../shared/styles';
17
- import { DialogContainer as ModalContainer } from '../Dialog/Dialog';
3
+ import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager.js';
4
+ import { DialogContainer } from '../Dialog/Dialog.js';
5
+
18
6
  class Modal extends React.Component {
19
- constructor() {
20
- super(...arguments);
21
- this.state = {
22
- open: false,
23
- };
24
- this.onClose = () => {
25
- this.setState({
26
- open: false,
27
- });
28
- this.props.onClose && this.props.onClose();
29
- this.closeCallback = null;
30
- this.layer = null;
31
- };
32
- }
33
- static getDerivedStateFromProps(props) {
7
+ /**
8
+ * Syncs state with props.
9
+ */ static getDerivedStateFromProps(props) {
34
10
  if (props.open) {
35
11
  return {
36
- open: true,
12
+ open: true
37
13
  };
38
14
  }
39
15
  return null;
40
16
  }
41
- getSnapshotBeforeUpdate(prevProps) {
42
- const _a = this.props, { open, closeOnEsc, closeOnOverlayClick, children } = _a, rest = __rest(_a, ["open", "closeOnEsc", "closeOnOverlayClick", "children"]);
17
+ /**
18
+ * Lifecycle method to save the currently focused element when the modal mounts while open.
19
+ */ componentDidMount() {
20
+ if (this.props.open) {
21
+ this.lastFocusedElement = document.activeElement;
22
+ }
23
+ }
24
+ /**
25
+ * Lifecycle method to restore focus when the modal unmounts.
26
+ */ componentWillUnmount() {
27
+ if (this.props.open) {
28
+ this.restoreFocus();
29
+ }
30
+ // Clean up layer references
31
+ if (this.closeCallback) {
32
+ this.closeCallback();
33
+ this.closeCallback = undefined;
34
+ }
35
+ this.layer = undefined;
36
+ }
37
+ /**
38
+ * Lifecycle method to handle Modal updates.
39
+ * Manages opening/closing logic via LayerManager and focus preservation.
40
+ */ getSnapshotBeforeUpdate(prevProps) {
41
+ const { open, closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;
43
42
  if (prevProps.open && !open) {
44
- this.closeCallback && this.closeCallback();
43
+ this.closeCallback?.();
44
+ this.restoreFocus();
45
45
  }
46
46
  if (!prevProps.open && open) {
47
+ // Save current focus
48
+ this.lastFocusedElement = document.activeElement;
47
49
  this.layer = LayerManager.renderLayer({
48
50
  overlay: true,
49
51
  exitDelay: 300,
@@ -51,33 +53,130 @@ class Modal extends React.Component {
51
53
  closeCallback: this.onClose,
52
54
  closeOnEsc: closeOnEsc,
53
55
  closeOnOverlayClick: closeOnOverlayClick,
54
- component: (_jsx(ModalContainer, Object.assign({}, rest, { onClick: e => e.stopPropagation(), elevated: true, children: children })))
56
+ component: /*#__PURE__*/ jsx(DialogContainer, {
57
+ ...rest,
58
+ ref: this.setModalRef,
59
+ role: "dialog",
60
+ "aria-modal": "true",
61
+ tabIndex: -1,
62
+ onKeyDown: this.handleKeyDown,
63
+ onClick: (e)=>e.stopPropagation(),
64
+ elevated: true,
65
+ children: children
66
+ })
55
67
  });
56
68
  this.closeCallback = this.layer[1];
57
69
  this.forceUpdate();
58
70
  }
59
71
  }
60
- render() {
72
+ /**
73
+ * Renders the Modal component via the LayerManager portal.
74
+ */ render() {
61
75
  if (this.state.open && this.layer) {
62
76
  const [Component] = this.layer;
63
- return _jsx(Component, {});
77
+ return /*#__PURE__*/ jsx(Component, {});
64
78
  }
65
79
  return null;
66
80
  }
81
+ constructor(...args){
82
+ super(...args), this.state = {
83
+ open: false
84
+ }, /**
85
+ * Internal close handler.
86
+ * Restores focus and calls the external onClose callback.
87
+ */ this.onClose = ()=>{
88
+ this.restoreFocus();
89
+ this.setState({
90
+ open: false
91
+ });
92
+ this.props.onClose?.();
93
+ this.closeCallback = undefined;
94
+ this.layer = undefined;
95
+ }, this.lastFocusedElement = null, this.modalRef = /*#__PURE__*/ React.createRef(), /**
96
+ * Retrieves all focusable elements within the modal.
97
+ */ this.getFocusableElements = ()=>{
98
+ if (!this.modalRef.current) return [];
99
+ return Array.from(this.modalRef.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'));
100
+ }, /**
101
+ * Handles keydown events to implement the focus trap.
102
+ * Traps Tab and Shift+Tab within the modal.
103
+ */ this.handleKeyDown = (e)=>{
104
+ if (e.key === 'Tab') {
105
+ const focusableElements = this.getFocusableElements();
106
+ if (focusableElements.length === 0) return;
107
+ const firstElement = focusableElements[0];
108
+ const lastElement = focusableElements[focusableElements.length - 1];
109
+ if (e.shiftKey) {
110
+ if (document.activeElement === firstElement) {
111
+ lastElement.focus();
112
+ e.preventDefault();
113
+ }
114
+ } else {
115
+ if (document.activeElement === lastElement) {
116
+ firstElement.focus();
117
+ e.preventDefault();
118
+ }
119
+ }
120
+ }
121
+ }, /**
122
+ * Restores focus to the element that was focused before the modal opened.
123
+ */ this.restoreFocus = ()=>{
124
+ if (this.lastFocusedElement) {
125
+ // Check if the element is still in the document
126
+ const elementToBeFocused = this.lastFocusedElement;
127
+ this.lastFocusedElement = null;
128
+ setTimeout(()=>{
129
+ if (document.body.contains(elementToBeFocused)) {
130
+ elementToBeFocused.focus();
131
+ }
132
+ }, 100);
133
+ }
134
+ }, /**
135
+ * Callback ref to capture the Modal DOM element.
136
+ * Triggers initial focus setting when the element mounts.
137
+ */ this.setModalRef = (node)=>{
138
+ // Update ref
139
+ this.modalRef.current = node;
140
+ if (node) {
141
+ // Set initial focus when the node is mounted
142
+ this.setInitialFocus(node);
143
+ }
144
+ if (this.props.forwardRef) {
145
+ try {
146
+ this.props.forwardRef.current = node;
147
+ } catch (e) {
148
+ console.warn(e);
149
+ }
150
+ }
151
+ }, /**
152
+ * Sets initial focus within the modal.
153
+ * Tries to focus the header (first child) first, then the first interactive element, or falls back to the container.
154
+ */ this.setInitialFocus = (root)=>{
155
+ // Try to find the header (assumed to be the first child)
156
+ const firstChild = root.firstElementChild;
157
+ if (firstChild) {
158
+ // Ensure it's focusable
159
+ if (firstChild.getAttribute('tabindex') === null) {
160
+ firstChild.setAttribute('tabindex', '-1');
161
+ }
162
+ firstChild.focus();
163
+ return;
164
+ }
165
+ // Fallback to focusable elements
166
+ const focusableElements = this.getFocusableElements();
167
+ if (focusableElements.length > 0) {
168
+ focusableElements[0].focus();
169
+ } else {
170
+ // Fallback to container
171
+ root.focus();
172
+ }
173
+ };
174
+ }
67
175
  }
68
- Modal.propTypes = {
69
- /** Opens the modal */
70
- open: PropTypes.bool.isRequired,
71
- /** Closes the modal on esc */
72
- closeOnEsc: PropTypes.bool,
73
- /** Closes the modal on overlay click */
74
- closeOnOverlayClick: PropTypes.bool,
75
- /** Call back function called when the modal closes. */
76
- onClose: PropTypes.func,
77
- };
78
176
  Modal.defaultProps = {
79
177
  closeOnEsc: true,
80
- closeOnOverlayClick: true,
178
+ closeOnOverlayClick: true
81
179
  };
82
- export default Modal;
83
- //# sourceMappingURL=Modal.js.map
180
+
181
+ export { Modal as default };
182
+ //# sourceMappingURL=Modal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.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"}
1
+ {"version":3,"file":"Modal.js","sources":["../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import React from 'react';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\nexport {\n Header as ModalHeader,\n Body as ModalBody,\n Footer as ModalFooter,\n} from '../../shared/styles';\nimport { DialogContainer as ModalContainer } from '../Dialog/Dialog';\n\ntype ModalProps = {\n /** Opens the modal */\n open: boolean;\n /** Closes the modal on esc */\n closeOnEsc?: boolean;\n /** Closes the modal on overlay click */\n closeOnOverlayClick?: boolean;\n /** Call back function called when the modal closes. */\n onClose?: () => void;\n /** Ref forwarded to the modal container */\n forwardRef?: React.Ref<HTMLDivElement>;\n} & React.HTMLAttributes<HTMLDivElement>;\n\ninterface ModalState {\n open: boolean;\n}\n\n/**\n * Modal component\n *\n * A dialog window that sits on top of the main application content.\n * It disrupts the user's workflow to demand attention for a critical task or decision.\n *\n * Accessibility:\n * - Implements ARIA `role=\"dialog\"` and `aria-modal=\"true\"`.\n * - Traps focus effectively within the modal while open.\n * - Restores focus to the triggering element upon closure.\n * - Supports closing via ESC key and overlay click.\n */\nexport default class Modal extends React.Component<\n React.PropsWithChildren<ModalProps>,\n ModalState\n> {\n state = {\n open: false,\n };\n\n static defaultProps = {\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n /**\n * Syncs state with props.\n */\n static getDerivedStateFromProps(props: ModalProps) {\n if (props.open) {\n return {\n open: true,\n };\n }\n return null;\n }\n\n private layer?: ReturnType<typeof LayerManager.renderLayer>;\n\n private closeCallback?: (resp?: unknown) => void;\n\n /**\n * Internal close handler.\n * Restores focus and calls the external onClose callback.\n */\n private onClose = () => {\n this.restoreFocus();\n this.setState({\n open: false,\n });\n this.props.onClose?.();\n this.closeCallback = undefined;\n this.layer = undefined;\n };\n\n private lastFocusedElement: HTMLElement | null = null;\n private modalRef = React.createRef<HTMLDivElement>();\n\n /**\n * Retrieves all focusable elements within the modal.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.modalRef.current) return [];\n return Array.from(\n this.modalRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n ),\n ) as HTMLElement[];\n };\n\n /**\n * Handles keydown events to implement the focus trap.\n * Traps Tab and Shift+Tab within the modal.\n */\n private handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Tab') {\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length === 0) return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey) {\n if (document.activeElement === firstElement) {\n lastElement.focus();\n e.preventDefault();\n }\n } else {\n if (document.activeElement === lastElement) {\n firstElement.focus();\n e.preventDefault();\n }\n }\n }\n };\n\n /**\n * Lifecycle method to save the currently focused element when the modal mounts while open.\n */\n componentDidMount() {\n if (this.props.open) {\n this.lastFocusedElement = document.activeElement as HTMLElement;\n }\n }\n\n /**\n * Lifecycle method to restore focus when the modal unmounts.\n */\n componentWillUnmount() {\n if (this.props.open) {\n this.restoreFocus();\n }\n // Clean up layer references\n if (this.closeCallback) {\n this.closeCallback();\n this.closeCallback = undefined;\n }\n this.layer = undefined;\n }\n\n /**\n * Restores focus to the element that was focused before the modal opened.\n */\n private restoreFocus = () => {\n if (this.lastFocusedElement) {\n // Check if the element is still in the document\n const elementToBeFocused = this.lastFocusedElement;\n this.lastFocusedElement = null;\n setTimeout(() => {\n if (document.body.contains(elementToBeFocused)) {\n elementToBeFocused.focus();\n }\n }, 100);\n }\n };\n\n /**\n * Callback ref to capture the Modal DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setModalRef = (node: HTMLDivElement | null) => {\n // Update ref\n (this.modalRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\n if (node) {\n // Set initial focus when the node is mounted\n this.setInitialFocus(node);\n }\n\n if (this.props.forwardRef) {\n try {\n (this.props.forwardRef as React.MutableRefObject<HTMLDivElement | null>).current =\n node;\n } catch (e) {\n console.warn(e);\n }\n }\n };\n\n /**\n * Sets initial focus within the modal.\n * Tries to focus the header (first child) first, then the first interactive element, or falls back to the container.\n */\n private setInitialFocus = (root: HTMLElement) => {\n // Try to find the header (assumed to be the first child)\n const firstChild = root.firstElementChild as HTMLElement;\n if (firstChild) {\n // Ensure it's focusable\n if (firstChild.getAttribute('tabindex') === null) {\n firstChild.setAttribute('tabindex', '-1');\n }\n firstChild.focus();\n return;\n }\n\n // Fallback to focusable elements\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n } else {\n // Fallback to container\n root.focus();\n }\n };\n\n /**\n * Lifecycle method to handle Modal updates.\n * Manages opening/closing logic via LayerManager and focus preservation.\n */\n getSnapshotBeforeUpdate(prevProps: ModalProps) {\n const { open, closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;\n\n if (prevProps.open && !open) {\n this.closeCallback?.();\n this.restoreFocus();\n }\n\n if (!prevProps.open && open) {\n // Save current focus\n this.lastFocusedElement = document.activeElement as HTMLElement;\n\n this.layer = LayerManager.renderLayer({\n overlay: true,\n exitDelay: 300,\n position: LAYER_POSITION.DIALOG,\n closeCallback: this.onClose,\n closeOnEsc: closeOnEsc,\n closeOnOverlayClick: closeOnOverlayClick,\n component: (\n <ModalContainer\n {...rest}\n ref={this.setModalRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n onKeyDown={this.handleKeyDown}\n onClick={(e) => e.stopPropagation()}\n elevated\n >\n {children}\n </ModalContainer>\n ),\n });\n this.closeCallback = this.layer[1];\n this.forceUpdate();\n }\n }\n\n /**\n * Renders the Modal component via the LayerManager portal.\n */\n render() {\n if (this.state.open && this.layer) {\n const [Component] = this.layer;\n return <Component />;\n }\n\n return null;\n }\n}\n"],"names":["Modal","React","Component","getDerivedStateFromProps","props","open","componentDidMount","lastFocusedElement","document","activeElement","componentWillUnmount","restoreFocus","closeCallback","undefined","layer","getSnapshotBeforeUpdate","prevProps","closeOnEsc","closeOnOverlayClick","children","rest","LayerManager","renderLayer","overlay","exitDelay","position","LAYER_POSITION","DIALOG","onClose","component","_jsx","ModalContainer","ref","setModalRef","role","aria-modal","tabIndex","onKeyDown","handleKeyDown","onClick","e","stopPropagation","elevated","forceUpdate","render","state","setState","modalRef","createRef","getFocusableElements","current","Array","from","querySelectorAll","key","focusableElements","length","firstElement","lastElement","shiftKey","focus","preventDefault","elementToBeFocused","setTimeout","body","contains","node","setInitialFocus","forwardRef","console","warn","root","firstChild","firstElementChild","getAttribute","setAttribute","defaultProps"],"mappings":";;;;;AAsCe,MAAMA,KAAAA,SAAcC,MAAMC,SAAS,CAAA;AAa9C;;QAGA,OAAOC,wBAAAA,CAAyBC,KAAiB,EAAE;QAC/C,IAAIA,KAAAA,CAAMC,IAAI,EAAE;YACZ,OAAO;gBACHA,IAAAA,EAAM;AACV,aAAA;AACJ,QAAA;QACA,OAAO,IAAA;AACX,IAAA;AA6DA;;AAEC,QACDC,iBAAAA,GAAoB;AAChB,QAAA,IAAI,IAAI,CAACF,KAAK,CAACC,IAAI,EAAE;AACjB,YAAA,IAAI,CAACE,kBAAkB,GAAGC,QAAAA,CAASC,aAAa;AACpD,QAAA;AACJ,IAAA;AAEA;;AAEC,QACDC,oBAAAA,GAAuB;AACnB,QAAA,IAAI,IAAI,CAACN,KAAK,CAACC,IAAI,EAAE;AACjB,YAAA,IAAI,CAACM,YAAY,EAAA;AACrB,QAAA;;QAEA,IAAI,IAAI,CAACC,aAAa,EAAE;AACpB,YAAA,IAAI,CAACA,aAAa,EAAA;YAClB,IAAI,CAACA,aAAa,GAAGC,SAAAA;AACzB,QAAA;QACA,IAAI,CAACC,KAAK,GAAGD,SAAAA;AACjB,IAAA;AAmEA;;;QAIAE,uBAAAA,CAAwBC,SAAqB,EAAE;AAC3C,QAAA,MAAM,EAAEX,IAAI,EAAEY,UAAU,EAAEC,mBAAmB,EAAEC,QAAQ,EAAE,GAAGC,IAAAA,EAAM,GAAG,IAAI,CAAChB,KAAK;AAE/E,QAAA,IAAI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CAAC9B,CAAAA,CAAAA;AACjB,gBAAA;AACJ,YAAA;QACJ,CAAA;;;AAKC,QAAA,IAAA,CACO2B,kBAAkB,CAACI,IAAAA,GAAAA;;YAEvB,MAAMC,UAAAA,GAAaD,KAAKE,iBAAiB;AACzC,YAAA,IAAID,UAAAA,EAAY;;AAEZ,gBAAA,IAAIA,UAAAA,CAAWE,YAAY,CAAC,UAAA,CAAA,KAAgB,IAAA,EAAM;oBAC9CF,UAAAA,CAAWG,YAAY,CAAC,UAAA,EAAY,IAAA,CAAA;AACxC,gBAAA;AACAH,gBAAAA,UAAAA,CAAWZ,KAAK,EAAA;AAChB,gBAAA;AACJ,YAAA;;YAGA,MAAML,iBAAAA,GAAoB,IAAI,CAACN,oBAAoB,EAAA;YACnD,IAAIM,iBAAAA,CAAkBC,MAAM,GAAG,CAAA,EAAG;gBAC9BD,iBAAiB,CAAC,CAAA,CAAE,CAACK,KAAK,EAAA;YAC9B,CAAA,MAAO;;AAEHW,gBAAAA,IAAAA,CAAKX,KAAK,EAAA;AACd,YAAA;AACJ,QAAA,CAAA;;AAwDJ;AAnOqB5D,KAAAA,CAQV4E,YAAAA,GAAe;IAClB3D,UAAAA,EAAY,IAAA;IACZC,mBAAAA,EAAqB;AACzB,CAAA;;;;"}
@@ -1,36 +1,41 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
1
  import { NOTIFICATION_POSITION, NOTIFICATION_TYPE, NotificationOptions } from './types';
4
- type NotificationProps = PropTypes.InferProps<typeof StoryProps.propTypes>;
5
- /** This component is only used for storybook documentation */
6
- export declare class StoryProps extends React.Component<NotificationProps> {
7
- static propTypes: {
8
- /** Title of the notification */
9
- title: PropTypes.Validator<string>;
10
- /** Body of the notification */
11
- description: PropTypes.Validator<string>;
12
- /** Id for the notification, helps in de-duplication. */
13
- id: PropTypes.Requireable<string>;
14
- /** Duration for the notification in milliseconds */
15
- duration: PropTypes.Requireable<number>;
16
- /** Creates sticky notification */
17
- sticky: PropTypes.Requireable<boolean>;
18
- /** Type of notification */
19
- type: PropTypes.Requireable<NOTIFICATION_TYPE>;
20
- /** Action button text */
21
- buttonText: PropTypes.Requireable<string>;
22
- /** Action button click callback */
23
- buttonClick: PropTypes.Requireable<(...args: any[]) => any>;
24
- /** Notification close callback. */
25
- onClose: PropTypes.Requireable<(...args: any[]) => any>;
26
- };
27
- static defaultProps: {
28
- duration: number;
29
- sticky: boolean;
30
- type: NOTIFICATION_TYPE;
31
- };
32
- render(): React.ReactNode;
33
- }
2
+ type NotificationProps = {
3
+ /** Title of the notification */
4
+ title: string;
5
+ /** Body of the notification */
6
+ description: string;
7
+ /** Id for the notification, helps in de-duplication. */
8
+ id?: string;
9
+ /**
10
+ * Duration for the notification in milliseconds
11
+ * @default 5000
12
+ */
13
+ duration?: number;
14
+ /**
15
+ * Creates sticky notification
16
+ * @default false
17
+ */
18
+ sticky?: boolean;
19
+ /**
20
+ * Type of notification
21
+ * @default NOTIFICATION_TYPE.INFO
22
+ */
23
+ type?: NOTIFICATION_TYPE;
24
+ /** Action button text */
25
+ buttonText?: string;
26
+ /** Action button click callback */
27
+ buttonClick?: () => void;
28
+ /** Notification close callback. */
29
+ onClose?: () => void;
30
+ /** Aria label for the close button on the notification. Defaults to "Close notification" */
31
+ closeButtonAriaLabel?: string;
32
+ };
33
+ /**
34
+ * This dummy component is used to extract props for documentation in Storybook.
35
+ * @param props
36
+ * @returns
37
+ */
38
+ export declare function StoryProps(props: NotificationProps): null;
34
39
  /** Notification class */
35
40
  declare class Notification {
36
41
  /** Helps in maintaining single instance for different positions. */
@@ -38,21 +43,23 @@ declare class Notification {
38
43
  /**
39
44
  * Adds a notification
40
45
  *
41
- * @param position
42
- * @param options
46
+ * @param position - The position where the notification should appear
47
+ * @param options - Configuration options for the notification
48
+ * @returns The notification ID or a promise that resolves to the notification ID
43
49
  */
44
- add: (position: NOTIFICATION_POSITION, options: NotificationOptions) => string;
50
+ add: (position: NOTIFICATION_POSITION, options: NotificationOptions, ariaLabel?: string) => Promise<string>;
45
51
  /**
46
52
  * Removes a notification
47
53
  *
48
- * @param position
49
- * @param id
54
+ * @param position - The position of the notification container
55
+ * @param id - The unique ID of the notification to remove
50
56
  */
51
57
  remove: (position: NOTIFICATION_POSITION, id: string) => void;
52
58
  /**
53
- * Destroys entire stack of notifications.
59
+ * Destroys entire stack of notifications at a position.
60
+ * Unmounts the React root and cleans up DOM elements.
54
61
  *
55
- * @param position
62
+ * @param position - The position of the notification container to destroy
56
63
  */
57
64
  destroy: (position: NOTIFICATION_POSITION) => void;
58
65
  }