no-frills-ui 0.0.14-alpha.0 → 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 (221) hide show
  1. package/README.md +63 -24
  2. package/dist/index.js +3550 -4336
  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 +8 -3
  32. package/lib-esm/components/Chip/Chip.js +44 -42
  33. package/lib-esm/components/Chip/Chip.js.map +1 -1
  34. package/lib-esm/components/ChipInput/ChipInput.d.ts +31 -0
  35. package/lib-esm/components/ChipInput/ChipInput.js +198 -0
  36. package/lib-esm/components/ChipInput/ChipInput.js.map +1 -0
  37. package/lib-esm/components/ChipInput/index.d.ts +1 -0
  38. package/lib-esm/components/Dialog/AlertDialog.d.ts +11 -12
  39. package/lib-esm/components/Dialog/AlertDialog.js +44 -28
  40. package/lib-esm/components/Dialog/AlertDialog.js.map +1 -1
  41. package/lib-esm/components/Dialog/ConfirmDialog.d.ts +13 -14
  42. package/lib-esm/components/Dialog/ConfirmDialog.js +49 -33
  43. package/lib-esm/components/Dialog/ConfirmDialog.js.map +1 -1
  44. package/lib-esm/components/Dialog/Dialog.d.ts +40 -18
  45. package/lib-esm/components/Dialog/Dialog.js +125 -70
  46. package/lib-esm/components/Dialog/Dialog.js.map +1 -1
  47. package/lib-esm/components/Dialog/PromptDialog.d.ts +18 -19
  48. package/lib-esm/components/Dialog/PromptDialog.js +78 -49
  49. package/lib-esm/components/Dialog/PromptDialog.js.map +1 -1
  50. package/lib-esm/components/DragAndDrop/DragAndDrop.d.ts +43 -14
  51. package/lib-esm/components/DragAndDrop/DragAndDrop.js +128 -19
  52. package/lib-esm/components/DragAndDrop/DragAndDrop.js.map +1 -1
  53. package/lib-esm/components/DragAndDrop/DragItem.d.ts +41 -0
  54. package/lib-esm/components/DragAndDrop/DragItem.js +253 -36
  55. package/lib-esm/components/DragAndDrop/DragItem.js.map +1 -1
  56. package/lib-esm/components/DragAndDrop/types.d.ts +25 -3
  57. package/lib-esm/components/DragAndDrop/types.js +9 -6
  58. package/lib-esm/components/DragAndDrop/types.js.map +1 -1
  59. package/lib-esm/components/Drawer/Drawer.d.ts +86 -22
  60. package/lib-esm/components/Drawer/Drawer.js +176 -97
  61. package/lib-esm/components/Drawer/Drawer.js.map +1 -1
  62. package/lib-esm/components/Drawer/index.d.ts +1 -1
  63. package/lib-esm/components/Groups/Group.d.ts +5 -8
  64. package/lib-esm/components/Groups/Group.js +34 -79
  65. package/lib-esm/components/Groups/Group.js.map +1 -1
  66. package/lib-esm/components/Groups/GroupLabel.js +8 -17
  67. package/lib-esm/components/Groups/GroupLabel.js.map +1 -1
  68. package/lib-esm/components/Input/Checkbox.d.ts +12 -15
  69. package/lib-esm/components/Input/Checkbox.js +51 -118
  70. package/lib-esm/components/Input/Checkbox.js.map +1 -1
  71. package/lib-esm/components/Input/Dropdown.d.ts +11 -12
  72. package/lib-esm/components/Input/Dropdown.js +133 -52
  73. package/lib-esm/components/Input/Dropdown.js.map +1 -1
  74. package/lib-esm/components/Input/Input.d.ts +3 -3
  75. package/lib-esm/components/Input/Input.js +61 -109
  76. package/lib-esm/components/Input/Input.js.map +1 -1
  77. package/lib-esm/components/Input/Radio.d.ts +4 -8
  78. package/lib-esm/components/Input/Radio.js +35 -79
  79. package/lib-esm/components/Input/Radio.js.map +1 -1
  80. package/lib-esm/components/Input/RadioButton.d.ts +4 -8
  81. package/lib-esm/components/Input/RadioButton.js +34 -71
  82. package/lib-esm/components/Input/RadioButton.js.map +1 -1
  83. package/lib-esm/components/Input/Select.d.ts +6 -13
  84. package/lib-esm/components/Input/Select.js +75 -122
  85. package/lib-esm/components/Input/Select.js.map +1 -1
  86. package/lib-esm/components/Input/TextArea.d.ts +6 -13
  87. package/lib-esm/components/Input/TextArea.js +64 -108
  88. package/lib-esm/components/Input/TextArea.js.map +1 -1
  89. package/lib-esm/components/Input/Toggle.d.ts +4 -9
  90. package/lib-esm/components/Input/Toggle.js +31 -80
  91. package/lib-esm/components/Input/Toggle.js.map +1 -1
  92. package/lib-esm/components/Menu/Menu.d.ts +8 -6
  93. package/lib-esm/components/Menu/Menu.js +116 -31
  94. package/lib-esm/components/Menu/Menu.js.map +1 -1
  95. package/lib-esm/components/Menu/MenuContext.d.ts +11 -5
  96. package/lib-esm/components/Menu/MenuContext.js +6 -2
  97. package/lib-esm/components/Menu/MenuContext.js.map +1 -1
  98. package/lib-esm/components/Menu/MenuItem.d.ts +7 -4
  99. package/lib-esm/components/Menu/MenuItem.js +46 -47
  100. package/lib-esm/components/Menu/MenuItem.js.map +1 -1
  101. package/lib-esm/components/Modal/Modal.d.ts +75 -16
  102. package/lib-esm/components/Modal/Modal.js +150 -51
  103. package/lib-esm/components/Modal/Modal.js.map +1 -1
  104. package/lib-esm/components/Notification/Notification.d.ts +46 -39
  105. package/lib-esm/components/Notification/Notification.js +80 -87
  106. package/lib-esm/components/Notification/Notification.js.map +1 -1
  107. package/lib-esm/components/Notification/NotificationManager.d.ts +19 -5
  108. package/lib-esm/components/Notification/NotificationManager.js +177 -79
  109. package/lib-esm/components/Notification/NotificationManager.js.map +1 -1
  110. package/lib-esm/components/Notification/style.d.ts +6 -3
  111. package/lib-esm/components/Notification/style.js +64 -140
  112. package/lib-esm/components/Notification/style.js.map +1 -1
  113. package/lib-esm/components/Notification/types.d.ts +2 -0
  114. package/lib-esm/components/Notification/types.js +9 -10
  115. package/lib-esm/components/Notification/types.js.map +1 -1
  116. package/lib-esm/components/Popover/Popover.d.ts +21 -20
  117. package/lib-esm/components/Popover/Popover.js +159 -126
  118. package/lib-esm/components/Popover/Popover.js.map +1 -1
  119. package/lib-esm/components/Spinner/Spinner.d.ts +14 -12
  120. package/lib-esm/components/Spinner/Spinner.js +22 -27
  121. package/lib-esm/components/Spinner/Spinner.js.map +1 -1
  122. package/lib-esm/components/Stepper/Step.d.ts +15 -12
  123. package/lib-esm/components/Stepper/Step.js +18 -25
  124. package/lib-esm/components/Stepper/Step.js.map +1 -1
  125. package/lib-esm/components/Stepper/Stepper.d.ts +11 -17
  126. package/lib-esm/components/Stepper/Stepper.js +104 -102
  127. package/lib-esm/components/Stepper/Stepper.js.map +1 -1
  128. package/lib-esm/components/Tabs/Tab.d.ts +10 -16
  129. package/lib-esm/components/Tabs/Tab.js +9 -15
  130. package/lib-esm/components/Tabs/Tab.js.map +1 -1
  131. package/lib-esm/components/Tabs/Tabs.d.ts +11 -22
  132. package/lib-esm/components/Tabs/Tabs.js +97 -55
  133. package/lib-esm/components/Tabs/Tabs.js.map +1 -1
  134. package/lib-esm/components/Toast/Toast.d.ts +34 -7
  135. package/lib-esm/components/Toast/Toast.js +200 -109
  136. package/lib-esm/components/Toast/Toast.js.map +1 -1
  137. package/lib-esm/components/Toast/ToastStory.d.ts +21 -24
  138. package/lib-esm/components/Tooltip/Tooltip.d.ts +11 -14
  139. package/lib-esm/components/Tooltip/Tooltip.js +52 -67
  140. package/lib-esm/components/Tooltip/Tooltip.js.map +1 -1
  141. package/lib-esm/components/index.d.ts +1 -0
  142. package/lib-esm/components/index.js +43 -20
  143. package/lib-esm/components/index.js.map +1 -1
  144. package/lib-esm/icons/CheckCircle.d.ts +1 -1
  145. package/lib-esm/icons/CheckCircle.js +22 -4
  146. package/lib-esm/icons/CheckCircle.js.map +1 -1
  147. package/lib-esm/icons/Close.d.ts +1 -1
  148. package/lib-esm/icons/Close.js +22 -4
  149. package/lib-esm/icons/Close.js.map +1 -1
  150. package/lib-esm/icons/DragIndicator.d.ts +1 -1
  151. package/lib-esm/icons/DragIndicator.js +22 -4
  152. package/lib-esm/icons/DragIndicator.js.map +1 -1
  153. package/lib-esm/icons/ErrorOutline.d.ts +1 -1
  154. package/lib-esm/icons/ErrorOutline.js +16 -4
  155. package/lib-esm/icons/ErrorOutline.js.map +1 -1
  156. package/lib-esm/icons/ExpandMore.d.ts +1 -1
  157. package/lib-esm/icons/ExpandMore.js +22 -4
  158. package/lib-esm/icons/ExpandMore.js.map +1 -1
  159. package/lib-esm/icons/FiberManualRecord.d.ts +1 -1
  160. package/lib-esm/icons/FiberManualRecord.js +24 -4
  161. package/lib-esm/icons/FiberManualRecord.js.map +1 -1
  162. package/lib-esm/icons/Info.d.ts +1 -1
  163. package/lib-esm/icons/Info.js +22 -4
  164. package/lib-esm/icons/Info.js.map +1 -1
  165. package/lib-esm/icons/ReportProblem.d.ts +1 -1
  166. package/lib-esm/icons/ReportProblem.js +22 -4
  167. package/lib-esm/icons/ReportProblem.js.map +1 -1
  168. package/lib-esm/shared/LayerManager.d.ts +34 -4
  169. package/lib-esm/shared/LayerManager.js +248 -114
  170. package/lib-esm/shared/LayerManager.js.map +1 -1
  171. package/lib-esm/shared/constants.d.ts +58 -27
  172. package/lib-esm/shared/constants.js +62 -26
  173. package/lib-esm/shared/constants.js.map +1 -1
  174. package/lib-esm/shared/styles.d.ts +1 -1
  175. package/lib-esm/shared/styles.js +21 -24
  176. package/lib-esm/shared/styles.js.map +1 -1
  177. package/package.json +130 -72
  178. package/lib-esm/components/Accordion/index.js +0 -3
  179. package/lib-esm/components/Accordion/index.js.map +0 -1
  180. package/lib-esm/components/Badge/index.js +0 -2
  181. package/lib-esm/components/Badge/index.js.map +0 -1
  182. package/lib-esm/components/Button/index.js +0 -6
  183. package/lib-esm/components/Button/index.js.map +0 -1
  184. package/lib-esm/components/Card/index.js +0 -3
  185. package/lib-esm/components/Card/index.js.map +0 -1
  186. package/lib-esm/components/Chip/index.js +0 -2
  187. package/lib-esm/components/Chip/index.js.map +0 -1
  188. package/lib-esm/components/Dialog/index.js +0 -5
  189. package/lib-esm/components/Dialog/index.js.map +0 -1
  190. package/lib-esm/components/DragAndDrop/index.js +0 -3
  191. package/lib-esm/components/DragAndDrop/index.js.map +0 -1
  192. package/lib-esm/components/Drawer/index.js +0 -2
  193. package/lib-esm/components/Drawer/index.js.map +0 -1
  194. package/lib-esm/components/Groups/index.js +0 -3
  195. package/lib-esm/components/Groups/index.js.map +0 -1
  196. package/lib-esm/components/Input/index.js +0 -9
  197. package/lib-esm/components/Input/index.js.map +0 -1
  198. package/lib-esm/components/Menu/index.js +0 -3
  199. package/lib-esm/components/Menu/index.js.map +0 -1
  200. package/lib-esm/components/Modal/index.js +0 -2
  201. package/lib-esm/components/Modal/index.js.map +0 -1
  202. package/lib-esm/components/Notification/index.js +0 -3
  203. package/lib-esm/components/Notification/index.js.map +0 -1
  204. package/lib-esm/components/Popover/index.js +0 -2
  205. package/lib-esm/components/Popover/index.js.map +0 -1
  206. package/lib-esm/components/Spinner/index.js +0 -2
  207. package/lib-esm/components/Spinner/index.js.map +0 -1
  208. package/lib-esm/components/Stepper/index.js +0 -4
  209. package/lib-esm/components/Stepper/index.js.map +0 -1
  210. package/lib-esm/components/Tabs/index.js +0 -3
  211. package/lib-esm/components/Tabs/index.js.map +0 -1
  212. package/lib-esm/components/Toast/ToastStory.js +0 -35
  213. package/lib-esm/components/Toast/ToastStory.js.map +0 -1
  214. package/lib-esm/components/Toast/index.js +0 -2
  215. package/lib-esm/components/Toast/index.js.map +0 -1
  216. package/lib-esm/components/Tooltip/index.js +0 -2
  217. package/lib-esm/components/Tooltip/index.js.map +0 -1
  218. package/lib-esm/icons/index.js +0 -9
  219. package/lib-esm/icons/index.js.map +0 -1
  220. package/lib-esm/index.js +0 -2
  221. package/lib-esm/index.js.map +0 -1
@@ -1,8 +1,11 @@
1
- import { createContext } from "react";
2
- export var ORIENTATION;
3
- (function (ORIENTATION) {
1
+ import { createContext } from 'react';
2
+
3
+ var ORIENTATION = /*#__PURE__*/ function(ORIENTATION) {
4
4
  ORIENTATION["HORIZONTAL"] = "horizontal";
5
5
  ORIENTATION["VERTICAL"] = "vertical";
6
- })(ORIENTATION || (ORIENTATION = {}));
7
- export const DragContext = createContext(null);
8
- //# sourceMappingURL=types.js.map
6
+ return ORIENTATION;
7
+ }({});
8
+ const DragContext = createContext(null);
9
+
10
+ export { DragContext, ORIENTATION };
11
+ //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/DragAndDrop/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,wCAAuB,CAAA;IACvB,oCAAmB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAIrC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"types.js","sources":["../../../src/components/DragAndDrop/types.ts"],"sourcesContent":["import { createContext } from 'react';\n\nexport enum ORIENTATION {\n HORIZONTAL = 'horizontal',\n VERTICAL = 'vertical',\n}\n\nexport const DragContext = createContext<{\n startIndex: number | null;\n setStartIndex: (value: number) => void;\n drop: (index: number | null) => void;\n onDrop: (start: number, end: number) => void;\n cancel: () => void;\n startGrab: (index: number) => void;\n isDragging: boolean;\n setIsDragging: (value: boolean) => void;\n setDragOver: (value: number) => void;\n i18n: {\n itemAriaLabelTemplate: string;\n dragHandleAriaLabel: string;\n grabbedAnnouncementTemplate: string;\n movedAnnouncementTemplate: string;\n droppedAnnouncementTemplate: string;\n cancelledAnnouncementTemplate: string;\n replacePlaceholders: (\n template: string,\n data: {\n position?: number;\n grabKey?: string;\n dropKey?: string;\n altDropKey?: string;\n cancelKey?: string;\n moveKeys?: string;\n },\n ) => string;\n };\n} | null>(null);\n"],"names":["ORIENTATION","DragContext","createContext"],"mappings":";;AAEO,IAAA,WAAKA,iBAAAA,SAAAA,WAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,WAAAA;AAGX,CAAA,CAAA,EAAA;AAEM,MAAMC,WAAAA,GAAcC,aAAAA,CA6BjB,IAAA;;;;"}
@@ -1,47 +1,111 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  export { Header as DrawerHeader, Body as DrawerBody, Footer as DrawerFooter, } from '../../shared/styles';
4
3
  export declare enum DRAWER_POSITION {
5
4
  LEFT = "LEFT",
6
5
  RIGHT = "RIGHT",
7
6
  BOTTOM = "BOTTOM"
8
7
  }
9
- type DrawerProps = PropTypes.InferProps<typeof Drawer.propTypes>;
8
+ type DrawerProps = {
9
+ /** Opens the drawer */
10
+ open: boolean;
11
+ /** position of the drawer */
12
+ position: DRAWER_POSITION;
13
+ /** size of the drawer */
14
+ size?: string;
15
+ /** Shows an overlay behind the drawer. */
16
+ overlay?: boolean;
17
+ /** Closes the drawer on esc */
18
+ closeOnEsc?: boolean;
19
+ /** Closes the drawer on overlay click */
20
+ closeOnOverlayClick?: boolean;
21
+ /** Call back function called when the drawer closes. */
22
+ onClose?: () => void;
23
+ /** Ref to the drawer element */
24
+ forwardRef?: React.Ref<HTMLDivElement> | React.MutableRefObject<HTMLDivElement | null>;
25
+ };
10
26
  interface DrawerState {
11
27
  open: boolean;
12
28
  }
29
+ /**
30
+ * Drawer component
31
+ *
32
+ * A panel that slides in from the edge of the screen.
33
+ * It sits on top of the application content and is often used for navigation or details.
34
+ *
35
+ * Accessibility:
36
+ * - Implements ARIA `role="dialog"` and `aria-modal="true"`.
37
+ * - Traps focus effectively within the drawer while open.
38
+ * - Restores focus to the triggering element upon closure.
39
+ * - Supports closing via ESC key and overlay click.
40
+ */
13
41
  export default class Drawer extends React.Component<React.PropsWithChildren<DrawerProps>, DrawerState> {
14
42
  state: {
15
43
  open: boolean;
16
44
  };
17
- static propTypes: {
18
- /** Opens the drawer */
19
- open: PropTypes.Validator<boolean>;
20
- /** position of the drawer */
21
- position: PropTypes.Requireable<DRAWER_POSITION>;
22
- /** size of the drawer */
23
- size: PropTypes.Requireable<string>;
24
- /** Shows an overlay behind the drawer. */
25
- overlay: PropTypes.Requireable<boolean>;
26
- /** Closes the drawer on esc */
27
- closeOnEsc: PropTypes.Requireable<boolean>;
28
- /** Closes the drawer on overlay click */
29
- closeOnOverlayClick: PropTypes.Requireable<boolean>;
30
- /** Call back function called when the drawer closes. */
31
- onClose: PropTypes.Requireable<(...args: any[]) => any>;
32
- };
33
45
  static defaultProps: {
34
46
  overlay: boolean;
35
47
  position: DRAWER_POSITION;
36
48
  closeOnEsc: boolean;
37
49
  closeOnOverlayClick: boolean;
38
50
  };
51
+ /**
52
+ * Syncs state with props.
53
+ */
39
54
  static getDerivedStateFromProps(props: DrawerProps): {
40
55
  open: boolean;
41
- };
42
- private layer;
43
- private closeCallback;
56
+ } | null;
57
+ private layer?;
58
+ private closeCallback?;
59
+ /**
60
+ * Internal close handler.
61
+ * Restores focus and calls the external onClose callback.
62
+ */
44
63
  private onClose;
64
+ private lastFocusedElement;
65
+ private drawerRef;
66
+ /**
67
+ * Retrieves all focusable elements within the drawer.
68
+ */
69
+ private getFocusableElements;
70
+ /**
71
+ * Handles keydown events to implement the focus trap.
72
+ * Traps Tab and Shift+Tab within the drawer.
73
+ */
74
+ private handleKeyDown;
75
+ /**
76
+ * Lifecycle method to save the currently focused element when the drawer mounts while open.
77
+ */
78
+ componentDidMount(): void;
79
+ /**
80
+ * Lifecycle method to restore focus when the drawer unmounts.
81
+ */
82
+ componentWillUnmount(): void;
83
+ /**
84
+ * Restores focus to the element that was focused before the drawer opened.
85
+ */
86
+ private restoreFocus;
87
+ /**
88
+ * Callback ref to capture the Drawer DOM element.
89
+ * Triggers initial focus setting when the element mounts.
90
+ */
91
+ private setDrawerRef;
92
+ /**
93
+ * Sets initial focus within the drawer.
94
+ * Tries to focus the header first, then the first interactive element, or falls back to the container.
95
+ */
96
+ private setInitialFocus;
97
+ /**
98
+ * Lifecycle method to handle Drawer updates.
99
+ * Manages opening/closing logic via LayerManager and focus preservation.
100
+ */
45
101
  getSnapshotBeforeUpdate(prevProps: DrawerProps): void;
46
- render(): import("@emotion/react/jsx-runtime").JSX.Element;
102
+ /**
103
+ * Sets the ref prop passed to the Drawer Container component.
104
+ * @param node
105
+ */
106
+ setRefProp: (node: HTMLDivElement | null) => void;
107
+ /**
108
+ * Renders the Drawer component via the LayerManager portal.
109
+ */
110
+ render(): import("@emotion/react/jsx-runtime").JSX.Element | null;
47
111
  }
@@ -1,38 +1,26 @@
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
3
  import styled from '@emotion/styled';
16
- import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';
17
- import constants from '../../shared/constants';
18
- export { Header as DrawerHeader, Body as DrawerBody, Footer as DrawerFooter, } from '../../shared/styles';
19
- export var DRAWER_POSITION;
20
- (function (DRAWER_POSITION) {
4
+ import { getThemeValue, THEME_NAME } from '../../shared/constants.js';
5
+ import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager.js';
6
+
7
+ var DRAWER_POSITION = /*#__PURE__*/ function(DRAWER_POSITION) {
21
8
  DRAWER_POSITION["LEFT"] = "LEFT";
22
9
  DRAWER_POSITION["RIGHT"] = "RIGHT";
23
10
  DRAWER_POSITION["BOTTOM"] = "BOTTOM";
24
- })(DRAWER_POSITION || (DRAWER_POSITION = {}));
25
- const positionStyle = (size) => ({
26
- [DRAWER_POSITION.LEFT]: {
27
- before: `height: 100vh; min-width: ${size || '300px'}; transform: translateX(-100%);`,
28
- after: 'transform: translateX(0%);',
29
- },
30
- [DRAWER_POSITION.RIGHT]: {
31
- before: `height: 100vh; min-width: ${size || '300px'}; transform: translateX(100%);`,
32
- after: 'transform: translateX(0%);',
33
- },
34
- [DRAWER_POSITION.BOTTOM]: {
35
- before: `
11
+ return DRAWER_POSITION;
12
+ }({});
13
+ const positionStyle$1 = (size)=>({
14
+ ["LEFT"]: {
15
+ before: `height: 100vh; min-width: ${size || '300px'}; transform: translateX(-100%);`,
16
+ after: 'transform: translateX(0%);'
17
+ },
18
+ ["RIGHT"]: {
19
+ before: `height: 100vh; min-width: ${size || '300px'}; transform: translateX(100%);`,
20
+ after: 'transform: translateX(0%);'
21
+ },
22
+ ["BOTTOM"]: {
23
+ before: `
36
24
  position: absolute;
37
25
  bottom: 0;
38
26
  width: 100%;
@@ -40,102 +28,193 @@ const positionStyle = (size) => ({
40
28
  transform: translateY(100%);
41
29
  border-radius: 15px 15px 0 0;
42
30
  `,
43
- after: 'transform: translateX(0%);',
44
- },
45
- });
46
- const DrawerDiv = styled.div `
47
- display: flex;
48
- flex-direction: column;
49
- background-color: #fff;
50
- transition: transform .3s ease;
51
- box-shadow: var(--modal-shadow, ${constants.MODAL_SHADOW});
52
- ${props => positionStyle(props.size)[props.position].before}
53
-
54
- .nf-layer-enter & {
55
- transform: translateX(0%);
56
- ${props => positionStyle(props.size)[props.position].after}
57
- }
58
- `;
59
- const positionMap = {
60
- [DRAWER_POSITION.LEFT]: LAYER_POSITION.TOP_LEFT,
61
- [DRAWER_POSITION.RIGHT]: LAYER_POSITION.TOP_RIGHT,
62
- [DRAWER_POSITION.BOTTOM]: LAYER_POSITION.BOTTOM_LEFT,
31
+ after: 'transform: translateX(0%);'
32
+ }
33
+ });
34
+ const DrawerDiv = /*#__PURE__*/ styled("div", {
35
+ target: "egs35xi0",
36
+ label: "DrawerDiv"
37
+ })("display:flex;flex-direction:column;background-color:", getThemeValue(THEME_NAME.BACKGROUND), ";transition:transform 0.3s ease;box-shadow:", getThemeValue(THEME_NAME.MODAL_SHADOW), ";", (props)=>positionStyle$1(props.size)[props.position].before, " .nf-layer-enter &{transform:translateX(0%);", (props)=>positionStyle$1(props.size)[props.position].after, "}");
38
+ const positionMap$1 = {
39
+ ["LEFT"]: LAYER_POSITION.TOP_LEFT,
40
+ ["RIGHT"]: LAYER_POSITION.TOP_RIGHT,
41
+ ["BOTTOM"]: LAYER_POSITION.BOTTOM_LEFT
63
42
  };
64
43
  class Drawer extends React.Component {
65
- constructor() {
66
- super(...arguments);
67
- this.state = {
68
- open: false,
69
- };
70
- this.onClose = () => {
71
- this.setState({
72
- open: false,
73
- });
74
- this.props.onClose && this.props.onClose();
75
- this.closeCallback = null;
76
- this.layer = null;
77
- };
78
- }
79
- static getDerivedStateFromProps(props) {
44
+ /**
45
+ * Syncs state with props.
46
+ */ static getDerivedStateFromProps(props) {
80
47
  if (props.open) {
81
48
  return {
82
- open: true,
49
+ open: true
83
50
  };
84
51
  }
85
52
  return null;
86
53
  }
87
- getSnapshotBeforeUpdate(prevProps) {
88
- const _a = this.props, { open, closeOnEsc, closeOnOverlayClick, overlay, position, children, size } = _a, rest = __rest(_a, ["open", "closeOnEsc", "closeOnOverlayClick", "overlay", "position", "children", "size"]);
54
+ /**
55
+ * Lifecycle method to save the currently focused element when the drawer mounts while open.
56
+ */ componentDidMount() {
57
+ if (this.props.open) {
58
+ this.lastFocusedElement = document.activeElement;
59
+ }
60
+ }
61
+ /**
62
+ * Lifecycle method to restore focus when the drawer unmounts.
63
+ */ componentWillUnmount() {
64
+ if (this.props.open) {
65
+ this.restoreFocus();
66
+ }
67
+ }
68
+ /**
69
+ * Lifecycle method to handle Drawer updates.
70
+ * Manages opening/closing logic via LayerManager and focus preservation.
71
+ */ getSnapshotBeforeUpdate(prevProps) {
72
+ const { open, closeOnEsc, closeOnOverlayClick, overlay, position, children, size, ...rest } = this.props;
89
73
  if (prevProps.open && !open) {
90
- this.closeCallback && this.closeCallback();
74
+ this.closeCallback?.();
75
+ this.restoreFocus();
91
76
  }
92
77
  if (!prevProps.open && open) {
78
+ // Save current focus
79
+ this.lastFocusedElement = document.activeElement;
93
80
  this.layer = LayerManager.renderLayer({
94
81
  overlay,
95
82
  exitDelay: 300,
96
- position: positionMap[position],
83
+ position: positionMap$1[position],
97
84
  closeCallback: this.onClose,
98
85
  closeOnEsc,
99
86
  closeOnOverlayClick,
100
- component: (_jsx(DrawerDiv, Object.assign({}, rest, { position: position, size: size, onClick: e => e.stopPropagation(), children: children })))
87
+ component: /*#__PURE__*/ jsx(DrawerDiv, {
88
+ ...rest,
89
+ ref: this.setDrawerRef,
90
+ role: "dialog",
91
+ "aria-modal": "true",
92
+ tabIndex: -1,
93
+ onKeyDown: this.handleKeyDown,
94
+ position: position,
95
+ size: size,
96
+ onClick: (e)=>e.stopPropagation(),
97
+ children: children
98
+ })
101
99
  });
102
100
  this.closeCallback = this.layer[1];
103
101
  this.forceUpdate();
104
102
  }
105
103
  }
106
- render() {
104
+ /**
105
+ * Renders the Drawer component via the LayerManager portal.
106
+ */ render() {
107
107
  if (this.state.open && this.layer) {
108
108
  const [Component] = this.layer;
109
- return _jsx(Component, {});
109
+ return /*#__PURE__*/ jsx(Component, {
110
+ ref: this.setRefProp
111
+ });
110
112
  }
111
113
  return null;
112
114
  }
115
+ constructor(...args){
116
+ super(...args), this.state = {
117
+ open: false
118
+ }, /**
119
+ * Internal close handler.
120
+ * Restores focus and calls the external onClose callback.
121
+ */ this.onClose = ()=>{
122
+ this.restoreFocus();
123
+ this.setState({
124
+ open: false
125
+ });
126
+ this.props.onClose?.();
127
+ this.closeCallback = undefined;
128
+ this.layer = undefined;
129
+ }, this.lastFocusedElement = null, this.drawerRef = /*#__PURE__*/ React.createRef(), /**
130
+ * Retrieves all focusable elements within the drawer.
131
+ */ this.getFocusableElements = ()=>{
132
+ if (!this.drawerRef.current) return [];
133
+ return Array.from(this.drawerRef.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'));
134
+ }, /**
135
+ * Handles keydown events to implement the focus trap.
136
+ * Traps Tab and Shift+Tab within the drawer.
137
+ */ this.handleKeyDown = (e)=>{
138
+ if (e.key === 'Tab') {
139
+ const focusableElements = this.getFocusableElements();
140
+ if (focusableElements.length === 0) return;
141
+ const firstElement = focusableElements[0];
142
+ const lastElement = focusableElements[focusableElements.length - 1];
143
+ if (e.shiftKey) {
144
+ if (document.activeElement === firstElement) {
145
+ lastElement.focus();
146
+ e.preventDefault();
147
+ }
148
+ } else {
149
+ if (document.activeElement === lastElement) {
150
+ firstElement.focus();
151
+ e.preventDefault();
152
+ }
153
+ }
154
+ }
155
+ }, /**
156
+ * Restores focus to the element that was focused before the drawer opened.
157
+ */ this.restoreFocus = ()=>{
158
+ if (this.lastFocusedElement) {
159
+ // Check if the element is still in the document
160
+ const elementToBeFocused = this.lastFocusedElement;
161
+ this.lastFocusedElement = null;
162
+ setTimeout(()=>{
163
+ if (document.body.contains(elementToBeFocused)) {
164
+ elementToBeFocused.focus();
165
+ }
166
+ }, 100);
167
+ }
168
+ }, /**
169
+ * Callback ref to capture the Drawer DOM element.
170
+ * Triggers initial focus setting when the element mounts.
171
+ */ this.setDrawerRef = (node)=>{
172
+ // Update ref
173
+ this.drawerRef.current = node;
174
+ if (node) {
175
+ // Set initial focus when the node is mounted
176
+ this.setInitialFocus(node);
177
+ }
178
+ }, /**
179
+ * Sets initial focus within the drawer.
180
+ * Tries to focus the header first, then the first interactive element, or falls back to the container.
181
+ */ this.setInitialFocus = (root)=>{
182
+ // Try to find the header (assumed to be the first child)
183
+ const firstChild = root.firstElementChild;
184
+ if (firstChild) {
185
+ // Ensure it's focusable
186
+ if (firstChild.getAttribute('tabindex') === null) {
187
+ firstChild.setAttribute('tabindex', '-1');
188
+ }
189
+ firstChild.focus();
190
+ return;
191
+ }
192
+ // Fallback to focusable elements
193
+ const focusableElements = this.getFocusableElements();
194
+ if (focusableElements.length > 0) {
195
+ focusableElements[0].focus();
196
+ } else {
197
+ // Fallback to container
198
+ root.focus();
199
+ }
200
+ }, /**
201
+ * Sets the ref prop passed to the Drawer Container component.
202
+ * @param node
203
+ */ this.setRefProp = (node)=>{
204
+ if (this.props.forwardRef && typeof this.props.forwardRef === 'function') {
205
+ this.props.forwardRef(node);
206
+ } else if (this.props.forwardRef && typeof this.props.forwardRef === 'object') {
207
+ this.props.forwardRef.current = node;
208
+ }
209
+ };
210
+ }
113
211
  }
114
- Drawer.propTypes = {
115
- /** Opens the drawer */
116
- open: PropTypes.bool.isRequired,
117
- /** position of the drawer */
118
- position: PropTypes.oneOf([
119
- DRAWER_POSITION.LEFT,
120
- DRAWER_POSITION.RIGHT,
121
- DRAWER_POSITION.BOTTOM,
122
- ]),
123
- /** size of the drawer */
124
- size: PropTypes.string,
125
- /** Shows an overlay behind the drawer. */
126
- overlay: PropTypes.bool,
127
- /** Closes the drawer on esc */
128
- closeOnEsc: PropTypes.bool,
129
- /** Closes the drawer on overlay click */
130
- closeOnOverlayClick: PropTypes.bool,
131
- /** Call back function called when the drawer closes. */
132
- onClose: PropTypes.func,
133
- };
134
212
  Drawer.defaultProps = {
135
213
  overlay: true,
136
- position: DRAWER_POSITION.LEFT,
214
+ position: "LEFT",
137
215
  closeOnEsc: true,
138
- closeOnOverlayClick: true,
216
+ closeOnOverlayClick: true
139
217
  };
140
- export default Drawer;
141
- //# sourceMappingURL=Drawer.js.map
218
+
219
+ export { DRAWER_POSITION, Drawer as default };
220
+ //# sourceMappingURL=Drawer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Drawer.js","sourceRoot":"","sources":["../../../src/components/Drawer/Drawer.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,YAAY,EAAE,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EACH,MAAM,IAAI,YAAY,EACtB,IAAI,IAAI,UAAU,EAClB,MAAM,IAAI,YAAY,GACzB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACvB,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,oCAAiB,CAAA;AACrB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QACpB,MAAM,EAAE,6BAA6B,IAAI,IAAI,OAAO,iCAAiC;QAC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,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC/B,OAAO,KAAC,SAAS,KAAG,CAAC;QACzB,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AArFM,gBAAS,GAAG;IACf,uBAAuB;IACvB,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IAC/B,6BAA6B;IAC7B,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC;QACtB,eAAe,CAAC,IAAI;QACpB,eAAe,CAAC,KAAK;QACrB,eAAe,CAAC,MAAM;KACzB,CAAC;IACF,yBAAyB;IACzB,IAAI,EAAE,SAAS,CAAC,MAAM;IACtB,0CAA0C;IAC1C,OAAO,EAAE,SAAS,CAAC,IAAI;IACvB,+BAA+B;IAC/B,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,yCAAyC;IACzC,mBAAmB,EAAE,SAAS,CAAC,IAAI;IACnC,wDAAwD;IACxD,OAAO,EAAE,SAAS,CAAC,IAAI;CAC1B,AAnBe,CAmBf;AAEM,mBAAY,GAAG;IAClB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,eAAe,CAAC,IAAI;IAC9B,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,IAAI;CAC5B,AALkB,CAKlB;eA/BgB,MAAM"}
1
+ {"version":3,"file":"Drawer.js","sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import React from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\n\nexport {\n Header as DrawerHeader,\n Body as DrawerBody,\n Footer as DrawerFooter,\n} from '../../shared/styles';\n\nexport enum DRAWER_POSITION {\n LEFT = 'LEFT',\n RIGHT = 'RIGHT',\n BOTTOM = 'BOTTOM',\n}\n\nconst positionStyle = (size?: string) => ({\n [DRAWER_POSITION.LEFT]: {\n before: `height: 100vh; min-width: ${size || '300px'}; transform: translateX(-100%);`,\n after: 'transform: translateX(0%);',\n },\n [DRAWER_POSITION.RIGHT]: {\n before: `height: 100vh; min-width: ${size || '300px'}; transform: translateX(100%);`,\n after: 'transform: translateX(0%);',\n },\n [DRAWER_POSITION.BOTTOM]: {\n before: `\n position: absolute;\n bottom: 0;\n width: 100%;\n height: ${size || '90vh'};\n transform: translateY(100%);\n border-radius: 15px 15px 0 0; \n `,\n after: 'transform: translateX(0%);',\n },\n});\n\nconst DrawerDiv = styled.div<{ position: DRAWER_POSITION; size?: string }>`\n display: flex;\n flex-direction: column;\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n transition: transform 0.3s ease;\n box-shadow: ${getThemeValue(THEME_NAME.MODAL_SHADOW)};\n ${(props) => positionStyle(props.size)[props.position].before}\n\n .nf-layer-enter & {\n transform: translateX(0%);\n ${(props) => positionStyle(props.size)[props.position].after}\n }\n`;\n\ntype DrawerProps = {\n /** Opens the drawer */\n open: boolean;\n /** position of the drawer */\n position: DRAWER_POSITION;\n /** size of the drawer */\n size?: string;\n /** Shows an overlay behind the drawer. */\n overlay?: boolean;\n /** Closes the drawer on esc */\n closeOnEsc?: boolean;\n /** Closes the drawer on overlay click */\n closeOnOverlayClick?: boolean;\n /** Call back function called when the drawer closes. */\n onClose?: () => void;\n /** Ref to the drawer element */\n forwardRef?: React.Ref<HTMLDivElement> | React.MutableRefObject<HTMLDivElement | null>;\n};\n\ninterface DrawerState {\n open: boolean;\n}\n\nconst positionMap = {\n [DRAWER_POSITION.LEFT]: LAYER_POSITION.TOP_LEFT,\n [DRAWER_POSITION.RIGHT]: LAYER_POSITION.TOP_RIGHT,\n [DRAWER_POSITION.BOTTOM]: LAYER_POSITION.BOTTOM_LEFT,\n};\n\n/**\n * Drawer component\n *\n * A panel that slides in from the edge of the screen.\n * It sits on top of the application content and is often used for navigation or details.\n *\n * Accessibility:\n * - Implements ARIA `role=\"dialog\"` and `aria-modal=\"true\"`.\n * - Traps focus effectively within the drawer while open.\n * - Restores focus to the triggering element upon closure.\n * - Supports closing via ESC key and overlay click.\n */\nexport default class Drawer extends React.Component<\n React.PropsWithChildren<DrawerProps>,\n DrawerState\n> {\n state = {\n open: false,\n };\n\n static defaultProps = {\n overlay: true,\n position: DRAWER_POSITION.LEFT,\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n /**\n * Syncs state with props.\n */\n static getDerivedStateFromProps(props: DrawerProps) {\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 drawerRef = React.createRef<HTMLDivElement>();\n\n /**\n * Retrieves all focusable elements within the drawer.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.drawerRef.current) return [];\n return Array.from(\n this.drawerRef.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 drawer.\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 drawer 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 drawer unmounts.\n */\n componentWillUnmount() {\n if (this.props.open) {\n this.restoreFocus();\n }\n }\n\n /**\n * Restores focus to the element that was focused before the drawer 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 Drawer DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setDrawerRef = (node: HTMLDivElement | null) => {\n // Update ref\n (this.drawerRef 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\n /**\n * Sets initial focus within the drawer.\n * Tries to focus the header 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 Drawer updates.\n * Manages opening/closing logic via LayerManager and focus preservation.\n */\n getSnapshotBeforeUpdate(prevProps: DrawerProps) {\n const {\n open,\n closeOnEsc,\n closeOnOverlayClick,\n overlay,\n position,\n children,\n size,\n ...rest\n } = 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,\n exitDelay: 300,\n position: positionMap[position],\n closeCallback: this.onClose,\n closeOnEsc,\n closeOnOverlayClick,\n component: (\n <DrawerDiv\n {...rest}\n ref={this.setDrawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n onKeyDown={this.handleKeyDown}\n position={position}\n size={size}\n onClick={(e) => e.stopPropagation()}\n >\n {children}\n </DrawerDiv>\n ),\n });\n this.closeCallback = this.layer[1];\n this.forceUpdate();\n }\n }\n\n /**\n * Sets the ref prop passed to the Drawer Container component.\n * @param node\n */\n setRefProp = (node: HTMLDivElement | null) => {\n if (this.props.forwardRef && typeof this.props.forwardRef === 'function') {\n this.props.forwardRef(node);\n } else if (this.props.forwardRef && typeof this.props.forwardRef === 'object') {\n (this.props.forwardRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n };\n\n /**\n * Renders the Drawer component via the LayerManager portal.\n */\n render() {\n if (this.state.open && this.layer) {\n const [Component] = this.layer;\n return <Component ref={this.setRefProp} />;\n }\n\n return null;\n }\n}\n"],"names":["DRAWER_POSITION","positionStyle","size","before","after","DrawerDiv","styled","getThemeValue","THEME_NAME","BACKGROUND","MODAL_SHADOW","props","position","positionMap","LAYER_POSITION","TOP_LEFT","TOP_RIGHT","BOTTOM_LEFT","Drawer","React","Component","getDerivedStateFromProps","open","componentDidMount","lastFocusedElement","document","activeElement","componentWillUnmount","restoreFocus","getSnapshotBeforeUpdate","prevProps","closeOnEsc","closeOnOverlayClick","overlay","children","rest","closeCallback","layer","LayerManager","renderLayer","exitDelay","onClose","component","_jsx","ref","setDrawerRef","role","aria-modal","tabIndex","onKeyDown","handleKeyDown","onClick","e","stopPropagation","forceUpdate","render","state","setRefProp","setState","undefined","drawerRef","createRef","getFocusableElements","current","Array","from","querySelectorAll","key","focusableElements","length","firstElement","lastElement","shiftKey","focus","preventDefault","elementToBeFocused","setTimeout","body","contains","node","setInitialFocus","root","firstChild","firstElementChild","getAttribute","setAttribute","forwardRef","defaultProps"],"mappings":";;;;;;AAWO,IAAA,eAAKA,iBAAAA,SAAAA,eAAAA,EAAAA;;;;AAAAA,IAAAA,OAAAA,eAAAA;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IAAI,CAAC3E,KAAK,CAAC2E,UAAU,KAAK,UAAA,EAAY;AACtE,gBAAA,IAAI,CAAC3E,KAAK,CAAC2E,UAAU,CAACP,IAAAA,CAAAA;AAC1B,YAAA,CAAA,MAAO,IAAI,IAAI,CAACpE,KAAK,CAAC2E,UAAU,IAAI,OAAO,IAAI,CAAC3E,KAAK,CAAC2E,UAAU,KAAK,QAAA,EAAU;AAC1E,gBAAA,IAAI,CAAC3E,KAAK,CAAC2E,UAAU,CAAmDvB,OAAO,GAAGgB,IAAAA;AACvF,YAAA;AACJ,QAAA,CAAA;;AAaJ;AA5OqB7D,MAAAA,CAQVqE,YAAAA,GAAe;IAClBtD,OAAAA,EAAS,IAAA;IACTrB,QAAQ,EAAA,MAAA;IACRmB,UAAAA,EAAY,IAAA;IACZC,mBAAAA,EAAqB;AACzB,CAAA;;;;"}
@@ -1 +1 @@
1
- export { default as Drawer, DrawerHeader, DrawerBody, DrawerFooter, DRAWER_POSITION } from './Drawer';
1
+ export { default as Drawer, DrawerHeader, DrawerBody, DrawerFooter, DRAWER_POSITION, } from './Drawer';
@@ -1,10 +1,7 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
- declare function Group(props: React.PropsWithChildren<PropTypes.InferProps<typeof Group.propTypes>>): import("@emotion/react/jsx-runtime").JSX.Element;
4
- declare namespace Group {
5
- var propTypes: {
6
- /** Error Message for the group */
7
- errorText: PropTypes.Requireable<string>;
8
- };
9
- }
2
+ type GroupProps = {
3
+ /** Error Message for the group */
4
+ errorText?: string;
5
+ };
6
+ declare const Group: React.ForwardRefExoticComponent<GroupProps & React.RefAttributes<HTMLDivElement>>;
10
7
  export default Group;