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.
- package/README.md +63 -24
- package/dist/index.js +3550 -4336
- package/dist/index.js.map +1 -1
- package/lib-esm/components/Accordion/Accordion.d.ts +11 -16
- package/lib-esm/components/Accordion/Accordion.js +25 -29
- package/lib-esm/components/Accordion/Accordion.js.map +1 -1
- package/lib-esm/components/Accordion/AccordionStep.d.ts +22 -22
- package/lib-esm/components/Accordion/AccordionStep.js +111 -109
- package/lib-esm/components/Accordion/AccordionStep.js.map +1 -1
- package/lib-esm/components/Badge/Badge.d.ts +13 -16
- package/lib-esm/components/Badge/Badge.js +31 -51
- package/lib-esm/components/Badge/Badge.js.map +1 -1
- package/lib-esm/components/Button/ActionButton.d.ts +9 -5
- package/lib-esm/components/Button/ActionButton.js +18 -38
- package/lib-esm/components/Button/ActionButton.js.map +1 -1
- package/lib-esm/components/Button/Button.d.ts +9 -5
- package/lib-esm/components/Button/Button.js +18 -40
- package/lib-esm/components/Button/Button.js.map +1 -1
- package/lib-esm/components/Button/IconButton.d.ts +9 -5
- package/lib-esm/components/Button/IconButton.js +18 -42
- package/lib-esm/components/Button/IconButton.js.map +1 -1
- package/lib-esm/components/Button/LinkButton.d.ts +9 -5
- package/lib-esm/components/Button/LinkButton.js +18 -32
- package/lib-esm/components/Button/LinkButton.js.map +1 -1
- package/lib-esm/components/Button/RaisedButton.d.ts +9 -5
- package/lib-esm/components/Button/RaisedButton.js +18 -46
- package/lib-esm/components/Button/RaisedButton.js.map +1 -1
- package/lib-esm/components/Card/Card.d.ts +4 -6
- package/lib-esm/components/Card/Card.js +18 -13
- package/lib-esm/components/Card/Card.js.map +1 -1
- package/lib-esm/components/Chip/Chip.d.ts +8 -3
- package/lib-esm/components/Chip/Chip.js +44 -42
- package/lib-esm/components/Chip/Chip.js.map +1 -1
- package/lib-esm/components/ChipInput/ChipInput.d.ts +31 -0
- package/lib-esm/components/ChipInput/ChipInput.js +198 -0
- package/lib-esm/components/ChipInput/ChipInput.js.map +1 -0
- package/lib-esm/components/ChipInput/index.d.ts +1 -0
- package/lib-esm/components/Dialog/AlertDialog.d.ts +11 -12
- package/lib-esm/components/Dialog/AlertDialog.js +44 -28
- package/lib-esm/components/Dialog/AlertDialog.js.map +1 -1
- package/lib-esm/components/Dialog/ConfirmDialog.d.ts +13 -14
- package/lib-esm/components/Dialog/ConfirmDialog.js +49 -33
- package/lib-esm/components/Dialog/ConfirmDialog.js.map +1 -1
- package/lib-esm/components/Dialog/Dialog.d.ts +40 -18
- package/lib-esm/components/Dialog/Dialog.js +125 -70
- package/lib-esm/components/Dialog/Dialog.js.map +1 -1
- package/lib-esm/components/Dialog/PromptDialog.d.ts +18 -19
- package/lib-esm/components/Dialog/PromptDialog.js +78 -49
- package/lib-esm/components/Dialog/PromptDialog.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragAndDrop.d.ts +43 -14
- package/lib-esm/components/DragAndDrop/DragAndDrop.js +128 -19
- package/lib-esm/components/DragAndDrop/DragAndDrop.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragItem.d.ts +41 -0
- package/lib-esm/components/DragAndDrop/DragItem.js +253 -36
- package/lib-esm/components/DragAndDrop/DragItem.js.map +1 -1
- package/lib-esm/components/DragAndDrop/types.d.ts +25 -3
- package/lib-esm/components/DragAndDrop/types.js +9 -6
- package/lib-esm/components/DragAndDrop/types.js.map +1 -1
- package/lib-esm/components/Drawer/Drawer.d.ts +86 -22
- package/lib-esm/components/Drawer/Drawer.js +176 -97
- package/lib-esm/components/Drawer/Drawer.js.map +1 -1
- package/lib-esm/components/Drawer/index.d.ts +1 -1
- package/lib-esm/components/Groups/Group.d.ts +5 -8
- package/lib-esm/components/Groups/Group.js +34 -79
- package/lib-esm/components/Groups/Group.js.map +1 -1
- package/lib-esm/components/Groups/GroupLabel.js +8 -17
- package/lib-esm/components/Groups/GroupLabel.js.map +1 -1
- package/lib-esm/components/Input/Checkbox.d.ts +12 -15
- package/lib-esm/components/Input/Checkbox.js +51 -118
- package/lib-esm/components/Input/Checkbox.js.map +1 -1
- package/lib-esm/components/Input/Dropdown.d.ts +11 -12
- package/lib-esm/components/Input/Dropdown.js +133 -52
- package/lib-esm/components/Input/Dropdown.js.map +1 -1
- package/lib-esm/components/Input/Input.d.ts +3 -3
- package/lib-esm/components/Input/Input.js +61 -109
- package/lib-esm/components/Input/Input.js.map +1 -1
- package/lib-esm/components/Input/Radio.d.ts +4 -8
- package/lib-esm/components/Input/Radio.js +35 -79
- package/lib-esm/components/Input/Radio.js.map +1 -1
- package/lib-esm/components/Input/RadioButton.d.ts +4 -8
- package/lib-esm/components/Input/RadioButton.js +34 -71
- package/lib-esm/components/Input/RadioButton.js.map +1 -1
- package/lib-esm/components/Input/Select.d.ts +6 -13
- package/lib-esm/components/Input/Select.js +75 -122
- package/lib-esm/components/Input/Select.js.map +1 -1
- package/lib-esm/components/Input/TextArea.d.ts +6 -13
- package/lib-esm/components/Input/TextArea.js +64 -108
- package/lib-esm/components/Input/TextArea.js.map +1 -1
- package/lib-esm/components/Input/Toggle.d.ts +4 -9
- package/lib-esm/components/Input/Toggle.js +31 -80
- package/lib-esm/components/Input/Toggle.js.map +1 -1
- package/lib-esm/components/Menu/Menu.d.ts +8 -6
- package/lib-esm/components/Menu/Menu.js +116 -31
- package/lib-esm/components/Menu/Menu.js.map +1 -1
- package/lib-esm/components/Menu/MenuContext.d.ts +11 -5
- package/lib-esm/components/Menu/MenuContext.js +6 -2
- package/lib-esm/components/Menu/MenuContext.js.map +1 -1
- package/lib-esm/components/Menu/MenuItem.d.ts +7 -4
- package/lib-esm/components/Menu/MenuItem.js +46 -47
- package/lib-esm/components/Menu/MenuItem.js.map +1 -1
- package/lib-esm/components/Modal/Modal.d.ts +75 -16
- package/lib-esm/components/Modal/Modal.js +150 -51
- package/lib-esm/components/Modal/Modal.js.map +1 -1
- package/lib-esm/components/Notification/Notification.d.ts +46 -39
- package/lib-esm/components/Notification/Notification.js +80 -87
- package/lib-esm/components/Notification/Notification.js.map +1 -1
- package/lib-esm/components/Notification/NotificationManager.d.ts +19 -5
- package/lib-esm/components/Notification/NotificationManager.js +177 -79
- package/lib-esm/components/Notification/NotificationManager.js.map +1 -1
- package/lib-esm/components/Notification/style.d.ts +6 -3
- package/lib-esm/components/Notification/style.js +64 -140
- package/lib-esm/components/Notification/style.js.map +1 -1
- package/lib-esm/components/Notification/types.d.ts +2 -0
- package/lib-esm/components/Notification/types.js +9 -10
- package/lib-esm/components/Notification/types.js.map +1 -1
- package/lib-esm/components/Popover/Popover.d.ts +21 -20
- package/lib-esm/components/Popover/Popover.js +159 -126
- package/lib-esm/components/Popover/Popover.js.map +1 -1
- package/lib-esm/components/Spinner/Spinner.d.ts +14 -12
- package/lib-esm/components/Spinner/Spinner.js +22 -27
- package/lib-esm/components/Spinner/Spinner.js.map +1 -1
- package/lib-esm/components/Stepper/Step.d.ts +15 -12
- package/lib-esm/components/Stepper/Step.js +18 -25
- package/lib-esm/components/Stepper/Step.js.map +1 -1
- package/lib-esm/components/Stepper/Stepper.d.ts +11 -17
- package/lib-esm/components/Stepper/Stepper.js +104 -102
- package/lib-esm/components/Stepper/Stepper.js.map +1 -1
- package/lib-esm/components/Tabs/Tab.d.ts +10 -16
- package/lib-esm/components/Tabs/Tab.js +9 -15
- package/lib-esm/components/Tabs/Tab.js.map +1 -1
- package/lib-esm/components/Tabs/Tabs.d.ts +11 -22
- package/lib-esm/components/Tabs/Tabs.js +97 -55
- package/lib-esm/components/Tabs/Tabs.js.map +1 -1
- package/lib-esm/components/Toast/Toast.d.ts +34 -7
- package/lib-esm/components/Toast/Toast.js +200 -109
- package/lib-esm/components/Toast/Toast.js.map +1 -1
- package/lib-esm/components/Toast/ToastStory.d.ts +21 -24
- package/lib-esm/components/Tooltip/Tooltip.d.ts +11 -14
- package/lib-esm/components/Tooltip/Tooltip.js +52 -67
- package/lib-esm/components/Tooltip/Tooltip.js.map +1 -1
- package/lib-esm/components/index.d.ts +1 -0
- package/lib-esm/components/index.js +43 -20
- package/lib-esm/components/index.js.map +1 -1
- package/lib-esm/icons/CheckCircle.d.ts +1 -1
- package/lib-esm/icons/CheckCircle.js +22 -4
- package/lib-esm/icons/CheckCircle.js.map +1 -1
- package/lib-esm/icons/Close.d.ts +1 -1
- package/lib-esm/icons/Close.js +22 -4
- package/lib-esm/icons/Close.js.map +1 -1
- package/lib-esm/icons/DragIndicator.d.ts +1 -1
- package/lib-esm/icons/DragIndicator.js +22 -4
- package/lib-esm/icons/DragIndicator.js.map +1 -1
- package/lib-esm/icons/ErrorOutline.d.ts +1 -1
- package/lib-esm/icons/ErrorOutline.js +16 -4
- package/lib-esm/icons/ErrorOutline.js.map +1 -1
- package/lib-esm/icons/ExpandMore.d.ts +1 -1
- package/lib-esm/icons/ExpandMore.js +22 -4
- package/lib-esm/icons/ExpandMore.js.map +1 -1
- package/lib-esm/icons/FiberManualRecord.d.ts +1 -1
- package/lib-esm/icons/FiberManualRecord.js +24 -4
- package/lib-esm/icons/FiberManualRecord.js.map +1 -1
- package/lib-esm/icons/Info.d.ts +1 -1
- package/lib-esm/icons/Info.js +22 -4
- package/lib-esm/icons/Info.js.map +1 -1
- package/lib-esm/icons/ReportProblem.d.ts +1 -1
- package/lib-esm/icons/ReportProblem.js +22 -4
- package/lib-esm/icons/ReportProblem.js.map +1 -1
- package/lib-esm/shared/LayerManager.d.ts +34 -4
- package/lib-esm/shared/LayerManager.js +248 -114
- package/lib-esm/shared/LayerManager.js.map +1 -1
- package/lib-esm/shared/constants.d.ts +58 -27
- package/lib-esm/shared/constants.js +62 -26
- package/lib-esm/shared/constants.js.map +1 -1
- package/lib-esm/shared/styles.d.ts +1 -1
- package/lib-esm/shared/styles.js +21 -24
- package/lib-esm/shared/styles.js.map +1 -1
- package/package.json +130 -72
- package/lib-esm/components/Accordion/index.js +0 -3
- package/lib-esm/components/Accordion/index.js.map +0 -1
- package/lib-esm/components/Badge/index.js +0 -2
- package/lib-esm/components/Badge/index.js.map +0 -1
- package/lib-esm/components/Button/index.js +0 -6
- package/lib-esm/components/Button/index.js.map +0 -1
- package/lib-esm/components/Card/index.js +0 -3
- package/lib-esm/components/Card/index.js.map +0 -1
- package/lib-esm/components/Chip/index.js +0 -2
- package/lib-esm/components/Chip/index.js.map +0 -1
- package/lib-esm/components/Dialog/index.js +0 -5
- package/lib-esm/components/Dialog/index.js.map +0 -1
- package/lib-esm/components/DragAndDrop/index.js +0 -3
- package/lib-esm/components/DragAndDrop/index.js.map +0 -1
- package/lib-esm/components/Drawer/index.js +0 -2
- package/lib-esm/components/Drawer/index.js.map +0 -1
- package/lib-esm/components/Groups/index.js +0 -3
- package/lib-esm/components/Groups/index.js.map +0 -1
- package/lib-esm/components/Input/index.js +0 -9
- package/lib-esm/components/Input/index.js.map +0 -1
- package/lib-esm/components/Menu/index.js +0 -3
- package/lib-esm/components/Menu/index.js.map +0 -1
- package/lib-esm/components/Modal/index.js +0 -2
- package/lib-esm/components/Modal/index.js.map +0 -1
- package/lib-esm/components/Notification/index.js +0 -3
- package/lib-esm/components/Notification/index.js.map +0 -1
- package/lib-esm/components/Popover/index.js +0 -2
- package/lib-esm/components/Popover/index.js.map +0 -1
- package/lib-esm/components/Spinner/index.js +0 -2
- package/lib-esm/components/Spinner/index.js.map +0 -1
- package/lib-esm/components/Stepper/index.js +0 -4
- package/lib-esm/components/Stepper/index.js.map +0 -1
- package/lib-esm/components/Tabs/index.js +0 -3
- package/lib-esm/components/Tabs/index.js.map +0 -1
- package/lib-esm/components/Toast/ToastStory.js +0 -35
- package/lib-esm/components/Toast/ToastStory.js.map +0 -1
- package/lib-esm/components/Toast/index.js +0 -2
- package/lib-esm/components/Toast/index.js.map +0 -1
- package/lib-esm/components/Tooltip/index.js +0 -2
- package/lib-esm/components/Tooltip/index.js.map +0 -1
- package/lib-esm/icons/index.js +0 -9
- package/lib-esm/icons/index.js.map +0 -1
- package/lib-esm/index.js +0 -2
- package/lib-esm/index.js.map +0 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
// Context may be undefined if used outside a Menu provider
|
|
4
|
+
var MenuContext = createContext(undefined);
|
|
5
|
+
|
|
6
|
+
export { MenuContext as default };
|
|
7
|
+
//# sourceMappingURL=MenuContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuContext.js","
|
|
1
|
+
{"version":3,"file":"MenuContext.js","sources":["../../../src/components/Menu/MenuContext.ts"],"sourcesContent":["import { createContext } from 'react';\n\ntype SingleSelect<T> = {\n value?: T;\n multiSelect: false;\n updateValue: (newVal: T) => void;\n};\n\ntype MultiSelect<T> = {\n value?: T[];\n multiSelect: true;\n // updateValue takes a single item and the provider will add/remove it\n updateValue: (newVal: T) => void;\n};\nexport type MenuContextType<T> = SingleSelect<T> | MultiSelect<T>;\n\n// Context may be undefined if used outside a Menu provider\nexport default createContext<MenuContextType<unknown> | undefined>(undefined);\n"],"names":["createContext","undefined"],"mappings":";;AAgBA;AACA,kBAAeA,cAAoDC,SAAAA,CAAAA;;;;"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
type MenuItemProps<T> = {
|
|
3
3
|
/** Value of the element */
|
|
4
4
|
value: T;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value'>;
|
|
6
|
+
declare const MenuItemInner: <T>(props: MenuItemProps<T>, ref: React.Ref<HTMLButtonElement>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare const MenuItem: <T>(props: MenuItemProps<T> & {
|
|
8
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
9
|
+
}) => ReturnType<typeof MenuItemInner>;
|
|
10
|
+
export default MenuItem;
|
|
@@ -1,53 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
13
|
-
import { useContext } from 'react';
|
|
1
|
+
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
|
+
import React, { useContext } from 'react';
|
|
14
3
|
import styled from '@emotion/styled';
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
const Container = styled.button `
|
|
19
|
-
font-weight: ${props => props.selected ? 'bold' : 'normal'};
|
|
20
|
-
padding: 8px 6px;
|
|
21
|
-
border: none;
|
|
22
|
-
background-color: transparent;
|
|
23
|
-
font-size: 16px;
|
|
24
|
-
border-bottom: 1px solid var(--border-light-color, ${constants.BORDER_LIGHT_COLOR});
|
|
25
|
-
min-height: 41px;
|
|
26
|
-
display: flex;
|
|
27
|
-
align-items: center;
|
|
28
|
-
cursor: pointer;
|
|
29
|
-
position: relative;
|
|
30
|
-
|
|
31
|
-
&:hover, &:focus, &:focus-within {
|
|
32
|
-
background-color: var(--border-light-color, ${constants.BORDER_LIGHT_COLOR});
|
|
33
|
-
}
|
|
4
|
+
import { getThemeValue, THEME_NAME } from '../../shared/constants.js';
|
|
5
|
+
import Checkbox from '../Input/Checkbox.js';
|
|
6
|
+
import MenuContext from './MenuContext.js';
|
|
34
7
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var _a, _b;
|
|
8
|
+
const Container$4 = /*#__PURE__*/ styled("button", {
|
|
9
|
+
target: "eum9bel0",
|
|
10
|
+
label: "Container"
|
|
11
|
+
})("font-weight:", (props)=>props.selected ? 'bold' : 'normal', ";padding:8px;border:none;border-left:4px solid\n ", (props)=>props.selected && !props.multiselect ? getThemeValue(THEME_NAME.TEXT_COLOR_DARK) : 'transparent', ";background-color:transparent;font-size:16px;border-bottom:1px solid ", getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR), ";min-height:41px;display:flex;align-items:center;cursor:pointer;position:relative;color:", getThemeValue(THEME_NAME.TEXT_COLOR_DARK), ";&:hover,&:focus,&:focus-within{background-color:", getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR), ";}& > label{margin:0 4px 0 0;}");
|
|
12
|
+
const MenuItemInner = (props, ref)=>{
|
|
41
13
|
const context = useContext(MenuContext);
|
|
42
|
-
|
|
43
|
-
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error('`MenuItem` must be used within a `Menu` provider');
|
|
16
|
+
}
|
|
17
|
+
const { value, children, ...rest } = props;
|
|
18
|
+
const clickHandler = (e)=>{
|
|
44
19
|
e.stopPropagation();
|
|
45
|
-
if (context.multiSelect) {
|
|
46
|
-
e.nativeEvent.stopImmediatePropagation();
|
|
47
|
-
}
|
|
48
20
|
context.updateValue(value);
|
|
49
21
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
22
|
+
let selected = false;
|
|
23
|
+
if (context.multiSelect) {
|
|
24
|
+
const arr = context.value;
|
|
25
|
+
selected = Array.isArray(arr) && arr.includes(value);
|
|
26
|
+
} else {
|
|
27
|
+
selected = context.value === value;
|
|
28
|
+
}
|
|
29
|
+
return /*#__PURE__*/ jsxs(Container$4, {
|
|
30
|
+
...rest,
|
|
31
|
+
ref: ref,
|
|
32
|
+
type: "button",
|
|
33
|
+
role: "option",
|
|
34
|
+
"aria-selected": selected,
|
|
35
|
+
selected: selected,
|
|
36
|
+
onClick: clickHandler,
|
|
37
|
+
multiselect: context.multiSelect ? true : undefined,
|
|
38
|
+
children: [
|
|
39
|
+
context.multiSelect && /*#__PURE__*/ jsx(Checkbox, {
|
|
40
|
+
checked: selected,
|
|
41
|
+
readOnly: true,
|
|
42
|
+
tabIndex: -1,
|
|
43
|
+
onClick: (e)=>e.stopPropagation()
|
|
44
|
+
}),
|
|
45
|
+
children
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const MenuItem = /*#__PURE__*/ React.forwardRef(MenuItemInner);
|
|
50
|
+
|
|
51
|
+
export { MenuItem as default };
|
|
52
|
+
//# sourceMappingURL=MenuItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItem.js","
|
|
1
|
+
{"version":3,"file":"MenuItem.js","sources":["../../../src/components/Menu/MenuItem.tsx"],"sourcesContent":["import React, { SyntheticEvent, useContext } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\nimport Checkbox from '../Input/Checkbox';\nimport MenuContext, { MenuContextType } from './MenuContext';\n\ntype MenuItemProps<T> = {\n /** Value of the element */\n value: T;\n} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value'>;\n\nconst Container = styled.button<{ selected: boolean; multiselect?: boolean }>`\n font-weight: ${(props) => (props.selected ? 'bold' : 'normal')};\n padding: 8px;\n border: none;\n border-left: 4px solid\n ${(props) =>\n props.selected && !props.multiselect\n ? getThemeValue(THEME_NAME.TEXT_COLOR_DARK)\n : 'transparent'};\n background-color: transparent;\n font-size: 16px;\n border-bottom: 1px solid ${getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR)};\n min-height: 41px;\n display: flex;\n align-items: center;\n cursor: pointer;\n position: relative;\n color: ${getThemeValue(THEME_NAME.TEXT_COLOR_DARK)};\n\n &:hover,\n &:focus,\n &:focus-within {\n background-color: ${getThemeValue(THEME_NAME.BORDER_LIGHT_COLOR)};\n }\n\n & > label {\n margin: 0 4px 0 0;\n }\n`;\n\nconst MenuItemInner = <T,>(props: MenuItemProps<T>, ref: React.Ref<HTMLButtonElement>) => {\n const context = useContext(MenuContext) as MenuContextType<T> | undefined;\n if (!context) {\n throw new Error('`MenuItem` must be used within a `Menu` provider');\n }\n const { value, children, ...rest } = props;\n const clickHandler = (e: SyntheticEvent) => {\n e.stopPropagation();\n context.updateValue(value as T);\n };\n\n let selected = false;\n if (context.multiSelect) {\n const arr = context.value as unknown as T[] | undefined;\n selected = Array.isArray(arr) && arr.includes(value as unknown as T);\n } else {\n selected = (context.value as unknown as T) === value;\n }\n\n return (\n <Container\n {...rest}\n ref={ref}\n type=\"button\"\n role=\"option\"\n aria-selected={selected}\n selected={selected}\n onClick={clickHandler}\n multiselect={context.multiSelect ? true : undefined}\n >\n {context.multiSelect && (\n <Checkbox\n checked={selected}\n readOnly\n tabIndex={-1}\n onClick={(e) => e.stopPropagation()}\n />\n )}\n {children}\n </Container>\n );\n};\n\nconst MenuItem = React.forwardRef(MenuItemInner) as <T>(\n props: MenuItemProps<T> & { ref?: React.Ref<HTMLButtonElement> },\n) => ReturnType<typeof MenuItemInner>;\nexport default MenuItem;\n"],"names":["Container","styled","props","selected","multiselect","getThemeValue","THEME_NAME","TEXT_COLOR_DARK","BORDER_LIGHT_COLOR","MenuItemInner","ref","context","useContext","MenuContext","Error","value","children","rest","clickHandler","e","stopPropagation","updateValue","multiSelect","arr","Array","isArray","includes","_jsxs","type","role","aria-selected","onClick","undefined","_jsx","Checkbox","checked","readOnly","tabIndex","MenuItem","React","forwardRef"],"mappings":";;;;;;;AAWA,MAAMA,WAAAA,iBAAYC,MAAAA,CAAAA,QAAAA,EAAAA;;;AACC,CAAA,CAAA,CAAA,cAAA,EAAA,CAACC,KAAAA,GAAWA,KAAAA,CAAMC,QAAQ,GAAG,MAAA,GAAS,QAAA,EAAA,0DAAA,EAI/C,CAACD,KAAAA,GACCA,KAAAA,CAA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K,QAAA;QACLC,eAAAA,EAAe3B,QAAAA;QACfA,QAAAA,EAAUA,QAAAA;QACV4B,OAAAA,EAASb,YAAAA;QACTd,WAAAA,EAAaO,OAAAA,CAAQW,WAAW,GAAG,IAAA,GAAOU,SAAAA;;YAEzCrB,OAAAA,CAAQW,WAAW,kBAChBW,GAAA,CAACC,QAAAA,EAAAA;gBACGC,OAAAA,EAAShC,QAAAA;gBACTiC,QAAQ,EAAA,IAAA;AACRC,gBAAAA,QAAAA,EAAU,EAAC;gBACXN,OAAAA,EAAS,CAACZ,CAAAA,GAAMA,CAAAA,CAAEC,eAAe;;AAGxCJ,YAAAA;;;AAGb,CAAA;AAEA,MAAMsB,QAAAA,iBAAWC,KAAAA,CAAMC,UAAU,CAAC/B,aAAAA;;;;"}
|
|
@@ -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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
15
|
-
import
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
83
|
-
|
|
180
|
+
|
|
181
|
+
export { Modal as default };
|
|
182
|
+
//# sourceMappingURL=Modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,YAAY,EAAE,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EACH,MAAM,IAAI,WAAW,EACrB,IAAI,IAAI,SAAS,EACjB,MAAM,IAAI,WAAW,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQrE,MAAqB,KAAM,SAAQ,KAAK,CAAC,SAA0D;IAAnG;;QACI,UAAK,GAAG;YACJ,IAAI,EAAE,KAAK;SACd,CAAA;QA+BO,YAAO,GAA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,CAAC;YACH,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnC,IAAI,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;IAED,MAAM;QACF,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC/B,OAAO,KAAC,SAAS,KAAG,CAAC;QACzB,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AAvEM,eAAS,GAAG;IACf,sBAAsB;IACtB,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IAC/B,8BAA8B;IAC9B,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,wCAAwC;IACxC,mBAAmB,EAAE,SAAS,CAAC,IAAI;IACnC,uDAAuD;IACvD,OAAO,EAAE,SAAS,CAAC,IAAI;CAC1B,AATe,CASf;AAEM,kBAAY,GAAG;IAClB,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,IAAI;CAC5B,AAHkB,CAGlB;eAnBgB,KAAK"}
|
|
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,IA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AkBC,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 =
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
}
|