@arquimedes.co/eureka-forms 3.0.44-test → 3.0.45-mui9

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 (52) hide show
  1. package/dist/@Types/FormStep.d.ts +4 -2
  2. package/dist/@Types/GenericFormSteps.d.ts +1 -1
  3. package/dist/App/AppHooks.js +13 -13
  4. package/dist/Form/ConfirmationDialog/ConfirmationDialog.js +7 -5
  5. package/dist/Form/Terms/Term/MaterialTerm/MaterialTerm.js +5 -3
  6. package/dist/FormSteps/@Construction/CBRPropertyStep/CBRPropertyStep.js +7 -5
  7. package/dist/FormSteps/@StoryDecorators/FormStepDecorator.d.ts +9 -0
  8. package/dist/FormSteps/@StoryDecorators/FormStepDecorator.js +86 -0
  9. package/dist/FormSteps/AYFStepMapper.js +2 -2
  10. package/dist/FormSteps/DatePickerRangeStep/MaterialDatePickerRangeStep/MaterialDatePickerRangeStep.js +3 -3
  11. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.js +7 -5
  12. package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.js +1 -1
  13. package/dist/FormSteps/StepFunctions.js +1 -1
  14. package/dist/Shared/ErkCheckbox/ErkCheckBox.d.ts +1 -0
  15. package/dist/Shared/ErkCheckbox/ErkCheckBox.js +2 -2
  16. package/dist/Shared/ErkDatePicker/ErkDatePicker.js +41 -35
  17. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +4 -1
  18. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +38 -25
  19. package/dist/Shared/ErkMenuItem.d.ts +1 -1
  20. package/dist/Shared/ErkSelect/ErkSelect.d.ts +2 -2
  21. package/dist/Shared/ErkTextField/ErkTextField.d.ts +17 -2
  22. package/dist/Shared/ErkTextField/ErkTextField.js +3 -3
  23. package/dist/Shared/ErkTimePicker/ErkTimePicker.js +1 -1
  24. package/dist/Shared/Rating/Ratings/ScaleRating.js +1 -1
  25. package/dist/States/GlobalSlice.d.ts +8 -26
  26. package/dist/States/GlobalSlice.js +3 -2
  27. package/dist/States/SiteSlice.d.ts +8 -33
  28. package/dist/States/SiteSlice.js +11 -9
  29. package/dist/States/WidthStatsSlice.d.ts +5 -1
  30. package/dist/Utils/DraftFunctions.js +1 -1
  31. package/dist/index.css +7 -0
  32. package/dist/main.d.ts +1 -1
  33. package/dist/main.js +1 -1
  34. package/package.json +34 -33
  35. package/dist/Shared/ErkButton/ErkButton.stories.d.ts +0 -16
  36. package/dist/Shared/ErkButton/ErkButton.stories.js +0 -28
  37. package/dist/Shared/ErkCheckbox/ErkCheckBox.stories.d.ts +0 -13
  38. package/dist/Shared/ErkCheckbox/ErkCheckBox.stories.js +0 -34
  39. package/dist/Shared/ErkDatePicker/ErkDatePicker.stories.d.ts +0 -23
  40. package/dist/Shared/ErkDatePicker/ErkDatePicker.stories.js +0 -98
  41. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.stories.d.ts +0 -36
  42. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.stories.js +0 -274
  43. package/dist/Shared/ErkSelect/ErkSelect.stories.d.ts +0 -21
  44. package/dist/Shared/ErkSelect/ErkSelect.stories.js +0 -87
  45. package/dist/Shared/ErkSmartSelect/ErkSmartSelect.stories.d.ts +0 -26
  46. package/dist/Shared/ErkSmartSelect/ErkSmartSelect.stories.js +0 -159
  47. package/dist/Shared/ErkTextField/ErkTextField.stories.d.ts +0 -24
  48. package/dist/Shared/ErkTextField/ErkTextField.stories.js +0 -99
  49. package/dist/Shared/Navbar/Navbar.stories.d.ts +0 -13
  50. package/dist/Shared/Navbar/Navbar.stories.js +0 -13
  51. package/dist/Shared/Rating/Rating.stories.d.ts +0 -15
  52. package/dist/Shared/Rating/Rating.stories.js +0 -47
@@ -47,9 +47,11 @@ export interface TextInput extends GSteps.GTextInput {
47
47
  }
48
48
  export interface DatePicker extends GSteps.GDatePicker {
49
49
  type: FormStepTypes.DATEPICKER;
50
+ defaultValue?: string;
50
51
  }
51
52
  export interface DatePickerRange extends GSteps.GDatePickerRange {
52
53
  type: FormStepTypes.DATEPICKER_RANGE;
54
+ defaultValue?: string[];
53
55
  }
54
56
  export interface Collapsible extends GSteps.GBaseStep {
55
57
  type: FormStepTypes.COLLAPSIBLE;
@@ -60,10 +62,10 @@ export interface Collapsible extends GSteps.GBaseStep {
60
62
  export interface FormSelector extends GSteps.GBaseStep {
61
63
  type: FormStepTypes.SELECTOR;
62
64
  label: string;
63
- description: string;
65
+ description: string | null;
64
66
  required: boolean;
65
67
  searchable: boolean;
66
- options: FormSelectorOption[];
68
+ options: readonly FormSelectorOption[];
67
69
  size: 1 | 2 | 3 | 4;
68
70
  maxSize?: number;
69
71
  defaultValue?: string;
@@ -2,7 +2,7 @@ import { Condition } from './Condition';
2
2
  export interface GBaseStep {
3
3
  id: string;
4
4
  idSection: string;
5
- stepPath: string[];
5
+ stepPath: readonly string[];
6
6
  type: string;
7
7
  editable?: boolean;
8
8
  partial?: boolean;
@@ -57,33 +57,33 @@ export const useSetupApp = (isEmbedded, props) => {
57
57
  idOrganization = match ? match[1] : '';
58
58
  }
59
59
  if (form) {
60
- form = createNextState(form, (form) => {
61
- const firstSection = form.sections[form.firstSection];
62
- if (firstSection.steps === undefined && form.rootSteps !== undefined) {
63
- firstSection.steps = form.rootSteps;
60
+ form = createNextState(form, (draft) => {
61
+ const firstSection = draft.sections[draft.firstSection];
62
+ if (firstSection.steps === undefined && draft.rootSteps !== undefined) {
63
+ firstSection.steps = draft.rootSteps;
64
64
  }
65
65
  //If a rootStep is a mapper of type section
66
- if (form && classifiers)
67
- form.classifiers = classifiers;
66
+ if (classifiers)
67
+ draft.classifiers = classifiers;
68
68
  /** Assign the idSection to all the forms steps */
69
- for (const section of Object.values(form.sections)) {
69
+ for (const section of Object.values(draft.sections)) {
70
70
  for (const idStep of section.steps) {
71
- iterateNestedSteps(idStep, form.steps, (step, path) => {
71
+ iterateNestedSteps(idStep, draft.steps, (step, path) => {
72
72
  step.idSection = section.id;
73
73
  step.stepPath = path;
74
74
  });
75
75
  }
76
- for (const idStep of form.hiddenSteps ?? []) {
77
- iterateNestedSteps(idStep, form.steps, (step, path) => {
76
+ for (const idStep of draft.hiddenSteps ?? []) {
77
+ iterateNestedSteps(idStep, draft.steps, (step, path) => {
78
78
  step.idSection = section.id;
79
79
  step.stepPath = path;
80
80
  });
81
81
  }
82
82
  }
83
- const CBRStep = Object.values(form.steps).find((step) => step.type.startsWith('CBR'));
84
- if (CBRStep)
85
- form = calcCbrForm(form, valuesData ?? {});
86
83
  });
84
+ const CBRStep = Object.values(form.steps).find((step) => step.type.startsWith('CBR'));
85
+ if (CBRStep)
86
+ form = calcCbrForm(form, valuesData ?? {});
87
87
  }
88
88
  setForm(form);
89
89
  if (!form || !idOrganization)
@@ -46,11 +46,13 @@ function ConfirmationDialog({ onClose, confirmation, customConfirmation }) {
46
46
  fontSize: widthStats.isMobile ? '1rem' : '1.2rem',
47
47
  }, children: confirmation.url })] }));
48
48
  };
49
- return (_jsx(Dialog, { PaperProps: {
50
- style: {
51
- borderRadius: '20px',
52
- maxWidth: '100vw',
53
- boxSizing: 'content-box',
49
+ return (_jsx(Dialog, { slotProps: {
50
+ paper: {
51
+ style: {
52
+ borderRadius: '20px',
53
+ maxWidth: '100vw',
54
+ boxSizing: 'content-box',
55
+ },
54
56
  },
55
57
  }, open: true, children: _jsxs("div", { className: styles.confirmationContainer, style: {
56
58
  color: '#293241',
@@ -44,9 +44,11 @@ function TermComponent({ term, tempError }) {
44
44
  return parts;
45
45
  }
46
46
  };
47
- return (_jsxs(React.Fragment, { children: [_jsx(Dialog, { PaperProps: {
48
- style: {
49
- borderRadius: '20px',
47
+ return (_jsxs(React.Fragment, { children: [_jsx(Dialog, { slotProps: {
48
+ paper: {
49
+ style: {
50
+ borderRadius: '20px',
51
+ },
50
52
  },
51
53
  }, onClose: () => {
52
54
  setShowDialog(false);
@@ -66,11 +66,13 @@ function CBRPropertyStepComponent(props) {
66
66
  }
67
67
  }
68
68
  }
69
- : undefined, getOptions: getInmueblesOptions }), showWarning !== undefined && (_jsx(Dialog, { PaperProps: {
70
- style: {
71
- borderRadius: '20px',
72
- maxWidth: '100vw',
73
- boxSizing: 'content-box',
69
+ : undefined, getOptions: getInmueblesOptions }), showWarning !== undefined && (_jsx(Dialog, { slotProps: {
70
+ paper: {
71
+ style: {
72
+ borderRadius: '20px',
73
+ maxWidth: '100vw',
74
+ boxSizing: 'content-box',
75
+ },
74
76
  },
75
77
  }, open: true, children: _jsxs("div", { className: styles.confirmationContainer, style: { color: formStyle.textColor }, children: [_jsx("div", { className: styles.closeIcon, onClick: () => {
76
78
  setShowWarning(undefined);
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { Form } from '../../@Types';
3
+ /** Minimal form object shared across FormStep stories */
4
+ export declare const storyForm: Form;
5
+ /**
6
+ * Decorator for FormStep stories.
7
+ * Provides: Redux store, form ID, react-hook-form, FormContext, SectionContext.
8
+ */
9
+ export declare function withFormStepProviders(Story: React.ComponentType): JSX.Element;
@@ -0,0 +1,86 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Provider } from 'react-redux';
3
+ import { useForm, FormProvider } from 'react-hook-form';
4
+ import { configureStore } from '@reduxjs/toolkit';
5
+ import { EurekaFormsReducer, defaultRootState } from '../../Utils/store';
6
+ import { RootApi } from '../../Utils/_api';
7
+ import FormStepTypes from '../../constants/FormStepTypes';
8
+ import { StoreContext } from '../../Utils/StoreContext';
9
+ import { IdFormContext } from '../../Contexts/FormContext';
10
+ import FormContext from '../../Contexts/FormContext';
11
+ import SectionContext from '../../Contexts/SectionContext';
12
+ import MaterialProviders from '../../Utils/MaterialProviders';
13
+ import InternalFormStyle from '../../constants/InternalFormStyle';
14
+ const STORY_FORM_ID = 'STORY_FORM';
15
+ /** Minimal form object shared across FormStep stories */
16
+ export const storyForm = {
17
+ firstSection: 'SECTION_1',
18
+ sections: {
19
+ SECTION_1: {
20
+ id: 'SECTION_1',
21
+ name: 'Sección 1',
22
+ steps: [],
23
+ nextSection: null,
24
+ },
25
+ },
26
+ steps: {
27
+ 'inner-step-1': {
28
+ id: 'inner-step-1',
29
+ idSection: 'SECTION_1',
30
+ stepPath: ['inner-step-1'],
31
+ type: FormStepTypes.TEXTINPUT,
32
+ label: 'Campo interior 1',
33
+ description: null,
34
+ required: false,
35
+ size: 4,
36
+ editable: true,
37
+ },
38
+ 'inner-step-2': {
39
+ id: 'inner-step-2',
40
+ idSection: 'SECTION_1',
41
+ stepPath: ['inner-step-2'],
42
+ type: FormStepTypes.TEXTINPUT,
43
+ label: 'Campo interior 2',
44
+ description: null,
45
+ required: false,
46
+ size: 4,
47
+ editable: true,
48
+ },
49
+ },
50
+ confirmationMessage: {
51
+ blocks: [],
52
+ entityMap: {},
53
+ },
54
+ showLink: false,
55
+ size: {
56
+ blockSize: 200,
57
+ blockNum: 4,
58
+ spacingSize: 10,
59
+ },
60
+ };
61
+ function createStoryStore() {
62
+ return configureStore({
63
+ reducer: {
64
+ forms: EurekaFormsReducer,
65
+ [RootApi.reducerPath]: RootApi.reducer,
66
+ },
67
+ preloadedState: {
68
+ forms: {
69
+ [STORY_FORM_ID]: defaultRootState,
70
+ },
71
+ },
72
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(RootApi.middleware),
73
+ });
74
+ }
75
+ /**
76
+ * Decorator for FormStep stories.
77
+ * Provides: Redux store, form ID, react-hook-form, FormContext, SectionContext.
78
+ */
79
+ export function withFormStepProviders(Story) {
80
+ const store = createStoryStore();
81
+ function FormStepWrapper({ children }) {
82
+ const methods = useForm({ mode: 'onChange' });
83
+ return _jsx(FormProvider, { ...methods, children: children });
84
+ }
85
+ return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: store, context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: storyForm, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormStepWrapper, { children: _jsx(Story, {}) }) }) }) }) }) }));
86
+ }
@@ -64,7 +64,7 @@ function AYFStepMapper(props) {
64
64
  switch (props.step.type) {
65
65
  case AYFFormStepTypes.AYF_START_MONTH:
66
66
  case AYFFormStepTypes.AYF_END_MONTH:
67
- return (_jsx(SmartSelectStep, { ...props, step: props.step, getOptions: getMonths, getOptionSelected: (option, value) => option.id === value.id, defaultValue: props.step.type === AYFFormStepTypes.AYF_START_MONTH
67
+ return (_jsx(SmartSelectStep, { ...props, step: { ...props.step, searchable: false }, getOptions: getMonths, getOptionSelected: (option, value) => option.id === value.id, defaultValue: props.step.type === AYFFormStepTypes.AYF_START_MONTH
68
68
  ? { id: '1', label: 'Enero' }
69
69
  : { id: '12', label: 'Diciembre' }, getValueString: (value) => value?.id, IconComponent: () => _jsx(CalendarIcon, {}) }));
70
70
  case AYFFormStepTypes.AYF_YEAR:
@@ -78,7 +78,7 @@ function AYFStepMapper(props) {
78
78
  case AYFFormStepTypes.AYF_CUT_OFF_DATE:
79
79
  return _jsx(DatePickerStep, { ...props, step: props.step, defaultValue: new Date().toString() });
80
80
  case AYFFormStepTypes.AYF_ICA_CITY:
81
- return (_jsx(SmartSelectStep, { ...props, step: props.step, getOptions: getCiudadesOptions, getOptionSelected: (option, value) => option === value, getValueString: (value) => value, IconComponent: () => _jsx(LocationIcon, {}) }));
81
+ return (_jsx(SmartSelectStep, { ...props, step: { ...props.step, searchable: false }, getOptions: getCiudadesOptions, getOptionSelected: (option, value) => option === value, getValueString: (value) => value, IconComponent: () => _jsx(LocationIcon, {}) }));
82
82
  default:
83
83
  return _jsx("div", {});
84
84
  }
@@ -20,11 +20,11 @@ function MaterialDatePickerRangeStep({ step, editable, defaultValue }) {
20
20
  });
21
21
  const handleChange = useCallback((dateRange) => {
22
22
  const [start, end] = dateRange;
23
- if (start && end) {
24
- onChange([start.toISOString(), end.toISOString()]);
23
+ if (!start && !end) {
24
+ onChange(null);
25
25
  }
26
26
  else {
27
- onChange(null);
27
+ onChange([start?.toISOString() ?? null, end?.toISOString() ?? null]);
28
28
  }
29
29
  }, [onChange]);
30
30
  const [minDate, maxDate] = [safeDate(step.minDate), safeDate(step.maxDate)];
@@ -18,11 +18,13 @@ function MaterialEntityValueDialog({ type, entity, message, entityValue, handleC
18
18
  const editorState = useMemo(() => {
19
19
  return EditorState.createWithContent(convertFromRaw(mapDraftEntities({ form, dependencies, entity, entityValue }, message)));
20
20
  }, [form, message, dependencies, entity, entityValue]);
21
- return (_jsx(Dialog, { PaperProps: {
22
- style: {
23
- borderRadius: '20px',
24
- maxWidth: '100vw',
25
- boxSizing: 'content-box',
21
+ return (_jsx(Dialog, { slotProps: {
22
+ paper: {
23
+ style: {
24
+ borderRadius: '20px',
25
+ maxWidth: '100vw',
26
+ boxSizing: 'content-box',
27
+ },
26
28
  },
27
29
  }, open: true, children: _jsxs("div", { className: styles.confirmationContainer, style: { color: formStyle.textColor }, children: [_jsx("div", { className: styles.closeIcon, onClick: () => handleClose(), children: _jsx(CloseIcon, { style: { fontSize: 'inherit' } }) }), _jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.contentContainer, children: [_jsx("div", { className: styles.warningContainer, style: {
28
30
  color: type === 'INFO' ? formStyle.primaryColor : formStyle.errorColor,
@@ -64,7 +64,7 @@ function SelectorStep({ step, editable }) {
64
64
  }
65
65
  // eslint-disable-next-line react-hooks/exhaustive-deps
66
66
  }, [filteredOptions]);
67
- return (_jsxs(React.Fragment, { children: [_jsx(MaterialInputContainer, { step: step, editable: editable, children: _jsx(ErkSmartSelect, { ...field, value: value, inputRef: ref, error: !!error, label: step.label, onChange: onChange, required: step.required, options: filteredOptions, searchable: step.searchable, readOnly: !editable || postview, helperText: error?.message?.toString() ?? step.description, getOptionSelected: (option, value) => option?.value === value?.value }) }), value && mapNestedOption()] }));
67
+ return (_jsxs(React.Fragment, { children: [_jsx(MaterialInputContainer, { step: step, editable: editable, children: _jsx(ErkSmartSelect, { ...field, value: value, inputRef: ref, error: !!error, label: step.label, onChange: onChange, required: step.required, options: filteredOptions, searchable: step.searchable, readOnly: !editable || postview, helperText: error?.message?.toString() ?? step.description ?? undefined, getOptionSelected: (option, value) => option?.value === value?.value }) }), value && mapNestedOption()] }));
68
68
  }
69
69
  function SelectorStepContainer(props) {
70
70
  return (_jsx(StepFillerContainer, { step: props.step, children: _jsx(SelectorStep, { ...props }) }));
@@ -483,7 +483,7 @@ const evaluateEntityPropertyCondition = (condition, entity, entityValue) => {
483
483
  return !boolFactor;
484
484
  }
485
485
  const property = entity.steps[condition.idProperty];
486
- if (!property || property.type !== condition.propertyType) {
486
+ if (property?.type !== condition.propertyType) {
487
487
  return false;
488
488
  }
489
489
  const value = entityValue[condition.idProperty];
@@ -9,6 +9,7 @@ interface ErkCheckboxProps extends Omit<StyleProps, 'error'>, Omit<MuiCheckboxPr
9
9
  onChange?: (checked: boolean) => void;
10
10
  checked: boolean;
11
11
  error?: boolean;
12
+ inputRef?: React.Ref<HTMLInputElement>;
12
13
  }
13
14
  /**
14
15
  * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
@@ -17,8 +17,8 @@ const StyledCheckbox = styled(MuiCheckbox, { shouldForwardProp: (prop) => prop !
17
17
  /**
18
18
  * Generic capta checkbox
19
19
  */
20
- function CustomCheckBox({ onChange, error = false, readOnly = false, disabled = false, ...others }) {
21
- return (_jsx(FormControl, { error: true, children: _jsx(StyledCheckbox, { ...others, error: +error, readOnly: readOnly, disabled: disabled, inputProps: { disabled: disabled || readOnly }, icon: _jsx(CheckboxUncheckedIcon, {}), checkedIcon: _jsx(CheckboxCheckedIcon, {}), onChange: (event) => onChange?.(typeof event === 'boolean' ? event : event.target.checked) }) }));
20
+ function CustomCheckBox({ onChange, error = false, readOnly = false, disabled = false, inputRef, ...others }) {
21
+ return (_jsx(FormControl, { error: true, children: _jsx(StyledCheckbox, { ...others, error: +error, readOnly: readOnly, disabled: disabled, slotProps: { input: { disabled: disabled ?? readOnly, ref: inputRef } }, icon: _jsx(CheckboxUncheckedIcon, {}), checkedIcon: _jsx(CheckboxCheckedIcon, {}), onChange: (event) => onChange?.(typeof event === 'boolean' ? event : event.target.checked) }) }));
22
22
  }
23
23
  /**
24
24
  * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
@@ -1,7 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { forwardRef } from 'react';
3
- import { styled, Dialog as MuiDialog } from '@mui/material';
4
- import { MobileDatePicker as MuiDatePicker, MobileDateTimePicker as MuiDateTimePicker, DatePickerToolbar as MuiDatePickerToolbar, DateTimePickerToolbar as MuiDateTimePickerToolbar, PickersDay as MuiPickerDay, usePickerContext, } from '@mui/x-date-pickers';
2
+ import React, { useMemo } from 'react';
3
+ import { format as dateFnsFormat, isValid } from 'date-fns';
4
+ import { InputAdornment, styled, Dialog as MuiDialog } from '@mui/material';
5
+ import { MobileDatePicker as MuiDatePicker, MobileDateTimePicker as MuiDateTimePicker, DatePickerToolbar as MuiDatePickerToolbar, DateTimePickerToolbar as MuiDateTimePickerToolbar, usePickerContext, } from '@mui/x-date-pickers';
6
+ import { PickerDay as MuiPickerDay } from '@mui/x-date-pickers/PickerDay';
5
7
  import { StyledTextField } from '../ErkTextField/ErkTextField';
6
8
  import CalendarIcon from '../../Icons/CalendarIcon';
7
9
  import { renderTimeViewClock } from '@mui/x-date-pickers/timeViewRenderers';
@@ -136,20 +138,36 @@ const StyledDay = styled(MuiPickerDay)(({ theme }) => ({
136
138
  },
137
139
  },
138
140
  }));
139
- // eslint-disable-next-line react/display-name
140
- const CustomTextField = forwardRef((props, ref) => {
141
- const pickerContext = usePickerContext();
141
+ function CustomPickerField({ error, required, helperText, size = 'small', labelMargin = 5, inputRef, fullWidth = true, }) {
142
+ const { value, fieldFormat, setOpen, disabled, readOnly, label } = usePickerContext();
143
+ const { displayValue, isInvalid } = useMemo(() => {
144
+ if (!value)
145
+ return { displayValue: '', isInvalid: false };
146
+ if (!isValid(value))
147
+ return { displayValue: '', isInvalid: true };
148
+ try {
149
+ return { displayValue: dateFnsFormat(value, fieldFormat ?? 'P'), isInvalid: false };
150
+ }
151
+ catch {
152
+ return { displayValue: '', isInvalid: true };
153
+ }
154
+ }, [value, fieldFormat]);
142
155
  const handleClick = () => {
143
- if (!props.disabled && !props.readOnly) {
144
- pickerContext.setOpen((prev) => !prev);
156
+ if (!disabled && !readOnly) {
157
+ setOpen((prev) => !prev);
145
158
  }
146
159
  };
147
- return (_jsx(StyledTextField, { ...props, inputRef: ref, onClick: handleClick, InputProps: {
148
- ...props.InputProps,
149
- disabled: !!props.readOnly || !!props.disabled,
160
+ return (_jsx(StyledTextField, { value: displayValue, label: label, disabled: disabled, readOnly: readOnly, error: isInvalid || error, required: required, helperText: isInvalid ? 'Fecha inválida' : helperText, size: size, labelMargin: labelMargin, inputRef: inputRef, onClick: handleClick, fullWidth: fullWidth, placeholder: "", slotProps: {
161
+ input: {
162
+ endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(CalendarIcon, { style: {
163
+ fontSize: size === 'small' ? 18 : 20,
164
+ opacity: disabled || readOnly ? 0.5 : 1,
165
+ } }) })),
166
+ readOnly: true,
167
+ },
150
168
  } }));
151
- });
152
- function CustomDatePicker({ error, required, disabled, readOnly, helperText, size = 'small', labelMargin = 5, pickTime = false,
169
+ }
170
+ function CustomDatePicker({ error, required, disabled, readOnly, helperText, size = 'small', labelMargin = 5, pickTime = false, inputRef,
153
171
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
154
172
  orientation: _orientation, ...others }) {
155
173
  if (pickTime) {
@@ -192,19 +210,14 @@ orientation: _orientation, ...others }) {
192
210
  hidden: false,
193
211
  toolbarPlaceholder: '– –',
194
212
  },
195
- textField: {
213
+ field: {
196
214
  error,
197
- size,
198
215
  required,
199
- disabled,
200
- readOnly: !disabled && readOnly,
201
216
  helperText,
217
+ size,
202
218
  labelMargin,
203
- placeholder: '',
204
219
  fullWidth: true,
205
- InputProps: {
206
- readOnly: !disabled && readOnly,
207
- },
220
+ inputRef,
208
221
  },
209
222
  }, viewRenderers: {
210
223
  hours: renderTimeViewClock,
@@ -214,9 +227,8 @@ orientation: _orientation, ...others }) {
214
227
  day: StyledDay,
215
228
  dialog: StyledDialog,
216
229
  toolbar: StyledDateTimeToolBar,
217
- textField: CustomTextField,
218
- openPickerIcon: CalendarIcon,
219
- }, enableAccessibleFieldDOMStructure: false }));
230
+ field: CustomPickerField,
231
+ } }));
220
232
  }
221
233
  else {
222
234
  return (_jsx(StyledDatePicker, { ...others, size: size, reduceAnimations: true, readOnly: readOnly, disabled: disabled, defaultValue: required ? new Date() : undefined, showDaysOutsideCurrentMonth: true, views: ['year', 'month', 'day'], slotProps: {
@@ -248,27 +260,21 @@ orientation: _orientation, ...others }) {
248
260
  hidden: false,
249
261
  toolbarPlaceholder: '– –',
250
262
  },
251
- textField: {
252
- size,
263
+ field: {
253
264
  error,
254
265
  required,
255
- disabled,
256
- readOnly: !disabled && readOnly,
257
266
  helperText,
267
+ size,
258
268
  labelMargin,
259
269
  fullWidth: true,
260
- placeholder: '',
261
- InputProps: {
262
- readOnly: !disabled && readOnly,
263
- },
270
+ inputRef,
264
271
  },
265
272
  }, slots: {
266
273
  day: StyledDay,
267
274
  dialog: StyledDialog,
268
275
  toolbar: StyledDateToolBar,
269
- textField: CustomTextField,
270
- openPickerIcon: CalendarIcon,
271
- }, enableAccessibleFieldDOMStructure: false }));
276
+ field: CustomPickerField,
277
+ } }));
272
278
  }
273
279
  }
274
280
  /**
@@ -1,13 +1,16 @@
1
1
  import React from 'react';
2
2
  import { MobileDateRangePickerProps as MuiDateRangePickerProps } from '@mui/x-date-pickers-pro/MobileDateRangePicker';
3
3
  import { DateRange } from '@mui/x-date-pickers-pro';
4
+ import { PickersShortcutsItem } from '@mui/x-date-pickers/PickersShortcuts';
4
5
  import { ErkTextFieldProps } from '../ErkTextField/ErkTextField';
5
- interface ErkDateRangePickerProps extends Omit<MuiDateRangePickerProps<boolean>, 'ref' | 'onChange' | 'value' | 'slotProps'>, Pick<ErkTextFieldProps, 'error' | 'required' | 'helperText' | 'size'> {
6
+ interface ErkDateRangePickerProps extends Omit<MuiDateRangePickerProps, 'ref' | 'onChange' | 'value' | 'slotProps'>, Pick<ErkTextFieldProps, 'error' | 'required' | 'helperText' | 'size'> {
6
7
  onChange?: (dateRange: DateRange<Date>) => void;
7
8
  value?: DateRange<Date>;
8
9
  inputRef?: React.Ref<HTMLInputElement>;
9
10
  /** labelMargin */
10
11
  labelMargin?: number;
12
+ /** Shortcuts to display in the picker */
13
+ shortcuts?: PickersShortcutsItem<DateRange<Date>>[];
11
14
  }
12
15
  /**
13
16
  * Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
@@ -1,10 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { styled, Dialog as MuiDialog } from '@mui/material';
2
+ import React, { useMemo } from 'react';
3
+ import { InputAdornment, styled, Dialog as MuiDialog } from '@mui/material';
4
4
  import { DatePickerToolbar as MuiDatePickerToolbar, usePickerContext, } from '@mui/x-date-pickers';
5
5
  import { MobileDateRangePicker as MuiDateRangePicker, } from '@mui/x-date-pickers-pro/MobileDateRangePicker';
6
6
  import { DateRangePickerDay as MuiDateRangePickerDay } from '@mui/x-date-pickers-pro';
7
- import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField';
8
7
  import { format, isValid } from 'date-fns';
9
8
  import { StyledTextField } from '../ErkTextField/ErkTextField';
10
9
  import CalendarIcon from '../../Icons/CalendarIcon';
@@ -85,17 +84,39 @@ const StyledDay = styled(MuiDateRangePickerDay)(({ theme }) => ({
85
84
  backgroundColor: theme.palette.primary.main + '1a',
86
85
  },
87
86
  }));
88
- // eslint-disable-next-line react/display-name
89
- const CustomTextField = React.forwardRef((props, ref) => {
90
- const pickerContext = usePickerContext();
87
+ const CustomRangePickerField = React.forwardRef(function CustomRangePickerField({ error, required, helperText, size = 'small', labelMargin = 5, fullWidth = true, inputRef, }, ref) {
88
+ const { value, fieldFormat, setOpen, disabled, readOnly, label } = usePickerContext();
89
+ const { displayValue, isInvalid } = useMemo(() => {
90
+ const [startDate, endDate] = value ?? [null, null];
91
+ if (!startDate)
92
+ return { displayValue: '', isInvalid: false };
93
+ if (!isValid(startDate))
94
+ return { displayValue: '', isInvalid: true };
95
+ if (endDate && !isValid(endDate))
96
+ return { displayValue: '', isInvalid: true };
97
+ try {
98
+ const fmt = fieldFormat ?? 'P';
99
+ const start = format(startDate, fmt);
100
+ const end = endDate ? format(endDate, fmt) : '';
101
+ return { displayValue: end ? `${start} – ${end}` : start, isInvalid: false };
102
+ }
103
+ catch {
104
+ return { displayValue: '', isInvalid: true };
105
+ }
106
+ }, [value, fieldFormat]);
91
107
  const handleClick = () => {
92
- if (!props.disabled && !props.readOnly) {
93
- pickerContext.setOpen((prev) => !prev);
108
+ if (!disabled && !readOnly) {
109
+ setOpen((prev) => !prev);
94
110
  }
95
111
  };
96
- return (_jsx(StyledTextField, { ...props, inputRef: ref, onClick: handleClick, InputProps: {
97
- ...props.InputProps,
98
- disabled: !!props.readOnly || !!props.disabled,
112
+ return (_jsx(StyledTextField, { ref: ref, value: displayValue, label: label, disabled: disabled, readOnly: readOnly, error: isInvalid || error, required: required, helperText: isInvalid ? 'Fecha inválida' : helperText, size: size, labelMargin: labelMargin, inputRef: inputRef, onClick: handleClick, fullWidth: fullWidth, placeholder: "", slotProps: {
113
+ input: {
114
+ endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(CalendarIcon, { style: {
115
+ fontSize: size === 'small' ? 18 : 20,
116
+ opacity: disabled || readOnly ? 0.5 : 1,
117
+ } }) })),
118
+ readOnly: true,
119
+ },
99
120
  } }));
100
121
  });
101
122
  const formatDate = (date, showYear) => {
@@ -103,7 +124,7 @@ const formatDate = (date, showYear) => {
103
124
  return '';
104
125
  return format(date, showYear ? 'PP' : 'dd MMM');
105
126
  };
106
- function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = 'small', labelMargin = 5, value, onChange, ...others }) {
127
+ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = 'small', labelMargin = 5, value, onChange, inputRef, shortcuts, ...others }) {
107
128
  const [startDate, endDate] = value ?? [null, null];
108
129
  const hasCompleteRange = Boolean(startDate) && Boolean(endDate);
109
130
  const showYear = startDate &&
@@ -114,19 +135,16 @@ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = '
114
135
  const formattedStartDate = formatDate(startDate, Boolean(showYear));
115
136
  const formattedEndDate = formatDate(endDate, Boolean(showYear));
116
137
  const toolbarText = hasCompleteRange ? `${formattedStartDate} – ${formattedEndDate}` : '– –';
117
- return (_jsx(StyledDateRangePicker, { ...others, value: value, onChange: onChange, size: size, disabled: disabled, readOnly: readOnly, reduceAnimations: true, showDaysOutsideCurrentMonth: true, enableAccessibleFieldDOMStructure: false, slots: {
118
- //TODO: create system for shortcuts customs or default (enums)
119
- shortcuts: undefined,
120
- field: SingleInputDateRangeField,
138
+ return (_jsx(StyledDateRangePicker, { ...others, value: value, onChange: onChange, size: size, disabled: disabled, readOnly: readOnly, reduceAnimations: true, showDaysOutsideCurrentMonth: true, slots: {
139
+ field: CustomRangePickerField,
121
140
  day: StyledDay,
122
141
  dialog: StyledDialog,
123
142
  toolbar: StyledDateToolBar,
124
- openPickerIcon: CalendarIcon,
125
- textField: CustomTextField,
126
143
  }, slotProps: {
127
144
  actionBar: {
128
145
  actions: ['clear', 'accept'],
129
146
  },
147
+ shortcuts: shortcuts ? { items: shortcuts } : undefined,
130
148
  layout: {
131
149
  sx: {
132
150
  backgroundColor: '#ffffff',
@@ -157,19 +175,14 @@ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = '
157
175
  hidden: false,
158
176
  toolbarPlaceholder: toolbarText,
159
177
  },
160
- textField: {
178
+ field: {
161
179
  size,
162
180
  error,
163
181
  required: others.required,
164
- disabled,
165
- readOnly: !disabled && readOnly,
166
182
  helperText,
167
183
  labelMargin,
168
184
  fullWidth: true,
169
- placeholder: '',
170
- InputProps: {
171
- readOnly: !disabled && readOnly,
172
- },
185
+ inputRef,
173
186
  },
174
187
  } }));
175
188
  }
@@ -1,2 +1,2 @@
1
- declare const Styled: import("@emotion/styled").StyledComponent<import("@mui/material").MenuItemOwnProps & Omit<import("@mui/material").ButtonBaseOwnProps, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "children" | "className" | "style" | "classes" | "autoFocus" | "tabIndex" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "dense" | "disableGutters" | "divider" | "selected"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
1
+ declare const Styled: import("@emotion/styled").StyledComponent<import("@mui/material").MenuItemOwnProps & Omit<import("@mui/material").ButtonBaseOwnProps, keyof import("@mui/material").MenuItemOwnProps> & Omit<import("@mui/material").ButtonBaseOwnProps, "type" | "children" | "tabIndex" | "action" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "nativeButton" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | keyof import("@mui/material").MenuItemOwnProps> & import("@mui/material/OverridableComponent").CommonProps & Omit<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "type" | "children" | "className" | "style" | "classes" | "autoFocus" | "tabIndex" | "action" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "nativeButton" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "dense" | "disableGutters" | "divider" | "selected"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
2
2
  export default Styled;
@@ -6,12 +6,12 @@ export interface SelectorStyleProps {
6
6
  }
7
7
  export declare const StyledSelect: import("@emotion/styled").StyledComponent<(import("@mui/material").FilledSelectProps & import("@mui/material").BaseSelectProps<unknown> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>) | (import("@mui/material").StandardSelectProps & import("@mui/material").BaseSelectProps<unknown> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>) | (import("@mui/material").OutlinedSelectProps & import("@mui/material").BaseSelectProps<unknown> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>), {}, {}>;
8
8
  export declare const StyledInputLabel: import("@emotion/styled").StyledComponent<import("@mui/material").InputLabelOwnProps & Pick<import("@mui/material").FormLabelOwnProps, "color" | "filled"> & import("@mui/material/OverridableComponent").CommonProps & Omit<React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "required" | "size" | "color" | "children" | "className" | "style" | "classes" | "disabled" | "sx" | "margin" | "error" | "filled" | "variant" | "focused" | "disableAnimation" | "shrink"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
9
- component?: React.ElementType;
9
+ component?: React.ElementType | undefined;
10
10
  } & {
11
11
  open: boolean;
12
12
  }, {}, {}>;
13
13
  export declare const StyledHelperText: import("@emotion/styled").StyledComponent<import("@mui/material").FormHelperTextOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>, "required" | "children" | "className" | "style" | "classes" | "disabled" | "sx" | "margin" | "error" | "filled" | "variant" | "focused"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
14
- component?: React.ElementType;
14
+ component?: React.ElementType | undefined;
15
15
  }, {}, {}>;
16
16
  export type ErkSelectValue<Type extends string | number, Multiple, Clearable> = Multiple extends true ? Type[] : Clearable extends true ? Type | undefined : Type;
17
17
  export interface ErkSelectProps<Type extends string | number = string, Multiple extends boolean | undefined = false, Clearable extends boolean | undefined = true> extends Omit<MuiSelectProps, 'color' | 'onChange' | 'ref'>, SelectorStyleProps {