@arquimedes.co/eureka-forms 2.0.23 → 2.0.24-test

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.
Files changed (47) hide show
  1. package/dist/App/App.d.ts +2 -0
  2. package/dist/App/App.js +1 -1
  3. package/dist/App/AppFunctions.js +2 -3
  4. package/dist/Form/Form.d.ts +3 -1
  5. package/dist/Form/Form.js +2 -2
  6. package/dist/Form/FormFunctions.js +1 -0
  7. package/dist/Form/FormTypes/StepperForm/StepperForm.d.ts +1 -1
  8. package/dist/Form/FormTypes/StepperForm/StepperForm.js +3 -1
  9. package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/MaterialCBRIncidentsStep.js +1 -0
  10. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +1 -0
  11. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +2 -0
  12. package/dist/FormSteps/CustomStep.js +1 -1
  13. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +1 -0
  14. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.d.ts +8 -4
  15. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.js +51 -79
  16. package/dist/FormSteps/RatingStep/MaterialRatingStep/MaterialRatingStep.js +2 -0
  17. package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.js +2 -0
  18. package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js +1 -1
  19. package/dist/FormSteps/StepHooks.d.ts +2 -2
  20. package/dist/FormSteps/StepHooks.js +5 -5
  21. package/dist/FormSteps/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaEditorStep.js +2 -1
  22. package/dist/FormSteps/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaStep.js +1 -0
  23. package/dist/FormSteps/TextInputStep/MaterialTextInputStep/MaterialTextInputStep.js +1 -1
  24. package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.js +4 -2
  25. package/dist/Shared/Navbar/Navbar.stories.d.ts +13 -0
  26. package/dist/Shared/Navbar/Navbar.stories.js +13 -0
  27. package/dist/Shared/Rating/Rating.stories.d.ts +15 -0
  28. package/dist/Shared/Rating/Rating.stories.js +59 -0
  29. package/dist/Shared/RoundedButton/RoundedButton.stories.d.ts +23 -0
  30. package/dist/Shared/RoundedButton/RoundedButton.stories.js +36 -0
  31. package/dist/Shared/RoundedCheckBox/RoundedCheckBox.stories.d.ts +21 -0
  32. package/dist/Shared/RoundedCheckBox/RoundedCheckBox.stories.js +50 -0
  33. package/dist/Shared/RoundedDatePicker/RoundedDatePicker.d.ts +3 -2
  34. package/dist/Shared/RoundedDatePicker/RoundedDatePicker.js +3 -3
  35. package/dist/Shared/RoundedDatePicker/RoundedDatePicker.stories.d.ts +36 -0
  36. package/dist/Shared/RoundedDatePicker/RoundedDatePicker.stories.js +223 -0
  37. package/dist/Shared/RoundedSelect/RoundedSelect.stories.d.ts +28 -0
  38. package/dist/Shared/RoundedSelect/RoundedSelect.stories.js +91 -0
  39. package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.d.ts +0 -2
  40. package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.js +3 -3
  41. package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.stories.d.ts +36 -0
  42. package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.stories.js +318 -0
  43. package/dist/Shared/RoundedTextField/RoundedTextField.js +2 -2
  44. package/dist/Shared/RoundedTextField/RoundedTextField.stories.d.ts +13 -0
  45. package/dist/Shared/RoundedTextField/RoundedTextField.stories.js +200 -1
  46. package/dist/index.js +5 -1
  47. package/package.json +4 -1
package/dist/App/App.d.ts CHANGED
@@ -39,6 +39,8 @@ export interface AppProps {
39
39
  fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
40
40
  /** Function to call after the confimation dialog has been closed */
41
41
  handleConfirmed?: () => void;
42
+ /** Function called to scroll to the top */
43
+ scrollToTop?: () => void;
42
44
  }
43
45
  export declare const IdFormContext: React.Context<string>;
44
46
  declare function AppComponent({ formData, valuesData, ...props }: AppProps): JSX.Element;
package/dist/App/App.js CHANGED
@@ -74,6 +74,6 @@ function App(_a) {
74
74
  sendLabel: props.sendLabel,
75
75
  fetchDownloadUrl: props.fetchDownloadUrl,
76
76
  customStepProps: (_g = props.customStepProps) !== null && _g !== void 0 ? _g : {},
77
- } }, { children: _jsx("div", __assign({ className: styles.container }, { children: _jsx(FormComponent, { form: form, reload: reload, branding: branding, apiKey: props.apiKey, isWidget: !!isWidget, customSteps: customSteps, containerRef: containerRef, customSubmit: props.customSubmit, customSubmitBtns: props.customSubmitBtns }) })) })));
77
+ } }, { children: _jsx("div", __assign({ className: styles.container }, { children: _jsx(FormComponent, { form: form, reload: reload, branding: branding, apiKey: props.apiKey, isWidget: !!isWidget, customSteps: customSteps, containerRef: containerRef, customSubmit: props.customSubmit, scrollToTop: props.scrollToTop, customSubmitBtns: props.customSubmitBtns }) })) })));
78
78
  }
79
79
  }
@@ -173,10 +173,9 @@ export var mapOriginalValue = function (step, value, values, form) {
173
173
  }
174
174
  case StepTypes.CLASSIFIER_SELECTOR: {
175
175
  var stepClassifier = (_d = form === null || form === void 0 ? void 0 : form.classifiers) === null || _d === void 0 ? void 0 : _d[(_e = step.idClassifier) !== null && _e !== void 0 ? _e : ''];
176
- if (stepClassifier) {
176
+ if (stepClassifier && !value.value) {
177
177
  var classifier = (_f = form.classifiers) === null || _f === void 0 ? void 0 : _f[value];
178
- if (!(value === null || value === void 0 ? void 0 : value.value))
179
- return { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name };
178
+ return { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name };
180
179
  }
181
180
  break;
182
181
  }
@@ -29,10 +29,12 @@ export interface BaseFormProps extends CustomAppProps {
29
29
  apiKey: string | undefined;
30
30
  customSubmit: AppProps['customSubmit'];
31
31
  containerRef: React.RefObject<HTMLDivElement>;
32
+ scrollToTop?: () => void;
32
33
  }
33
34
  export interface FormComponentProps extends CustomAppProps {
34
35
  /** Function called when users clicks submit */
35
36
  onSubmit: (values: FieldValues) => Promise<any>;
37
+ scrollToTop?: () => void;
36
38
  }
37
- declare function FormComponent({ form, apiKey, reload, isWidget, branding, customSteps, containerRef, customSubmit, customSubmitBtns, }: BaseFormProps): JSX.Element;
39
+ declare function FormComponent({ form, apiKey, reload, isWidget, branding, scrollToTop, customSteps, containerRef, customSubmit, customSubmitBtns, }: BaseFormProps): JSX.Element;
38
40
  export default FormComponent;
package/dist/Form/Form.js CHANGED
@@ -84,7 +84,7 @@ export var getLocale = function () {
84
84
  function FormComponent(_a) {
85
85
  var _this = this;
86
86
  var _b, _c, _d, _e, _f, _g, _h, _j, _k;
87
- var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, isWidget = _a.isWidget, branding = _a.branding, customSteps = _a.customSteps, containerRef = _a.containerRef, customSubmit = _a.customSubmit, customSubmitBtns = _a.customSubmitBtns;
87
+ var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, isWidget = _a.isWidget, branding = _a.branding, scrollToTop = _a.scrollToTop, customSteps = _a.customSteps, containerRef = _a.containerRef, customSubmit = _a.customSubmit, customSubmitBtns = _a.customSubmitBtns;
88
88
  var _l = useAppSelector(function (state) { return state.global; }), idOrganization = _l.idOrganization, internal = _l.internal, postview = _l.postview;
89
89
  var formMethods = useForm({
90
90
  mode: 'onTouched',
@@ -168,7 +168,7 @@ function FormComponent(_a) {
168
168
  return (_jsxs(React.Fragment, { children: [showConfirmation !== undefined && (_jsx(ConfirmationDialog, { confirmation: showConfirmation, onClose: function () {
169
169
  reload();
170
170
  setShowConfirmation(undefined);
171
- } })), form.hasCaptcha && !internal && (_jsx(ReCAPTCHA, { ref: recaptchaRef, sitekey: "6LcL22kkAAAAAEotDeAFbRATob-u5vbibbCyWL2p", size: 'invisible', badge: 'bottomright' })), _jsx(FormProvider, __assign({}, formMethods, { children: _jsx(FormContext.Provider, __assign({ value: form }, { children: _jsx(FormTypeComponent, { onSubmit: onSubmit, customSubmitBtns: customSubmitBtns }) })) }))] }));
171
+ } })), form.hasCaptcha && !internal && (_jsx(ReCAPTCHA, { ref: recaptchaRef, sitekey: "6LcL22kkAAAAAEotDeAFbRATob-u5vbibbCyWL2p", size: 'invisible', badge: 'bottomright' })), _jsx(FormProvider, __assign({}, formMethods, { children: _jsx(FormContext.Provider, __assign({ value: form }, { children: _jsx(FormTypeComponent, { onSubmit: onSubmit, scrollToTop: scrollToTop, customSubmitBtns: customSubmitBtns }) })) }))] }));
172
172
  };
173
173
  if (!idOrganization)
174
174
  return _jsx(_Fragment, {});
@@ -88,6 +88,7 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
88
88
  return mappedValues;
89
89
  }
90
90
  case StepTypes.TITLE:
91
+ deleteIds.push(idStep);
91
92
  return;
92
93
  default:
93
94
  if ((step === null || step === void 0 ? void 0 : step.type) === 'CBR_INCIDENCIAS') {
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { FormComponentProps } from '../../Form';
3
- declare function StepperForm({ onSubmit }: FormComponentProps): JSX.Element;
3
+ declare function StepperForm({ onSubmit, scrollToTop, }: FormComponentProps): JSX.Element;
4
4
  export default StepperForm;
@@ -59,7 +59,7 @@ import { getAppState } from '../../../Utils/store';
59
59
  import { IdFormContext } from '../../../App/App';
60
60
  function StepperForm(_a) {
61
61
  var _this = this;
62
- var onSubmit = _a.onSubmit;
62
+ var onSubmit = _a.onSubmit, scrollToTop = _a.scrollToTop;
63
63
  var _b = useState(undefined), loading = _b[0], setLoading = _b[1];
64
64
  var _c = useAppSelector(function (state) { return state.global; }), postview = _c.postview, editable = _c.editable, formStyle = _c.formStyle;
65
65
  var _d = useFormContext(), trigger = _d.trigger, getValues = _d.getValues, handleSubmit = _d.handleSubmit;
@@ -75,6 +75,7 @@ function StepperForm(_a) {
75
75
  });
76
76
  var handlePrevious = useCallback(function () {
77
77
  dispatch(SiteReducer.handlePrevious(getValues()));
78
+ scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
78
79
  }, []);
79
80
  var handleNext = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
80
81
  var valid, state, values, response;
@@ -92,6 +93,7 @@ function StepperForm(_a) {
92
93
  }
93
94
  if (next.length > 0) {
94
95
  dispatch(SiteReducer.handleNext(getValues()));
96
+ scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
95
97
  return [2 /*return*/, setLoading(undefined)];
96
98
  }
97
99
  return [4 /*yield*/, dispatch(getAppState({ idForm: idForm })).unwrap()];
@@ -45,6 +45,7 @@ import { useFormStep } from '../../../StepHooks';
45
45
  function CBRIncidentsStep(_a) {
46
46
  var step = _a.step, editable = _a.editable, others = __rest(_a, ["step", "editable"]);
47
47
  var _b = useFormStep(step, {
48
+ defaultValue: [],
48
49
  rules: {
49
50
  validate: function (array) {
50
51
  return !step.required ||
@@ -22,6 +22,7 @@ import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialI
22
22
  function CheckBoxStep(_a) {
23
23
  var step = _a.step, editable = _a.editable;
24
24
  var _b = useFormStep(step, {
25
+ defaultValue: false,
25
26
  rules: {
26
27
  required: step.required ? 'Este campo es obligatorio' : undefined,
27
28
  },
@@ -19,10 +19,12 @@ import { useAppSelector } from '../../../hooks';
19
19
  import { useFormStep } from '../../StepHooks';
20
20
  import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
21
21
  import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
22
+ import { calcDefaultValue } from '../../StepFunctions';
22
23
  function ClassifierSelectorStep(_a) {
23
24
  var _b, _c, _d, _e;
24
25
  var step = _a.step, editable = _a.editable;
25
26
  var _f = useFormStep(step, {
27
+ defaultValue: calcDefaultValue(step),
26
28
  sizeChange: true,
27
29
  rules: {
28
30
  required: step.required ? 'Este campo es obligatorio' : undefined,
@@ -33,7 +33,7 @@ function CustomStepComponent(_a) {
33
33
  var customStepProps = useContext(CustomStepPropsContext).customStepProps;
34
34
  var dependencyStore = useAppSelector(function (state) { return state.site.dependencies; });
35
35
  var widthStats = useAppSelector(function (state) { return state.widthStats; });
36
- var dependencyInfo = useStepDependency(props.step);
36
+ var dependencyInfo = useStepDependency(props.step, undefined);
37
37
  return customStep.component(__assign(__assign(__assign(__assign(__assign({}, global), dependencyInfo), props), { dependencyStore: dependencyStore, widthStats: widthStats, form: form, customStepProps: customStepProps }), ((_b = customStep.componentProps) !== null && _b !== void 0 ? _b : {})));
38
38
  }
39
39
  export default CustomStepComponent;
@@ -72,6 +72,7 @@ export function isUploadedFileObject(file) {
72
72
  function FileUploadStep(_a) {
73
73
  var step = _a.step, editable = _a.editable;
74
74
  var _b = useFormStep(step, {
75
+ defaultValue: [],
75
76
  rules: {
76
77
  validate: function (array) {
77
78
  return ((step.required && array.length > 0) || !step.required) &&
@@ -2,12 +2,16 @@
2
2
  import { MapperStepProps } from '../MapperStep';
3
3
  import { FieldError } from 'react-hook-form';
4
4
  import { MapperElement } from '../../../@Types/MapperElement';
5
- declare function MapperStep<Type>({ step, editable, customAdd, ...others }: MapperStepProps<Type>): JSX.Element;
6
- export declare function CustomMapperStep<Type>({ step, error, editable, customAdd, loading, elements, inputRef, onChange, ...others }: MapperStepProps<Type> & {
7
- loading: boolean;
5
+ import { Form } from '../../../@Types';
6
+ export interface MapperComponentProps<Type> extends MapperStepProps<Type> {
7
+ form: Form;
8
+ loading?: boolean;
8
9
  error: FieldError | undefined;
9
10
  onChange: (elements: MapperElement<Type>[]) => void;
11
+ handleAddElement: (elementValue?: Type) => void;
10
12
  elements: MapperElement<Type>[];
11
13
  inputRef: any;
12
- }): JSX.Element;
14
+ }
15
+ declare function MapperStep<Type>(props: MapperStepProps<Type>): JSX.Element;
16
+ export declare function CustomMapperStep<Type>(props: Omit<MapperComponentProps<Type>, 'form' | 'handleAddElement'>): JSX.Element;
13
17
  export default MapperStep;
@@ -44,14 +44,53 @@ import CustomContext from '../../../Contexts/CustomContext';
44
44
  import { useFormStep } from '../../StepHooks';
45
45
  import { addMapperStep } from '../../../App/AppFunctions';
46
46
  import { calcMapperSubSteps } from '../../../Form/FormFunctions';
47
- function MapperStep(_a) {
48
- var step = _a.step, editable = _a.editable, customAdd = _a.customAdd, others = __rest(_a, ["step", "editable", "customAdd"]);
49
- var form = useContext(FormContext);
47
+ function MapperComponent(_a) {
48
+ var form = _a.form, step = _a.step, error = _a.error, loading = _a.loading, inputRef = _a.inputRef, editable = _a.editable, customAdd = _a.customAdd, elements = _a.elements, onChange = _a.onChange, handleAddElement = _a.handleAddElement, others = __rest(_a, ["form", "step", "error", "loading", "inputRef", "editable", "customAdd", "elements", "onChange", "handleAddElement"]);
49
+ var handleDeleteElement = useCallback(function (index) { return function () {
50
+ var tempElements = __spreadArray([], elements, true);
51
+ tempElements[index] = __assign(__assign({}, tempElements[index]), { deleted: true });
52
+ onChange(tempElements);
53
+ }; }, [elements, onChange]);
54
+ var inputValue = useMemo(function () { return JSON.stringify(elements); }, [elements]);
50
55
  var _b = useAppSelector(function (state) { return state.global; }), formStyle = _b.formStyle, postview = _b.postview;
56
+ var container = useMemo(function () {
57
+ var _a;
58
+ switch ((_a = step.style) === null || _a === void 0 ? void 0 : _a.type) {
59
+ case MapperStyleTypes.LIST:
60
+ return { container: styles.listContainer };
61
+ case MapperStyleTypes.PILL:
62
+ default:
63
+ return { container: styles.pillContainer };
64
+ }
65
+ }, [step]).container;
66
+ var mapElements = function () {
67
+ return (_jsx(FormContext.Provider, __assign({ value: form }, { children: elements.map(function (element, index) { return (_createElement(MapperElementComponent, __assign({}, others, { key: element.id, num: index, element: element, step: step, editable: editable, loading: loading, handleDelete: handleDeleteElement(index) }))); }) })));
68
+ };
69
+ if (step.style.type === MapperStyleTypes.INLINE)
70
+ return _jsx(React.Fragment, { children: mapElements() });
71
+ return (_jsxs("div", __assign({ className: container, style: { color: formStyle.textColor }, "data-testid": step.id }, { children: [step.label && _jsx("div", __assign({ className: styles.titleLbl }, { children: step.label })), step.description && (_jsx("p", __assign({ className: styles.descriptionPar, style: {
72
+ margin: step.description
73
+ ? '10px 0px'
74
+ : '0px 0px 5px 0px',
75
+ } }, { children: step.description }))), mapElements(), _jsx("input", { id: step.id, ref: inputRef, className: 'hidden-input', readOnly: true, value: inputValue }), step.creatable !== false &&
76
+ (!step.max ||
77
+ elements.filter(function (elem) { return !elem.deleted; }).length < step.max) && (_jsxs("div", __assign({ className: styles.btnContainer }, { children: [!customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel +
78
+ (step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
79
+ if (editable && !postview) {
80
+ handleAddElement();
81
+ }
82
+ } })), customAdd === null || customAdd === void 0 ? void 0 : customAdd(inputRef, !editable || postview, handleAddElement)] }))), !!error &&
83
+ elements.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
84
+ }
85
+ function MapperStep(props) {
86
+ var step = props.step, editable = props.editable, customAdd = props.customAdd;
87
+ var form = useContext(FormContext);
88
+ var postview = useAppSelector(function (state) { return state.global; }).postview;
51
89
  var customSteps = useContext(CustomContext).customSteps;
52
90
  var dispatch = useAppDispatch();
53
91
  var setValue = useFormContext().setValue;
54
- var _c = useFormStep(step, {
92
+ var _a = useFormStep(step, {
93
+ defaultValue: [],
55
94
  rules: {
56
95
  validate: function (array) {
57
96
  return !step.required ||
@@ -59,9 +98,9 @@ function MapperStep(_a) {
59
98
  array.filter(function (elem) { return !elem.deleted; }).length > 0);
60
99
  },
61
100
  },
62
- }), ref = _c.ref, value = _c.value, onChange = _c.onChange, error = _c.error;
63
- var _d = useState(calcMapperSubSteps(step, value, customSteps)), localSteps = _d[0], setLocalSteps = _d[1];
64
- //Por alguna razón si se saca del componente no se ejecuta.
101
+ }), ref = _a.ref, value = _a.value, onChange = _a.onChange, error = _a.error;
102
+ var _b = useState(calcMapperSubSteps(step, value, customSteps)), localSteps = _b[0], setLocalSteps = _b[1];
103
+ //Por alguna razón si se saca esto del componente no se ejecuta el agregar inicial
65
104
  useEffect(function () {
66
105
  if (value.length === 0 && !postview && editable && step.creatable) {
67
106
  if (!customAdd)
@@ -85,50 +124,16 @@ function MapperStep(_a) {
85
124
  allSteps: __assign(__assign({}, form.steps), steps),
86
125
  }));
87
126
  }, [step, form, customSteps, value, onChange]);
88
- var handleDeleteElement = useCallback(function (index) { return function () {
89
- var tempElements = __spreadArray([], value, true);
90
- tempElements[index] = __assign(__assign({}, tempElements[index]), { deleted: true });
91
- onChange(tempElements);
92
- }; }, [value, onChange]);
93
127
  var subForm = useMemo(function () { return (__assign(__assign({}, form), { steps: __assign(__assign({}, form.steps), localSteps) })); }, [localSteps]);
94
- var inputValue = useMemo(function () { return JSON.stringify(value); }, [value]);
95
- var container = useMemo(function () {
96
- var _a;
97
- switch ((_a = step.style) === null || _a === void 0 ? void 0 : _a.type) {
98
- case MapperStyleTypes.LIST:
99
- return { container: styles.listContainer };
100
- case MapperStyleTypes.PILL:
101
- default:
102
- return { container: styles.pillContainer };
103
- }
104
- }, [step]).container;
105
- var mapElements = function () {
106
- return (_jsx(FormContext.Provider, __assign({ value: subForm }, { children: value.map(function (element, index) { return (_createElement(MapperElementComponent, __assign({}, others, { key: element.id, num: index, element: element, step: step, editable: editable, handleDelete: handleDeleteElement(index) }))); }) })));
107
- };
108
- if (step.style.type === MapperStyleTypes.INLINE)
109
- return _jsx(React.Fragment, { children: mapElements() });
110
- return (_jsxs("div", __assign({ className: container, style: { color: formStyle.textColor }, "data-testid": step.id }, { children: [step.label && _jsx("div", __assign({ className: styles.titleLbl }, { children: step.label })), step.description && (_jsx("p", __assign({ className: styles.descriptionPar, style: {
111
- margin: step.description
112
- ? '10px 0px'
113
- : '0px 0px 5px 0px',
114
- } }, { children: step.description }))), mapElements(), _jsx("input", { id: step.id, ref: ref, className: 'hidden-input', readOnly: true, value: inputValue }), step.creatable !== false &&
115
- (!step.max ||
116
- value.filter(function (elem) { return !elem.deleted; })
117
- .length < step.max) && (_jsxs("div", __assign({ className: styles.btnContainer }, { children: [!customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel +
118
- (step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
119
- if (editable && !postview) {
120
- handleAddElement();
121
- }
122
- } })), customAdd === null || customAdd === void 0 ? void 0 : customAdd(ref, !editable || postview, handleAddElement)] }))), !!error && value.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
128
+ return (_jsx(MapperComponent, __assign({}, props, { error: error, inputRef: ref, onChange: onChange, handleAddElement: handleAddElement, form: subForm, elements: value })));
123
129
  }
124
- export function CustomMapperStep(_a) {
125
- var step = _a.step, error = _a.error, editable = _a.editable, customAdd = _a.customAdd, _b = _a.loading, loading = _b === void 0 ? false : _b, elements = _a.elements, inputRef = _a.inputRef, onChange = _a.onChange, others = __rest(_a, ["step", "error", "editable", "customAdd", "loading", "elements", "inputRef", "onChange"]);
130
+ export function CustomMapperStep(props) {
131
+ var step = props.step, elements = props.elements, onChange = props.onChange;
126
132
  var form = useContext(FormContext);
127
- var _c = useAppSelector(function (state) { return state.global; }), formStyle = _c.formStyle, postview = _c.postview;
128
133
  var customSteps = useContext(CustomContext).customSteps;
129
134
  var dispatch = useAppDispatch();
130
135
  var setValue = useFormContext().setValue;
131
- var _d = useState(calcMapperSubSteps(step, elements, customSteps)), localSteps = _d[0], setLocalSteps = _d[1];
136
+ var _a = useState(calcMapperSubSteps(step, elements, customSteps)), localSteps = _a[0], setLocalSteps = _a[1];
132
137
  var handleAddElement = useCallback(function (elementValue) {
133
138
  var _a = addMapperStep(step, customSteps), element = _a.element, steps = _a.steps, mappers = _a.mappers;
134
139
  if (elementValue)
@@ -146,40 +151,7 @@ export function CustomMapperStep(_a) {
146
151
  allSteps: __assign(__assign({}, form.steps), steps),
147
152
  }));
148
153
  }, [step, form, customSteps, elements, onChange]);
149
- var handleDeleteElement = useCallback(function (index) { return function () {
150
- var tempElements = __spreadArray([], elements, true);
151
- tempElements[index] = __assign(__assign({}, tempElements[index]), { deleted: true });
152
- onChange(tempElements);
153
- }; }, [elements, onChange]);
154
154
  var subForm = useMemo(function () { return (__assign(__assign({}, form), { steps: __assign(__assign({}, form.steps), localSteps) })); }, [localSteps]);
155
- var inputValue = useMemo(function () { return JSON.stringify(elements); }, [elements]);
156
- var container = useMemo(function () {
157
- var _a;
158
- switch ((_a = step.style) === null || _a === void 0 ? void 0 : _a.type) {
159
- case MapperStyleTypes.LIST:
160
- return { container: styles.listContainer };
161
- case MapperStyleTypes.PILL:
162
- default:
163
- return { container: styles.pillContainer };
164
- }
165
- }, [step]).container;
166
- var mapElements = function () {
167
- return (_jsx(FormContext.Provider, __assign({ value: subForm }, { children: elements.map(function (element, index) { return (_createElement(MapperElementComponent, __assign({}, others, { key: element.id, num: index, loading: loading, element: element, step: step, editable: editable, handleDelete: handleDeleteElement(index) }))); }) })));
168
- };
169
- if (step.style.type === MapperStyleTypes.INLINE)
170
- return _jsx(React.Fragment, { children: mapElements() });
171
- return (_jsxs("div", __assign({ className: container, style: { color: formStyle.textColor }, "data-testid": step.id }, { children: [step.label && _jsx("div", __assign({ className: styles.titleLbl }, { children: step.label })), step.description && (_jsx("p", __assign({ className: styles.descriptionPar, style: {
172
- margin: step.description
173
- ? '10px 0px'
174
- : '0px 0px 5px 0px',
175
- } }, { children: step.description }))), mapElements(), _jsx("input", { id: step.id, ref: inputRef, className: 'hidden-input', readOnly: true, value: inputValue }), step.creatable !== false &&
176
- (!step.max ||
177
- elements.filter(function (elem) { return !elem.deleted; }).length < step.max) && (_jsxs("div", __assign({ className: styles.btnContainer }, { children: [!customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel +
178
- (step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
179
- if (editable && !postview) {
180
- handleAddElement();
181
- }
182
- } })), customAdd === null || customAdd === void 0 ? void 0 : customAdd(inputRef, !editable || postview, handleAddElement)] }))), !!error &&
183
- elements.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
155
+ return (_jsx(MapperComponent, __assign({}, props, { form: subForm, elements: elements, onChange: onChange, handleAddElement: handleAddElement })));
184
156
  }
185
157
  export default MapperStep;
@@ -18,10 +18,12 @@ import StepComponent from '../../Step';
18
18
  import FormContext from '../../../Contexts/FormContext';
19
19
  import { useAppSelector } from '../../../hooks';
20
20
  import { useFormStep } from '../../StepHooks';
21
+ import { calcDefaultValue } from '../../StepFunctions';
21
22
  function RatingStep(_a) {
22
23
  var _b, _c, _d, _e;
23
24
  var step = _a.step, editable = _a.editable;
24
25
  var _f = useFormStep(step, {
26
+ defaultValue: calcDefaultValue(step),
25
27
  rules: {
26
28
  required: step.required ? 'Este campo es obligatorio' : undefined,
27
29
  },
@@ -19,10 +19,12 @@ import { useAppSelector } from '../../../hooks';
19
19
  import { useFormStep } from '../../StepHooks';
20
20
  import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
21
21
  import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
22
+ import { calcDefaultValue } from '../../StepFunctions';
22
23
  function SelectorStep(_a) {
23
24
  var _b, _c, _d;
24
25
  var step = _a.step, editable = _a.editable;
25
26
  var _e = useFormStep(step, {
27
+ defaultValue: calcDefaultValue(step),
26
28
  rules: {
27
29
  required: step.required ? 'Este campo es obligatorio' : undefined,
28
30
  },
@@ -61,7 +61,7 @@ function SmartSelectStep(_a) {
61
61
  var icon = _a.icon, step = _a.step, editable = _a.editable, getOptions = _a.getOptions, calcDepError = _a.calcDepError, defaultValue = _a.defaultValue, valueOverwrite = _a.valueOverwrite, getValueString = _a.getValueString, changeListener = _a.changeListener, getValueWarning = _a.getValueWarning, getOptionSelected = _a.getOptionSelected, renderNestedSteps = _a.renderNestedSteps;
62
62
  var _j = useFormStep(step, {
63
63
  sizeChange: true,
64
- defaultValue: defaultValue,
64
+ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : null,
65
65
  rules: {
66
66
  required: step.required ? 'Este campo es obligatorio' : undefined,
67
67
  },
@@ -27,14 +27,14 @@ export declare const selectDependencies: ((state: RootState, step: GBaseStep, fo
27
27
  clearCache: () => void;
28
28
  };
29
29
  export interface UseFormStepOptions<ValueType> {
30
- defaultValue?: ValueType;
30
+ defaultValue: ValueType;
31
31
  /** If true, will not trigger onChange until the user has finished typing */
32
32
  debounce?: boolean;
33
33
  rules?: UseControllerProps['rules'];
34
34
  /** If the step should trigger a filler(root StepFiller) size change */
35
35
  sizeChange?: boolean;
36
36
  }
37
- export declare const useFormStep: <ValueType = unknown>(step: GBaseStep, { rules, debounce, sizeChange, defaultValue, }?: UseFormStepOptions<ValueType>) => {
37
+ export declare const useFormStep: <ValueType = unknown>(step: GBaseStep, { rules, debounce, sizeChange, defaultValue }: UseFormStepOptions<ValueType>) => {
38
38
  value: ValueType;
39
39
  ref: RefCallBack;
40
40
  onChange: (value: ValueType) => void;
@@ -102,15 +102,15 @@ var calcDeepDependencies = function (idStep, form, deps) {
102
102
  return deps;
103
103
  };
104
104
  export var useFormStep = function (step, _a) {
105
- var _b = _a === void 0 ? {} : _a, rules = _b.rules, debounce = _b.debounce, sizeChange = _b.sizeChange, defaultValue = _b.defaultValue;
106
- var _c = useState(), timer = _c[0], setTimer = _c[1];
107
- var _d = useStepDependency(step, defaultValue), isDependency = _d.isDependency, handleStepDep = _d.handleStepDep, originalValue = _d.originalValue;
108
- var _e = useController({
105
+ var rules = _a.rules, debounce = _a.debounce, sizeChange = _a.sizeChange, defaultValue = _a.defaultValue;
106
+ var _b = useState(), timer = _b[0], setTimer = _b[1];
107
+ var _c = useStepDependency(step, defaultValue), isDependency = _c.isDependency, handleStepDep = _c.handleStepDep, originalValue = _c.originalValue;
108
+ var _d = useController({
109
109
  name: step.id,
110
110
  rules: rules,
111
111
  shouldUnregister: true,
112
112
  defaultValue: originalValue,
113
- }), _f = _e.field, ref = _f.ref, value = _f.value, fieldOnChange = _f.onChange, field = __rest(_f, ["ref", "value", "onChange"]), error = _e.fieldState.error;
113
+ }), _e = _d.field, ref = _e.ref, value = _e.value, fieldOnChange = _e.onChange, field = __rest(_e, ["ref", "value", "onChange"]), error = _d.fieldState.error;
114
114
  var handleSizeChange = useContext(SizeChangeContext);
115
115
  var onChange = useCallback(function (value) {
116
116
  if (isDependency) {
@@ -31,6 +31,7 @@ import { ClickAwayListener } from '@material-ui/core';
31
31
  import { useAppSelector } from '../../../hooks';
32
32
  import { useStepDependency } from '../../StepHooks';
33
33
  import { EditorState, convertFromRaw } from 'draft-js';
34
+ import { getRawText } from '../../../Utils/DraftFunctions';
34
35
  function TextAreaStep(_a) {
35
36
  var _b;
36
37
  var step = _a.step, editable = _a.editable;
@@ -38,7 +39,7 @@ function TextAreaStep(_a) {
38
39
  var _d = useState(false), hovering = _d[0], setHovering = _d[1];
39
40
  var _e = useState(false), focus = _e[0], setFocus = _e[1];
40
41
  var _f = useState(), timer = _f[0], setTimer = _f[1];
41
- var _g = useStepDependency(step), handleStepDep = _g.handleStepDep, originalValue = _g.originalValue, isDependency = _g.isDependency;
42
+ var _g = useStepDependency(step, getRawText()), handleStepDep = _g.handleStepDep, originalValue = _g.originalValue, isDependency = _g.isDependency;
42
43
  var _h = useController({
43
44
  name: step.id,
44
45
  shouldUnregister: true,
@@ -20,6 +20,7 @@ function TextAreaStep(_a) {
20
20
  var _d = useAppSelector(function (state) { return state.global; }), formStyle = _d.formStyle, postview = _d.postview, partial = _d.partial;
21
21
  var _e = useFormStep(step, {
22
22
  debounce: true,
23
+ defaultValue: '',
23
24
  rules: {
24
25
  required: step.required ? 'Este campo es obligatorio' : undefined,
25
26
  },
@@ -24,7 +24,7 @@ function TextInputStep(_a) {
24
24
  var _d = useAppSelector(function (state) { return state.global; }), formStyle = _d.formStyle, postview = _d.postview;
25
25
  var form = useContext(FormContext);
26
26
  var _e = useFormStep(step, {
27
- defaultValue: defaultValue,
27
+ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : '',
28
28
  debounce: true,
29
29
  rules: {
30
30
  required: step.required ? 'Este campo es obligatorio' : undefined,
@@ -10,7 +10,7 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { calcStepWidth } from '../../StepFunctions';
13
+ import { calcDefaultValue, calcStepWidth } from '../../StepFunctions';
14
14
  import styles from './MaterialTitleStep.module.css';
15
15
  import { useAppSelector } from '../../../hooks';
16
16
  import FormContext from '../../../Contexts/FormContext';
@@ -19,7 +19,9 @@ import { useFormStep } from '../../StepHooks';
19
19
  function TitleStep(_a) {
20
20
  var _b;
21
21
  var step = _a.step;
22
- var _c = useFormStep(step).value, title = _c.title, description = _c.description;
22
+ var _c = useFormStep(step, {
23
+ defaultValue: calcDefaultValue(step),
24
+ }).value, title = _c.title, description = _c.description;
23
25
  var formStyle = useAppSelector(function (state) { return state.global; }).formStyle;
24
26
  var form = useContext(FormContext);
25
27
  var widthStats = useAppSelector(function (state) { return state.widthStats; });
@@ -0,0 +1,13 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import Navbar from './Navbar';
3
+ declare const meta: {
4
+ component: typeof Navbar;
5
+ tags: string[];
6
+ args: {
7
+ logo: string;
8
+ color: string;
9
+ };
10
+ };
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+ export declare const Default: Story;
@@ -0,0 +1,13 @@
1
+ import Navbar from './Navbar';
2
+ var meta = {
3
+ component: Navbar,
4
+ tags: ['autodocs'],
5
+ args: {
6
+ logo: 'https://content.capta.co/Capta/CaptaWhite.svg',
7
+ color: '#3d5a7f',
8
+ },
9
+ };
10
+ export default meta;
11
+ export var Default = {
12
+ args: {},
13
+ };
@@ -0,0 +1,15 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import Rating from './Rating';
3
+ declare const meta: {
4
+ component: typeof Rating;
5
+ tags: string[];
6
+ args: {};
7
+ };
8
+ export default meta;
9
+ type Story = StoryObj<typeof meta>;
10
+ export declare const ScaleRating: Story;
11
+ export declare const ScaleRatingWidthValue: Story;
12
+ export declare const LikeRating: Story;
13
+ export declare const LikeRatingWithValue: Story;
14
+ export declare const SatisfactionRating: Story;
15
+ export declare const SatisfactionRatingWidthValue: Story;
@@ -0,0 +1,59 @@
1
+ import Rating from './Rating';
2
+ import { RatingTypes } from '../../constants/FormStepTypes';
3
+ var meta = {
4
+ component: Rating,
5
+ tags: ['autodocs'],
6
+ args: {},
7
+ };
8
+ export default meta;
9
+ export var ScaleRating = {
10
+ args: {
11
+ type: RatingTypes.SCALE,
12
+ name: 'Rating',
13
+ focusColor: '#3d5a7f',
14
+ unSelectedColor: '#d8d8d8',
15
+ },
16
+ };
17
+ export var ScaleRatingWidthValue = {
18
+ args: {
19
+ type: RatingTypes.SCALE,
20
+ name: 'Rating',
21
+ focusColor: '#3d5a7f',
22
+ unSelectedColor: '#d8d8d8',
23
+ value: 4,
24
+ },
25
+ };
26
+ export var LikeRating = {
27
+ args: {
28
+ type: RatingTypes.LIKE,
29
+ name: 'Rating',
30
+ focusColor: '#3d5a7f',
31
+ unSelectedColor: '#d8d8d8',
32
+ },
33
+ };
34
+ export var LikeRatingWithValue = {
35
+ args: {
36
+ type: RatingTypes.LIKE,
37
+ name: 'Rating',
38
+ focusColor: '#3d5a7f',
39
+ unSelectedColor: '#d8d8d8',
40
+ value: 1,
41
+ },
42
+ };
43
+ export var SatisfactionRating = {
44
+ args: {
45
+ type: RatingTypes.SATISFACTION,
46
+ name: 'Rating',
47
+ focusColor: '#3d5a7f',
48
+ unSelectedColor: '#d8d8d8',
49
+ },
50
+ };
51
+ export var SatisfactionRatingWidthValue = {
52
+ args: {
53
+ type: RatingTypes.SATISFACTION,
54
+ name: 'Rating',
55
+ focusColor: '#3d5a7f',
56
+ unSelectedColor: '#d8d8d8',
57
+ value: 3,
58
+ },
59
+ };
@@ -0,0 +1,23 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import RoundedButton from './RoundedButton';
3
+ declare const meta: {
4
+ component: typeof RoundedButton;
5
+ tags: string[];
6
+ args: {
7
+ text: string;
8
+ backgroundColor: string;
9
+ color: string;
10
+ disabled: false;
11
+ fontSize: string;
12
+ padding: string;
13
+ borderRadius: number;
14
+ height: number;
15
+ bold: false;
16
+ width: string;
17
+ };
18
+ };
19
+ export default meta;
20
+ type Story = StoryObj<typeof meta>;
21
+ export declare const Default: Story;
22
+ export declare const Disabled: Story;
23
+ export declare const DifferentColors: Story;