@coveord/plasma-mantine 48.6.0 → 48.7.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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-test.log +6 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/modal-wizard/ModalWizard.js +24 -21
- package/dist/cjs/components/modal-wizard/ModalWizard.js.map +1 -1
- package/dist/definitions/components/modal-wizard/ModalWizard.d.ts +3 -14
- package/dist/definitions/components/modal-wizard/ModalWizard.d.ts.map +1 -1
- package/dist/esm/components/modal-wizard/ModalWizard.js +25 -22
- package/dist/esm/components/modal-wizard/ModalWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/components/modal-wizard/ModalWizard.tsx +14 -42
- package/src/components/modal-wizard/__tests__/ModalWizard.spec.tsx +45 -39
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "ModalWizard", {
|
|
|
10
10
|
});
|
|
11
11
|
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
|
|
12
12
|
var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
|
|
13
|
+
var _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default;
|
|
13
14
|
var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default;
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
var _core = require("@mantine/core");
|
|
@@ -17,17 +18,22 @@ var _react = require("react");
|
|
|
17
18
|
var _stickyFooter = require("../sticky-footer");
|
|
18
19
|
var _modalWizardStep = require("./ModalWizardStep");
|
|
19
20
|
var _header = require("../header");
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
var ModalWizard = function(_param) {
|
|
22
|
+
var _cancelButtonLabel = _param.cancelButtonLabel, cancelButtonLabel = _cancelButtonLabel === void 0 ? "Cancel" : _cancelButtonLabel, _nextButtonLabel = _param.nextButtonLabel, nextButtonLabel = _nextButtonLabel === void 0 ? "Next" : _nextButtonLabel, _previousButtonLabel = _param.previousButtonLabel, previousButtonLabel = _previousButtonLabel === void 0 ? "Previous" : _previousButtonLabel, _finishButtonLabel = _param.finishButtonLabel, finishButtonLabel = _finishButtonLabel === void 0 ? "Finish" : _finishButtonLabel, opened = _param.opened, onNext = _param.onNext, onPrevious = _param.onPrevious, onClose = _param.onClose, onFinish = _param.onFinish, isDirty = _param.isDirty, handleDirtyState = _param.handleDirtyState, classNames = _param.classNames, children = _param.children, modalProps = _objectWithoutProperties(_param, [
|
|
23
|
+
"cancelButtonLabel",
|
|
24
|
+
"nextButtonLabel",
|
|
25
|
+
"previousButtonLabel",
|
|
26
|
+
"finishButtonLabel",
|
|
27
|
+
"opened",
|
|
28
|
+
"onNext",
|
|
29
|
+
"onPrevious",
|
|
30
|
+
"onClose",
|
|
31
|
+
"onFinish",
|
|
32
|
+
"isDirty",
|
|
33
|
+
"handleDirtyState",
|
|
34
|
+
"classNames",
|
|
35
|
+
"children"
|
|
36
|
+
]);
|
|
31
37
|
var ref, ref1;
|
|
32
38
|
var ref2 = _slicedToArray((0, _react.useState)(0), 2), currentStepIndex = ref2[0], setCurrentStepIndex = ref2[1];
|
|
33
39
|
var modalSteps = _react.Children.toArray(children).filter(function(child) {
|
|
@@ -47,7 +53,6 @@ var ModalWizard = function(param) {
|
|
|
47
53
|
isValid: true
|
|
48
54
|
}).isValid;
|
|
49
55
|
var isModalDirty = isDirty && isDirty();
|
|
50
|
-
var classes = useStyles().classes;
|
|
51
56
|
var closeModalWizard = function() {
|
|
52
57
|
if (isModalDirty && handleDirtyState) {
|
|
53
58
|
handleDirtyState() && (onClose === null || onClose === void 0 ? void 0 : onClose());
|
|
@@ -67,15 +72,11 @@ var ModalWizard = function(param) {
|
|
|
67
72
|
currentStepIndex
|
|
68
73
|
]);
|
|
69
74
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_core.Modal, _objectSpreadProps(_objectSpread({
|
|
70
|
-
opened:
|
|
71
|
-
classNames:
|
|
72
|
-
modal: classes.modal
|
|
73
|
-
},
|
|
75
|
+
opened: opened,
|
|
76
|
+
classNames: classNames,
|
|
74
77
|
centered: true,
|
|
75
|
-
closeButtonLabel: closeButtonLabel,
|
|
76
|
-
padding: "xl",
|
|
77
78
|
title: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_header.Header, {
|
|
78
|
-
docLink: currentStep.props.
|
|
79
|
+
docLink: currentStep.props.docLink,
|
|
79
80
|
description: typeof currentStep.props.description === "function" ? currentStep.props.description(currentStepIndex + 1, numberOfSteps) : currentStep.props.description,
|
|
80
81
|
py: null,
|
|
81
82
|
px: null,
|
|
@@ -85,6 +86,8 @@ var ModalWizard = function(param) {
|
|
|
85
86
|
}, modalProps), {
|
|
86
87
|
children: [
|
|
87
88
|
currentStep.props.showProgressBar && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Progress, {
|
|
89
|
+
color: "teal",
|
|
90
|
+
size: "lg",
|
|
88
91
|
value: getProgressMemo
|
|
89
92
|
}),
|
|
90
93
|
currentStep,
|
|
@@ -97,7 +100,7 @@ var ModalWizard = function(param) {
|
|
|
97
100
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Button, {
|
|
98
101
|
name: isFirstStep ? cancelButtonLabel : previousButtonLabel,
|
|
99
102
|
disabled: false,
|
|
100
|
-
size: "
|
|
103
|
+
size: "sm",
|
|
101
104
|
variant: "outline",
|
|
102
105
|
onClick: function() {
|
|
103
106
|
if (isFirstStep) {
|
|
@@ -111,7 +114,7 @@ var ModalWizard = function(param) {
|
|
|
111
114
|
}),
|
|
112
115
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Button, {
|
|
113
116
|
disabled: !isValid,
|
|
114
|
-
size: "
|
|
117
|
+
size: "sm",
|
|
115
118
|
onClick: function() {
|
|
116
119
|
if (isLastStep) {
|
|
117
120
|
onFinish ? onFinish() : onClose();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/modal-wizard/ModalWizard.tsx"],"sourcesContent":["import {Button, createStyles, Modal, Progress} from '@mantine/core';\nimport {Children, ReactElement, useMemo, useState} from 'react';\nimport {StickyFooter} from '../sticky-footer';\nimport {ModalWizardStep} from './ModalWizardStep';\nimport {Header} from '../header';\n\ninterface ModalWizardProps {\n /**\n * The label of the cancel button\n *\n * @default \"Cancel\"\n */\n cancelButtonLabel?: string;\n\n /**\n * The label of the next button\n *\n * @default \"Next\"\n */\n\n nextButtonLabel?: string;\n /**\n * The label of the previous button\n *\n * @default \"Previous\"\n */\n previousButtonLabel?: string;\n /**\n * The label of the finish button\n *\n * @default \"Finish\"\n */\n\n finishButtonLabel?: string;\n\n /**\n * A callback function that is executed when the user clicks on the next button\n */\n onNext?: () => unknown;\n\n /**\n * A callback function that is executed when the user clicks on the previous button\n */\n onPrevious?: () => unknown;\n\n /**\n * A callback function that is executed when the user clicks on the cancel button\n */\n\n onClose?: () => unknown;\n\n /**\n * A function that is executed when user completes all the steps.\n *\n * @param close A function that closes the modal when called.\n */\n onFinish?: () => unknown;\n\n /**\n * Determine if user interacted with any steps in the modal wizard\n */\n\n isDirty?: () => boolean;\n\n /**\n * A function to confirm close if the state is dirty before closing\n */\n handleDirtyState?: () => boolean;\n\n /**\n * Props to pass to each modal\n */\n modalProps?: any;\n\n /**\n * Label for close button\n */\n closeButtonLabel?: string;\n\n /**\n * Children to display in modal wizard\n * */\n children?: Array<ReturnType<typeof ModalWizardStep>>;\n}\n\nconst useStyles = createStyles(() => ({\n modal: {\n height: '70%',\n display: 'flex',\n flexDirection: 'column',\n },\n}));\n\ninterface ModalWizardType {\n <T>(props: ModalWizardProps): ReactElement;\n\n Step: typeof ModalWizardStep;\n}\n\nexport const ModalWizard: ModalWizardType = ({\n cancelButtonLabel = 'Cancel',\n nextButtonLabel = 'Next',\n previousButtonLabel = 'Previous',\n finishButtonLabel = 'Finish',\n onNext,\n onPrevious,\n onClose,\n onFinish,\n isDirty,\n modalProps,\n handleDirtyState,\n closeButtonLabel,\n children,\n}) => {\n const [currentStepIndex, setCurrentStepIndex] = useState(0);\n const modalSteps = (Children.toArray(children) as ReactElement[]).filter((child) => child.type === ModalWizardStep);\n\n const numberOfSteps = modalSteps.length;\n const numberOfStepsCountAsProgress = modalSteps.filter((step) => step.props.countsAsProgress).length;\n const isFirstStep = currentStepIndex === 0;\n const isLastStep = currentStepIndex === numberOfSteps - 1;\n const currentStep = modalSteps.filter((step: ReactElement, index: number) => index === currentStepIndex)[0];\n\n const {isValid} = currentStep?.props?.validateStep?.(currentStepIndex, numberOfSteps) ?? {isValid: true};\n const isModalDirty = isDirty && isDirty();\n\n const {classes} = useStyles();\n\n const closeModalWizard = () => {\n if (isModalDirty && handleDirtyState) {\n handleDirtyState() && onClose?.();\n } else {\n onClose?.();\n }\n };\n\n const getProgress = (currStepIndex: number) => {\n const validSteps = modalSteps.filter(\n (step, index) => step.props.countsAsProgress && index <= currStepIndex\n ).length;\n return (validSteps / numberOfStepsCountAsProgress) * 100;\n };\n\n const getProgressMemo = useMemo(() => getProgress(currentStepIndex), [currentStepIndex]);\n\n return (\n <Modal\n opened\n classNames={{modal: classes.modal}}\n centered\n closeButtonLabel={closeButtonLabel}\n padding=\"xl\"\n title={\n <Header\n docLink={currentStep.props.docLin}\n description={\n typeof currentStep.props.description === 'function'\n ? currentStep.props.description(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.description\n }\n py={null}\n px={null}\n >\n {typeof currentStep.props.title === 'function'\n ? currentStep.props.title(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.title}\n </Header>\n }\n onClose={closeModalWizard}\n {...modalProps}\n >\n {currentStep.props.showProgressBar && <Progress value={getProgressMemo} />}\n {currentStep}\n <StickyFooter borderTop py={null} px={null} pt=\"md\">\n <Button\n name={isFirstStep ? cancelButtonLabel : previousButtonLabel}\n disabled={false}\n size=\"md\"\n variant=\"outline\"\n onClick={() => {\n if (isFirstStep) {\n closeModalWizard();\n } else {\n onPrevious?.();\n setCurrentStepIndex(currentStepIndex - 1);\n }\n }}\n >\n {isFirstStep ? cancelButtonLabel : previousButtonLabel}\n </Button>\n\n <Button\n disabled={!isValid}\n size=\"md\"\n onClick={() => {\n if (isLastStep) {\n onFinish ? onFinish() : onClose();\n } else {\n onNext?.();\n setCurrentStepIndex(currentStepIndex + 1);\n }\n }}\n >\n {isLastStep ? finishButtonLabel : nextButtonLabel}\n </Button>\n </StickyFooter>\n </Modal>\n );\n};\n\nModalWizard.Step = ModalWizardStep;\n"],"names":["ModalWizard","useStyles","createStyles","modal","height","display","flexDirection","cancelButtonLabel","nextButtonLabel","previousButtonLabel","finishButtonLabel","onNext","onPrevious","onClose","onFinish","isDirty","modalProps","handleDirtyState","closeButtonLabel","children","currentStep","useState","currentStepIndex","setCurrentStepIndex","modalSteps","Children","toArray","filter","child","type","ModalWizardStep","numberOfSteps","length","numberOfStepsCountAsProgress","step","props","countsAsProgress","isFirstStep","isLastStep","index","isValid","validateStep","isModalDirty","classes","closeModalWizard","getProgress","currStepIndex","validSteps","getProgressMemo","useMemo","Modal","opened","classNames","centered","padding","title","Header","docLink","docLin","description","py","px","showProgressBar","Progress","value","StickyFooter","borderTop","pt","Button","name","disabled","size","variant","onClick","Step"],"mappings":"AAAA;;;;+BAmGaA,aAAW;;;eAAXA,WAAW;;;;;;;oBAnG4B,eAAe;qBACX,OAAO;4BACpC,kBAAkB;+BACf,mBAAmB;sBAC5B,WAAW;AAiFhC,IAAMC,SAAS,GAAGC,IAAAA,KAAY,aAAA,EAAC;WAAO;QAClCC,KAAK,EAAE;YACHC,MAAM,EAAE,KAAK;YACbC,OAAO,EAAE,MAAM;YACfC,aAAa,EAAE,QAAQ;SAC1B;KACJ;CAAC,CAAC,AAAC;AAQG,IAAMN,WAAW,GAAoB,gBActC;mCAbFO,iBAAiB,EAAjB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,IAAI;wBACTC,OAAO,EAAC,SAAS;wBACjBC,OAAO,EAAE,WAAM;4BACX,IAAIpC,WAAW,EAAE;gCACbO,gBAAgB,EAAE,CAAC;4BACvB,OAAO;gCACHhC,UAAU,aAAVA,UAAU,WAAI,GAAdA,KAAAA,CAAc,GAAdA,UAAU,EAAI,CAAC;gCACfW,mBAAmB,CAACD,gBAAgB,GAAG,CAAC,CAAC,CAAC;4BAC9C,CAAC;wBACL,CAAC;kCAEAe,WAAW,GAAG9B,iBAAiB,GAAGE,mBAAmB;sBACjD;kCAET,qBAAC2D,KAAM,OAAA;wBACHE,QAAQ,EAAE,CAAC9B,OAAO;wBAClB+B,IAAI,EAAC,IAAI;wBACTE,OAAO,EAAE,WAAM;4BACX,IAAInC,UAAU,EAAE;gCACZxB,QAAQ,GAAGA,QAAQ,EAAE,GAAGD,OAAO,EAAE,CAAC;4BACtC,OAAO;gCACHF,MAAM,aAANA,MAAM,WAAI,GAAVA,KAAAA,CAAU,GAAVA,MAAM,EAAI,CAAC;gCACXY,mBAAmB,CAACD,gBAAgB,GAAG,CAAC,CAAC,CAAC;4BAC9C,CAAC;wBACL,CAAC;kCAEAgB,UAAU,GAAG5B,iBAAiB,GAAGF,eAAe;sBAC5C;;cACE;;OACX,CACV;AACN,CAAC,AAAC;AAEFR,WAAW,CAAC0E,IAAI,GAAG5C,gBAAe,gBAAA,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/modal-wizard/ModalWizard.tsx"],"sourcesContent":["import {Button, Modal, ModalProps, Progress} from '@mantine/core';\nimport {Children, ReactElement, useMemo, useState} from 'react';\nimport {StickyFooter} from '../sticky-footer';\nimport {ModalWizardStep} from './ModalWizardStep';\nimport {Header} from '../header';\n\ninterface ModalWizardProps extends Omit<ModalProps, 'centered' | 'title'> {\n /**\n * The label of the cancel button\n *\n * @default \"Cancel\"\n */\n cancelButtonLabel?: string;\n\n /**\n * The label of the next button\n *\n * @default \"Next\"\n */\n nextButtonLabel?: string;\n\n /**\n * The label of the previous button\n *\n * @default \"Previous\"\n */\n previousButtonLabel?: string;\n\n /**\n * The label of the finish button\n *\n * @default \"Finish\"\n */\n finishButtonLabel?: string;\n\n /**\n * A callback function that is executed when the user clicks on the next button\n */\n onNext?: () => unknown;\n\n /**\n * A callback function that is executed when the user clicks on the previous button\n */\n onPrevious?: () => unknown;\n\n /**\n * A function that is executed when user completes all the steps.\n *\n * @param close A function that closes the modal when called.\n */\n onFinish?: () => unknown;\n\n /**\n * Determine if user interacted with any steps in the modal wizard\n */\n isDirty?: () => boolean;\n\n /**\n * A function to confirm close if the state is dirty before closing\n */\n handleDirtyState?: () => boolean;\n\n /**\n * Children to display in modal wizard\n * */\n children?: Array<ReturnType<typeof ModalWizardStep>>;\n}\n\ninterface ModalWizardType {\n (props: ModalWizardProps): ReactElement;\n\n Step: typeof ModalWizardStep;\n}\n\nexport const ModalWizard: ModalWizardType = ({\n cancelButtonLabel = 'Cancel',\n nextButtonLabel = 'Next',\n previousButtonLabel = 'Previous',\n finishButtonLabel = 'Finish',\n opened,\n onNext,\n onPrevious,\n onClose,\n onFinish,\n isDirty,\n handleDirtyState,\n classNames,\n children,\n ...modalProps\n}) => {\n const [currentStepIndex, setCurrentStepIndex] = useState(0);\n const modalSteps = (Children.toArray(children) as ReactElement[]).filter((child) => child.type === ModalWizardStep);\n\n const numberOfSteps = modalSteps.length;\n const numberOfStepsCountAsProgress = modalSteps.filter((step) => step.props.countsAsProgress).length;\n const isFirstStep = currentStepIndex === 0;\n const isLastStep = currentStepIndex === numberOfSteps - 1;\n const currentStep = modalSteps.filter((step: ReactElement, index: number) => index === currentStepIndex)[0];\n\n const {isValid} = currentStep?.props?.validateStep?.(currentStepIndex, numberOfSteps) ?? {isValid: true};\n const isModalDirty = isDirty && isDirty();\n\n const closeModalWizard = () => {\n if (isModalDirty && handleDirtyState) {\n handleDirtyState() && onClose?.();\n } else {\n onClose?.();\n }\n };\n\n const getProgress = (currStepIndex: number) => {\n const validSteps = modalSteps.filter(\n (step, index) => step.props.countsAsProgress && index <= currStepIndex\n ).length;\n return (validSteps / numberOfStepsCountAsProgress) * 100;\n };\n\n const getProgressMemo = useMemo(() => getProgress(currentStepIndex), [currentStepIndex]);\n\n return (\n <Modal\n opened={opened}\n classNames={classNames}\n centered\n title={\n <Header\n docLink={currentStep.props.docLink}\n description={\n typeof currentStep.props.description === 'function'\n ? currentStep.props.description(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.description\n }\n py={null}\n px={null}\n >\n {typeof currentStep.props.title === 'function'\n ? currentStep.props.title(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.title}\n </Header>\n }\n onClose={closeModalWizard}\n {...modalProps}\n >\n {currentStep.props.showProgressBar && <Progress color=\"teal\" size=\"lg\" value={getProgressMemo} />}\n {currentStep}\n <StickyFooter borderTop py={null} px={null} pt=\"md\">\n <Button\n name={isFirstStep ? cancelButtonLabel : previousButtonLabel}\n disabled={false}\n size=\"sm\"\n variant=\"outline\"\n onClick={() => {\n if (isFirstStep) {\n closeModalWizard();\n } else {\n onPrevious?.();\n setCurrentStepIndex(currentStepIndex - 1);\n }\n }}\n >\n {isFirstStep ? cancelButtonLabel : previousButtonLabel}\n </Button>\n\n <Button\n disabled={!isValid}\n size=\"sm\"\n onClick={() => {\n if (isLastStep) {\n onFinish ? onFinish() : onClose();\n } else {\n onNext?.();\n setCurrentStepIndex(currentStepIndex + 1);\n }\n }}\n >\n {isLastStep ? finishButtonLabel : nextButtonLabel}\n </Button>\n </StickyFooter>\n </Modal>\n );\n};\n\nModalWizard.Step = ModalWizardStep;\n"],"names":["ModalWizard","cancelButtonLabel","nextButtonLabel","previousButtonLabel","finishButtonLabel","opened","onNext","onPrevious","onClose","onFinish","isDirty","handleDirtyState","classNames","children","modalProps","currentStep","useState","currentStepIndex","setCurrentStepIndex","modalSteps","Children","toArray","filter","child","type","ModalWizardStep","numberOfSteps","length","numberOfStepsCountAsProgress","step","props","countsAsProgress","isFirstStep","isLastStep","index","isValid","validateStep","isModalDirty","closeModalWizard","getProgress","currStepIndex","validSteps","getProgressMemo","useMemo","Modal","centered","title","Header","docLink","description","py","px","showProgressBar","Progress","color","size","value","StickyFooter","borderTop","pt","Button","name","disabled","variant","onClick","Step"],"mappings":"AAAA;;;;+BA0EaA,aAAW;;;eAAXA,WAAW;;;;;;;;oBA1E0B,eAAe;qBACT,OAAO;4BACpC,kBAAkB;+BACf,mBAAmB;sBAC5B,WAAW;AAsEzB,IAAMA,WAAW,GAAoB,iBAetC;oCAdFC,iBAAiB,EAAjBA,iBAAiB,mCAAG,QAAQ,qBAAA,4BAC5BC,eAAe,EAAfA,eAAe,iCAAG,MAAM,mBAAA,gCACxBC,mBAAmB,EAAnBA,mBAAmB,qCAAG,UAAU,uBAAA,8BAChCC,iBAAiB,EAAjBA,iBAAiB,mCAAG,QAAQ,qBAAA,EAC5BC,MAAM,UAANA,MAAM,EACNC,MAAM,UAANA,MAAM,EACNC,UAAU,UAAVA,UAAU,EACVC,OAAO,UAAPA,OAAO,EACPC,QAAQ,UAARA,QAAQ,EACRC,OAAO,UAAPA,OAAO,EACPC,gBAAgB,UAAhBA,gBAAgB,EAChBC,UAAU,UAAVA,UAAU,EACVC,QAAQ,UAARA,QAAQ,EACLC,UAAU;QAbbb,mBAAiB;QACjBC,iBAAe;QACfC,qBAAmB;QACnBC,mBAAiB;QACjBC,QAAM;QACNC,QAAM;QACNC,YAAU;QACVC,SAAO;QACPC,UAAQ;QACRC,SAAO;QACPC,kBAAgB;QAChBC,YAAU;QACVC,UAAQ;;QAYUE,GAAkB;IATpC,IAAgDC,IAAW,kBAAXA,IAAAA,MAAQ,SAAA,EAAC,CAAC,CAAC,IAAA,EAApDC,gBAAgB,GAAyBD,IAAW,GAApC,EAAEE,mBAAmB,GAAIF,IAAW,GAAf,AAAgB;IAC5D,IAAMG,UAAU,GAAG,AAACC,MAAQ,SAAA,CAACC,OAAO,CAACR,QAAQ,CAAC,CAAoBS,MAAM,CAAC,SAACC,KAAK;eAA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AI,GAAGxC,gBAAe,gBAAA,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ModalProps } from '@mantine/core';
|
|
1
2
|
import { ReactElement } from 'react';
|
|
2
3
|
import { ModalWizardStep } from './ModalWizardStep';
|
|
3
|
-
interface ModalWizardProps {
|
|
4
|
+
interface ModalWizardProps extends Omit<ModalProps, 'centered' | 'title'> {
|
|
4
5
|
/**
|
|
5
6
|
* The label of the cancel button
|
|
6
7
|
*
|
|
@@ -33,10 +34,6 @@ interface ModalWizardProps {
|
|
|
33
34
|
* A callback function that is executed when the user clicks on the previous button
|
|
34
35
|
*/
|
|
35
36
|
onPrevious?: () => unknown;
|
|
36
|
-
/**
|
|
37
|
-
* A callback function that is executed when the user clicks on the cancel button
|
|
38
|
-
*/
|
|
39
|
-
onClose?: () => unknown;
|
|
40
37
|
/**
|
|
41
38
|
* A function that is executed when user completes all the steps.
|
|
42
39
|
*
|
|
@@ -51,21 +48,13 @@ interface ModalWizardProps {
|
|
|
51
48
|
* A function to confirm close if the state is dirty before closing
|
|
52
49
|
*/
|
|
53
50
|
handleDirtyState?: () => boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Props to pass to each modal
|
|
56
|
-
*/
|
|
57
|
-
modalProps?: any;
|
|
58
|
-
/**
|
|
59
|
-
* Label for close button
|
|
60
|
-
*/
|
|
61
|
-
closeButtonLabel?: string;
|
|
62
51
|
/**
|
|
63
52
|
* Children to display in modal wizard
|
|
64
53
|
* */
|
|
65
54
|
children?: Array<ReturnType<typeof ModalWizardStep>>;
|
|
66
55
|
}
|
|
67
56
|
interface ModalWizardType {
|
|
68
|
-
|
|
57
|
+
(props: ModalWizardProps): ReactElement;
|
|
69
58
|
Step: typeof ModalWizardStep;
|
|
70
59
|
}
|
|
71
60
|
export declare const ModalWizard: ModalWizardType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalWizard.d.ts","sourceRoot":"","sources":["../../../../src/components/modal-wizard/ModalWizard.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ModalWizard.d.ts","sourceRoot":"","sources":["../../../../src/components/modal-wizard/ModalWizard.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAW,MAAM,eAAe,CAAC;AAClE,OAAO,EAAW,YAAY,EAAoB,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAGlD,UAAU,gBAAiB,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC;IACrE;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC;IAEvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC;IAExB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC;IAEjC;;SAEK;IACL,QAAQ,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC;CACxD;AAED,UAAU,eAAe;IACrB,CAAC,KAAK,EAAE,gBAAgB,GAAG,YAAY,CAAC;IAExC,IAAI,EAAE,OAAO,eAAe,CAAC;CAChC;AAED,eAAO,MAAM,WAAW,EAAE,eA0GzB,CAAC"}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
|
|
2
2
|
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
|
|
3
|
+
import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
|
|
3
4
|
import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
|
|
4
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { Button,
|
|
6
|
+
import { Button, Modal, Progress } from "@mantine/core";
|
|
6
7
|
import { Children, useMemo, useState } from "react";
|
|
7
8
|
import { StickyFooter } from "../sticky-footer";
|
|
8
9
|
import { ModalWizardStep } from "./ModalWizardStep";
|
|
9
10
|
import { Header } from "../header";
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
export var ModalWizard = function(_param) {
|
|
12
|
+
var _cancelButtonLabel = _param.cancelButtonLabel, cancelButtonLabel = _cancelButtonLabel === void 0 ? "Cancel" : _cancelButtonLabel, _nextButtonLabel = _param.nextButtonLabel, nextButtonLabel = _nextButtonLabel === void 0 ? "Next" : _nextButtonLabel, _previousButtonLabel = _param.previousButtonLabel, previousButtonLabel = _previousButtonLabel === void 0 ? "Previous" : _previousButtonLabel, _finishButtonLabel = _param.finishButtonLabel, finishButtonLabel = _finishButtonLabel === void 0 ? "Finish" : _finishButtonLabel, opened = _param.opened, onNext = _param.onNext, onPrevious = _param.onPrevious, onClose = _param.onClose, onFinish = _param.onFinish, isDirty = _param.isDirty, handleDirtyState = _param.handleDirtyState, classNames = _param.classNames, children = _param.children, modalProps = _object_without_properties(_param, [
|
|
13
|
+
"cancelButtonLabel",
|
|
14
|
+
"nextButtonLabel",
|
|
15
|
+
"previousButtonLabel",
|
|
16
|
+
"finishButtonLabel",
|
|
17
|
+
"opened",
|
|
18
|
+
"onNext",
|
|
19
|
+
"onPrevious",
|
|
20
|
+
"onClose",
|
|
21
|
+
"onFinish",
|
|
22
|
+
"isDirty",
|
|
23
|
+
"handleDirtyState",
|
|
24
|
+
"classNames",
|
|
25
|
+
"children"
|
|
26
|
+
]);
|
|
21
27
|
var ref, ref1;
|
|
22
28
|
var ref2 = _sliced_to_array(useState(0), 2), currentStepIndex = ref2[0], setCurrentStepIndex = ref2[1];
|
|
23
29
|
var modalSteps = Children.toArray(children).filter(function(child) {
|
|
@@ -37,7 +43,6 @@ export var ModalWizard = function(param) {
|
|
|
37
43
|
isValid: true
|
|
38
44
|
}).isValid;
|
|
39
45
|
var isModalDirty = isDirty && isDirty();
|
|
40
|
-
var classes = useStyles().classes;
|
|
41
46
|
var closeModalWizard = function() {
|
|
42
47
|
if (isModalDirty && handleDirtyState) {
|
|
43
48
|
handleDirtyState() && (onClose === null || onClose === void 0 ? void 0 : onClose());
|
|
@@ -57,15 +62,11 @@ export var ModalWizard = function(param) {
|
|
|
57
62
|
currentStepIndex
|
|
58
63
|
]);
|
|
59
64
|
return /*#__PURE__*/ _jsxs(Modal, _object_spread_props(_object_spread({
|
|
60
|
-
opened:
|
|
61
|
-
classNames:
|
|
62
|
-
modal: classes.modal
|
|
63
|
-
},
|
|
65
|
+
opened: opened,
|
|
66
|
+
classNames: classNames,
|
|
64
67
|
centered: true,
|
|
65
|
-
closeButtonLabel: closeButtonLabel,
|
|
66
|
-
padding: "xl",
|
|
67
68
|
title: /*#__PURE__*/ _jsx(Header, {
|
|
68
|
-
docLink: currentStep.props.
|
|
69
|
+
docLink: currentStep.props.docLink,
|
|
69
70
|
description: typeof currentStep.props.description === "function" ? currentStep.props.description(currentStepIndex + 1, numberOfSteps) : currentStep.props.description,
|
|
70
71
|
py: null,
|
|
71
72
|
px: null,
|
|
@@ -75,6 +76,8 @@ export var ModalWizard = function(param) {
|
|
|
75
76
|
}, modalProps), {
|
|
76
77
|
children: [
|
|
77
78
|
currentStep.props.showProgressBar && /*#__PURE__*/ _jsx(Progress, {
|
|
79
|
+
color: "teal",
|
|
80
|
+
size: "lg",
|
|
78
81
|
value: getProgressMemo
|
|
79
82
|
}),
|
|
80
83
|
currentStep,
|
|
@@ -87,7 +90,7 @@ export var ModalWizard = function(param) {
|
|
|
87
90
|
/*#__PURE__*/ _jsx(Button, {
|
|
88
91
|
name: isFirstStep ? cancelButtonLabel : previousButtonLabel,
|
|
89
92
|
disabled: false,
|
|
90
|
-
size: "
|
|
93
|
+
size: "sm",
|
|
91
94
|
variant: "outline",
|
|
92
95
|
onClick: function() {
|
|
93
96
|
if (isFirstStep) {
|
|
@@ -101,7 +104,7 @@ export var ModalWizard = function(param) {
|
|
|
101
104
|
}),
|
|
102
105
|
/*#__PURE__*/ _jsx(Button, {
|
|
103
106
|
disabled: !isValid,
|
|
104
|
-
size: "
|
|
107
|
+
size: "sm",
|
|
105
108
|
onClick: function() {
|
|
106
109
|
if (isLastStep) {
|
|
107
110
|
onFinish ? onFinish() : onClose();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/modal-wizard/ModalWizard.tsx"],"sourcesContent":["import {Button, createStyles, Modal, Progress} from '@mantine/core';\nimport {Children, ReactElement, useMemo, useState} from 'react';\nimport {StickyFooter} from '../sticky-footer';\nimport {ModalWizardStep} from './ModalWizardStep';\nimport {Header} from '../header';\n\ninterface ModalWizardProps {\n /**\n * The label of the cancel button\n *\n * @default \"Cancel\"\n */\n cancelButtonLabel?: string;\n\n /**\n * The label of the next button\n *\n * @default \"Next\"\n */\n\n nextButtonLabel?: string;\n /**\n * The label of the previous button\n *\n * @default \"Previous\"\n */\n previousButtonLabel?: string;\n /**\n * The label of the finish button\n *\n * @default \"Finish\"\n */\n\n finishButtonLabel?: string;\n\n /**\n * A callback function that is executed when the user clicks on the next button\n */\n onNext?: () => unknown;\n\n /**\n * A callback function that is executed when the user clicks on the previous button\n */\n onPrevious?: () => unknown;\n\n /**\n * A callback function that is executed when the user clicks on the cancel button\n */\n\n onClose?: () => unknown;\n\n /**\n * A function that is executed when user completes all the steps.\n *\n * @param close A function that closes the modal when called.\n */\n onFinish?: () => unknown;\n\n /**\n * Determine if user interacted with any steps in the modal wizard\n */\n\n isDirty?: () => boolean;\n\n /**\n * A function to confirm close if the state is dirty before closing\n */\n handleDirtyState?: () => boolean;\n\n /**\n * Props to pass to each modal\n */\n modalProps?: any;\n\n /**\n * Label for close button\n */\n closeButtonLabel?: string;\n\n /**\n * Children to display in modal wizard\n * */\n children?: Array<ReturnType<typeof ModalWizardStep>>;\n}\n\nconst useStyles = createStyles(() => ({\n modal: {\n height: '70%',\n display: 'flex',\n flexDirection: 'column',\n },\n}));\n\ninterface ModalWizardType {\n <T>(props: ModalWizardProps): ReactElement;\n\n Step: typeof ModalWizardStep;\n}\n\nexport const ModalWizard: ModalWizardType = ({\n cancelButtonLabel = 'Cancel',\n nextButtonLabel = 'Next',\n previousButtonLabel = 'Previous',\n finishButtonLabel = 'Finish',\n onNext,\n onPrevious,\n onClose,\n onFinish,\n isDirty,\n modalProps,\n handleDirtyState,\n closeButtonLabel,\n children,\n}) => {\n const [currentStepIndex, setCurrentStepIndex] = useState(0);\n const modalSteps = (Children.toArray(children) as ReactElement[]).filter((child) => child.type === ModalWizardStep);\n\n const numberOfSteps = modalSteps.length;\n const numberOfStepsCountAsProgress = modalSteps.filter((step) => step.props.countsAsProgress).length;\n const isFirstStep = currentStepIndex === 0;\n const isLastStep = currentStepIndex === numberOfSteps - 1;\n const currentStep = modalSteps.filter((step: ReactElement, index: number) => index === currentStepIndex)[0];\n\n const {isValid} = currentStep?.props?.validateStep?.(currentStepIndex, numberOfSteps) ?? {isValid: true};\n const isModalDirty = isDirty && isDirty();\n\n const {classes} = useStyles();\n\n const closeModalWizard = () => {\n if (isModalDirty && handleDirtyState) {\n handleDirtyState() && onClose?.();\n } else {\n onClose?.();\n }\n };\n\n const getProgress = (currStepIndex: number) => {\n const validSteps = modalSteps.filter(\n (step, index) => step.props.countsAsProgress && index <= currStepIndex\n ).length;\n return (validSteps / numberOfStepsCountAsProgress) * 100;\n };\n\n const getProgressMemo = useMemo(() => getProgress(currentStepIndex), [currentStepIndex]);\n\n return (\n <Modal\n opened\n classNames={{modal: classes.modal}}\n centered\n closeButtonLabel={closeButtonLabel}\n padding=\"xl\"\n title={\n <Header\n docLink={currentStep.props.docLin}\n description={\n typeof currentStep.props.description === 'function'\n ? currentStep.props.description(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.description\n }\n py={null}\n px={null}\n >\n {typeof currentStep.props.title === 'function'\n ? currentStep.props.title(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.title}\n </Header>\n }\n onClose={closeModalWizard}\n {...modalProps}\n >\n {currentStep.props.showProgressBar && <Progress value={getProgressMemo} />}\n {currentStep}\n <StickyFooter borderTop py={null} px={null} pt=\"md\">\n <Button\n name={isFirstStep ? cancelButtonLabel : previousButtonLabel}\n disabled={false}\n size=\"md\"\n variant=\"outline\"\n onClick={() => {\n if (isFirstStep) {\n closeModalWizard();\n } else {\n onPrevious?.();\n setCurrentStepIndex(currentStepIndex - 1);\n }\n }}\n >\n {isFirstStep ? cancelButtonLabel : previousButtonLabel}\n </Button>\n\n <Button\n disabled={!isValid}\n size=\"md\"\n onClick={() => {\n if (isLastStep) {\n onFinish ? onFinish() : onClose();\n } else {\n onNext?.();\n setCurrentStepIndex(currentStepIndex + 1);\n }\n }}\n >\n {isLastStep ? finishButtonLabel : nextButtonLabel}\n </Button>\n </StickyFooter>\n </Modal>\n );\n};\n\nModalWizard.Step = ModalWizardStep;\n"],"names":["Button","createStyles","Modal","Progress","Children","useMemo","useState","StickyFooter","ModalWizardStep","Header","useStyles","modal","height","display","flexDirection","ModalWizard","cancelButtonLabel","nextButtonLabel","previousButtonLabel","finishButtonLabel","onNext","onPrevious","onClose","onFinish","isDirty","modalProps","handleDirtyState","closeButtonLabel","children","currentStep","currentStepIndex","setCurrentStepIndex","modalSteps","toArray","filter","child","type","numberOfSteps","length","numberOfStepsCountAsProgress","step","props","countsAsProgress","isFirstStep","isLastStep","index","isValid","validateStep","isModalDirty","classes","closeModalWizard","getProgress","currStepIndex","validSteps","getProgressMemo","opened","classNames","centered","padding","title","docLink","docLin","description","py","px","showProgressBar","value","borderTop","pt","name","disabled","size","variant","onClick","Step"],"mappings":"AAAA;;;;AAAA,SAAQA,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAEC,QAAQ,QAAO,eAAe,CAAC;AACpE,SAAQC,QAAQ,EAAgBC,OAAO,EAAEC,QAAQ,QAAO,OAAO,CAAC;AAChE,SAAQC,YAAY,QAAO,kBAAkB,CAAC;AAC9C,SAAQC,eAAe,QAAO,mBAAmB,CAAC;AAClD,SAAQC,MAAM,QAAO,WAAW,CAAC;AAiFjC,IAAMC,SAAS,GAAGT,YAAY,CAAC;WAAO;QAClCU,KAAK,EAAE;YACHC,MAAM,EAAE,KAAK;YACbC,OAAO,EAAE,MAAM;YACfC,aAAa,EAAE,QAAQ;SAC1B;KACJ;CAAC,CAAC,AAAC;AAQJ,OAAO,IAAMC,WAAW,GAAoB,gBActC;mCAbFC,iBAAiB,EAAjBA,iBAAiB,mCAAG,QAAQ,qBAAA,2BAC5BC,eAAe,EAAfA,eAAe,iCAAG,MAAM,mBAAA,+BACxBC,mBAAmB,EAAnBA,mBAAmB,qCAAG,UAAU,uBAAA,6BAChCC,iBAAiB,EAAjBA,iBAAiB,mCAAG,QAAQ,qBAAA,EAC5BC,MAAM,SAANA,MAAM,EACNC,UAAU,SAAVA,UAAU,EACVC,OAAO,SAAPA,OAAO,EACPC,QAAQ,SAARA,QAAQ,EACRC,OAAO,SAAPA,OAAO,EACPC,UAAU,SAAVA,UAAU,EACVC,gBAAgB,SAAhBA,gBAAgB,EAChBC,gBAAgB,SAAhBA,gBAAgB,EAChBC,QAAQ,SAARA,QAAQ;QAWUC,GAAkB;IATpC,IAAgDvB,IAAW,oBAAXA,QAAQ,CAAC,CAAC,CAAC,IAAA,EAApDwB,gBAAgB,GAAyBxB,IAAW,GAApC,EAAEyB,mBAAmB,GAAIzB,IAAW,GAAf,AAAgB;IAC5D,IAAM0B,UAAU,GAAG,AAAC5B,QAA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CAAC;wBACL,CAAC;kCAEAc,UAAU,GAAGzB,iBAAiB,GAAGF,eAAe;sBAC5C;;cACE;;OACX,CACV;AACN,CAAC,CAAC;AAEFF,WAAW,CAAC2D,IAAI,GAAGlE,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/modal-wizard/ModalWizard.tsx"],"sourcesContent":["import {Button, Modal, ModalProps, Progress} from '@mantine/core';\nimport {Children, ReactElement, useMemo, useState} from 'react';\nimport {StickyFooter} from '../sticky-footer';\nimport {ModalWizardStep} from './ModalWizardStep';\nimport {Header} from '../header';\n\ninterface ModalWizardProps extends Omit<ModalProps, 'centered' | 'title'> {\n /**\n * The label of the cancel button\n *\n * @default \"Cancel\"\n */\n cancelButtonLabel?: string;\n\n /**\n * The label of the next button\n *\n * @default \"Next\"\n */\n nextButtonLabel?: string;\n\n /**\n * The label of the previous button\n *\n * @default \"Previous\"\n */\n previousButtonLabel?: string;\n\n /**\n * The label of the finish button\n *\n * @default \"Finish\"\n */\n finishButtonLabel?: string;\n\n /**\n * A callback function that is executed when the user clicks on the next button\n */\n onNext?: () => unknown;\n\n /**\n * A callback function that is executed when the user clicks on the previous button\n */\n onPrevious?: () => unknown;\n\n /**\n * A function that is executed when user completes all the steps.\n *\n * @param close A function that closes the modal when called.\n */\n onFinish?: () => unknown;\n\n /**\n * Determine if user interacted with any steps in the modal wizard\n */\n isDirty?: () => boolean;\n\n /**\n * A function to confirm close if the state is dirty before closing\n */\n handleDirtyState?: () => boolean;\n\n /**\n * Children to display in modal wizard\n * */\n children?: Array<ReturnType<typeof ModalWizardStep>>;\n}\n\ninterface ModalWizardType {\n (props: ModalWizardProps): ReactElement;\n\n Step: typeof ModalWizardStep;\n}\n\nexport const ModalWizard: ModalWizardType = ({\n cancelButtonLabel = 'Cancel',\n nextButtonLabel = 'Next',\n previousButtonLabel = 'Previous',\n finishButtonLabel = 'Finish',\n opened,\n onNext,\n onPrevious,\n onClose,\n onFinish,\n isDirty,\n handleDirtyState,\n classNames,\n children,\n ...modalProps\n}) => {\n const [currentStepIndex, setCurrentStepIndex] = useState(0);\n const modalSteps = (Children.toArray(children) as ReactElement[]).filter((child) => child.type === ModalWizardStep);\n\n const numberOfSteps = modalSteps.length;\n const numberOfStepsCountAsProgress = modalSteps.filter((step) => step.props.countsAsProgress).length;\n const isFirstStep = currentStepIndex === 0;\n const isLastStep = currentStepIndex === numberOfSteps - 1;\n const currentStep = modalSteps.filter((step: ReactElement, index: number) => index === currentStepIndex)[0];\n\n const {isValid} = currentStep?.props?.validateStep?.(currentStepIndex, numberOfSteps) ?? {isValid: true};\n const isModalDirty = isDirty && isDirty();\n\n const closeModalWizard = () => {\n if (isModalDirty && handleDirtyState) {\n handleDirtyState() && onClose?.();\n } else {\n onClose?.();\n }\n };\n\n const getProgress = (currStepIndex: number) => {\n const validSteps = modalSteps.filter(\n (step, index) => step.props.countsAsProgress && index <= currStepIndex\n ).length;\n return (validSteps / numberOfStepsCountAsProgress) * 100;\n };\n\n const getProgressMemo = useMemo(() => getProgress(currentStepIndex), [currentStepIndex]);\n\n return (\n <Modal\n opened={opened}\n classNames={classNames}\n centered\n title={\n <Header\n docLink={currentStep.props.docLink}\n description={\n typeof currentStep.props.description === 'function'\n ? currentStep.props.description(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.description\n }\n py={null}\n px={null}\n >\n {typeof currentStep.props.title === 'function'\n ? currentStep.props.title(currentStepIndex + 1, numberOfSteps)\n : currentStep.props.title}\n </Header>\n }\n onClose={closeModalWizard}\n {...modalProps}\n >\n {currentStep.props.showProgressBar && <Progress color=\"teal\" size=\"lg\" value={getProgressMemo} />}\n {currentStep}\n <StickyFooter borderTop py={null} px={null} pt=\"md\">\n <Button\n name={isFirstStep ? cancelButtonLabel : previousButtonLabel}\n disabled={false}\n size=\"sm\"\n variant=\"outline\"\n onClick={() => {\n if (isFirstStep) {\n closeModalWizard();\n } else {\n onPrevious?.();\n setCurrentStepIndex(currentStepIndex - 1);\n }\n }}\n >\n {isFirstStep ? cancelButtonLabel : previousButtonLabel}\n </Button>\n\n <Button\n disabled={!isValid}\n size=\"sm\"\n onClick={() => {\n if (isLastStep) {\n onFinish ? onFinish() : onClose();\n } else {\n onNext?.();\n setCurrentStepIndex(currentStepIndex + 1);\n }\n }}\n >\n {isLastStep ? finishButtonLabel : nextButtonLabel}\n </Button>\n </StickyFooter>\n </Modal>\n );\n};\n\nModalWizard.Step = ModalWizardStep;\n"],"names":["Button","Modal","Progress","Children","useMemo","useState","StickyFooter","ModalWizardStep","Header","ModalWizard","cancelButtonLabel","nextButtonLabel","previousButtonLabel","finishButtonLabel","opened","onNext","onPrevious","onClose","onFinish","isDirty","handleDirtyState","classNames","children","modalProps","currentStep","currentStepIndex","setCurrentStepIndex","modalSteps","toArray","filter","child","type","numberOfSteps","length","numberOfStepsCountAsProgress","step","props","countsAsProgress","isFirstStep","isLastStep","index","isValid","validateStep","isModalDirty","closeModalWizard","getProgress","currStepIndex","validSteps","getProgressMemo","centered","title","docLink","description","py","px","showProgressBar","color","size","value","borderTop","pt","name","disabled","variant","onClick","Step"],"mappings":"AAAA;;;;;AAAA,SAAQA,MAAM,EAAEC,KAAK,EAAcC,QAAQ,QAAO,eAAe,CAAC;AAClE,SAAQC,QAAQ,EAAgBC,OAAO,EAAEC,QAAQ,QAAO,OAAO,CAAC;AAChE,SAAQC,YAAY,QAAO,kBAAkB,CAAC;AAC9C,SAAQC,eAAe,QAAO,mBAAmB,CAAC;AAClD,SAAQC,MAAM,QAAO,WAAW,CAAC;AAsEjC,OAAO,IAAMC,WAAW,GAAoB,iBAetC;oCAdFC,iBAAiB,EAAjBA,iBAAiB,mCAAG,QAAQ,qBAAA,4BAC5BC,eAAe,EAAfA,eAAe,iCAAG,MAAM,mBAAA,gCACxBC,mBAAmB,EAAnBA,mBAAmB,qCAAG,UAAU,uBAAA,8BAChCC,iBAAiB,EAAjBA,iBAAiB,mCAAG,QAAQ,qBAAA,EAC5BC,MAAM,UAANA,MAAM,EACNC,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mB,CAACD,gBAAgB,GAAG,CAAC,CAAC,CAAC;4BAC9C,CAAC;wBACL,CAAC;kCAEAa,WAAW,GAAG5B,iBAAiB,GAAGE,mBAAmB;sBACjD;kCAET,KAACZ,MAAM;wBACH8D,QAAQ,EAAE,CAACrB,OAAO;wBAClBgB,IAAI,EAAC,IAAI;wBACTO,OAAO,EAAE,WAAM;4BACX,IAAIzB,UAAU,EAAE;gCACZrB,QAAQ,GAAGA,QAAQ,EAAE,GAAGD,OAAO,EAAE,CAAC;4BACtC,OAAO;gCACHF,MAAM,aAANA,MAAM,WAAI,GAAVA,KAAAA,CAAU,GAAVA,MAAM,EAAI,CAAC;gCACXW,mBAAmB,CAACD,gBAAgB,GAAG,CAAC,CAAC,CAAC;4BAC9C,CAAC;wBACL,CAAC;kCAEAc,UAAU,GAAG1B,iBAAiB,GAAGF,eAAe;sBAC5C;;cACE;;OACX,CACV;AACN,CAAC,CAAC;AAEFF,WAAW,CAACwD,IAAI,GAAG1D,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {Button,
|
|
1
|
+
import {Button, Modal, ModalProps, Progress} from '@mantine/core';
|
|
2
2
|
import {Children, ReactElement, useMemo, useState} from 'react';
|
|
3
3
|
import {StickyFooter} from '../sticky-footer';
|
|
4
4
|
import {ModalWizardStep} from './ModalWizardStep';
|
|
5
5
|
import {Header} from '../header';
|
|
6
6
|
|
|
7
|
-
interface ModalWizardProps {
|
|
7
|
+
interface ModalWizardProps extends Omit<ModalProps, 'centered' | 'title'> {
|
|
8
8
|
/**
|
|
9
9
|
* The label of the cancel button
|
|
10
10
|
*
|
|
@@ -17,20 +17,20 @@ interface ModalWizardProps {
|
|
|
17
17
|
*
|
|
18
18
|
* @default "Next"
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
nextButtonLabel?: string;
|
|
21
|
+
|
|
22
22
|
/**
|
|
23
23
|
* The label of the previous button
|
|
24
24
|
*
|
|
25
25
|
* @default "Previous"
|
|
26
26
|
*/
|
|
27
27
|
previousButtonLabel?: string;
|
|
28
|
+
|
|
28
29
|
/**
|
|
29
30
|
* The label of the finish button
|
|
30
31
|
*
|
|
31
32
|
* @default "Finish"
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
34
|
finishButtonLabel?: string;
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -43,12 +43,6 @@ interface ModalWizardProps {
|
|
|
43
43
|
*/
|
|
44
44
|
onPrevious?: () => unknown;
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
* A callback function that is executed when the user clicks on the cancel button
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
onClose?: () => unknown;
|
|
51
|
-
|
|
52
46
|
/**
|
|
53
47
|
* A function that is executed when user completes all the steps.
|
|
54
48
|
*
|
|
@@ -59,7 +53,6 @@ interface ModalWizardProps {
|
|
|
59
53
|
/**
|
|
60
54
|
* Determine if user interacted with any steps in the modal wizard
|
|
61
55
|
*/
|
|
62
|
-
|
|
63
56
|
isDirty?: () => boolean;
|
|
64
57
|
|
|
65
58
|
/**
|
|
@@ -67,32 +60,14 @@ interface ModalWizardProps {
|
|
|
67
60
|
*/
|
|
68
61
|
handleDirtyState?: () => boolean;
|
|
69
62
|
|
|
70
|
-
/**
|
|
71
|
-
* Props to pass to each modal
|
|
72
|
-
*/
|
|
73
|
-
modalProps?: any;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Label for close button
|
|
77
|
-
*/
|
|
78
|
-
closeButtonLabel?: string;
|
|
79
|
-
|
|
80
63
|
/**
|
|
81
64
|
* Children to display in modal wizard
|
|
82
65
|
* */
|
|
83
66
|
children?: Array<ReturnType<typeof ModalWizardStep>>;
|
|
84
67
|
}
|
|
85
68
|
|
|
86
|
-
const useStyles = createStyles(() => ({
|
|
87
|
-
modal: {
|
|
88
|
-
height: '70%',
|
|
89
|
-
display: 'flex',
|
|
90
|
-
flexDirection: 'column',
|
|
91
|
-
},
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
69
|
interface ModalWizardType {
|
|
95
|
-
|
|
70
|
+
(props: ModalWizardProps): ReactElement;
|
|
96
71
|
|
|
97
72
|
Step: typeof ModalWizardStep;
|
|
98
73
|
}
|
|
@@ -102,15 +77,16 @@ export const ModalWizard: ModalWizardType = ({
|
|
|
102
77
|
nextButtonLabel = 'Next',
|
|
103
78
|
previousButtonLabel = 'Previous',
|
|
104
79
|
finishButtonLabel = 'Finish',
|
|
80
|
+
opened,
|
|
105
81
|
onNext,
|
|
106
82
|
onPrevious,
|
|
107
83
|
onClose,
|
|
108
84
|
onFinish,
|
|
109
85
|
isDirty,
|
|
110
|
-
modalProps,
|
|
111
86
|
handleDirtyState,
|
|
112
|
-
|
|
87
|
+
classNames,
|
|
113
88
|
children,
|
|
89
|
+
...modalProps
|
|
114
90
|
}) => {
|
|
115
91
|
const [currentStepIndex, setCurrentStepIndex] = useState(0);
|
|
116
92
|
const modalSteps = (Children.toArray(children) as ReactElement[]).filter((child) => child.type === ModalWizardStep);
|
|
@@ -124,8 +100,6 @@ export const ModalWizard: ModalWizardType = ({
|
|
|
124
100
|
const {isValid} = currentStep?.props?.validateStep?.(currentStepIndex, numberOfSteps) ?? {isValid: true};
|
|
125
101
|
const isModalDirty = isDirty && isDirty();
|
|
126
102
|
|
|
127
|
-
const {classes} = useStyles();
|
|
128
|
-
|
|
129
103
|
const closeModalWizard = () => {
|
|
130
104
|
if (isModalDirty && handleDirtyState) {
|
|
131
105
|
handleDirtyState() && onClose?.();
|
|
@@ -145,14 +119,12 @@ export const ModalWizard: ModalWizardType = ({
|
|
|
145
119
|
|
|
146
120
|
return (
|
|
147
121
|
<Modal
|
|
148
|
-
opened
|
|
149
|
-
classNames={
|
|
122
|
+
opened={opened}
|
|
123
|
+
classNames={classNames}
|
|
150
124
|
centered
|
|
151
|
-
closeButtonLabel={closeButtonLabel}
|
|
152
|
-
padding="xl"
|
|
153
125
|
title={
|
|
154
126
|
<Header
|
|
155
|
-
docLink={currentStep.props.
|
|
127
|
+
docLink={currentStep.props.docLink}
|
|
156
128
|
description={
|
|
157
129
|
typeof currentStep.props.description === 'function'
|
|
158
130
|
? currentStep.props.description(currentStepIndex + 1, numberOfSteps)
|
|
@@ -169,13 +141,13 @@ export const ModalWizard: ModalWizardType = ({
|
|
|
169
141
|
onClose={closeModalWizard}
|
|
170
142
|
{...modalProps}
|
|
171
143
|
>
|
|
172
|
-
{currentStep.props.showProgressBar && <Progress value={getProgressMemo} />}
|
|
144
|
+
{currentStep.props.showProgressBar && <Progress color="teal" size="lg" value={getProgressMemo} />}
|
|
173
145
|
{currentStep}
|
|
174
146
|
<StickyFooter borderTop py={null} px={null} pt="md">
|
|
175
147
|
<Button
|
|
176
148
|
name={isFirstStep ? cancelButtonLabel : previousButtonLabel}
|
|
177
149
|
disabled={false}
|
|
178
|
-
size="
|
|
150
|
+
size="sm"
|
|
179
151
|
variant="outline"
|
|
180
152
|
onClick={() => {
|
|
181
153
|
if (isFirstStep) {
|
|
@@ -191,7 +163,7 @@ export const ModalWizard: ModalWizardType = ({
|
|
|
191
163
|
|
|
192
164
|
<Button
|
|
193
165
|
disabled={!isValid}
|
|
194
|
-
size="
|
|
166
|
+
size="sm"
|
|
195
167
|
onClick={() => {
|
|
196
168
|
if (isLastStep) {
|
|
197
169
|
onFinish ? onFinish() : onClose();
|