@cratis/components 1.1.5 → 1.2.0
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/cjs/CommandDialog/CommandDialog.js +24 -10
- package/dist/cjs/CommandDialog/CommandDialog.js.map +1 -1
- package/dist/cjs/Dialogs/Dialog.js +6 -6
- package/dist/cjs/Dialogs/Dialog.js.map +1 -1
- package/dist/esm/CommandDialog/CommandDialog.d.ts +3 -11
- package/dist/esm/CommandDialog/CommandDialog.d.ts.map +1 -1
- package/dist/esm/CommandDialog/CommandDialog.js +26 -12
- package/dist/esm/CommandDialog/CommandDialog.js.map +1 -1
- package/dist/esm/CommandDialog/CommandDialog.stories.d.ts +1 -0
- package/dist/esm/CommandDialog/CommandDialog.stories.d.ts.map +1 -1
- package/dist/esm/CommandDialog/CommandDialog.stories.js +61 -17
- package/dist/esm/CommandDialog/CommandDialog.stories.js.map +1 -1
- package/dist/esm/Dialogs/Dialog.d.ts +4 -2
- package/dist/esm/Dialogs/Dialog.d.ts.map +1 -1
- package/dist/esm/Dialogs/Dialog.js +6 -6
- package/dist/esm/Dialogs/Dialog.js.map +1 -1
- package/dist/esm/Dialogs/Dialog.stories.d.ts +1 -0
- package/dist/esm/Dialogs/Dialog.stories.d.ts.map +1 -1
- package/dist/esm/Dialogs/Dialog.stories.js +18 -0
- package/dist/esm/Dialogs/Dialog.stories.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -6,23 +6,36 @@ var Dialog = require('../Dialogs/Dialog.js');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var commands = require('@cratis/arc.react/commands');
|
|
8
8
|
|
|
9
|
-
const CommandDialogWrapper = ({
|
|
10
|
-
const { setCommandValues, setCommandResult, isValid } = commands.useCommandFormContext();
|
|
9
|
+
const CommandDialogWrapper = ({ title, visible, width, style, resizable, buttons, okLabel, cancelLabel, yesLabel, noLabel, isValid, onClose, onConfirm, onCancel, onBeforeExecute, children }) => {
|
|
10
|
+
const { setCommandValues, setCommandResult, isValid: isCommandFormValid } = commands.useCommandFormContext();
|
|
11
11
|
const commandInstance = commands.useCommandInstance();
|
|
12
|
+
const [isBusy, setIsBusy] = React.useState(false);
|
|
12
13
|
const handleConfirm = async () => {
|
|
13
14
|
if (onBeforeExecute) {
|
|
14
15
|
const transformedValues = onBeforeExecute(commandInstance);
|
|
15
16
|
setCommandValues(transformedValues);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
setIsBusy(true);
|
|
19
|
+
let result;
|
|
20
|
+
try {
|
|
21
|
+
result = await commandInstance.execute();
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
setIsBusy(false);
|
|
21
25
|
}
|
|
22
|
-
|
|
26
|
+
if (!result.isSuccess) {
|
|
23
27
|
setCommandResult(result);
|
|
24
28
|
return false;
|
|
25
29
|
}
|
|
30
|
+
if (onConfirm) {
|
|
31
|
+
const closeResult = await onConfirm();
|
|
32
|
+
return closeResult === true;
|
|
33
|
+
}
|
|
34
|
+
if (onClose) {
|
|
35
|
+
const closeResult = await onClose(dialogs.DialogResult.Ok);
|
|
36
|
+
return closeResult !== false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
26
39
|
};
|
|
27
40
|
const processChildren = (nodes) => {
|
|
28
41
|
return React.Children.map(nodes, (child) => {
|
|
@@ -42,11 +55,12 @@ const CommandDialogWrapper = ({ header, visible, width, confirmLabel, cancelLabe
|
|
|
42
55
|
});
|
|
43
56
|
};
|
|
44
57
|
const processedChildren = processChildren(children);
|
|
45
|
-
|
|
58
|
+
const isDialogValid = (isValid !== false) && isCommandFormValid;
|
|
59
|
+
return (jsxRuntime.jsx(Dialog.Dialog, { title: title, visible: visible, width: width, style: style, resizable: resizable, buttons: buttons, onClose: onClose, onConfirm: handleConfirm, onCancel: onCancel, okLabel: okLabel, cancelLabel: cancelLabel, yesLabel: yesLabel, noLabel: noLabel, isValid: isDialogValid, isBusy: isBusy, children: jsxRuntime.jsx("div", { style: { display: 'flex', flexDirection: 'column', width: '100%' }, children: processedChildren }) }));
|
|
46
60
|
};
|
|
47
61
|
const CommandDialogComponent = (props) => {
|
|
48
|
-
const { visible,
|
|
49
|
-
return (jsxRuntime.jsx(commands.CommandForm, { ...commandFormProps, children: jsxRuntime.jsx(CommandDialogWrapper, {
|
|
62
|
+
const { title, visible, width, style, resizable, buttons = dialogs.DialogButtons.OkCancel, okLabel, cancelLabel, yesLabel, noLabel, isValid, onClose, onConfirm, onCancel, children, ...commandFormProps } = props;
|
|
63
|
+
return (jsxRuntime.jsx(commands.CommandForm, { ...commandFormProps, children: jsxRuntime.jsx(CommandDialogWrapper, { title: title, visible: visible, width: width, style: style, resizable: resizable, buttons: buttons, okLabel: okLabel, cancelLabel: cancelLabel, yesLabel: yesLabel, noLabel: noLabel, isValid: isValid, onClose: onClose, onConfirm: onConfirm, onCancel: onCancel, onBeforeExecute: commandFormProps.onBeforeExecute, children: children }) }));
|
|
50
64
|
};
|
|
51
65
|
const CommandDialogColumnWrapper = ({ children }) => (jsxRuntime.jsx(commands.CommandForm.Column, { children: children }));
|
|
52
66
|
CommandDialogColumnWrapper.displayName = 'CommandFormColumn';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { DialogButtons } from '@cratis/arc.react/dialogs';\nimport { Dialog } from '../Dialogs/Dialog';\nimport React from 'react';\nimport {\n CommandForm,\n CommandFormFieldWrapper,\n useCommandFormContext,\n useCommandInstance,\n type CommandFormProps\n} from '@cratis/arc.react/commands';\n\nexport interface CommandDialogProps<TCommand extends object
|
|
1
|
+
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';\nimport { Dialog, type DialogProps } from '../Dialogs/Dialog';\nimport React, { useState } from 'react';\nimport {\n CommandForm,\n CommandFormFieldWrapper,\n useCommandFormContext,\n useCommandInstance,\n type CommandFormProps\n} from '@cratis/arc.react/commands';\n\nexport interface CommandDialogProps<TCommand extends object>\n extends Omit<CommandFormProps<TCommand>, 'children'>,\n Omit<DialogProps, 'children'> {\n children?: React.ReactNode;\n}\n\nconst CommandDialogWrapper = <TCommand extends object>({\n title,\n visible,\n width,\n style,\n resizable,\n buttons,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n onBeforeExecute,\n children\n}: {\n title: string;\n visible?: boolean;\n width?: string;\n style?: DialogProps['style'];\n resizable?: boolean;\n buttons?: DialogProps['buttons'];\n okLabel?: string;\n cancelLabel?: string;\n yesLabel?: string;\n noLabel?: string;\n isValid?: boolean;\n onClose?: DialogProps['onClose'];\n onConfirm?: DialogProps['onConfirm'];\n onCancel?: DialogProps['onCancel'];\n onBeforeExecute?: (values: TCommand) => TCommand;\n children?: React.ReactNode;\n}) => {\n const { setCommandValues, setCommandResult, isValid: isCommandFormValid } = useCommandFormContext<TCommand>();\n const commandInstance = useCommandInstance<TCommand>();\n const [isBusy, setIsBusy] = useState(false);\n\n const handleConfirm = async () => {\n if (onBeforeExecute) {\n const transformedValues = onBeforeExecute(commandInstance);\n setCommandValues(transformedValues);\n }\n\n setIsBusy(true);\n let result: ICommandResult<unknown>;\n try {\n result = await (commandInstance as unknown as { execute: () => Promise<ICommandResult<unknown>> }).execute();\n } finally {\n setIsBusy(false);\n }\n\n if (!result.isSuccess) {\n setCommandResult(result);\n return false;\n }\n\n if (onConfirm) {\n const closeResult = await onConfirm();\n return closeResult === true;\n }\n\n if (onClose) {\n const closeResult = await onClose(DialogResult.Ok);\n return closeResult !== false;\n }\n\n return true;\n };\n\n const processChildren = (nodes: React.ReactNode): React.ReactNode => {\n return React.Children.map(nodes, (child) => {\n if (!React.isValidElement(child)) return child;\n\n const component = child.type as React.ComponentType<unknown>;\n if (component.displayName === 'CommandFormField') {\n type FieldElement = Parameters<typeof CommandFormFieldWrapper>[0]['field'];\n return <CommandFormFieldWrapper field={child as unknown as FieldElement} />;\n }\n\n const childProps = child.props as Record<string, unknown>;\n if (childProps.children != null) {\n return React.cloneElement(child as React.ReactElement<Record<string, unknown>>, {\n children: processChildren(childProps.children as React.ReactNode)\n });\n }\n\n return child;\n });\n };\n\n const processedChildren = processChildren(children);\n const isDialogValid = (isValid !== false) && isCommandFormValid;\n\n return (\n <Dialog\n title={title}\n visible={visible}\n width={width}\n style={style}\n resizable={resizable}\n buttons={buttons}\n onClose={onClose}\n onConfirm={handleConfirm}\n onCancel={onCancel}\n okLabel={okLabel}\n cancelLabel={cancelLabel}\n yesLabel={yesLabel}\n noLabel={noLabel}\n isValid={isDialogValid}\n isBusy={isBusy}\n >\n <div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>\n {processedChildren}\n </div>\n </Dialog>\n );\n};\n\nconst CommandDialogComponent = <TCommand extends object = object>(props: CommandDialogProps<TCommand>) => {\n const {\n title,\n visible,\n width,\n style,\n resizable,\n buttons = DialogButtons.OkCancel,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n children,\n ...commandFormProps\n } = props;\n\n return (\n <CommandForm<TCommand> {...commandFormProps}>\n <CommandDialogWrapper<TCommand>\n title={title}\n visible={visible}\n width={width}\n style={style}\n resizable={resizable}\n buttons={buttons}\n okLabel={okLabel}\n cancelLabel={cancelLabel}\n yesLabel={yesLabel}\n noLabel={noLabel}\n isValid={isValid}\n onClose={onClose}\n onConfirm={onConfirm}\n onCancel={onCancel}\n onBeforeExecute={commandFormProps.onBeforeExecute}\n >\n {children}\n </CommandDialogWrapper>\n </CommandForm>\n );\n};\n\nconst CommandDialogColumnWrapper = ({ children }: { children: React.ReactNode }) => (\n <CommandForm.Column>{children}</CommandForm.Column>\n);\nCommandDialogColumnWrapper.displayName = 'CommandFormColumn';\n\nCommandDialogComponent.Column = CommandDialogColumnWrapper;\n\nexport const CommandDialog = CommandDialogComponent;\n"],"names":["useCommandFormContext","useCommandInstance","useState","DialogResult","_jsx","CommandFormFieldWrapper","Dialog","DialogButtons","CommandForm"],"mappings":";;;;;;;;AAqBA,MAAM,oBAAoB,GAAG,CAA0B,EACnD,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,eAAe,EACf,QAAQ,EAkBX,KAAI;AACD,IAAA,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAGA,8BAAqB,EAAY;AAC7G,IAAA,MAAM,eAAe,GAAGC,2BAAkB,EAAY;IACtD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;AAE3C,IAAA,MAAM,aAAa,GAAG,YAAW;QAC7B,IAAI,eAAe,EAAE;AACjB,YAAA,MAAM,iBAAiB,GAAG,eAAe,CAAC,eAAe,CAAC;YAC1D,gBAAgB,CAAC,iBAAiB,CAAC;QACvC;QAEA,SAAS,CAAC,IAAI,CAAC;AACf,QAAA,IAAI,MAA+B;AACnC,QAAA,IAAI;AACA,YAAA,MAAM,GAAG,MAAO,eAAkF,CAAC,OAAO,EAAE;QAChH;gBAAU;YACN,SAAS,CAAC,KAAK,CAAC;QACpB;AAEA,QAAA,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YACnB,gBAAgB,CAAC,MAAM,CAAC;AACxB,YAAA,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EAAE,QAAQ,EAClB,eAAe,EAAE,gBAAgB,CAAC,eAAe,EAAA,QAAA,EAEhD,QAAQ,EAAA,CACU,EAAA,CACb;AAEtB,CAAC;AAED,MAAM,0BAA0B,GAAG,CAAC,EAAE,QAAQ,EAAiC,MAC3EA,cAAA,CAACI,oBAAW,CAAC,MAAM,cAAE,QAAQ,EAAA,CAAsB,CACtD;AACD,0BAA0B,CAAC,WAAW,GAAG,mBAAmB;AAE5D,sBAAsB,CAAC,MAAM,GAAG,0BAA0B;AAEnD,MAAM,aAAa,GAAG;;;;"}
|
|
@@ -5,7 +5,7 @@ var dialog = require('primereact/dialog');
|
|
|
5
5
|
var button = require('primereact/button');
|
|
6
6
|
var dialogs = require('@cratis/arc.react/dialogs');
|
|
7
7
|
|
|
8
|
-
const Dialog = ({ title, visible = true, onClose, onConfirm, onCancel, buttons = dialogs.DialogButtons.OkCancel, children, width = '450px', resizable = false, isValid, okLabel = 'Ok', cancelLabel = 'Cancel', yesLabel = 'Yes', noLabel = 'No' }) => {
|
|
8
|
+
const Dialog = ({ title, visible = true, onClose, onConfirm, onCancel, buttons = dialogs.DialogButtons.OkCancel, children, width = '450px', style, resizable = false, isValid, isBusy = false, okLabel = 'Ok', cancelLabel = 'Cancel', yesLabel = 'Yes', noLabel = 'No' }) => {
|
|
9
9
|
let contextCloseDialog;
|
|
10
10
|
try {
|
|
11
11
|
const context = dialogs.useDialogContext();
|
|
@@ -42,10 +42,10 @@ const Dialog = ({ title, visible = true, onClose, onConfirm, onCancel, buttons =
|
|
|
42
42
|
contextCloseDialog?.(result);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
const okFooter = (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(button.Button, { label: okLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Ok), disabled: !isDialogValid, autoFocus: true }) }));
|
|
46
|
-
const okCancelFooter = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { label: okLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Ok), disabled: !isDialogValid, autoFocus: true }), jsxRuntime.jsx(button.Button, { label: cancelLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.Cancelled) })] }));
|
|
47
|
-
const yesNoFooter = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { label: yesLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Yes), disabled: !isDialogValid, autoFocus: true }), jsxRuntime.jsx(button.Button, { label: noLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.No) })] }));
|
|
48
|
-
const yesNoCancelFooter = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { label: yesLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Yes), disabled: !isDialogValid, autoFocus: true }), jsxRuntime.jsx(button.Button, { label: noLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.No) }), jsxRuntime.jsx(button.Button, { label: cancelLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.Cancelled) })] }));
|
|
45
|
+
const okFooter = (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(button.Button, { label: okLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Ok), disabled: !isDialogValid || isBusy, loading: isBusy, autoFocus: true }) }));
|
|
46
|
+
const okCancelFooter = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { label: okLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Ok), disabled: !isDialogValid || isBusy, loading: isBusy, autoFocus: true }), jsxRuntime.jsx(button.Button, { label: cancelLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.Cancelled), disabled: isBusy })] }));
|
|
47
|
+
const yesNoFooter = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { label: yesLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Yes), disabled: !isDialogValid || isBusy, loading: isBusy, autoFocus: true }), jsxRuntime.jsx(button.Button, { label: noLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.No), disabled: isBusy })] }));
|
|
48
|
+
const yesNoCancelFooter = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { label: yesLabel, icon: "pi pi-check", onClick: () => handleClose(dialogs.DialogResult.Yes), disabled: !isDialogValid || isBusy, loading: isBusy, autoFocus: true }), jsxRuntime.jsx(button.Button, { label: noLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.No), disabled: isBusy }), jsxRuntime.jsx(button.Button, { label: cancelLabel, icon: "pi pi-times", outlined: true, onClick: () => handleClose(dialogs.DialogResult.Cancelled), disabled: isBusy })] }));
|
|
49
49
|
const getFooterInterior = () => {
|
|
50
50
|
if (typeof buttons !== 'number') {
|
|
51
51
|
return buttons;
|
|
@@ -63,7 +63,7 @@ const Dialog = ({ title, visible = true, onClose, onConfirm, onCancel, buttons =
|
|
|
63
63
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, {}));
|
|
64
64
|
};
|
|
65
65
|
const footer = (jsxRuntime.jsx("div", { className: "flex flex-wrap justify-content-start gap-3", children: getFooterInterior() }));
|
|
66
|
-
return (jsxRuntime.jsx(dialog.Dialog, { header: headerElement, modal: true, footer: footer, onHide: typeof buttons === 'number' ? () => handleClose(dialogs.DialogResult.Cancelled) : () => { }, visible: visible, style: { width }, resizable: resizable, closable: typeof buttons === 'number', children: children }));
|
|
66
|
+
return (jsxRuntime.jsx(dialog.Dialog, { header: headerElement, modal: true, footer: footer, onHide: typeof buttons === 'number' ? () => handleClose(dialogs.DialogResult.Cancelled) : () => { }, visible: visible, style: { width, ...style }, resizable: resizable, closable: typeof buttons === 'number', children: children }));
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
exports.Dialog = Dialog;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sources":["../../../Dialogs/Dialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Dialog as PrimeDialog } from 'primereact/dialog';\nimport { Button } from 'primereact/button';\nimport { DialogResult, DialogButtons, useDialogContext } from '@cratis/arc.react/dialogs';\nimport { ReactNode } from 'react';\n\nexport type CloseDialog = (result: DialogResult) => boolean | void | Promise<boolean> | Promise<void>;\nexport type ConfirmCallback = () => boolean | void | Promise<boolean> | Promise<void>;\nexport type CancelCallback = () => boolean | void | Promise<boolean> | Promise<void>;\n\nexport interface DialogProps {\n title: string;\n visible?: boolean;\n onClose?: CloseDialog;\n onConfirm?: ConfirmCallback;\n onCancel?: CancelCallback;\n buttons?: DialogButtons | ReactNode;\n children: ReactNode;\n width?: string;\n resizable?: boolean;\n isValid?: boolean;\n okLabel?: string;\n cancelLabel?: string;\n yesLabel?: string;\n noLabel?: string;\n}\n\nexport const Dialog = ({ \n title, \n visible = true, \n onClose, \n onConfirm,\n onCancel,\n buttons = DialogButtons.OkCancel, \n children, \n width = '450px', \n resizable = false, \n isValid,\n okLabel = 'Ok',\n cancelLabel = 'Cancel',\n yesLabel = 'Yes',\n noLabel = 'No'\n}: DialogProps) => {\n // Try to get dialog context, but allow it to be undefined for standalone usage\n let contextCloseDialog: ((result: DialogResult) => void) | undefined;\n try {\n const context = useDialogContext();\n contextCloseDialog = context?.closeDialog;\n } catch {\n // No context available - dialog is being used standalone\n contextCloseDialog = undefined;\n }\n \n const isDialogValid = isValid !== false;\n const headerElement = (\n <div className=\"inline-flex align-items-center justify-content-center gap-2\">\n <span className=\"font-bold white-space-nowrap\">{title}</span>\n </div>\n );\n\n const handleClose = async (result: DialogResult) => {\n let shouldCloseThroughContext = true;\n\n if (result === DialogResult.Ok || result === DialogResult.Yes) {\n if (onConfirm) {\n const closeResult = await onConfirm();\n shouldCloseThroughContext = closeResult === true;\n } else if (onClose) {\n const closeResult = await onClose(result);\n shouldCloseThroughContext = closeResult !== false;\n }\n } else {\n if (onCancel) {\n const closeResult = await onCancel();\n shouldCloseThroughContext = closeResult === true;\n } else if (onClose) {\n const closeResult = await onClose(result);\n shouldCloseThroughContext = closeResult !== false;\n }\n }\n\n if (shouldCloseThroughContext) {\n contextCloseDialog?.(result);\n }\n };\n\n const okFooter = (\n <>\n <Button label={okLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Ok)} disabled={!isDialogValid} autoFocus />\n </>\n );\n\n const okCancelFooter = (\n <>\n <Button label={okLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Ok)} disabled={!isDialogValid} autoFocus />\n <Button label={cancelLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.Cancelled)} />\n </>\n );\n\n const yesNoFooter = (\n <>\n <Button label={yesLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Yes)} disabled={!isDialogValid} autoFocus />\n <Button label={noLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.No)} />\n </>\n );\n\n const yesNoCancelFooter = (\n <>\n <Button label={yesLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Yes)} disabled={!isDialogValid} autoFocus />\n <Button label={noLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.No)} />\n <Button label={cancelLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.Cancelled)} />\n </>\n );\n\n const getFooterInterior = () => {\n // If buttons is a ReactNode (custom buttons), use it directly\n if (typeof buttons !== 'number') {\n return buttons;\n }\n\n // Otherwise, use predefined buttons based on DialogButtons enum\n switch (buttons) {\n case DialogButtons.Ok:\n return okFooter;\n case DialogButtons.OkCancel:\n return okCancelFooter;\n case DialogButtons.YesNo:\n return yesNoFooter;\n case DialogButtons.YesNoCancel:\n return yesNoCancelFooter;\n }\n\n return (<></>);\n };\n\n const footer = (\n <div className=\"flex flex-wrap justify-content-start gap-3\">\n {getFooterInterior()}\n </div>\n );\n\n return (\n <PrimeDialog\n header={headerElement}\n modal\n footer={footer}\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n onHide={typeof buttons === 'number' ? () => handleClose(DialogResult.Cancelled) : () => {}}\n visible={visible}\n style={{ width }}\n resizable={resizable}\n closable={typeof buttons === 'number'}>\n {children}\n </PrimeDialog>\n );\n};\n"],"names":["DialogButtons","useDialogContext","_jsx","DialogResult","_Fragment","Button","_jsxs","PrimeDialog"],"mappings":";;;;;;;AA6BO,MAAM,MAAM,GAAG,CAAC,EACnB,KAAK,EACL,OAAO,GAAG,IAAI,EACd,OAAO,EACP,SAAS,EACT,QAAQ,EACR,OAAO,GAAGA,qBAAa,CAAC,QAAQ,EAChC,QAAQ,EACR,KAAK,GAAG,OAAO,EACf,SAAS,GAAG,KAAK,EACjB,OAAO,EACP,OAAO,GAAG,IAAI,EACd,WAAW,GAAG,QAAQ,EACtB,QAAQ,GAAG,KAAK,EAChB,OAAO,GAAG,IAAI,EACJ,KAAI;AAEd,IAAA,IAAI,kBAAgE;AACpE,IAAA,IAAI;AACA,QAAA,MAAM,OAAO,GAAGC,wBAAgB,EAAE;AAClC,QAAA,kBAAkB,GAAG,OAAO,EAAE,WAAW;IAC7C;AAAE,IAAA,MAAM;QAEJ,kBAAkB,GAAG,SAAS;IAClC;AAEA,IAAA,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK;AACvC,IAAA,MAAM,aAAa,IACfC,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,6DAA6D,EAAA,QAAA,EACxEA,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,8BAA8B,EAAA,QAAA,EAAE,KAAK,EAAA,CAAQ,EAAA,CAC3D,CACT;AAED,IAAA,MAAM,WAAW,GAAG,OAAO,MAA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) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Dialog as PrimeDialog } from 'primereact/dialog';\nimport { Button } from 'primereact/button';\nimport { DialogResult, DialogButtons, useDialogContext } from '@cratis/arc.react/dialogs';\nimport { CSSProperties, ReactNode } from 'react';\n\nexport type CloseDialog = (result: DialogResult) => boolean | void | Promise<boolean> | Promise<void>;\nexport type ConfirmCallback = () => boolean | void | Promise<boolean> | Promise<void>;\nexport type CancelCallback = () => boolean | void | Promise<boolean> | Promise<void>;\n\nexport interface DialogProps {\n title: string;\n visible?: boolean;\n onClose?: CloseDialog;\n onConfirm?: ConfirmCallback;\n onCancel?: CancelCallback;\n buttons?: DialogButtons | ReactNode;\n children: ReactNode;\n width?: string;\n style?: CSSProperties;\n resizable?: boolean;\n isValid?: boolean;\n isBusy?: boolean;\n okLabel?: string;\n cancelLabel?: string;\n yesLabel?: string;\n noLabel?: string;\n}\n\nexport const Dialog = ({ \n title, \n visible = true, \n onClose, \n onConfirm,\n onCancel,\n buttons = DialogButtons.OkCancel, \n children, \n width = '450px', \n style,\n resizable = false, \n isValid,\n isBusy = false,\n okLabel = 'Ok',\n cancelLabel = 'Cancel',\n yesLabel = 'Yes',\n noLabel = 'No'\n}: DialogProps) => {\n // Try to get dialog context, but allow it to be undefined for standalone usage\n let contextCloseDialog: ((result: DialogResult) => void) | undefined;\n try {\n const context = useDialogContext();\n contextCloseDialog = context?.closeDialog;\n } catch {\n // No context available - dialog is being used standalone\n contextCloseDialog = undefined;\n }\n \n const isDialogValid = isValid !== false;\n const headerElement = (\n <div className=\"inline-flex align-items-center justify-content-center gap-2\">\n <span className=\"font-bold white-space-nowrap\">{title}</span>\n </div>\n );\n\n const handleClose = async (result: DialogResult) => {\n let shouldCloseThroughContext = true;\n\n if (result === DialogResult.Ok || result === DialogResult.Yes) {\n if (onConfirm) {\n const closeResult = await onConfirm();\n shouldCloseThroughContext = closeResult === true;\n } else if (onClose) {\n const closeResult = await onClose(result);\n shouldCloseThroughContext = closeResult !== false;\n }\n } else {\n if (onCancel) {\n const closeResult = await onCancel();\n shouldCloseThroughContext = closeResult === true;\n } else if (onClose) {\n const closeResult = await onClose(result);\n shouldCloseThroughContext = closeResult !== false;\n }\n }\n\n if (shouldCloseThroughContext) {\n contextCloseDialog?.(result);\n }\n };\n\n const okFooter = (\n <>\n <Button label={okLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Ok)} disabled={!isDialogValid || isBusy} loading={isBusy} autoFocus />\n </>\n );\n\n const okCancelFooter = (\n <>\n <Button label={okLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Ok)} disabled={!isDialogValid || isBusy} loading={isBusy} autoFocus />\n <Button label={cancelLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.Cancelled)} disabled={isBusy} />\n </>\n );\n\n const yesNoFooter = (\n <>\n <Button label={yesLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Yes)} disabled={!isDialogValid || isBusy} loading={isBusy} autoFocus />\n <Button label={noLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.No)} disabled={isBusy} />\n </>\n );\n\n const yesNoCancelFooter = (\n <>\n <Button label={yesLabel} icon=\"pi pi-check\" onClick={() => handleClose(DialogResult.Yes)} disabled={!isDialogValid || isBusy} loading={isBusy} autoFocus />\n <Button label={noLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.No)} disabled={isBusy} />\n <Button label={cancelLabel} icon=\"pi pi-times\" outlined onClick={() => handleClose(DialogResult.Cancelled)} disabled={isBusy} />\n </>\n );\n\n const getFooterInterior = () => {\n // If buttons is a ReactNode (custom buttons), use it directly\n if (typeof buttons !== 'number') {\n return buttons;\n }\n\n // Otherwise, use predefined buttons based on DialogButtons enum\n switch (buttons) {\n case DialogButtons.Ok:\n return okFooter;\n case DialogButtons.OkCancel:\n return okCancelFooter;\n case DialogButtons.YesNo:\n return yesNoFooter;\n case DialogButtons.YesNoCancel:\n return yesNoCancelFooter;\n }\n\n return (<></>);\n };\n\n const footer = (\n <div className=\"flex flex-wrap justify-content-start gap-3\">\n {getFooterInterior()}\n </div>\n );\n\n return (\n <PrimeDialog\n header={headerElement}\n modal\n footer={footer}\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n onHide={typeof buttons === 'number' ? () => handleClose(DialogResult.Cancelled) : () => {}}\n visible={visible}\n style={{ width, ...style }}\n resizable={resizable}\n closable={typeof buttons === 'number'}>\n {children}\n </PrimeDialog>\n );\n};\n"],"names":["DialogButtons","useDialogContext","_jsx","DialogResult","Button","_jsxs","_Fragment","PrimeDialog"],"mappings":";;;;;;;AA+BO,MAAM,MAAM,GAAG,CAAC,EACnB,KAAK,EACL,OAAO,GAAG,IAAI,EACd,OAAO,EACP,SAAS,EACT,QAAQ,EACR,OAAO,GAAGA,qBAAa,CAAC,QAAQ,EAChC,QAAQ,EACR,KAAK,GAAG,OAAO,EACf,KAAK,EACL,SAAS,GAAG,KAAK,EACjB,OAAO,EACP,MAAM,GAAG,KAAK,EACd,OAAO,GAAG,IAAI,EACd,WAAW,GAAG,QAAQ,EACtB,QAAQ,GAAG,KAAK,EAChB,OAAO,GAAG,IAAI,EACJ,KAAI;AAEd,IAAA,IAAI,kBAAgE;AACpE,IAAA,IAAI;AACA,QAAA,MAAM,OAAO,GAAGC,wBAAgB,EAAE;AAClC,QAAA,kBAAkB,GAAG,OAAO,EAAE,WAAW;IAC7C;AAAE,IAAA,MAAM;QAEJ,kBAAkB,GAAG,SAAS;IAClC;AAEA,IAAA,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK;AACvC,IAAA,MAAM,aAAa,IACfC,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,6DAA6D,EAAA,QAAA,EACxEA,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,8BAA8B,EAAA,QAAA,EAAE,KAAK,EAAA,CAAQ,EAAA,CAC3D,CACT;AAED,IAAA,MAAM,WAAW,GAAG,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,OAAO,EAChB,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAC1B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,OAAO,OAAO,KAAK,QAAQ,EAAA,QAAA,EACpC,QAAQ,EAAA,CACC;AAEtB;;;;"}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type DialogProps } from '../Dialogs/Dialog';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { type CommandFormProps } from '@cratis/arc.react/commands';
|
|
4
|
-
export interface CommandDialogProps<TCommand extends object
|
|
5
|
-
visible?: boolean;
|
|
6
|
-
header: string;
|
|
7
|
-
confirmLabel?: string;
|
|
8
|
-
cancelLabel?: string;
|
|
9
|
-
onConfirm: (result: ICommandResult<TResponse>) => void | Promise<void>;
|
|
10
|
-
onCancel: () => void;
|
|
4
|
+
export interface CommandDialogProps<TCommand extends object> extends Omit<CommandFormProps<TCommand>, 'children'>, Omit<DialogProps, 'children'> {
|
|
11
5
|
children?: React.ReactNode;
|
|
12
|
-
style?: React.CSSProperties;
|
|
13
|
-
width?: string;
|
|
14
6
|
}
|
|
15
7
|
export declare const CommandDialog: {
|
|
16
|
-
<TCommand extends object = object
|
|
8
|
+
<TCommand extends object = object>(props: CommandDialogProps<TCommand>): import("react/jsx-runtime").JSX.Element;
|
|
17
9
|
Column: {
|
|
18
10
|
({ children }: {
|
|
19
11
|
children: React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandDialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommandDialog.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAKH,KAAK,gBAAgB,EACxB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,kBAAkB,CAAC,QAAQ,SAAS,MAAM,CACvD,SAAQ,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,EAChD,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AA8KD,eAAO,MAAM,aAAa;KApDM,QAAQ,SAAS,MAAM,kBAAkB,kBAAkB,CAAC,QAAQ,CAAC;;uBA6CnD;YAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;SAAE;;;CAO5B,CAAC"}
|
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { DialogButtons } from '@cratis/arc.react/dialogs';
|
|
2
|
+
import { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';
|
|
3
3
|
import { Dialog } from '../Dialogs/Dialog.js';
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
5
|
import { CommandForm, useCommandFormContext, useCommandInstance, CommandFormFieldWrapper } from '@cratis/arc.react/commands';
|
|
6
6
|
|
|
7
|
-
const CommandDialogWrapper = ({
|
|
8
|
-
const { setCommandValues, setCommandResult, isValid } = useCommandFormContext();
|
|
7
|
+
const CommandDialogWrapper = ({ title, visible, width, style, resizable, buttons, okLabel, cancelLabel, yesLabel, noLabel, isValid, onClose, onConfirm, onCancel, onBeforeExecute, children }) => {
|
|
8
|
+
const { setCommandValues, setCommandResult, isValid: isCommandFormValid } = useCommandFormContext();
|
|
9
9
|
const commandInstance = useCommandInstance();
|
|
10
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
10
11
|
const handleConfirm = async () => {
|
|
11
12
|
if (onBeforeExecute) {
|
|
12
13
|
const transformedValues = onBeforeExecute(commandInstance);
|
|
13
14
|
setCommandValues(transformedValues);
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
setIsBusy(true);
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
result = await commandInstance.execute();
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setIsBusy(false);
|
|
19
23
|
}
|
|
20
|
-
|
|
24
|
+
if (!result.isSuccess) {
|
|
21
25
|
setCommandResult(result);
|
|
22
26
|
return false;
|
|
23
27
|
}
|
|
28
|
+
if (onConfirm) {
|
|
29
|
+
const closeResult = await onConfirm();
|
|
30
|
+
return closeResult === true;
|
|
31
|
+
}
|
|
32
|
+
if (onClose) {
|
|
33
|
+
const closeResult = await onClose(DialogResult.Ok);
|
|
34
|
+
return closeResult !== false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
24
37
|
};
|
|
25
38
|
const processChildren = (nodes) => {
|
|
26
39
|
return React.Children.map(nodes, (child) => {
|
|
@@ -40,11 +53,12 @@ const CommandDialogWrapper = ({ header, visible, width, confirmLabel, cancelLabe
|
|
|
40
53
|
});
|
|
41
54
|
};
|
|
42
55
|
const processedChildren = processChildren(children);
|
|
43
|
-
|
|
56
|
+
const isDialogValid = (isValid !== false) && isCommandFormValid;
|
|
57
|
+
return (jsx(Dialog, { title: title, visible: visible, width: width, style: style, resizable: resizable, buttons: buttons, onClose: onClose, onConfirm: handleConfirm, onCancel: onCancel, okLabel: okLabel, cancelLabel: cancelLabel, yesLabel: yesLabel, noLabel: noLabel, isValid: isDialogValid, isBusy: isBusy, children: jsx("div", { style: { display: 'flex', flexDirection: 'column', width: '100%' }, children: processedChildren }) }));
|
|
44
58
|
};
|
|
45
59
|
const CommandDialogComponent = (props) => {
|
|
46
|
-
const { visible,
|
|
47
|
-
return (jsx(CommandForm, { ...commandFormProps, children: jsx(CommandDialogWrapper, {
|
|
60
|
+
const { title, visible, width, style, resizable, buttons = DialogButtons.OkCancel, okLabel, cancelLabel, yesLabel, noLabel, isValid, onClose, onConfirm, onCancel, children, ...commandFormProps } = props;
|
|
61
|
+
return (jsx(CommandForm, { ...commandFormProps, children: jsx(CommandDialogWrapper, { title: title, visible: visible, width: width, style: style, resizable: resizable, buttons: buttons, okLabel: okLabel, cancelLabel: cancelLabel, yesLabel: yesLabel, noLabel: noLabel, isValid: isValid, onClose: onClose, onConfirm: onConfirm, onCancel: onCancel, onBeforeExecute: commandFormProps.onBeforeExecute, children: children }) }));
|
|
48
62
|
};
|
|
49
63
|
const CommandDialogColumnWrapper = ({ children }) => (jsx(CommandForm.Column, { children: children }));
|
|
50
64
|
CommandDialogColumnWrapper.displayName = 'CommandFormColumn';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { DialogButtons } from '@cratis/arc.react/dialogs';\nimport { Dialog } from '../Dialogs/Dialog';\nimport React from 'react';\nimport {\n CommandForm,\n CommandFormFieldWrapper,\n useCommandFormContext,\n useCommandInstance,\n type CommandFormProps\n} from '@cratis/arc.react/commands';\n\nexport interface CommandDialogProps<TCommand extends object
|
|
1
|
+
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';\nimport { Dialog, type DialogProps } from '../Dialogs/Dialog';\nimport React, { useState } from 'react';\nimport {\n CommandForm,\n CommandFormFieldWrapper,\n useCommandFormContext,\n useCommandInstance,\n type CommandFormProps\n} from '@cratis/arc.react/commands';\n\nexport interface CommandDialogProps<TCommand extends object>\n extends Omit<CommandFormProps<TCommand>, 'children'>,\n Omit<DialogProps, 'children'> {\n children?: React.ReactNode;\n}\n\nconst CommandDialogWrapper = <TCommand extends object>({\n title,\n visible,\n width,\n style,\n resizable,\n buttons,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n onBeforeExecute,\n children\n}: {\n title: string;\n visible?: boolean;\n width?: string;\n style?: DialogProps['style'];\n resizable?: boolean;\n buttons?: DialogProps['buttons'];\n okLabel?: string;\n cancelLabel?: string;\n yesLabel?: string;\n noLabel?: string;\n isValid?: boolean;\n onClose?: DialogProps['onClose'];\n onConfirm?: DialogProps['onConfirm'];\n onCancel?: DialogProps['onCancel'];\n onBeforeExecute?: (values: TCommand) => TCommand;\n children?: React.ReactNode;\n}) => {\n const { setCommandValues, setCommandResult, isValid: isCommandFormValid } = useCommandFormContext<TCommand>();\n const commandInstance = useCommandInstance<TCommand>();\n const [isBusy, setIsBusy] = useState(false);\n\n const handleConfirm = async () => {\n if (onBeforeExecute) {\n const transformedValues = onBeforeExecute(commandInstance);\n setCommandValues(transformedValues);\n }\n\n setIsBusy(true);\n let result: ICommandResult<unknown>;\n try {\n result = await (commandInstance as unknown as { execute: () => Promise<ICommandResult<unknown>> }).execute();\n } finally {\n setIsBusy(false);\n }\n\n if (!result.isSuccess) {\n setCommandResult(result);\n return false;\n }\n\n if (onConfirm) {\n const closeResult = await onConfirm();\n return closeResult === true;\n }\n\n if (onClose) {\n const closeResult = await onClose(DialogResult.Ok);\n return closeResult !== false;\n }\n\n return true;\n };\n\n const processChildren = (nodes: React.ReactNode): React.ReactNode => {\n return React.Children.map(nodes, (child) => {\n if (!React.isValidElement(child)) return child;\n\n const component = child.type as React.ComponentType<unknown>;\n if (component.displayName === 'CommandFormField') {\n type FieldElement = Parameters<typeof CommandFormFieldWrapper>[0]['field'];\n return <CommandFormFieldWrapper field={child as unknown as FieldElement} />;\n }\n\n const childProps = child.props as Record<string, unknown>;\n if (childProps.children != null) {\n return React.cloneElement(child as React.ReactElement<Record<string, unknown>>, {\n children: processChildren(childProps.children as React.ReactNode)\n });\n }\n\n return child;\n });\n };\n\n const processedChildren = processChildren(children);\n const isDialogValid = (isValid !== false) && isCommandFormValid;\n\n return (\n <Dialog\n title={title}\n visible={visible}\n width={width}\n style={style}\n resizable={resizable}\n buttons={buttons}\n onClose={onClose}\n onConfirm={handleConfirm}\n onCancel={onCancel}\n okLabel={okLabel}\n cancelLabel={cancelLabel}\n yesLabel={yesLabel}\n noLabel={noLabel}\n isValid={isDialogValid}\n isBusy={isBusy}\n >\n <div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>\n {processedChildren}\n </div>\n </Dialog>\n );\n};\n\nconst CommandDialogComponent = <TCommand extends object = object>(props: CommandDialogProps<TCommand>) => {\n const {\n title,\n visible,\n width,\n style,\n resizable,\n buttons = DialogButtons.OkCancel,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n children,\n ...commandFormProps\n } = props;\n\n return (\n <CommandForm<TCommand> {...commandFormProps}>\n <CommandDialogWrapper<TCommand>\n title={title}\n visible={visible}\n width={width}\n style={style}\n resizable={resizable}\n buttons={buttons}\n okLabel={okLabel}\n cancelLabel={cancelLabel}\n yesLabel={yesLabel}\n noLabel={noLabel}\n isValid={isValid}\n onClose={onClose}\n onConfirm={onConfirm}\n onCancel={onCancel}\n onBeforeExecute={commandFormProps.onBeforeExecute}\n >\n {children}\n </CommandDialogWrapper>\n </CommandForm>\n );\n};\n\nconst CommandDialogColumnWrapper = ({ children }: { children: React.ReactNode }) => (\n <CommandForm.Column>{children}</CommandForm.Column>\n);\nCommandDialogColumnWrapper.displayName = 'CommandFormColumn';\n\nCommandDialogComponent.Column = CommandDialogColumnWrapper;\n\nexport const CommandDialog = CommandDialogComponent;\n"],"names":["_jsx"],"mappings":";;;;;;AAqBA,MAAM,oBAAoB,GAAG,CAA0B,EACnD,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAA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CACD;AAEjB,CAAC;AAED,MAAM,sBAAsB,GAAG,CAAmC,KAAmC,KAAI;AACrG,IAAA,MAAM,EACF,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,EACT,OAAO,GAAG,aAAa,CAAC,QAAQ,EAChC,OAAO,EACP,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,GAAG,gBAAgB,EACtB,GAAG,KAAK;AAET,IAAA,QACIA,GAAA,CAAC,WAAW,EAAA,EAAA,GAAe,gBAAgB,EAAA,QAAA,EACvCA,GAAA,CAAC,oBAAoB,EAAA,EACjB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,gBAAgB,CAAC,eAAe,EAAA,QAAA,EAEhD,QAAQ,EAAA,CACU,EAAA,CACb;AAEtB,CAAC;AAED,MAAM,0BAA0B,GAAG,CAAC,EAAE,QAAQ,EAAiC,MAC3EA,GAAA,CAAC,WAAW,CAAC,MAAM,cAAE,QAAQ,EAAA,CAAsB,CACtD;AACD,0BAA0B,CAAC,WAAW,GAAG,mBAAmB;AAE5D,sBAAsB,CAAC,MAAM,GAAG,0BAA0B;AAEnD,MAAM,aAAa,GAAG;;;;"}
|
|
@@ -16,4 +16,5 @@ export declare const BeforeExecute: Story;
|
|
|
16
16
|
export declare const WithIcons: Story;
|
|
17
17
|
export declare const MultiColumnLayout: Story;
|
|
18
18
|
export declare const MixedChildren: Story;
|
|
19
|
+
export declare const WithBusyState: Story;
|
|
19
20
|
//# sourceMappingURL=CommandDialog.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.stories.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandDialog.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKhD,OAAO,wBAAwB,CAAC;AAEhC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,aAAa,CAGpC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,aAAa,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandDialog.stories.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandDialog.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKhD,OAAO,wBAAwB,CAAC;AAEhC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,aAAa,CAGpC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,aAAa,CAAC,CAAC;AAmO5C,eAAO,MAAM,OAAO,EAAE,KAErB,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,KAElC,CAAC;AA6DF,eAAO,MAAM,iBAAiB,EAAE,KAE/B,CAAC;AA+DF,eAAO,MAAM,oBAAoB,EAAE,KAElC,CAAC;AA6BF,eAAO,MAAM,gBAAgB,EAAE,KAE9B,CAAC;AA6BF,eAAO,MAAM,kBAAkB,EAAE,KAEhC,CAAC;AA8BF,eAAO,MAAM,cAAc,EAAE,KAE5B,CAAC;AA8BF,eAAO,MAAM,yBAAyB,EAAE,KAEvC,CAAC;AA4CF,eAAO,MAAM,aAAa,EAAE,KAE3B,CAAC;AA4CF,eAAO,MAAM,SAAS,EAAE,KAEvB,CAAC;AAsFF,eAAO,MAAM,iBAAiB,EAAE,KAE/B,CAAC;AAmCF,eAAO,MAAM,aAAa,EAAE,KAE3B,CAAC;AA6CF,eAAO,MAAM,aAAa,EAAE,KAE3B,CAAC"}
|
|
@@ -47,6 +47,38 @@ class UpdateUserCommand extends Command {
|
|
|
47
47
|
return CommandResult.empty;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
class DemoSlowUpdateUserCommand extends Command {
|
|
51
|
+
route = '/api/users/update';
|
|
52
|
+
validation = new UpdateUserCommandValidator();
|
|
53
|
+
propertyDescriptors = [
|
|
54
|
+
new PropertyDescriptor('name', String),
|
|
55
|
+
new PropertyDescriptor('email', String),
|
|
56
|
+
new PropertyDescriptor('age', Number),
|
|
57
|
+
];
|
|
58
|
+
name = '';
|
|
59
|
+
email = '';
|
|
60
|
+
age = 0;
|
|
61
|
+
constructor() {
|
|
62
|
+
super(Object, false);
|
|
63
|
+
}
|
|
64
|
+
get requestParameters() {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
get properties() {
|
|
68
|
+
return ['name', 'email', 'age'];
|
|
69
|
+
}
|
|
70
|
+
async validate() {
|
|
71
|
+
const errors = this.validation?.validate(this) ?? [];
|
|
72
|
+
if (errors.length > 0) {
|
|
73
|
+
return CommandResult.validationFailed(errors);
|
|
74
|
+
}
|
|
75
|
+
return CommandResult.empty;
|
|
76
|
+
}
|
|
77
|
+
async execute() {
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
79
|
+
return CommandResult.empty;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
50
82
|
class UpdateUserCommandWithServer extends Command {
|
|
51
83
|
route = '/api/users/update';
|
|
52
84
|
validation = new UpdateUserCommandValidator();
|
|
@@ -76,8 +108,8 @@ const ServerValidationWrapper = () => {
|
|
|
76
108
|
setVisible(true);
|
|
77
109
|
setValidationErrors([]);
|
|
78
110
|
setResult('');
|
|
79
|
-
}, children: "Open Dialog" }), validationErrors.length > 0 && (_jsxs("div", { className: "p-3 mt-3 bg-red-100 border-round", children: [_jsx("strong", { children: "Validation Errors:" }), _jsx("ul", { className: "mt-2 mb-0", children: validationErrors.map((error, index) => (_jsx("li", { children: error }, index))) })] })), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Command executed:" }), " ", result] })), _jsxs(CommandDialog, { command: UpdateUserCommandWithServer, visible: visible,
|
|
80
|
-
setResult(
|
|
111
|
+
}, children: "Open Dialog" }), validationErrors.length > 0 && (_jsxs("div", { className: "p-3 mt-3 bg-red-100 border-round", children: [_jsx("strong", { children: "Validation Errors:" }), _jsx("ul", { className: "mt-2 mb-0", children: validationErrors.map((error, index) => (_jsx("li", { children: error }, index))) })] })), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Command executed:" }), " ", result] })), _jsxs(CommandDialog, { command: UpdateUserCommandWithServer, visible: visible, title: "Update User Information (with Server Validation)", okLabel: "Save", cancelLabel: "Cancel", onConfirm: async () => {
|
|
112
|
+
setResult('Command executed successfully');
|
|
81
113
|
setVisible(false);
|
|
82
114
|
}, onCancel: () => setVisible(false), onFieldChange: async (command) => {
|
|
83
115
|
const validationResult = await command.validate();
|
|
@@ -93,7 +125,7 @@ const AwaitableWithResultWrapper = () => {
|
|
|
93
125
|
const [result, setResult] = useState('');
|
|
94
126
|
const UpdateUserDialog = () => {
|
|
95
127
|
const { closeDialog } = useDialogContext();
|
|
96
|
-
return (_jsxs(CommandDialog, { command: UpdateUserCommand,
|
|
128
|
+
return (_jsxs(CommandDialog, { command: UpdateUserCommand, title: "Update User Information (awaitable result)", okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, onConfirm: async () => closeDialog(DialogResult.Ok), onCancel: () => closeDialog(DialogResult.Cancelled), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Enter name (min 2 chars)" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Enter email", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Enter age (18-120)" })] }));
|
|
97
129
|
};
|
|
98
130
|
const [UpdateUserDialogComponent, showUpdateUserDialog] = useDialog(UpdateUserDialog);
|
|
99
131
|
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: async () => {
|
|
@@ -122,7 +154,7 @@ const EditUserWrapper = () => {
|
|
|
122
154
|
setResult('');
|
|
123
155
|
setVisible(true);
|
|
124
156
|
};
|
|
125
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("div", { style: { display: 'flex', gap: '0.5rem', marginBottom: '1rem' }, children: users.map(user => (_jsxs("button", { className: "p-button p-component", onClick: () => handleEdit(user), children: ["Edit ", user.name] }, user.email))) }), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Saved:" }), " ", result] })), _jsxs(CommandDialog, { command: UpdateUserCommand, initialValues: selectedUser, visible: visible,
|
|
157
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("div", { style: { display: 'flex', gap: '0.5rem', marginBottom: '1rem' }, children: users.map(user => (_jsxs("button", { className: "p-button p-component", onClick: () => handleEdit(user), children: ["Edit ", user.name] }, user.email))) }), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Saved:" }), " ", result] })), _jsxs(CommandDialog, { command: UpdateUserCommand, initialValues: selectedUser, visible: visible, title: `Edit User: ${selectedUser?.name ?? ''}`, okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, onConfirm: async () => {
|
|
126
158
|
setResult(`User "${selectedUser?.name}" updated successfully`);
|
|
127
159
|
setVisible(false);
|
|
128
160
|
}, onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Enter name" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Enter email", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Enter age" })] }, selectedUser?.email ?? 'empty')] }));
|
|
@@ -136,7 +168,7 @@ const CustomValidationWrapper = () => {
|
|
|
136
168
|
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => {
|
|
137
169
|
setResult('');
|
|
138
170
|
setVisible(true);
|
|
139
|
-
}, children: "Open Dialog" }), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Saved:" }), " ", result] })), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
171
|
+
}, children: "Open Dialog" }), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Saved:" }), " ", result] })), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Add User (with Custom Validation)", okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, onConfirm: async () => {
|
|
140
172
|
setResult('User added successfully');
|
|
141
173
|
setVisible(false);
|
|
142
174
|
}, onCancel: () => setVisible(false), onFieldValidate: (_command, fieldName, _oldValue, newValue) => {
|
|
@@ -163,28 +195,28 @@ export const WithCustomValidation = {
|
|
|
163
195
|
};
|
|
164
196
|
const ValidationOnBlurWrapper = () => {
|
|
165
197
|
const [visible, setVisible] = useState(true);
|
|
166
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
198
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Validation on Blur", okLabel: "Save", cancelLabel: "Cancel", validateOn: "blur", autoServerValidate: false, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Click away to validate" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Click away to validate", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Click away to validate" })] })] }));
|
|
167
199
|
};
|
|
168
200
|
export const ValidationOnBlur = {
|
|
169
201
|
render: () => _jsx(ValidationOnBlurWrapper, {}),
|
|
170
202
|
};
|
|
171
203
|
const ValidationOnChangeWrapper = () => {
|
|
172
204
|
const [visible, setVisible] = useState(true);
|
|
173
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
205
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Validation on Change", okLabel: "Save", cancelLabel: "Cancel", validateOn: "change", autoServerValidate: false, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Errors appear while typing" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Errors appear while typing", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Errors appear while typing" })] })] }));
|
|
174
206
|
};
|
|
175
207
|
export const ValidationOnChange = {
|
|
176
208
|
render: () => _jsx(ValidationOnChangeWrapper, {}),
|
|
177
209
|
};
|
|
178
210
|
const ValidateOnInitWrapper = () => {
|
|
179
211
|
const [visible, setVisible] = useState(true);
|
|
180
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
212
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Validate on Initialization", okLabel: "Save", cancelLabel: "Cancel", validateOnInit: true, autoServerValidate: false, initialValues: { name: 'A', email: 'invalid', age: 10 }, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Errors shown immediately" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Errors shown immediately", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Errors shown immediately" })] })] }));
|
|
181
213
|
};
|
|
182
214
|
export const ValidateOnInit = {
|
|
183
215
|
render: () => _jsx(ValidateOnInitWrapper, {}),
|
|
184
216
|
};
|
|
185
217
|
const ValidateAllFieldsWrapper = () => {
|
|
186
218
|
const [visible, setVisible] = useState(true);
|
|
187
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
219
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Validate All Fields on Change", okLabel: "Save", cancelLabel: "Cancel", validateOn: "blur", validateAllFieldsOnChange: true, autoServerValidate: false, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Blur one field \u2014 all validate" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Blur one field \u2014 all validate", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Blur one field \u2014 all validate" })] })] }));
|
|
188
220
|
};
|
|
189
221
|
export const ValidateAllFieldsOnChange = {
|
|
190
222
|
render: () => _jsx(ValidateAllFieldsWrapper, {}),
|
|
@@ -192,21 +224,19 @@ export const ValidateAllFieldsOnChange = {
|
|
|
192
224
|
const BeforeExecuteWrapper = () => {
|
|
193
225
|
const [visible, setVisible] = useState(true);
|
|
194
226
|
const [preprocessedData, setPreprocessedData] = useState('');
|
|
195
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => { setVisible(true); setPreprocessedData(''); }, children: "Open Dialog" }), preprocessedData && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Preprocessed before submit:" }), _jsx("pre", { style: { marginTop: '0.5rem', fontSize: '0.875rem' }, children: preprocessedData })] })), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
227
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => { setVisible(true); setPreprocessedData(''); }, children: "Open Dialog" }), preprocessedData && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Preprocessed before submit:" }), _jsx("pre", { style: { marginTop: '0.5rem', fontSize: '0.875rem' }, children: preprocessedData })] })), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Before Execute Callback", okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, initialValues: { name: '', email: '', age: 18 }, onBeforeExecute: (command) => {
|
|
196
228
|
command.name = command.name.trim().replace(/\s+/g, ' ');
|
|
197
229
|
command.email = command.email.toLowerCase().trim();
|
|
230
|
+
setPreprocessedData(JSON.stringify(command, null, 2));
|
|
198
231
|
return command;
|
|
199
|
-
}, onConfirm: async (
|
|
200
|
-
setPreprocessedData(JSON.stringify(result, null, 2));
|
|
201
|
-
setVisible(false);
|
|
202
|
-
}, onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: 'Try " Extra Spaces "' }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Try UPPERCASE@EMAIL.COM", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Enter age (18-120)" })] })] }));
|
|
232
|
+
}, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: 'Try " Extra Spaces "' }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Try UPPERCASE@EMAIL.COM", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Enter age (18-120)" })] })] }));
|
|
203
233
|
};
|
|
204
234
|
export const BeforeExecute = {
|
|
205
235
|
render: () => _jsx(BeforeExecuteWrapper, {}),
|
|
206
236
|
};
|
|
207
237
|
const WithIconsWrapper = () => {
|
|
208
238
|
const [visible, setVisible] = useState(true);
|
|
209
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible,
|
|
239
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateUserCommand, visible: visible, title: "Fields with Icons", okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Enter name", icon: _jsx("span", { style: { fontSize: '1.25rem' }, children: "\uD83D\uDC64" }) }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Enter email", type: "email", icon: _jsx("span", { style: { fontSize: '1.25rem' }, children: "\uD83D\uDCE7" }) }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Enter age", icon: _jsx("span", { style: { fontSize: '1.25rem' }, children: "\uD83C\uDF82" }) })] })] }));
|
|
210
240
|
};
|
|
211
241
|
export const WithIcons = {
|
|
212
242
|
render: () => _jsx(WithIconsWrapper, {}),
|
|
@@ -255,16 +285,30 @@ class UpdateProfileCommand extends Command {
|
|
|
255
285
|
}
|
|
256
286
|
const MultiColumnWrapper = () => {
|
|
257
287
|
const [visible, setVisible] = useState(true);
|
|
258
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateProfileCommand, visible: visible,
|
|
288
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateProfileCommand, visible: visible, title: "Edit Profile", okLabel: "Save", cancelLabel: "Cancel", width: "70vw", autoServerValidate: false, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsxs("div", { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1.5rem' }, children: [_jsxs(CommandDialog.Column, { children: [_jsx(InputTextField, { value: (c) => c.firstName, title: "First Name", placeholder: "Enter first name" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Enter email", type: "email" })] }), _jsxs(CommandDialog.Column, { children: [_jsx(InputTextField, { value: (c) => c.lastName, title: "Last Name", placeholder: "Enter last name" }), _jsx(InputTextField, { value: (c) => c.phone, title: "Phone", placeholder: "Enter phone number" })] })] }), _jsx(TextAreaField, { value: (c) => c.bio, title: "Bio", placeholder: "Tell us about yourself", rows: 3 })] })] }));
|
|
259
289
|
};
|
|
260
290
|
export const MultiColumnLayout = {
|
|
261
291
|
render: () => _jsx(MultiColumnWrapper, {}),
|
|
262
292
|
};
|
|
263
293
|
const MixedChildrenWrapper = () => {
|
|
264
294
|
const [visible, setVisible] = useState(true);
|
|
265
|
-
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateProfileCommand, visible: visible,
|
|
295
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => setVisible(true), children: "Open Dialog" }), _jsxs(CommandDialog, { command: UpdateProfileCommand, visible: visible, title: "Edit Profile (Mixed Children)", okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, onConfirm: async () => setVisible(false), onCancel: () => setVisible(false), children: [_jsx("h3", { style: { marginTop: 0, marginBottom: '0.75rem' }, children: "Personal Information" }), _jsx(InputTextField, { value: (c) => c.firstName, title: "First Name", placeholder: "Enter first name" }), _jsx(InputTextField, { value: (c) => c.lastName, title: "Last Name", placeholder: "Enter last name" }), _jsx("h3", { style: { marginTop: '1rem', marginBottom: '0.75rem' }, children: "Contact Details" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Enter email", type: "email" }), _jsx(InputTextField, { value: (c) => c.phone, title: "Phone", placeholder: "Enter phone number" }), _jsx("h3", { style: { marginTop: '1rem', marginBottom: '0.75rem' }, children: "About You" }), _jsx(TextAreaField, { value: (c) => c.bio, title: "Bio", placeholder: "Tell us about yourself (min 10 chars)", rows: 3 })] })] }));
|
|
266
296
|
};
|
|
267
297
|
export const MixedChildren = {
|
|
268
298
|
render: () => _jsx(MixedChildrenWrapper, {}),
|
|
269
299
|
};
|
|
300
|
+
const WithBusyStateWrapper = () => {
|
|
301
|
+
const [visible, setVisible] = useState(true);
|
|
302
|
+
const [result, setResult] = useState('');
|
|
303
|
+
return (_jsxs("div", { className: "storybook-wrapper", children: [_jsx("button", { className: "p-button p-component mb-3", onClick: () => {
|
|
304
|
+
setResult('');
|
|
305
|
+
setVisible(true);
|
|
306
|
+
}, children: "Open Dialog" }), result && (_jsxs("div", { className: "p-3 mt-3 bg-green-100 border-round", children: [_jsx("strong", { children: "Saved:" }), " ", result] })), _jsxs(CommandDialog, { command: DemoSlowUpdateUserCommand, visible: visible, title: "Save User (2s simulated delay)", okLabel: "Save", cancelLabel: "Cancel", autoServerValidate: false, onConfirm: async () => {
|
|
307
|
+
setResult('User saved successfully');
|
|
308
|
+
setVisible(false);
|
|
309
|
+
}, onCancel: () => setVisible(false), children: [_jsx(InputTextField, { value: (c) => c.name, title: "Name", placeholder: "Enter name (min 2 chars)" }), _jsx(InputTextField, { value: (c) => c.email, title: "Email", placeholder: "Enter email", type: "email" }), _jsx(NumberField, { value: (c) => c.age, title: "Age", placeholder: "Enter age (18-120)" })] })] }));
|
|
310
|
+
};
|
|
311
|
+
export const WithBusyState = {
|
|
312
|
+
render: () => _jsx(WithBusyStateWrapper, {}),
|
|
313
|
+
};
|
|
270
314
|
//# sourceMappingURL=CommandDialog.stories.js.map
|