@elementor/editor-ui 3.33.0-118 → 3.33.0-119
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/dist/index.d.mts +28 -2
- package/dist/index.d.ts +28 -2
- package/dist/index.js +51 -5
- package/dist/index.mjs +56 -3
- package/package.json +2 -2
- package/src/components/save-changes-dialog.tsx +106 -0
- package/src/index.ts +2 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
2
|
import { ReactNode, PropsWithChildren, ReactElement } from 'react';
|
|
3
|
-
import { MenuItemProps, AlertProps, InfotipProps, MenuList } from '@elementor/ui';
|
|
3
|
+
import { MenuItemProps, AlertProps, InfotipProps, MenuList, DialogProps, DialogContentTextProps } from '@elementor/ui';
|
|
4
4
|
import * as _emotion_styled from '@emotion/styled';
|
|
5
5
|
|
|
6
6
|
type EllipsisWithTooltipProps<T extends React$1.ElementType> = {
|
|
@@ -116,6 +116,32 @@ type Props = {
|
|
|
116
116
|
};
|
|
117
117
|
declare const PopoverSearch: ({ value, onSearch, placeholder }: Props) => React$1.JSX.Element;
|
|
118
118
|
|
|
119
|
+
declare const SaveChangesDialog: {
|
|
120
|
+
({ children, onClose }: Pick<DialogProps, "children" | "onClose">): React$1.JSX.Element;
|
|
121
|
+
Title: ({ children, onClose }: React$1.PropsWithChildren & {
|
|
122
|
+
onClose?: () => void;
|
|
123
|
+
}) => React$1.JSX.Element;
|
|
124
|
+
Content: ({ children }: React$1.PropsWithChildren) => React$1.JSX.Element;
|
|
125
|
+
ContentText: (props: DialogContentTextProps) => React$1.JSX.Element;
|
|
126
|
+
Actions: ({ actions }: ConfirmationDialogActionsProps) => React$1.JSX.Element;
|
|
127
|
+
};
|
|
128
|
+
type Action = {
|
|
129
|
+
label: string;
|
|
130
|
+
action: () => void | Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
type ConfirmationDialogActionsProps = {
|
|
133
|
+
actions: {
|
|
134
|
+
cancel?: Action;
|
|
135
|
+
confirm: Action;
|
|
136
|
+
discard?: Action;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
declare const useDialog: () => {
|
|
140
|
+
isOpen: boolean;
|
|
141
|
+
open: () => void;
|
|
142
|
+
close: () => void;
|
|
143
|
+
};
|
|
144
|
+
|
|
119
145
|
type UseEditableParams = {
|
|
120
146
|
value: string;
|
|
121
147
|
onSubmit: (value: string) => unknown;
|
|
@@ -142,4 +168,4 @@ declare const useEditable: ({ value, onSubmit, validation, onClick, onError }: U
|
|
|
142
168
|
};
|
|
143
169
|
};
|
|
144
170
|
|
|
145
|
-
export { EditableField, EllipsisWithTooltip, GlobalDialog, ITEM_HEIGHT, InfoAlert, InfoTipCard, IntroductionModal, MenuItemInfotip, MenuListItem, PopoverBody, PopoverHeader, PopoverMenuList, type PopoverMenuListProps, PopoverSearch, StyledMenuList, ThemeProvider, type VirtualizedItem, WarningInfotip, closeDialog, openDialog, useEditable };
|
|
171
|
+
export { EditableField, EllipsisWithTooltip, GlobalDialog, ITEM_HEIGHT, InfoAlert, InfoTipCard, IntroductionModal, MenuItemInfotip, MenuListItem, PopoverBody, PopoverHeader, PopoverMenuList, type PopoverMenuListProps, PopoverSearch, SaveChangesDialog, StyledMenuList, ThemeProvider, type VirtualizedItem, WarningInfotip, closeDialog, openDialog, useDialog, useEditable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
2
|
import { ReactNode, PropsWithChildren, ReactElement } from 'react';
|
|
3
|
-
import { MenuItemProps, AlertProps, InfotipProps, MenuList } from '@elementor/ui';
|
|
3
|
+
import { MenuItemProps, AlertProps, InfotipProps, MenuList, DialogProps, DialogContentTextProps } from '@elementor/ui';
|
|
4
4
|
import * as _emotion_styled from '@emotion/styled';
|
|
5
5
|
|
|
6
6
|
type EllipsisWithTooltipProps<T extends React$1.ElementType> = {
|
|
@@ -116,6 +116,32 @@ type Props = {
|
|
|
116
116
|
};
|
|
117
117
|
declare const PopoverSearch: ({ value, onSearch, placeholder }: Props) => React$1.JSX.Element;
|
|
118
118
|
|
|
119
|
+
declare const SaveChangesDialog: {
|
|
120
|
+
({ children, onClose }: Pick<DialogProps, "children" | "onClose">): React$1.JSX.Element;
|
|
121
|
+
Title: ({ children, onClose }: React$1.PropsWithChildren & {
|
|
122
|
+
onClose?: () => void;
|
|
123
|
+
}) => React$1.JSX.Element;
|
|
124
|
+
Content: ({ children }: React$1.PropsWithChildren) => React$1.JSX.Element;
|
|
125
|
+
ContentText: (props: DialogContentTextProps) => React$1.JSX.Element;
|
|
126
|
+
Actions: ({ actions }: ConfirmationDialogActionsProps) => React$1.JSX.Element;
|
|
127
|
+
};
|
|
128
|
+
type Action = {
|
|
129
|
+
label: string;
|
|
130
|
+
action: () => void | Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
type ConfirmationDialogActionsProps = {
|
|
133
|
+
actions: {
|
|
134
|
+
cancel?: Action;
|
|
135
|
+
confirm: Action;
|
|
136
|
+
discard?: Action;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
declare const useDialog: () => {
|
|
140
|
+
isOpen: boolean;
|
|
141
|
+
open: () => void;
|
|
142
|
+
close: () => void;
|
|
143
|
+
};
|
|
144
|
+
|
|
119
145
|
type UseEditableParams = {
|
|
120
146
|
value: string;
|
|
121
147
|
onSubmit: (value: string) => unknown;
|
|
@@ -142,4 +168,4 @@ declare const useEditable: ({ value, onSubmit, validation, onClick, onError }: U
|
|
|
142
168
|
};
|
|
143
169
|
};
|
|
144
170
|
|
|
145
|
-
export { EditableField, EllipsisWithTooltip, GlobalDialog, ITEM_HEIGHT, InfoAlert, InfoTipCard, IntroductionModal, MenuItemInfotip, MenuListItem, PopoverBody, PopoverHeader, PopoverMenuList, type PopoverMenuListProps, PopoverSearch, StyledMenuList, ThemeProvider, type VirtualizedItem, WarningInfotip, closeDialog, openDialog, useEditable };
|
|
171
|
+
export { EditableField, EllipsisWithTooltip, GlobalDialog, ITEM_HEIGHT, InfoAlert, InfoTipCard, IntroductionModal, MenuItemInfotip, MenuListItem, PopoverBody, PopoverHeader, PopoverMenuList, type PopoverMenuListProps, PopoverSearch, SaveChangesDialog, StyledMenuList, ThemeProvider, type VirtualizedItem, WarningInfotip, closeDialog, openDialog, useDialog, useEditable };
|
package/dist/index.js
CHANGED
|
@@ -43,11 +43,13 @@ __export(index_exports, {
|
|
|
43
43
|
PopoverHeader: () => PopoverHeader,
|
|
44
44
|
PopoverMenuList: () => PopoverMenuList,
|
|
45
45
|
PopoverSearch: () => PopoverSearch,
|
|
46
|
+
SaveChangesDialog: () => SaveChangesDialog,
|
|
46
47
|
StyledMenuList: () => StyledMenuList,
|
|
47
48
|
ThemeProvider: () => ThemeProvider,
|
|
48
49
|
WarningInfotip: () => WarningInfotip,
|
|
49
50
|
closeDialog: () => closeDialog,
|
|
50
51
|
openDialog: () => openDialog,
|
|
52
|
+
useDialog: () => useDialog,
|
|
51
53
|
useEditable: () => useEditable
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -605,11 +607,53 @@ var PopoverSearch = ({ value, onSearch, placeholder }) => {
|
|
|
605
607
|
));
|
|
606
608
|
};
|
|
607
609
|
|
|
608
|
-
// src/
|
|
610
|
+
// src/components/save-changes-dialog.tsx
|
|
611
|
+
var React14 = __toESM(require("react"));
|
|
609
612
|
var import_react12 = require("react");
|
|
613
|
+
var import_icons3 = require("@elementor/icons");
|
|
614
|
+
var import_ui14 = require("@elementor/ui");
|
|
615
|
+
var TITLE_ID = "save-changes-dialog";
|
|
616
|
+
var SaveChangesDialog = ({ children, onClose }) => /* @__PURE__ */ React14.createElement(import_ui14.Dialog, { open: true, onClose, "aria-labelledby": TITLE_ID, maxWidth: "xs" }, children);
|
|
617
|
+
var SaveChangesDialogTitle = ({ children, onClose }) => /* @__PURE__ */ React14.createElement(
|
|
618
|
+
import_ui14.DialogTitle,
|
|
619
|
+
{
|
|
620
|
+
id: TITLE_ID,
|
|
621
|
+
display: "flex",
|
|
622
|
+
alignItems: "center",
|
|
623
|
+
gap: 1,
|
|
624
|
+
sx: { lineHeight: 1, justifyContent: "space-between" }
|
|
625
|
+
},
|
|
626
|
+
/* @__PURE__ */ React14.createElement(import_ui14.Stack, { direction: "row", alignItems: "center", gap: 1 }, /* @__PURE__ */ React14.createElement(import_icons3.AlertTriangleFilledIcon, { color: "secondary" }), children),
|
|
627
|
+
onClose && /* @__PURE__ */ React14.createElement(import_ui14.IconButton, { onClick: onClose, size: "small" }, /* @__PURE__ */ React14.createElement(import_icons3.XIcon, null))
|
|
628
|
+
);
|
|
629
|
+
var SaveChangesDialogContent = ({ children }) => /* @__PURE__ */ React14.createElement(import_ui14.DialogContent, null, children);
|
|
630
|
+
var SaveChangesDialogContentText = (props) => /* @__PURE__ */ React14.createElement(import_ui14.DialogContentText, { variant: "body2", color: "textPrimary", display: "flex", flexDirection: "column", ...props });
|
|
631
|
+
var SaveChangesDialogActions = ({ actions }) => {
|
|
632
|
+
const [isConfirming, setIsConfirming] = (0, import_react12.useState)(false);
|
|
633
|
+
const { cancel, confirm, discard } = actions;
|
|
634
|
+
const onConfirm = async () => {
|
|
635
|
+
setIsConfirming(true);
|
|
636
|
+
await confirm.action();
|
|
637
|
+
setIsConfirming(false);
|
|
638
|
+
};
|
|
639
|
+
return /* @__PURE__ */ React14.createElement(import_ui14.DialogActions, null, cancel && /* @__PURE__ */ React14.createElement(import_ui14.Button, { variant: "text", color: "secondary", onClick: cancel.action }, cancel.label), discard && /* @__PURE__ */ React14.createElement(import_ui14.Button, { variant: "text", color: "secondary", onClick: discard.action }, discard.label), /* @__PURE__ */ React14.createElement(import_ui14.Button, { variant: "contained", color: "secondary", onClick: onConfirm, loading: isConfirming }, confirm.label));
|
|
640
|
+
};
|
|
641
|
+
SaveChangesDialog.Title = SaveChangesDialogTitle;
|
|
642
|
+
SaveChangesDialog.Content = SaveChangesDialogContent;
|
|
643
|
+
SaveChangesDialog.ContentText = SaveChangesDialogContentText;
|
|
644
|
+
SaveChangesDialog.Actions = SaveChangesDialogActions;
|
|
645
|
+
var useDialog = () => {
|
|
646
|
+
const [isOpen, setIsOpen] = (0, import_react12.useState)(false);
|
|
647
|
+
const open = () => setIsOpen(true);
|
|
648
|
+
const close = () => setIsOpen(false);
|
|
649
|
+
return { isOpen, open, close };
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// src/hooks/use-editable.ts
|
|
653
|
+
var import_react13 = require("react");
|
|
610
654
|
var useEditable = ({ value, onSubmit, validation, onClick, onError }) => {
|
|
611
|
-
const [isEditing, setIsEditing] = (0,
|
|
612
|
-
const [error, setError] = (0,
|
|
655
|
+
const [isEditing, setIsEditing] = (0, import_react13.useState)(false);
|
|
656
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
613
657
|
const ref = useSelection(isEditing);
|
|
614
658
|
const isDirty = (newValue) => newValue !== value;
|
|
615
659
|
const openEditMode = () => {
|
|
@@ -682,8 +726,8 @@ var useEditable = ({ value, onSubmit, validation, onClick, onError }) => {
|
|
|
682
726
|
};
|
|
683
727
|
};
|
|
684
728
|
var useSelection = (isEditing) => {
|
|
685
|
-
const ref = (0,
|
|
686
|
-
(0,
|
|
729
|
+
const ref = (0, import_react13.useRef)(null);
|
|
730
|
+
(0, import_react13.useEffect)(() => {
|
|
687
731
|
if (isEditing) {
|
|
688
732
|
selectAll(ref.current);
|
|
689
733
|
}
|
|
@@ -715,11 +759,13 @@ var selectAll = (el) => {
|
|
|
715
759
|
PopoverHeader,
|
|
716
760
|
PopoverMenuList,
|
|
717
761
|
PopoverSearch,
|
|
762
|
+
SaveChangesDialog,
|
|
718
763
|
StyledMenuList,
|
|
719
764
|
ThemeProvider,
|
|
720
765
|
WarningInfotip,
|
|
721
766
|
closeDialog,
|
|
722
767
|
openDialog,
|
|
768
|
+
useDialog,
|
|
723
769
|
useEditable
|
|
724
770
|
});
|
|
725
771
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -565,11 +565,62 @@ var PopoverSearch = ({ value, onSearch, placeholder }) => {
|
|
|
565
565
|
));
|
|
566
566
|
};
|
|
567
567
|
|
|
568
|
+
// src/components/save-changes-dialog.tsx
|
|
569
|
+
import * as React14 from "react";
|
|
570
|
+
import { useState as useState6 } from "react";
|
|
571
|
+
import { AlertTriangleFilledIcon, XIcon as XIcon2 } from "@elementor/icons";
|
|
572
|
+
import {
|
|
573
|
+
Button as Button3,
|
|
574
|
+
Dialog as Dialog3,
|
|
575
|
+
DialogActions as DialogActions2,
|
|
576
|
+
DialogContent,
|
|
577
|
+
DialogContentText,
|
|
578
|
+
DialogTitle as DialogTitle2,
|
|
579
|
+
IconButton as IconButton2,
|
|
580
|
+
Stack as Stack2
|
|
581
|
+
} from "@elementor/ui";
|
|
582
|
+
var TITLE_ID = "save-changes-dialog";
|
|
583
|
+
var SaveChangesDialog = ({ children, onClose }) => /* @__PURE__ */ React14.createElement(Dialog3, { open: true, onClose, "aria-labelledby": TITLE_ID, maxWidth: "xs" }, children);
|
|
584
|
+
var SaveChangesDialogTitle = ({ children, onClose }) => /* @__PURE__ */ React14.createElement(
|
|
585
|
+
DialogTitle2,
|
|
586
|
+
{
|
|
587
|
+
id: TITLE_ID,
|
|
588
|
+
display: "flex",
|
|
589
|
+
alignItems: "center",
|
|
590
|
+
gap: 1,
|
|
591
|
+
sx: { lineHeight: 1, justifyContent: "space-between" }
|
|
592
|
+
},
|
|
593
|
+
/* @__PURE__ */ React14.createElement(Stack2, { direction: "row", alignItems: "center", gap: 1 }, /* @__PURE__ */ React14.createElement(AlertTriangleFilledIcon, { color: "secondary" }), children),
|
|
594
|
+
onClose && /* @__PURE__ */ React14.createElement(IconButton2, { onClick: onClose, size: "small" }, /* @__PURE__ */ React14.createElement(XIcon2, null))
|
|
595
|
+
);
|
|
596
|
+
var SaveChangesDialogContent = ({ children }) => /* @__PURE__ */ React14.createElement(DialogContent, null, children);
|
|
597
|
+
var SaveChangesDialogContentText = (props) => /* @__PURE__ */ React14.createElement(DialogContentText, { variant: "body2", color: "textPrimary", display: "flex", flexDirection: "column", ...props });
|
|
598
|
+
var SaveChangesDialogActions = ({ actions }) => {
|
|
599
|
+
const [isConfirming, setIsConfirming] = useState6(false);
|
|
600
|
+
const { cancel, confirm, discard } = actions;
|
|
601
|
+
const onConfirm = async () => {
|
|
602
|
+
setIsConfirming(true);
|
|
603
|
+
await confirm.action();
|
|
604
|
+
setIsConfirming(false);
|
|
605
|
+
};
|
|
606
|
+
return /* @__PURE__ */ React14.createElement(DialogActions2, null, cancel && /* @__PURE__ */ React14.createElement(Button3, { variant: "text", color: "secondary", onClick: cancel.action }, cancel.label), discard && /* @__PURE__ */ React14.createElement(Button3, { variant: "text", color: "secondary", onClick: discard.action }, discard.label), /* @__PURE__ */ React14.createElement(Button3, { variant: "contained", color: "secondary", onClick: onConfirm, loading: isConfirming }, confirm.label));
|
|
607
|
+
};
|
|
608
|
+
SaveChangesDialog.Title = SaveChangesDialogTitle;
|
|
609
|
+
SaveChangesDialog.Content = SaveChangesDialogContent;
|
|
610
|
+
SaveChangesDialog.ContentText = SaveChangesDialogContentText;
|
|
611
|
+
SaveChangesDialog.Actions = SaveChangesDialogActions;
|
|
612
|
+
var useDialog = () => {
|
|
613
|
+
const [isOpen, setIsOpen] = useState6(false);
|
|
614
|
+
const open = () => setIsOpen(true);
|
|
615
|
+
const close = () => setIsOpen(false);
|
|
616
|
+
return { isOpen, open, close };
|
|
617
|
+
};
|
|
618
|
+
|
|
568
619
|
// src/hooks/use-editable.ts
|
|
569
|
-
import { useEffect as useEffect6, useRef as useRef3, useState as
|
|
620
|
+
import { useEffect as useEffect6, useRef as useRef3, useState as useState7 } from "react";
|
|
570
621
|
var useEditable = ({ value, onSubmit, validation, onClick, onError }) => {
|
|
571
|
-
const [isEditing, setIsEditing] =
|
|
572
|
-
const [error, setError] =
|
|
622
|
+
const [isEditing, setIsEditing] = useState7(false);
|
|
623
|
+
const [error, setError] = useState7(null);
|
|
573
624
|
const ref = useSelection(isEditing);
|
|
574
625
|
const isDirty = (newValue) => newValue !== value;
|
|
575
626
|
const openEditMode = () => {
|
|
@@ -674,11 +725,13 @@ export {
|
|
|
674
725
|
PopoverHeader,
|
|
675
726
|
PopoverMenuList,
|
|
676
727
|
PopoverSearch,
|
|
728
|
+
SaveChangesDialog,
|
|
677
729
|
StyledMenuList,
|
|
678
730
|
ThemeProvider,
|
|
679
731
|
WarningInfotip,
|
|
680
732
|
closeDialog,
|
|
681
733
|
openDialog,
|
|
734
|
+
useDialog,
|
|
682
735
|
useEditable
|
|
683
736
|
};
|
|
684
737
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-ui",
|
|
3
3
|
"description": "Elementor Editor UI",
|
|
4
|
-
"version": "3.33.0-
|
|
4
|
+
"version": "3.33.0-119",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"react-dom": "^18.3.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@elementor/editor-v1-adapters": "3.33.0-
|
|
40
|
+
"@elementor/editor-v1-adapters": "3.33.0-119",
|
|
41
41
|
"@elementor/icons": "1.46.0",
|
|
42
42
|
"@elementor/ui": "1.36.12",
|
|
43
43
|
"@tanstack/react-virtual": "^3.13.3",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { AlertTriangleFilledIcon, XIcon } from '@elementor/icons';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Dialog,
|
|
7
|
+
DialogActions,
|
|
8
|
+
DialogContent,
|
|
9
|
+
DialogContentText,
|
|
10
|
+
type DialogContentTextProps,
|
|
11
|
+
type DialogProps,
|
|
12
|
+
DialogTitle,
|
|
13
|
+
IconButton,
|
|
14
|
+
Stack,
|
|
15
|
+
} from '@elementor/ui';
|
|
16
|
+
|
|
17
|
+
const TITLE_ID = 'save-changes-dialog';
|
|
18
|
+
|
|
19
|
+
export const SaveChangesDialog = ( { children, onClose }: Pick< DialogProps, 'children' | 'onClose' > ) => (
|
|
20
|
+
<Dialog open onClose={ onClose } aria-labelledby={ TITLE_ID } maxWidth="xs">
|
|
21
|
+
{ children }
|
|
22
|
+
</Dialog>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const SaveChangesDialogTitle = ( { children, onClose }: React.PropsWithChildren & { onClose?: () => void } ) => (
|
|
26
|
+
<DialogTitle
|
|
27
|
+
id={ TITLE_ID }
|
|
28
|
+
display="flex"
|
|
29
|
+
alignItems="center"
|
|
30
|
+
gap={ 1 }
|
|
31
|
+
sx={ { lineHeight: 1, justifyContent: 'space-between' } }
|
|
32
|
+
>
|
|
33
|
+
<Stack direction="row" alignItems="center" gap={ 1 }>
|
|
34
|
+
<AlertTriangleFilledIcon color="secondary" />
|
|
35
|
+
{ children }
|
|
36
|
+
</Stack>
|
|
37
|
+
{ onClose && (
|
|
38
|
+
<IconButton onClick={ onClose } size="small">
|
|
39
|
+
<XIcon />
|
|
40
|
+
</IconButton>
|
|
41
|
+
) }
|
|
42
|
+
</DialogTitle>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const SaveChangesDialogContent = ( { children }: React.PropsWithChildren ) => (
|
|
46
|
+
<DialogContent>{ children }</DialogContent>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const SaveChangesDialogContentText = ( props: DialogContentTextProps ) => (
|
|
50
|
+
<DialogContentText variant="body2" color="textPrimary" display="flex" flexDirection="column" { ...props } />
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
type Action = {
|
|
54
|
+
label: string;
|
|
55
|
+
action: () => void | Promise< void >;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type ConfirmationDialogActionsProps = {
|
|
59
|
+
actions: {
|
|
60
|
+
cancel?: Action;
|
|
61
|
+
confirm: Action;
|
|
62
|
+
discard?: Action;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const SaveChangesDialogActions = ( { actions }: ConfirmationDialogActionsProps ) => {
|
|
67
|
+
const [ isConfirming, setIsConfirming ] = useState( false );
|
|
68
|
+
const { cancel, confirm, discard } = actions;
|
|
69
|
+
|
|
70
|
+
const onConfirm = async () => {
|
|
71
|
+
setIsConfirming( true );
|
|
72
|
+
await confirm.action();
|
|
73
|
+
setIsConfirming( false );
|
|
74
|
+
};
|
|
75
|
+
return (
|
|
76
|
+
<DialogActions>
|
|
77
|
+
{ cancel && (
|
|
78
|
+
<Button variant="text" color="secondary" onClick={ cancel.action }>
|
|
79
|
+
{ cancel.label }
|
|
80
|
+
</Button>
|
|
81
|
+
) }
|
|
82
|
+
{ discard && (
|
|
83
|
+
<Button variant="text" color="secondary" onClick={ discard.action }>
|
|
84
|
+
{ discard.label }
|
|
85
|
+
</Button>
|
|
86
|
+
) }
|
|
87
|
+
<Button variant="contained" color="secondary" onClick={ onConfirm } loading={ isConfirming }>
|
|
88
|
+
{ confirm.label }
|
|
89
|
+
</Button>
|
|
90
|
+
</DialogActions>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
SaveChangesDialog.Title = SaveChangesDialogTitle;
|
|
95
|
+
SaveChangesDialog.Content = SaveChangesDialogContent;
|
|
96
|
+
SaveChangesDialog.ContentText = SaveChangesDialogContentText;
|
|
97
|
+
SaveChangesDialog.Actions = SaveChangesDialogActions;
|
|
98
|
+
|
|
99
|
+
export const useDialog = () => {
|
|
100
|
+
const [ isOpen, setIsOpen ] = useState( false );
|
|
101
|
+
|
|
102
|
+
const open = () => setIsOpen( true );
|
|
103
|
+
const close = () => setIsOpen( false );
|
|
104
|
+
|
|
105
|
+
return { isOpen, open, close };
|
|
106
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -9,5 +9,7 @@ export { InfoAlert } from './components/info-alert';
|
|
|
9
9
|
export { WarningInfotip } from './components/warning-infotip';
|
|
10
10
|
export { GlobalDialog, openDialog, closeDialog } from './components/global-dialog';
|
|
11
11
|
export * from './components/popover';
|
|
12
|
+
export * from './components/save-changes-dialog';
|
|
13
|
+
|
|
12
14
|
// hooks
|
|
13
15
|
export { useEditable } from './hooks/use-editable';
|