@trackunit/react-form-wizard 0.1.4 → 0.1.6
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/index.cjs.js +37 -37
- package/index.esm.js +36 -36
- package/package.json +2 -2
- package/src/FormWizard/useFormWizard.d.ts +3 -1
- package/src/FormWizardFooter/FormWizardFooter.d.ts +1 -2
- package/src/FormWizardSidebarStep/FormWizardSidebarStep.d.ts +4 -2
- package/src/FormWizardStepWrapper/FormWizardStepWrapper.d.ts +3 -2
package/index.cjs.js
CHANGED
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
7
|
+
var reactRouter = require('@tanstack/react-router');
|
|
7
8
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
8
9
|
var react = require('react');
|
|
9
|
-
var reactRouterDom = require('react-router-dom');
|
|
10
10
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
11
11
|
var reactComponents = require('@trackunit/react-components');
|
|
12
12
|
var zod = require('@hookform/resolvers/zod');
|
|
@@ -154,9 +154,9 @@ const getStateIcon = (state) => {
|
|
|
154
154
|
* A sidebar step component used by the FormWizard component to render each step.
|
|
155
155
|
* This component is generally used internally by the FormWizard component.
|
|
156
156
|
*/
|
|
157
|
-
const FormWizardSidebarStep = ({ stepNumber, state, title, subTitle, path, dataTestId, onNavigate, isSubStep, }) => {
|
|
157
|
+
const FormWizardSidebarStep = ({ stepNumber, state, basePath, title, subTitle, path, dataTestId, onNavigate, isSubStep, }) => {
|
|
158
158
|
const stateIcon = getStateIcon(state);
|
|
159
|
-
return (jsxRuntime.jsx(
|
|
159
|
+
return (jsxRuntime.jsx(reactRouter.Link, { className: cvaFormWizardSidebarStep({ state, isSubStep }), "data-testid": dataTestId !== null && dataTestId !== void 0 ? dataTestId : `form-wizard-sidebar-step-${path}`, onClick: () => onNavigate(), params: { stepPath: path }, to: basePath, children: jsxRuntime.jsxs("div", { className: cvaSectionHeaderContainer(), children: [jsxRuntime.jsx("div", { children: stateIcon !== null && stateIcon !== void 0 ? stateIcon : jsxRuntime.jsx("span", { className: cvaStepNumber({ state, isSubStep }), children: stepNumber }) }), jsxRuntime.jsxs("div", { className: cvaTitleAndDescription(), children: [jsxRuntime.jsx("h1", { className: cvaHeader(), children: title }), subTitle ? jsxRuntime.jsx("p", { className: cvaSubtitle(), children: subTitle }) : null] })] }) }));
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
/******************************************************************************
|
|
@@ -200,9 +200,9 @@ const cvaNavigationContainer = cssClassVarianceUtilities.cvaMerge(["flex", "gap-
|
|
|
200
200
|
* The footer component for the FormWizard.
|
|
201
201
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
202
202
|
*/
|
|
203
|
-
const FormWizardFooter = ({ onBack, onCancel,
|
|
203
|
+
const FormWizardFooter = ({ onBack, onCancel, primaryActionLabel = "Next" }) => {
|
|
204
204
|
const [t] = useTranslation();
|
|
205
|
-
return (jsxRuntime.jsxs("div", { className: cvaFooterContainer(), children: [jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxRuntime.jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-next",
|
|
205
|
+
return (jsxRuntime.jsxs("div", { className: cvaFooterContainer(), children: [jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxRuntime.jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-next", type: "submit", children: primaryActionLabel ? primaryActionLabel : t("wizard.defaults.next") })] })] }));
|
|
206
206
|
};
|
|
207
207
|
|
|
208
208
|
const cvaFormWizardHeader = cssClassVarianceUtilities.cvaMerge([
|
|
@@ -229,7 +229,7 @@ const cvaFormWizardComponentStepForm = cssClassVarianceUtilities.cvaMerge(["grid
|
|
|
229
229
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
230
230
|
*/
|
|
231
231
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, formSchema, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, }) => {
|
|
232
|
-
const navigate =
|
|
232
|
+
const navigate = reactRouter.useNavigate();
|
|
233
233
|
const formRef = react.useRef(null);
|
|
234
234
|
const [submitHandlerInternal, setSubmitHandlerInternal] = react.useState(null);
|
|
235
235
|
const form = reactHookForm.useForm({
|
|
@@ -259,7 +259,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
259
259
|
const isLastStep = nextStepPath === null;
|
|
260
260
|
const handleCancel = react.useCallback(() => {
|
|
261
261
|
// TODO: Get previous path from before wizard the wizard was started
|
|
262
|
-
return onCancel ? onCancel() : navigate(basePath);
|
|
262
|
+
return onCancel ? onCancel() : navigate({ to: basePath, params: { stepPath: "" } });
|
|
263
263
|
}, [onCancel, navigate, basePath]);
|
|
264
264
|
const setSubmitHandler = react.useCallback(callback => {
|
|
265
265
|
setSubmitHandlerInternal(() => callback);
|
|
@@ -277,7 +277,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
277
277
|
submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(Object.assign(Object.assign({}, fullFormState), { [stepKey]: data }));
|
|
278
278
|
}
|
|
279
279
|
else if (nextStepPath) {
|
|
280
|
-
navigate(basePath
|
|
280
|
+
navigate({ to: basePath, params: { stepPath: nextStepPath } });
|
|
281
281
|
}
|
|
282
282
|
})), [
|
|
283
283
|
basePath,
|
|
@@ -296,10 +296,9 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
296
296
|
fullForm,
|
|
297
297
|
setSubmitHandler: isLastStep ? setSubmitHandler : null,
|
|
298
298
|
}) }), jsxRuntime.jsx(FormWizardFooter, { stepForms,
|
|
299
|
-
onBack: previousStepPath ? () => navigate(basePath
|
|
299
|
+
onBack: previousStepPath ? () => navigate({ to: basePath, params: { stepPath: previousStepPath } }) : null,
|
|
300
300
|
primaryActionLabel: isLastStep ? lastStepPrimaryActionLabel : undefined,
|
|
301
|
-
onCancel: handleCancel,
|
|
302
|
-
isValid: isEmptyStep ? true : form.formState.isValid })] }, String(stepKey)));
|
|
301
|
+
onCancel: handleCancel })] }, String(stepKey)));
|
|
303
302
|
};
|
|
304
303
|
|
|
305
304
|
const cvaFormWizardContainer = cssClassVarianceUtilities.cvaMerge(["h-full"]);
|
|
@@ -318,7 +317,7 @@ const cvaStepContainer = cssClassVarianceUtilities.cvaMerge(["h-full", "grid", "
|
|
|
318
317
|
*/
|
|
319
318
|
const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }) => {
|
|
320
319
|
var _a;
|
|
321
|
-
const
|
|
320
|
+
const { stepPath, subStepPath } = reactRouter.useParams({ from: basePath });
|
|
322
321
|
const [stepStates, setStepStates] = react.useState({});
|
|
323
322
|
const [stepForms, setStepForms] = react.useState({});
|
|
324
323
|
const [fullFormState, setFullFormState] = react.useState(
|
|
@@ -327,7 +326,7 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
|
|
|
327
326
|
// Any weakening of the type in a union would be worse and likely just push the issue forward until it hits react-hook-form
|
|
328
327
|
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
329
328
|
{});
|
|
330
|
-
const currentVisibleStepKey = (_a = sharedUtils.objectEntries(steps).find(([, { path }]) =>
|
|
329
|
+
const currentVisibleStepKey = (_a = sharedUtils.objectEntries(steps).find(([, { path }]) => subStepPath ? path === `${stepPath}/${subStepPath}` : path === stepPath)) === null || _a === void 0 ? void 0 : _a[0];
|
|
331
330
|
const currentVisibleStepIndex = sharedUtils.objectKeys(steps).findIndex(key => key === currentVisibleStepKey);
|
|
332
331
|
return (jsxRuntime.jsx("div", { className: cvaFormWizardContainer({ className }), "data-testid": dataTestId, children: jsxRuntime.jsxs("div", { className: cvaFormWizardLayout(), children: [jsxRuntime.jsx(FormWizardSidebar, { children: sharedUtils.objectEntries(steps)
|
|
333
332
|
.filter(([_, step]) => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })
|
|
@@ -367,32 +366,33 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
|
|
|
367
366
|
return (Object.assign(Object.assign({}, prev), { [previousStepKey]: (_a = stepForms[previousStepKey]) === null || _a === void 0 ? void 0 : _a.getValues() }));
|
|
368
367
|
});
|
|
369
368
|
},
|
|
370
|
-
|
|
369
|
+
basePath,
|
|
370
|
+
path: path,
|
|
371
371
|
subTitle: sidebarDescription,
|
|
372
372
|
isSubStep }));
|
|
373
|
-
}) }), jsxRuntime.jsx("div", { className: cvaStepContainer(), children:
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
373
|
+
}) }), jsxRuntime.jsx("div", { className: cvaStepContainer(), children: sharedUtils.objectEntries(steps)
|
|
374
|
+
.filter(([_, step]) => {
|
|
375
|
+
var _a, _b;
|
|
376
|
+
return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true;
|
|
377
|
+
})
|
|
378
|
+
.map(([stepKey, props], index) => {
|
|
379
|
+
var _a, _b, _c, _d;
|
|
380
|
+
return (subStepPath ? props.path === `${stepPath}/${subStepPath}` : props.path === stepPath) ? (jsxRuntime.jsx(FormWizardStepWrapper, Object.assign({}, props, {
|
|
381
|
+
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
382
|
+
formSchema: props.formSchema,
|
|
383
|
+
basePath,
|
|
384
|
+
stepKey: stepKey.toString(),
|
|
385
|
+
stepForms,
|
|
386
|
+
setStepForms,
|
|
387
|
+
onCancel,
|
|
388
|
+
fullFormState,
|
|
389
|
+
setFullFormState,
|
|
390
|
+
setStepStates,
|
|
391
|
+
fullFormSchema,
|
|
392
|
+
lastStepPrimaryActionLabel,
|
|
393
|
+
nextStepPath: (_b = (_a = sharedUtils.objectValues(steps).filter(step => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })[index + 1]) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : null,
|
|
394
|
+
previousStepPath: (_d = (_c = sharedUtils.objectValues(steps).filter(step => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })[index - 1]) === null || _c === void 0 ? void 0 : _c.path) !== null && _d !== void 0 ? _d : null }), stepKey.toString())) : null;
|
|
395
|
+
}) })] }) }));
|
|
396
396
|
};
|
|
397
397
|
|
|
398
398
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
|
+
import { Link, useNavigate, useParams } from '@tanstack/react-router';
|
|
3
4
|
import { objectKeys, objectEntries, objectValues, objectFromEntries } from '@trackunit/shared-utils';
|
|
4
5
|
import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
5
|
-
import { NavLink, useNavigate, useLocation, Routes, Route } from 'react-router-dom';
|
|
6
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
7
7
|
import { Icon, Button, Heading } from '@trackunit/react-components';
|
|
8
8
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
@@ -150,9 +150,9 @@ const getStateIcon = (state) => {
|
|
|
150
150
|
* A sidebar step component used by the FormWizard component to render each step.
|
|
151
151
|
* This component is generally used internally by the FormWizard component.
|
|
152
152
|
*/
|
|
153
|
-
const FormWizardSidebarStep = ({ stepNumber, state, title, subTitle, path, dataTestId, onNavigate, isSubStep, }) => {
|
|
153
|
+
const FormWizardSidebarStep = ({ stepNumber, state, basePath, title, subTitle, path, dataTestId, onNavigate, isSubStep, }) => {
|
|
154
154
|
const stateIcon = getStateIcon(state);
|
|
155
|
-
return (jsx(
|
|
155
|
+
return (jsx(Link, { className: cvaFormWizardSidebarStep({ state, isSubStep }), "data-testid": dataTestId !== null && dataTestId !== void 0 ? dataTestId : `form-wizard-sidebar-step-${path}`, onClick: () => onNavigate(), params: { stepPath: path }, to: basePath, children: jsxs("div", { className: cvaSectionHeaderContainer(), children: [jsx("div", { children: stateIcon !== null && stateIcon !== void 0 ? stateIcon : jsx("span", { className: cvaStepNumber({ state, isSubStep }), children: stepNumber }) }), jsxs("div", { className: cvaTitleAndDescription(), children: [jsx("h1", { className: cvaHeader(), children: title }), subTitle ? jsx("p", { className: cvaSubtitle(), children: subTitle }) : null] })] }) }));
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
/******************************************************************************
|
|
@@ -196,9 +196,9 @@ const cvaNavigationContainer = cvaMerge(["flex", "gap-responsive-space"]);
|
|
|
196
196
|
* The footer component for the FormWizard.
|
|
197
197
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
198
198
|
*/
|
|
199
|
-
const FormWizardFooter = ({ onBack, onCancel,
|
|
199
|
+
const FormWizardFooter = ({ onBack, onCancel, primaryActionLabel = "Next" }) => {
|
|
200
200
|
const [t] = useTranslation();
|
|
201
|
-
return (jsxs("div", { className: cvaFooterContainer(), children: [jsx(Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsx(Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsx(Button, { dataTestId: "wizard-next",
|
|
201
|
+
return (jsxs("div", { className: cvaFooterContainer(), children: [jsx(Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsx(Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsx(Button, { dataTestId: "wizard-next", type: "submit", children: primaryActionLabel ? primaryActionLabel : t("wizard.defaults.next") })] })] }));
|
|
202
202
|
};
|
|
203
203
|
|
|
204
204
|
const cvaFormWizardHeader = cvaMerge([
|
|
@@ -255,7 +255,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
255
255
|
const isLastStep = nextStepPath === null;
|
|
256
256
|
const handleCancel = useCallback(() => {
|
|
257
257
|
// TODO: Get previous path from before wizard the wizard was started
|
|
258
|
-
return onCancel ? onCancel() : navigate(basePath);
|
|
258
|
+
return onCancel ? onCancel() : navigate({ to: basePath, params: { stepPath: "" } });
|
|
259
259
|
}, [onCancel, navigate, basePath]);
|
|
260
260
|
const setSubmitHandler = useCallback(callback => {
|
|
261
261
|
setSubmitHandlerInternal(() => callback);
|
|
@@ -273,7 +273,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
273
273
|
submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(Object.assign(Object.assign({}, fullFormState), { [stepKey]: data }));
|
|
274
274
|
}
|
|
275
275
|
else if (nextStepPath) {
|
|
276
|
-
navigate(basePath
|
|
276
|
+
navigate({ to: basePath, params: { stepPath: nextStepPath } });
|
|
277
277
|
}
|
|
278
278
|
})), [
|
|
279
279
|
basePath,
|
|
@@ -292,10 +292,9 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
292
292
|
fullForm,
|
|
293
293
|
setSubmitHandler: isLastStep ? setSubmitHandler : null,
|
|
294
294
|
}) }), jsx(FormWizardFooter, { stepForms,
|
|
295
|
-
onBack: previousStepPath ? () => navigate(basePath
|
|
295
|
+
onBack: previousStepPath ? () => navigate({ to: basePath, params: { stepPath: previousStepPath } }) : null,
|
|
296
296
|
primaryActionLabel: isLastStep ? lastStepPrimaryActionLabel : undefined,
|
|
297
|
-
onCancel: handleCancel,
|
|
298
|
-
isValid: isEmptyStep ? true : form.formState.isValid })] }, String(stepKey)));
|
|
297
|
+
onCancel: handleCancel })] }, String(stepKey)));
|
|
299
298
|
};
|
|
300
299
|
|
|
301
300
|
const cvaFormWizardContainer = cvaMerge(["h-full"]);
|
|
@@ -314,7 +313,7 @@ const cvaStepContainer = cvaMerge(["h-full", "grid", "bg-white", "overflow-hidde
|
|
|
314
313
|
*/
|
|
315
314
|
const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }) => {
|
|
316
315
|
var _a;
|
|
317
|
-
const
|
|
316
|
+
const { stepPath, subStepPath } = useParams({ from: basePath });
|
|
318
317
|
const [stepStates, setStepStates] = useState({});
|
|
319
318
|
const [stepForms, setStepForms] = useState({});
|
|
320
319
|
const [fullFormState, setFullFormState] = useState(
|
|
@@ -323,7 +322,7 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
|
|
|
323
322
|
// Any weakening of the type in a union would be worse and likely just push the issue forward until it hits react-hook-form
|
|
324
323
|
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
325
324
|
{});
|
|
326
|
-
const currentVisibleStepKey = (_a = objectEntries(steps).find(([, { path }]) =>
|
|
325
|
+
const currentVisibleStepKey = (_a = objectEntries(steps).find(([, { path }]) => subStepPath ? path === `${stepPath}/${subStepPath}` : path === stepPath)) === null || _a === void 0 ? void 0 : _a[0];
|
|
327
326
|
const currentVisibleStepIndex = objectKeys(steps).findIndex(key => key === currentVisibleStepKey);
|
|
328
327
|
return (jsx("div", { className: cvaFormWizardContainer({ className }), "data-testid": dataTestId, children: jsxs("div", { className: cvaFormWizardLayout(), children: [jsx(FormWizardSidebar, { children: objectEntries(steps)
|
|
329
328
|
.filter(([_, step]) => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })
|
|
@@ -363,32 +362,33 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
|
|
|
363
362
|
return (Object.assign(Object.assign({}, prev), { [previousStepKey]: (_a = stepForms[previousStepKey]) === null || _a === void 0 ? void 0 : _a.getValues() }));
|
|
364
363
|
});
|
|
365
364
|
},
|
|
366
|
-
|
|
365
|
+
basePath,
|
|
366
|
+
path: path,
|
|
367
367
|
subTitle: sidebarDescription,
|
|
368
368
|
isSubStep }));
|
|
369
|
-
}) }), jsx("div", { className: cvaStepContainer(), children:
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
369
|
+
}) }), jsx("div", { className: cvaStepContainer(), children: objectEntries(steps)
|
|
370
|
+
.filter(([_, step]) => {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true;
|
|
373
|
+
})
|
|
374
|
+
.map(([stepKey, props], index) => {
|
|
375
|
+
var _a, _b, _c, _d;
|
|
376
|
+
return (subStepPath ? props.path === `${stepPath}/${subStepPath}` : props.path === stepPath) ? (jsx(FormWizardStepWrapper, Object.assign({}, props, {
|
|
377
|
+
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
378
|
+
formSchema: props.formSchema,
|
|
379
|
+
basePath,
|
|
380
|
+
stepKey: stepKey.toString(),
|
|
381
|
+
stepForms,
|
|
382
|
+
setStepForms,
|
|
383
|
+
onCancel,
|
|
384
|
+
fullFormState,
|
|
385
|
+
setFullFormState,
|
|
386
|
+
setStepStates,
|
|
387
|
+
fullFormSchema,
|
|
388
|
+
lastStepPrimaryActionLabel,
|
|
389
|
+
nextStepPath: (_b = (_a = objectValues(steps).filter(step => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })[index + 1]) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : null,
|
|
390
|
+
previousStepPath: (_d = (_c = objectValues(steps).filter(step => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })[index - 1]) === null || _c === void 0 ? void 0 : _c.path) !== null && _d !== void 0 ? _d : null }), stepKey.toString())) : null;
|
|
391
|
+
}) })] }) }));
|
|
392
392
|
};
|
|
393
393
|
|
|
394
394
|
/**
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-wizard",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"react": "^18.2.0",
|
|
8
|
-
"react-router-dom": "6.18.0",
|
|
9
8
|
"zod": "3.22.4",
|
|
10
9
|
"@trackunit/css-class-variance-utilities": "*",
|
|
11
10
|
"@trackunit/react-components": "*",
|
|
12
11
|
"@hookform/resolvers": "^3.3.4",
|
|
13
12
|
"react-hook-form": "7.40.0",
|
|
14
13
|
"@trackunit/i18n-library-translation": "*",
|
|
14
|
+
"@tanstack/react-router": "1.19.1",
|
|
15
15
|
"@trackunit/shared-utils": "*"
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RegisteredRouter, RouteIds } from "@tanstack/react-router";
|
|
1
2
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
3
|
import { ReactNode } from "react";
|
|
3
4
|
import { UseFormReturn } from "react-hook-form";
|
|
@@ -32,11 +33,12 @@ interface DefinedComponentStep<TStepSchema extends TFullSchemaValue[keyof TFullS
|
|
|
32
33
|
export interface FromWizardComponentProps<TFullSchema extends AnyZodObject, TComponentStepDefinitions extends ComponentStepDefinitions<TFullSchema>> extends Omit<UseFormWizardProps<TFullSchema, TComponentStepDefinitions>, "steps">, CommonProps {
|
|
33
34
|
steps: TComponentStepDefinitions;
|
|
34
35
|
}
|
|
36
|
+
export type StringWithStepKey<TPath> = TPath extends `${infer Prefix}/$stepPath` ? TPath : never;
|
|
35
37
|
export interface UseFormWizardProps<TFullSchema extends SomeZodObject, TStepDefinitions extends StepDefinitions<TFullSchema>> {
|
|
36
38
|
fullFormSchema: TFullSchema;
|
|
37
39
|
lastStepPrimaryActionLabel: string;
|
|
38
40
|
onCancel?: () => void;
|
|
39
|
-
basePath:
|
|
41
|
+
basePath: StringWithStepKey<`${RouteIds<RegisteredRouter["routeTree"]>}`>;
|
|
40
42
|
steps: TStepDefinitions;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { CommonProps } from "@trackunit/react-components";
|
|
3
3
|
interface FormWizardFooterProps extends CommonProps {
|
|
4
4
|
primaryActionLabel?: string;
|
|
5
|
-
isValid?: boolean;
|
|
6
5
|
onCancel: () => void;
|
|
7
6
|
onBack: (() => void) | null;
|
|
8
7
|
}
|
|
@@ -10,5 +9,5 @@ interface FormWizardFooterProps extends CommonProps {
|
|
|
10
9
|
* The footer component for the FormWizard.
|
|
11
10
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
12
11
|
*/
|
|
13
|
-
export declare const FormWizardFooter: ({ onBack, onCancel,
|
|
12
|
+
export declare const FormWizardFooter: ({ onBack, onCancel, primaryActionLabel }: FormWizardFooterProps) => JSX.Element;
|
|
14
13
|
export {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { RegisteredRouter, RouteIds } from "@tanstack/react-router";
|
|
2
3
|
import { CommonProps } from "@trackunit/react-components";
|
|
3
|
-
import { StepState } from "../FormWizard/useFormWizard";
|
|
4
|
+
import { StepState, StringWithStepKey } from "../FormWizard/useFormWizard";
|
|
4
5
|
interface FormWizardSidebarStepProps extends CommonProps {
|
|
5
6
|
state: StepState;
|
|
6
7
|
stepNumber?: number;
|
|
7
8
|
title: string;
|
|
9
|
+
basePath: StringWithStepKey<`${RouteIds<RegisteredRouter["routeTree"]>}`>;
|
|
8
10
|
subTitle?: string;
|
|
9
11
|
path: string;
|
|
10
12
|
onNavigate: () => void;
|
|
@@ -14,5 +16,5 @@ interface FormWizardSidebarStepProps extends CommonProps {
|
|
|
14
16
|
* A sidebar step component used by the FormWizard component to render each step.
|
|
15
17
|
* This component is generally used internally by the FormWizard component.
|
|
16
18
|
*/
|
|
17
|
-
export declare const FormWizardSidebarStep: ({ stepNumber, state, title, subTitle, path, dataTestId, onNavigate, isSubStep, }: FormWizardSidebarStepProps) => JSX.Element;
|
|
19
|
+
export declare const FormWizardSidebarStep: ({ stepNumber, state, basePath, title, subTitle, path, dataTestId, onNavigate, isSubStep, }: FormWizardSidebarStepProps) => JSX.Element;
|
|
18
20
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { RegisteredRouter, RoutePaths } from "@tanstack/react-router";
|
|
1
2
|
import { Dispatch, ReactNode, SetStateAction } from "react";
|
|
2
3
|
import { DeepPartial, UseFormReturn } from "react-hook-form";
|
|
3
4
|
import { AnyZodObject, z } from "zod";
|
|
4
5
|
import { FormWizardStepFormReturnMap } from "../FormWizard/FormWizard";
|
|
5
|
-
import { ComponentStepDefinitions, SimpleStepProps, StepComponentPropsInner } from "../FormWizard/useFormWizard";
|
|
6
|
+
import { ComponentStepDefinitions, SimpleStepProps, StepComponentPropsInner, StringWithStepKey } from "../FormWizard/useFormWizard";
|
|
6
7
|
export type StepFormValidity = "valid" | "invalid";
|
|
7
8
|
export interface FormWizardStepWrapperProps<TStepKey extends keyof z.TypeOf<TFullSchema>, TFullSchema extends AnyZodObject> extends SimpleStepProps {
|
|
8
9
|
description: string | ReactNode;
|
|
9
10
|
lastStepPrimaryActionLabel: string;
|
|
10
11
|
nextStepPath: string | null;
|
|
11
|
-
basePath:
|
|
12
|
+
basePath: StringWithStepKey<`${RoutePaths<RegisteredRouter["routeTree"]>}`>;
|
|
12
13
|
previousStepPath: string | null;
|
|
13
14
|
onCancel?: () => void;
|
|
14
15
|
fullFormSchema: TFullSchema;
|