no-frills-ui 0.0.14-alpha.1 → 0.0.14-alpha.11
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 +28 -22
- package/dist/index.js +3418 -2772
- 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 +6 -3
- package/lib-esm/components/Chip/Chip.js +44 -43
- package/lib-esm/components/Chip/Chip.js.map +1 -1
- package/lib-esm/components/ChipInput/ChipInput.d.ts +28 -30
- package/lib-esm/components/ChipInput/ChipInput.js +121 -139
- package/lib-esm/components/ChipInput/ChipInput.js.map +1 -1
- 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 -41
- package/lib-esm/components/DragAndDrop/DragAndDrop.js +104 -31
- package/lib-esm/components/DragAndDrop/DragAndDrop.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragItem.d.ts +5 -1
- package/lib-esm/components/DragAndDrop/DragItem.js +171 -92
- package/lib-esm/components/DragAndDrop/DragItem.js.map +1 -1
- package/lib-esm/components/DragAndDrop/types.d.ts +22 -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 +146 -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 +96 -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/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/index.js +43 -2
- package/lib-esm/index.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 -74
- 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/ChipInput/index.js +0 -2
- package/lib-esm/components/ChipInput/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/components/index.js +0 -20
- package/lib-esm/components/index.js.map +0 -1
- package/lib-esm/icons/index.js +0 -9
- package/lib-esm/icons/index.js.map +0 -1
|
@@ -1,43 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import React, { createRef } from 'react';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import Dialog from './Dialog.js';
|
|
4
|
+
import { Header, Body, Footer } from '../../shared/styles.js';
|
|
5
|
+
import Button from '../Button/Button.js';
|
|
6
|
+
import ActionButton from '../Button/ActionButton.js';
|
|
7
|
+
|
|
6
8
|
class ConfirmDialog extends React.Component {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.dialog = createRef();
|
|
10
|
-
this.show = () => {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const onClose = (resp) => {
|
|
13
|
-
resp ? resolve(null) : reject();
|
|
14
|
-
};
|
|
15
|
-
this.dialog.current.open(onClose);
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
this.cancel = () => this.dialog.current.close(false);
|
|
19
|
-
this.confirm = () => this.dialog.current.close(true);
|
|
20
|
-
}
|
|
21
9
|
render() {
|
|
22
10
|
const { header, body, yesText, noText, dialogProps } = this.props;
|
|
23
|
-
return (
|
|
11
|
+
return /*#__PURE__*/ jsxs(Dialog, {
|
|
12
|
+
...dialogProps,
|
|
13
|
+
ref: this.dialog,
|
|
14
|
+
closeOnEsc: false,
|
|
15
|
+
closeOnOverlayClick: false,
|
|
16
|
+
children: [
|
|
17
|
+
header && /*#__PURE__*/ jsx(Header, {
|
|
18
|
+
children: header
|
|
19
|
+
}),
|
|
20
|
+
/*#__PURE__*/ jsx(Body, {
|
|
21
|
+
children: body
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ jsxs(Footer, {
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ jsx(Button, {
|
|
26
|
+
onClick: this.cancel,
|
|
27
|
+
children: noText
|
|
28
|
+
}),
|
|
29
|
+
/*#__PURE__*/ jsx(ActionButton, {
|
|
30
|
+
onClick: this.confirm,
|
|
31
|
+
children: yesText
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
})
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
constructor(...args){
|
|
39
|
+
super(...args), this.dialog = /*#__PURE__*/ createRef(), this.show = ()=>{
|
|
40
|
+
return new Promise((resolve, reject)=>{
|
|
41
|
+
const onClose = (resp)=>{
|
|
42
|
+
if (resp) {
|
|
43
|
+
resolve(null);
|
|
44
|
+
} else {
|
|
45
|
+
reject();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
this.dialog.current?.open(onClose);
|
|
49
|
+
});
|
|
50
|
+
}, this.cancel = ()=>this.dialog.current?.close(false), this.confirm = ()=>this.dialog.current?.close(true);
|
|
24
51
|
}
|
|
25
52
|
}
|
|
26
|
-
ConfirmDialog.propTypes = {
|
|
27
|
-
/** Shown as header of the dialog */
|
|
28
|
-
header: PropTypes.string,
|
|
29
|
-
/** Rendered as body of the dialog */
|
|
30
|
-
body: PropTypes.string.isRequired,
|
|
31
|
-
/** Accept button text */
|
|
32
|
-
yesText: PropTypes.string,
|
|
33
|
-
/** Reject button text */
|
|
34
|
-
noText: PropTypes.string,
|
|
35
|
-
/** Props for the dialog */
|
|
36
|
-
dialogProps: PropTypes.object,
|
|
37
|
-
};
|
|
38
53
|
ConfirmDialog.defaultProps = {
|
|
39
54
|
yesText: 'Yes',
|
|
40
55
|
noText: 'No'
|
|
41
56
|
};
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
|
|
58
|
+
export { ConfirmDialog as default };
|
|
59
|
+
//# sourceMappingURL=ConfirmDialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmDialog.js","
|
|
1
|
+
{"version":3,"file":"ConfirmDialog.js","sources":["../../../src/components/Dialog/ConfirmDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport { Button, ActionButton } from '../Button';\nimport Dialog, { DialogBody, DialogFooter, DialogHeader } from './Dialog';\n\ntype ConfirmOption = {\n /** Shown as header of the dialog */\n header: string;\n /** Rendered as body of the dialog */\n body: string;\n /** Accept button text */\n yesText?: string;\n /** Reject button text */\n noText?: string;\n /** Props for the dialog */\n dialogProps?: React.ComponentProps<typeof Dialog>;\n};\n\nexport default class ConfirmDialog extends React.Component<ConfirmOption> {\n private dialog = createRef<Dialog>();\n\n static defaultProps = {\n yesText: 'Yes',\n noText: 'No',\n };\n\n public show = () => {\n return new Promise((resolve, reject) => {\n const onClose = (resp: unknown) => {\n if (resp) {\n resolve(null);\n } else {\n reject();\n }\n };\n this.dialog.current?.open(onClose);\n });\n };\n\n private cancel = () => this.dialog.current?.close(false);\n private confirm = () => this.dialog.current?.close(true);\n\n render() {\n const { header, body, yesText, noText, dialogProps } = this.props;\n return (\n <Dialog\n {...dialogProps}\n ref={this.dialog}\n closeOnEsc={false}\n closeOnOverlayClick={false}\n >\n {header && <DialogHeader>{header}</DialogHeader>}\n <DialogBody>{body}</DialogBody>\n <DialogFooter>\n <Button onClick={this.cancel}>{noText}</Button>\n <ActionButton onClick={this.confirm}>{yesText}</ActionButton>\n </DialogFooter>\n </Dialog>\n );\n }\n}\n"],"names":["ConfirmDialog","React","Component","render","header","body","yesText","noText","dialogProps","props","_jsxs","Dialog","ref","dialog","closeOnEsc","closeOnOverlayClick","_jsx","DialogHeader","DialogBody","DialogFooter","Button","onClick","cancel","ActionButton","confirm","createRef","show","Promise","resolve","reject","onClose","resp","current","open","close","defaultProps"],"mappings":";;;;;;;AAiBe,MAAMA,aAAAA,SAAsBC,MAAMC,SAAS,CAAA;IAwBtDC,MAAAA,GAAS;AACL,QAAA,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAG,IAAI,CAACC,KAAK;AACjE,QAAA,qBACI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AAM,IAAA,CAAA;;AAoBvD;AA1CqBlC,aAAAA,CAGVmC,YAAAA,GAAe;IAClB7B,OAAAA,EAAS,KAAA;IACTC,MAAAA,EAAQ;AACZ,CAAA;;;;"}
|
|
@@ -1,36 +1,58 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
export declare const DialogContainer: import("@emotion/styled").StyledComponent<{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} & import("../Card/Card").CardExtraProps & React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & {
|
|
3
|
+
elevated?: boolean;
|
|
4
|
+
} & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement> & {
|
|
7
5
|
theme?: import("@emotion/react").Theme;
|
|
8
6
|
}, {}, {}>;
|
|
9
7
|
export { Header as DialogHeader, Body as DialogBody, Footer as DialogFooter, } from '../../shared/styles';
|
|
10
|
-
|
|
8
|
+
interface DialogOptions {
|
|
9
|
+
/** Flag to close dialog on `esc` click. Default value is true. */
|
|
10
|
+
closeOnEsc?: boolean;
|
|
11
|
+
/** Close layer overlay is clicked. Default value is true. */
|
|
12
|
+
closeOnOverlayClick?: boolean;
|
|
13
|
+
}
|
|
11
14
|
interface DialogState {
|
|
12
15
|
show: boolean;
|
|
16
|
+
LayerComponent?: React.ComponentType | null;
|
|
13
17
|
}
|
|
14
|
-
declare class Dialog extends React.Component<React.PropsWithChildren<DialogOptions>, DialogState> {
|
|
15
|
-
static propTypes: {
|
|
16
|
-
/** Flag to close dialog on `esc` click. Default value is true. */
|
|
17
|
-
closeOnEsc: PropTypes.Requireable<boolean>;
|
|
18
|
-
/** Close layer overlay is clicked. Default value is true. */
|
|
19
|
-
closeOnOverlayClick: PropTypes.Requireable<boolean>;
|
|
20
|
-
};
|
|
18
|
+
declare class Dialog extends React.Component<React.PropsWithChildren<DialogOptions> & React.HTMLAttributes<HTMLDivElement>, DialogState> {
|
|
21
19
|
static defaultProps: {
|
|
22
20
|
closeOnEsc: boolean;
|
|
23
21
|
closeOnOverlayClick: boolean;
|
|
24
22
|
};
|
|
25
23
|
private closeDialog;
|
|
26
24
|
private onCloseFn;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
private lastFocusedElement;
|
|
26
|
+
private dialogRef;
|
|
27
|
+
state: DialogState;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves all focusable elements within the dialog.
|
|
30
|
+
*/
|
|
31
|
+
private getFocusableElements;
|
|
32
|
+
/**
|
|
33
|
+
* Handles keydown events to implement the focus trap.
|
|
34
|
+
* Traps Tab and Shift+Tab within the dialog.
|
|
35
|
+
*/
|
|
36
|
+
private handleKeyDown;
|
|
37
|
+
/**
|
|
38
|
+
* Restores focus to the element that was focused before the dialog opened.
|
|
39
|
+
*/
|
|
40
|
+
private restoreFocus;
|
|
41
|
+
/**
|
|
42
|
+
* Callback ref to capture the Dialog DOM element.
|
|
43
|
+
* Triggers initial focus setting when the element mounts.
|
|
44
|
+
*/
|
|
45
|
+
private setDialogRef;
|
|
46
|
+
/**
|
|
47
|
+
* Sets initial focus within the dialog.
|
|
48
|
+
* Tries to focus the header first, then the first interactive element, or falls back to the container.
|
|
49
|
+
*/
|
|
50
|
+
private setInitialFocus;
|
|
30
51
|
shouldComponentUpdate(nextProps: DialogOptions, nextState: DialogState): boolean;
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
componentWillUnmount(): void;
|
|
53
|
+
open: (closeCallback?: (resp?: unknown) => void) => void;
|
|
54
|
+
close: (resp?: unknown) => void;
|
|
33
55
|
private closeCallback;
|
|
34
|
-
render(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
56
|
+
render(): import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
35
57
|
}
|
|
36
58
|
export default Dialog;
|
|
@@ -1,66 +1,106 @@
|
|
|
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 PropTypes from 'prop-types';
|
|
15
3
|
import styled from '@emotion/styled';
|
|
16
|
-
import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';
|
|
17
|
-
import
|
|
18
|
-
export const DialogContainer = styled(Card) `
|
|
19
|
-
max-width: 768px;
|
|
20
|
-
max-height: 80vh;
|
|
21
|
-
transform: scale(0);
|
|
22
|
-
opacity: 0;
|
|
23
|
-
transition: all .3s ease;
|
|
4
|
+
import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager.js';
|
|
5
|
+
import Card from '../Card/Card.js';
|
|
24
6
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.nf-layer-exit & {
|
|
31
|
-
opacity: 0;
|
|
32
|
-
transform: scale(0);
|
|
33
|
-
}
|
|
34
|
-
`;
|
|
35
|
-
export { Header as DialogHeader, Body as DialogBody, Footer as DialogFooter, } from '../../shared/styles';
|
|
7
|
+
const DialogContainer = /*#__PURE__*/ styled(Card, {
|
|
8
|
+
target: "e6d22q10",
|
|
9
|
+
label: "DialogContainer"
|
|
10
|
+
})("max-width:768px;max-height:80vh;transform:scale(0);opacity:0;transition:all 0.3s ease;.nf-layer-enter &{opacity:1;transform:scale(1);}.nf-layer-exit &{opacity:0;transform:scale(0);}");
|
|
36
11
|
class Dialog extends React.Component {
|
|
37
|
-
constructor() {
|
|
38
|
-
super(...arguments);
|
|
39
|
-
this.state = {
|
|
40
|
-
show: false,
|
|
41
|
-
};
|
|
42
|
-
this.open = (closeCallback) => {
|
|
43
|
-
this.setState({
|
|
44
|
-
show: true,
|
|
45
|
-
});
|
|
46
|
-
this.onCloseFn = closeCallback;
|
|
47
|
-
};
|
|
48
|
-
this.close = (resp) => {
|
|
49
|
-
this.closeDialog && this.closeDialog(resp);
|
|
50
|
-
};
|
|
51
|
-
this.closeCallback = (resp) => {
|
|
52
|
-
this.setState({
|
|
53
|
-
show: false,
|
|
54
|
-
});
|
|
55
|
-
this.onCloseFn && this.onCloseFn(resp);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
12
|
shouldComponentUpdate(nextProps, nextState) {
|
|
59
13
|
return this.state.show !== nextState.show;
|
|
60
14
|
}
|
|
15
|
+
componentWillUnmount() {
|
|
16
|
+
// Clean up if component unmounts while dialog is open
|
|
17
|
+
if (this.state.show && this.closeDialog) {
|
|
18
|
+
this.closeDialog();
|
|
19
|
+
}
|
|
20
|
+
this.restoreFocus();
|
|
21
|
+
this.closeDialog = null;
|
|
22
|
+
this.onCloseFn = null;
|
|
23
|
+
}
|
|
61
24
|
render() {
|
|
62
|
-
const
|
|
63
|
-
if (this.state.show) {
|
|
25
|
+
const { LayerComponent } = this.state;
|
|
26
|
+
if (this.state.show && LayerComponent) {
|
|
27
|
+
return /*#__PURE__*/ jsx(LayerComponent, {});
|
|
28
|
+
} else {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
constructor(...args){
|
|
33
|
+
super(...args), this.closeDialog = null, this.onCloseFn = null, this.lastFocusedElement = null, this.dialogRef = /*#__PURE__*/ React.createRef(), this.state = {
|
|
34
|
+
show: false,
|
|
35
|
+
LayerComponent: undefined
|
|
36
|
+
}, /**
|
|
37
|
+
* Retrieves all focusable elements within the dialog.
|
|
38
|
+
*/ this.getFocusableElements = ()=>{
|
|
39
|
+
if (!this.dialogRef.current) return [];
|
|
40
|
+
return Array.from(this.dialogRef.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'));
|
|
41
|
+
}, /**
|
|
42
|
+
* Handles keydown events to implement the focus trap.
|
|
43
|
+
* Traps Tab and Shift+Tab within the dialog.
|
|
44
|
+
*/ this.handleKeyDown = (e)=>{
|
|
45
|
+
if (e.key === 'Tab') {
|
|
46
|
+
const focusableElements = this.getFocusableElements();
|
|
47
|
+
if (focusableElements.length === 0) return;
|
|
48
|
+
const firstElement = focusableElements[0];
|
|
49
|
+
const lastElement = focusableElements[focusableElements.length - 1];
|
|
50
|
+
if (e.shiftKey) {
|
|
51
|
+
if (document.activeElement === firstElement) {
|
|
52
|
+
lastElement.focus();
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
if (document.activeElement === lastElement) {
|
|
57
|
+
firstElement.focus();
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, /**
|
|
63
|
+
* Restores focus to the element that was focused before the dialog opened.
|
|
64
|
+
*/ this.restoreFocus = ()=>{
|
|
65
|
+
if (this.lastFocusedElement) {
|
|
66
|
+
const elementToBeFocused = this.lastFocusedElement;
|
|
67
|
+
this.lastFocusedElement = null;
|
|
68
|
+
setTimeout(()=>{
|
|
69
|
+
if (document.body.contains(elementToBeFocused)) {
|
|
70
|
+
elementToBeFocused.focus();
|
|
71
|
+
}
|
|
72
|
+
}, 100);
|
|
73
|
+
}
|
|
74
|
+
}, /**
|
|
75
|
+
* Callback ref to capture the Dialog DOM element.
|
|
76
|
+
* Triggers initial focus setting when the element mounts.
|
|
77
|
+
*/ this.setDialogRef = (node)=>{
|
|
78
|
+
this.dialogRef.current = node;
|
|
79
|
+
if (node) {
|
|
80
|
+
this.setInitialFocus(node);
|
|
81
|
+
}
|
|
82
|
+
}, /**
|
|
83
|
+
* Sets initial focus within the dialog.
|
|
84
|
+
* Tries to focus the header first, then the first interactive element, or falls back to the container.
|
|
85
|
+
*/ this.setInitialFocus = (root)=>{
|
|
86
|
+
const firstChild = root.firstElementChild;
|
|
87
|
+
if (firstChild) {
|
|
88
|
+
if (firstChild.getAttribute('tabindex') === null) {
|
|
89
|
+
firstChild.setAttribute('tabindex', '-1');
|
|
90
|
+
}
|
|
91
|
+
firstChild.focus();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const focusableElements = this.getFocusableElements();
|
|
95
|
+
if (focusableElements.length > 0) {
|
|
96
|
+
focusableElements[0].focus();
|
|
97
|
+
} else {
|
|
98
|
+
root.focus();
|
|
99
|
+
}
|
|
100
|
+
}, this.open = (closeCallback)=>{
|
|
101
|
+
const { closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;
|
|
102
|
+
// Save current focus
|
|
103
|
+
this.lastFocusedElement = document.activeElement;
|
|
64
104
|
const [Component, closeFn] = LayerManager.renderLayer({
|
|
65
105
|
exitDelay: 300,
|
|
66
106
|
overlay: true,
|
|
@@ -68,25 +108,40 @@ class Dialog extends React.Component {
|
|
|
68
108
|
closeCallback: this.closeCallback,
|
|
69
109
|
closeOnOverlayClick,
|
|
70
110
|
position: LAYER_POSITION.DIALOG,
|
|
71
|
-
component: (
|
|
111
|
+
component: /*#__PURE__*/ jsx(DialogContainer, {
|
|
112
|
+
...rest,
|
|
113
|
+
ref: this.setDialogRef,
|
|
114
|
+
role: "dialog",
|
|
115
|
+
"aria-modal": "true",
|
|
116
|
+
tabIndex: -1,
|
|
117
|
+
onKeyDown: this.handleKeyDown,
|
|
118
|
+
onClick: (e)=>e.stopPropagation(),
|
|
119
|
+
elevated: true,
|
|
120
|
+
children: children
|
|
121
|
+
})
|
|
72
122
|
});
|
|
73
123
|
this.closeDialog = closeFn;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
124
|
+
this.setState({
|
|
125
|
+
show: true,
|
|
126
|
+
LayerComponent: Component
|
|
127
|
+
});
|
|
128
|
+
this.onCloseFn = closeCallback ?? null;
|
|
129
|
+
}, this.close = (resp)=>{
|
|
130
|
+
this.closeDialog?.(resp);
|
|
131
|
+
}, this.closeCallback = (resp)=>{
|
|
132
|
+
this.restoreFocus();
|
|
133
|
+
this.setState({
|
|
134
|
+
show: false,
|
|
135
|
+
LayerComponent: undefined
|
|
136
|
+
});
|
|
137
|
+
this.onCloseFn?.(resp);
|
|
138
|
+
};
|
|
79
139
|
}
|
|
80
140
|
}
|
|
81
|
-
Dialog.propTypes = {
|
|
82
|
-
/** Flag to close dialog on `esc` click. Default value is true. */
|
|
83
|
-
closeOnEsc: PropTypes.bool,
|
|
84
|
-
/** Close layer overlay is clicked. Default value is true. */
|
|
85
|
-
closeOnOverlayClick: PropTypes.bool,
|
|
86
|
-
};
|
|
87
141
|
Dialog.defaultProps = {
|
|
88
142
|
closeOnEsc: true,
|
|
89
|
-
closeOnOverlayClick: true
|
|
143
|
+
closeOnOverlayClick: true
|
|
90
144
|
};
|
|
91
|
-
|
|
92
|
-
|
|
145
|
+
|
|
146
|
+
export { DialogContainer, Dialog as default };
|
|
147
|
+
//# sourceMappingURL=Dialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../src/components/Dialog/Dialog.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,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;;;;;;;;;;;;;;;CAgB1C,CAAC;AAEF,OAAO,EAC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C,mBAAmB;gBACnB,QAAQ,EAAE,cAAc,CAAC,MAAM;gBAC/B,SAAS,EAAE,CACP,KAAC,eAAe,oBAAK,IAAI,IAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,QAAQ,kBACjE,QAAQ,IACK,CACrB;aACJ,CAAC,CAAC;YACH,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;YAC3B,OAAO,KAAC,SAAS,KAAG,CAAC;QACzB,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;;AA/DM,gBAAS,GAAG;IACf,kEAAkE;IAClE,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,6DAA6D;IAC7D,mBAAmB,EAAE,SAAS,CAAC,IAAI;CACtC,AALe,CAKf;AAEM,mBAAY,GAAG;IAClB,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,IAAI;CAC5B,AAHkB,CAGlB;AAwDL,eAAe,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"Dialog.js","sources":["../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import React from 'react';\nimport styled from '@emotion/styled';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\nimport { Card } from '../Card';\n\nexport const DialogContainer = styled(Card)`\n max-width: 768px;\n max-height: 80vh;\n transform: scale(0);\n opacity: 0;\n transition: all 0.3s ease;\n\n .nf-layer-enter & {\n opacity: 1;\n transform: scale(1);\n }\n\n .nf-layer-exit & {\n opacity: 0;\n transform: scale(0);\n }\n`;\n\nexport {\n Header as DialogHeader,\n Body as DialogBody,\n Footer as DialogFooter,\n} from '../../shared/styles';\n\ninterface DialogOptions {\n /** Flag to close dialog on `esc` click. Default value is true. */\n closeOnEsc?: boolean;\n /** Close layer overlay is clicked. Default value is true. */\n closeOnOverlayClick?: boolean;\n}\n\ninterface DialogState {\n show: boolean;\n LayerComponent?: React.ComponentType | null;\n}\n\nclass Dialog extends React.Component<\n React.PropsWithChildren<DialogOptions> & React.HTMLAttributes<HTMLDivElement>,\n DialogState\n> {\n static defaultProps = {\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n private closeDialog: ((resp?: unknown) => void) | null = null;\n private onCloseFn: ((resp?: unknown) => void) | null = null;\n private lastFocusedElement: HTMLElement | null = null;\n private dialogRef = React.createRef<HTMLDivElement>();\n\n state: DialogState = {\n show: false,\n LayerComponent: undefined,\n };\n\n /**\n * Retrieves all focusable elements within the dialog.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.dialogRef.current) return [];\n return Array.from(\n this.dialogRef.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 dialog.\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 * Restores focus to the element that was focused before the dialog opened.\n */\n private restoreFocus = () => {\n if (this.lastFocusedElement) {\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 Dialog DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setDialogRef = (node: HTMLDivElement | null) => {\n (this.dialogRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\n if (node) {\n this.setInitialFocus(node);\n }\n };\n\n /**\n * Sets initial focus within the dialog.\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 const firstChild = root.firstElementChild as HTMLElement;\n if (firstChild) {\n if (firstChild.getAttribute('tabindex') === null) {\n firstChild.setAttribute('tabindex', '-1');\n }\n firstChild.focus();\n return;\n }\n\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n } else {\n root.focus();\n }\n };\n\n shouldComponentUpdate(nextProps: DialogOptions, nextState: DialogState) {\n return this.state.show !== nextState.show;\n }\n\n componentWillUnmount() {\n // Clean up if component unmounts while dialog is open\n if (this.state.show && this.closeDialog) {\n this.closeDialog();\n }\n this.restoreFocus();\n this.closeDialog = null;\n this.onCloseFn = null;\n }\n\n public open = (closeCallback?: (resp?: unknown) => void) => {\n const { closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;\n\n // Save current focus\n this.lastFocusedElement = document.activeElement as HTMLElement;\n\n const [Component, closeFn] = LayerManager.renderLayer({\n exitDelay: 300,\n overlay: true,\n closeOnEsc,\n closeCallback: this.closeCallback,\n closeOnOverlayClick,\n position: LAYER_POSITION.DIALOG,\n component: (\n <DialogContainer\n {...rest}\n ref={this.setDialogRef}\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 </DialogContainer>\n ),\n });\n\n this.closeDialog = closeFn;\n\n this.setState({\n show: true,\n LayerComponent: Component,\n });\n this.onCloseFn = closeCallback ?? null;\n };\n\n public close = (resp?: unknown) => {\n this.closeDialog?.(resp);\n };\n\n private closeCallback = (resp?: unknown) => {\n this.restoreFocus();\n this.setState({\n show: false,\n LayerComponent: undefined,\n });\n this.onCloseFn?.(resp);\n };\n\n render() {\n const { LayerComponent } = this.state;\n\n if (this.state.show && LayerComponent) {\n return <LayerComponent />;\n } else {\n return null;\n }\n }\n}\n\nexport default Dialog;\n"],"names":["DialogContainer","styled","Card","Dialog","React","Component","shouldComponentUpdate","nextProps","nextState","state","show","componentWillUnmount","closeDialog","restoreFocus","onCloseFn","render","LayerComponent","_jsx","lastFocusedElement","dialogRef","createRef","undefined","getFocusableElements","current","Array","from","querySelectorAll","handleKeyDown","e","key","focusableElements","length","firstElement","lastElement","shiftKey","document","activeElement","focus","preventDefault","elementToBeFocused","setTimeout","body","contains","setDialogRef","node","setInitialFocus","root","firstChild","firstElementChild","getAttribute","setAttribute","open","closeCallback","closeOnEsc","closeOnOverlayClick","children","rest","props","closeFn","LayerManager","renderLayer","exitDelay","overlay","position","LAYER_POSITION","DIALOG","component","ref","role","aria-modal","tabIndex","onKeyDown","onClick","stopPropagation","elevated","setState","close","resp","defaultProps"],"mappings":";;;;;;AAKO,MAAMA,gCAAkBC,MAAAA,CAAOC,IAAAA,EAAAA;;;AAgBpC,CAAA,CAAA,CAAA,uLAAA;AAoBF,MAAMC,MAAAA,SAAeC,MAAMC,SAAS,CAAA;IA0GhCC,qBAAAA,CAAsBC,SAAwB,EAAEC,SAAsB,EAAE;AACpE,QAAA,OAAO,IAAI,CAACC,KAAK,CAACC,IAAI,KAAKF,UAAUE,IAAI;AAC7C,IAAA;IAEAC,oBAAAA,GAAuB;;QAEnB,IAAI,IAAI,CAACF,KAAK,CAACC,IAAI,IAAI,IAAI,CAACE,WAAW,EAAE;AACrC,YAAA,IAAI,CAACA,WAAW,EAAA;AACpB,QAAA;AACA,QAAA,IAAI,CAACC,YAAY,EAAA;QACjB,IAAI,CAACD,WAAW,GAAG,IAAA;QACnB,IAAI,CAACE,SAAS,GAAG,IAAA;AACrB,IAAA;IAqDAC,MAAAA,GAAS;AACL,QAAA,MAAM,EAAEC,cAAc,EAAE,GAAG,IAAI,CAACP,KAAK;AAErC,QAAA,IAAI,IAAI,CAACA,KAAK,CAACC,IAAI,IAAIM,cAAAA,EAAgB;AACnC,YAAA,qBAAOC,GAAA,CAACD,cAAAA,EAAAA,EAAAA,CAAAA;QACZ,CAAA,MAAO;YACH,OAAO,IAAA;AACX,QAAA;AACJ,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AACjE,WAAW,GAAGiE,IAAAA,CAAAA;AACvB,QAAA,CAAA,EAAA,IAAA,CAEQzB,gBAAgB,CAACyB,IAAAA,GAAAA;AACrB,YAAA,IAAI,CAAChE,YAAY,EAAA;YACjB,IAAI,CAAC8D,QAAQ,CAAC;gBACVjE,IAAAA,EAAM,KAAA;gBACNM,cAAAA,EAAgBK;AACpB,aAAA,CAAA;YACA,IAAI,CAACP,SAAS,GAAG+D,IAAAA,CAAAA;AACrB,QAAA,CAAA;;AAWJ;AApLM1E,MAAAA,CAIK2E,YAAAA,GAAe;IAClBzB,UAAAA,EAAY,IAAA;IACZC,mBAAAA,EAAqB;AACzB,CAAA;;;;"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
type PromptOption =
|
|
2
|
+
import Dialog from './Dialog';
|
|
3
|
+
type PromptOption = {
|
|
4
|
+
/** Shown as header of the dialog */
|
|
5
|
+
header: string;
|
|
6
|
+
/** Rendered as the body of the dialog */
|
|
7
|
+
body: string;
|
|
8
|
+
/** Default value for the input. */
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
/** Submit button text. Default value is 'Submit' */
|
|
11
|
+
submitText?: string;
|
|
12
|
+
/** Cancel button text. Default value is 'Cancel' */
|
|
13
|
+
cancelText?: string;
|
|
14
|
+
/** Props for the input. */
|
|
15
|
+
inputProps?: React.HTMLProps<HTMLInputElement>;
|
|
16
|
+
/** Additional props for the dialog. */
|
|
17
|
+
dialogProps?: React.ComponentProps<typeof Dialog>;
|
|
18
|
+
};
|
|
4
19
|
export default class PromptDialog extends React.Component<PromptOption, {
|
|
5
|
-
value
|
|
20
|
+
value?: string;
|
|
6
21
|
}> {
|
|
7
|
-
static propTypes: {
|
|
8
|
-
/** Shown as header of the dialog */
|
|
9
|
-
header: PropTypes.Requireable<string>;
|
|
10
|
-
/** Rendered as the body of the dialog */
|
|
11
|
-
body: PropTypes.Requireable<string>;
|
|
12
|
-
/** Default value for the input. */
|
|
13
|
-
defaultValue: PropTypes.Requireable<string>;
|
|
14
|
-
/** Submit button text. Default value is 'Submit' */
|
|
15
|
-
submitText: PropTypes.Requireable<string>;
|
|
16
|
-
/** Cancel button text. Default value is 'Cancel' */
|
|
17
|
-
cancelText: PropTypes.Requireable<string>;
|
|
18
|
-
/** Props for the input. */
|
|
19
|
-
inputProps: PropTypes.Requireable<object>;
|
|
20
|
-
/** Additional props for the dialog. */
|
|
21
|
-
dialogProps: PropTypes.Requireable<object>;
|
|
22
|
-
};
|
|
23
22
|
static defaultProps: {
|
|
24
23
|
cancelText: string;
|
|
25
24
|
submitText: string;
|
|
@@ -1,72 +1,101 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import React, { createRef } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
3
|
import styled from '@emotion/styled';
|
|
5
|
-
import Dialog
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
import Dialog from './Dialog.js';
|
|
5
|
+
import { Header, Body, Footer } from '../../shared/styles.js';
|
|
6
|
+
import Button from '../Button/Button.js';
|
|
7
|
+
import ActionButton from '../Button/ActionButton.js';
|
|
8
|
+
import Input from '../Input/Input.js';
|
|
9
|
+
|
|
10
|
+
const BodyText = /*#__PURE__*/ styled("p", {
|
|
11
|
+
target: "evq93jk0",
|
|
12
|
+
label: "BodyText"
|
|
13
|
+
})("margin-top:0;");
|
|
14
|
+
const InputContainer = /*#__PURE__*/ styled("div", {
|
|
15
|
+
target: "evq93jk1",
|
|
16
|
+
label: "InputContainer"
|
|
17
|
+
})("display:flex;flex:1;margin-top:10px;& > label{flex:1;width:100%;padding:0;& > input{width:100%;padding:0 8px;box-sizing:border-box;}}");
|
|
18
|
+
const StyledInput = /*#__PURE__*/ styled(Input, {
|
|
19
|
+
target: "evq93jk2",
|
|
20
|
+
label: "StyledInput"
|
|
21
|
+
})("flex:1;padding:0;");
|
|
11
22
|
class PromptDialog extends React.Component {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
render() {
|
|
24
|
+
const { header, body, inputProps, submitText, cancelText, dialogProps } = this.props;
|
|
25
|
+
return /*#__PURE__*/ jsx(Dialog, {
|
|
26
|
+
...dialogProps,
|
|
27
|
+
ref: this.dialog,
|
|
28
|
+
closeOnEsc: false,
|
|
29
|
+
closeOnOverlayClick: false,
|
|
30
|
+
children: /*#__PURE__*/ jsxs("form", {
|
|
31
|
+
onSubmit: this.submit,
|
|
32
|
+
children: [
|
|
33
|
+
header && /*#__PURE__*/ jsx(Header, {
|
|
34
|
+
children: header
|
|
35
|
+
}),
|
|
36
|
+
/*#__PURE__*/ jsxs(Body, {
|
|
37
|
+
children: [
|
|
38
|
+
/*#__PURE__*/ jsx(BodyText, {
|
|
39
|
+
children: body
|
|
40
|
+
}),
|
|
41
|
+
/*#__PURE__*/ jsx(InputContainer, {
|
|
42
|
+
children: /*#__PURE__*/ jsx(StyledInput, {
|
|
43
|
+
value: this.state.value,
|
|
44
|
+
onChange: this.valueChange,
|
|
45
|
+
...inputProps
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ jsxs(Footer, {
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsx(Button, {
|
|
53
|
+
type: "button",
|
|
54
|
+
onClick: this.cancel,
|
|
55
|
+
children: cancelText
|
|
56
|
+
}),
|
|
57
|
+
/*#__PURE__*/ jsx(ActionButton, {
|
|
58
|
+
children: submitText
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
constructor(props){
|
|
67
|
+
super(props), this.dialog = /*#__PURE__*/ createRef(), this.valueChange = (e)=>{
|
|
16
68
|
this.setState({
|
|
17
|
-
value: e.target.value
|
|
69
|
+
value: e.target.value
|
|
18
70
|
});
|
|
19
|
-
}
|
|
20
|
-
this.cancel = () => this.dialog.current.close();
|
|
21
|
-
this.submit = (e) => {
|
|
71
|
+
}, this.cancel = ()=>this.dialog.current?.close(), this.submit = (e)=>{
|
|
22
72
|
e.preventDefault();
|
|
23
|
-
this.dialog.current
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const onClose = (value) => {
|
|
73
|
+
this.dialog.current?.close(this.state.value);
|
|
74
|
+
}, this.show = ()=>{
|
|
75
|
+
return new Promise((resolve, reject)=>{
|
|
76
|
+
const onClose = (value)=>{
|
|
28
77
|
if (value) {
|
|
29
78
|
resolve(value);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
79
|
+
} else {
|
|
32
80
|
reject();
|
|
33
81
|
}
|
|
34
82
|
this.setState({
|
|
35
|
-
value: this.props.defaultValue
|
|
83
|
+
value: this.props.defaultValue
|
|
36
84
|
});
|
|
37
85
|
};
|
|
38
|
-
this.dialog.current
|
|
86
|
+
this.dialog.current?.open(onClose);
|
|
39
87
|
});
|
|
40
88
|
};
|
|
41
89
|
this.state = {
|
|
42
|
-
value: props.defaultValue
|
|
90
|
+
value: props.defaultValue
|
|
43
91
|
};
|
|
44
92
|
}
|
|
45
|
-
render() {
|
|
46
|
-
const { header, body, inputProps, submitText, cancelText, dialogProps } = this.props;
|
|
47
|
-
return (_jsx(Dialog, Object.assign({}, dialogProps, { ref: this.dialog, closeOnEsc: false, closeOnOverlayClick: false, children: _jsxs("form", { onSubmit: this.submit, children: [header && _jsx(DialogHeader, { children: header }), _jsxs(DialogBody, { children: [_jsx(BodyText, { children: body }), _jsx("div", { style: { display: 'flex' }, children: _jsx(Input, Object.assign({ style: { width: 'auto', flex: '1' }, value: this.state.value, onChange: this.valueChange, autoFocus: true }, inputProps)) })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: 'button', onClick: this.cancel, children: cancelText }), _jsx(ActionButton, { children: submitText })] })] }) })));
|
|
48
|
-
}
|
|
49
93
|
}
|
|
50
|
-
PromptDialog.propTypes = {
|
|
51
|
-
/** Shown as header of the dialog */
|
|
52
|
-
header: PropTypes.string,
|
|
53
|
-
/** Rendered as the body of the dialog */
|
|
54
|
-
body: PropTypes.string,
|
|
55
|
-
/** Default value for the input. */
|
|
56
|
-
defaultValue: PropTypes.string,
|
|
57
|
-
/** Submit button text. Default value is 'Submit' */
|
|
58
|
-
submitText: PropTypes.string,
|
|
59
|
-
/** Cancel button text. Default value is 'Cancel' */
|
|
60
|
-
cancelText: PropTypes.string,
|
|
61
|
-
/** Props for the input. */
|
|
62
|
-
inputProps: PropTypes.object,
|
|
63
|
-
/** Additional props for the dialog. */
|
|
64
|
-
dialogProps: PropTypes.object,
|
|
65
|
-
};
|
|
66
94
|
PromptDialog.defaultProps = {
|
|
67
95
|
cancelText: 'Cancel',
|
|
68
96
|
submitText: 'Submit',
|
|
69
|
-
defaultValue: ''
|
|
97
|
+
defaultValue: ''
|
|
70
98
|
};
|
|
71
|
-
|
|
72
|
-
|
|
99
|
+
|
|
100
|
+
export { PromptDialog as default };
|
|
101
|
+
//# sourceMappingURL=PromptDialog.js.map
|