@topconsultnpm/sdkui-react-beta 6.17.3 → 6.17.5
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/lib/assets/icomoon.svg +96 -96
- package/lib/assets/italy.svg +16 -16
- package/lib/assets/topmedia-six.svg +65 -65
- package/lib/assets/topmeida-six-bianco.svg +65 -65
- package/lib/components/features/archive/TMArchive.d.ts +4 -1
- package/lib/components/features/archive/TMArchive.js +7 -3
- package/lib/components/features/documents/TMDcmtForm.d.ts +4 -1
- package/lib/components/features/documents/TMDcmtForm.js +53 -3
- package/lib/components/features/search/TMSearch.d.ts +8 -1
- package/lib/components/features/search/TMSearch.js +6 -6
- package/lib/components/features/search/TMSearchQueryPanel.d.ts +8 -1
- package/lib/components/features/search/TMSearchQueryPanel.js +44 -3
- package/lib/components/features/search/TMSearchResult.d.ts +4 -1
- package/lib/components/features/search/TMSearchResult.js +3 -3
- package/lib/components/features/search/TMSearchResultsMenuItems.d.ts +5 -2
- package/lib/components/features/search/TMSearchResultsMenuItems.js +7 -2
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.js +3 -0
- package/lib/components/wizard/TMStepIndicator.d.ts +11 -0
- package/lib/components/wizard/TMStepIndicator.js +165 -0
- package/lib/components/wizard/TMWizard.d.ts +18 -0
- package/lib/components/wizard/TMWizard.js +93 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ValidationItem } from '@topconsultnpm/sdk-ts-beta';
|
|
3
|
+
export interface WizardStep {
|
|
4
|
+
title: string;
|
|
5
|
+
content: ReactNode;
|
|
6
|
+
validator?: (data: any) => ValidationItem[];
|
|
7
|
+
}
|
|
8
|
+
interface TMWizardProps {
|
|
9
|
+
steps: WizardStep[];
|
|
10
|
+
initialData: any;
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
validateOnlyCurrentStep?: boolean;
|
|
14
|
+
onClose: () => void;
|
|
15
|
+
onFinish: (data: any) => void;
|
|
16
|
+
}
|
|
17
|
+
declare const TMWizard: React.FC<TMWizardProps>;
|
|
18
|
+
export default TMWizard;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// TMWizard.tsx
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
import { ResultTypes } from '@topconsultnpm/sdk-ts-beta';
|
|
6
|
+
import TMButton from '../base/TMButton';
|
|
7
|
+
import StepIndicator from './TMStepIndicator';
|
|
8
|
+
const WizardContainer = styled.div `
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
height: 100%;
|
|
12
|
+
background-color: white;
|
|
13
|
+
padding: 8px;
|
|
14
|
+
`;
|
|
15
|
+
const WizardHeader = styled.div `
|
|
16
|
+
flex-shrink: 0;
|
|
17
|
+
padding: 0 20px 20px 20px;
|
|
18
|
+
`;
|
|
19
|
+
const WizardTitle = styled.h2 `
|
|
20
|
+
font-size: 1.3em;
|
|
21
|
+
font-weight: bold;
|
|
22
|
+
margin: 0;
|
|
23
|
+
color: #333;
|
|
24
|
+
`;
|
|
25
|
+
const WizardDescription = styled.p `
|
|
26
|
+
font-size: 1em;
|
|
27
|
+
margin-top: 5px;
|
|
28
|
+
color: #666;
|
|
29
|
+
`;
|
|
30
|
+
const StepContent = styled.div `
|
|
31
|
+
flex-grow: 1;
|
|
32
|
+
overflow-y: auto;
|
|
33
|
+
padding: 20px;
|
|
34
|
+
`;
|
|
35
|
+
const ControlsContainer = styled.div `
|
|
36
|
+
flex-shrink: 0;
|
|
37
|
+
display: flex;
|
|
38
|
+
justify-content: flex-end;
|
|
39
|
+
gap: 15px;
|
|
40
|
+
padding: 15px 20px;
|
|
41
|
+
border-top: 1px solid #eee;
|
|
42
|
+
`;
|
|
43
|
+
const TMWizard = ({ steps, validateOnlyCurrentStep = true, onClose, onFinish, initialData, title, description }) => {
|
|
44
|
+
const [currentStep, setCurrentStep] = useState(0);
|
|
45
|
+
const [formData, setFormData] = useState(initialData);
|
|
46
|
+
const stepValidationErrors = steps.map((step, index) => {
|
|
47
|
+
if (validateOnlyCurrentStep) {
|
|
48
|
+
if (index <= currentStep) {
|
|
49
|
+
const validator = step.validator;
|
|
50
|
+
return validator ? validator(formData) : [];
|
|
51
|
+
}
|
|
52
|
+
// Per gli step futuri, lo stato di validazione è un array vuoto (nessun errore visualizzato)
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const validator = step.validator;
|
|
57
|
+
// Se c'è un validatore, esegue e ritorna l'array di ValidationItem, altrimenti un array vuoto
|
|
58
|
+
return validator ? validator(formData) : [];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const currentStepValidationErrors = stepValidationErrors[currentStep];
|
|
62
|
+
const isStepValid = !currentStepValidationErrors.some(v => v.ResultType === ResultTypes.ERROR);
|
|
63
|
+
const handleNext = () => {
|
|
64
|
+
if (currentStep < steps.length - 1) {
|
|
65
|
+
setCurrentStep(currentStep + 1);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const handleBack = () => {
|
|
69
|
+
if (currentStep > 0) {
|
|
70
|
+
setCurrentStep(currentStep - 1);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const handleFinish = () => {
|
|
74
|
+
// Logica finale di validazione/salvataggio
|
|
75
|
+
onFinish(formData);
|
|
76
|
+
};
|
|
77
|
+
// Funzione per passare i dati dello step al componente figlio
|
|
78
|
+
const currentStepContent = steps[currentStep].content;
|
|
79
|
+
const isLastStep = currentStep === steps.length - 1;
|
|
80
|
+
// Funzione per passare l'oggetto di stato COMPLETO al componente figlio
|
|
81
|
+
const renderStep = () => {
|
|
82
|
+
if (React.isValidElement(currentStepContent)) {
|
|
83
|
+
return React.cloneElement(currentStepContent, {
|
|
84
|
+
stepData: formData,
|
|
85
|
+
onDataChange: setFormData,
|
|
86
|
+
validationErrors: currentStepValidationErrors,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return currentStepContent;
|
|
90
|
+
};
|
|
91
|
+
return (_jsxs(WizardContainer, { children: [_jsxs(WizardHeader, { children: [_jsx(WizardTitle, { children: title }), _jsx(WizardDescription, { children: description })] }), _jsx(StepIndicator, { steps: steps, currentStepIndex: currentStep, stepValidityStatuses: stepValidationErrors }), _jsx(StepContent, { children: renderStep() }), _jsxs(ControlsContainer, { children: [_jsx(TMButton, { caption: 'Annulla', showTooltip: false, onClick: onClose }), _jsx(TMButton, { caption: 'Indietro', showTooltip: false, onClick: handleBack, disabled: currentStep === 0 }), !isLastStep ? (_jsx(TMButton, { caption: 'Avanti', showTooltip: false, onClick: handleNext, disabled: !isStepValid })) : (_jsx(TMButton, { caption: 'Fine', showTooltip: false, onClick: handleFinish, disabled: !isStepValid, color: "primary" }))] })] }));
|
|
92
|
+
};
|
|
93
|
+
export default TMWizard;
|