@arquimedes.co/eureka-forms 3.0.45-mui9 → 3.0.45-next-fix
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/dist/@Types/FormStep.d.ts +2 -4
- package/dist/@Types/GenericFormSteps.d.ts +1 -1
- package/dist/App/AppHooks.js +13 -13
- package/dist/Form/ConfirmationDialog/ConfirmationDialog.js +5 -7
- package/dist/Form/Terms/Term/MaterialTerm/MaterialTerm.js +3 -5
- package/dist/FormSteps/@Construction/CBRPropertyStep/CBRPropertyStep.js +5 -7
- package/dist/FormSteps/AYFStepMapper.js +2 -2
- package/dist/FormSteps/DatePickerRangeStep/MaterialDatePickerRangeStep/MaterialDatePickerRangeStep.js +3 -3
- package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.js +5 -7
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.js +1 -1
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +1 -1
- package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.js +1 -1
- package/dist/FormSteps/StepFunctions.js +1 -1
- package/dist/Shared/ErkButton/ErkButton.stories.d.ts +16 -0
- package/dist/Shared/ErkButton/ErkButton.stories.js +28 -0
- package/dist/Shared/ErkCheckbox/ErkCheckBox.d.ts +0 -1
- package/dist/Shared/ErkCheckbox/ErkCheckBox.js +2 -2
- package/dist/Shared/ErkCheckbox/ErkCheckBox.stories.d.ts +13 -0
- package/dist/Shared/ErkCheckbox/ErkCheckBox.stories.js +34 -0
- package/dist/Shared/ErkDatePicker/ErkDatePicker.js +33 -44
- package/dist/Shared/ErkDatePicker/ErkDatePicker.stories.d.ts +23 -0
- package/dist/Shared/ErkDatePicker/ErkDatePicker.stories.js +98 -0
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +1 -4
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +23 -40
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.stories.d.ts +36 -0
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.stories.js +274 -0
- package/dist/Shared/ErkMenuItem.d.ts +1 -1
- package/dist/Shared/ErkSelect/ErkSelect.d.ts +2 -2
- package/dist/Shared/ErkSelect/ErkSelect.stories.d.ts +21 -0
- package/dist/Shared/ErkSelect/ErkSelect.stories.js +87 -0
- package/dist/Shared/ErkSmartSelect/ErkSmartSelect.stories.d.ts +26 -0
- package/dist/Shared/ErkSmartSelect/ErkSmartSelect.stories.js +159 -0
- package/dist/Shared/ErkTextField/ErkTextField.d.ts +2 -17
- package/dist/Shared/ErkTextField/ErkTextField.js +3 -3
- package/dist/Shared/ErkTextField/ErkTextField.stories.d.ts +24 -0
- package/dist/Shared/ErkTextField/ErkTextField.stories.js +99 -0
- package/dist/Shared/ErkTimePicker/ErkTimePicker.js +1 -1
- package/dist/Shared/Navbar/Navbar.stories.d.ts +13 -0
- package/dist/Shared/Navbar/Navbar.stories.js +13 -0
- package/dist/Shared/Rating/Rating.stories.d.ts +15 -0
- package/dist/Shared/Rating/Rating.stories.js +47 -0
- package/dist/Shared/Rating/Ratings/ScaleRating.js +1 -1
- package/dist/States/GlobalSlice.d.ts +26 -8
- package/dist/States/GlobalSlice.js +2 -3
- package/dist/States/SiteSlice.d.ts +33 -8
- package/dist/States/SiteSlice.js +9 -11
- package/dist/States/WidthStatsSlice.d.ts +1 -5
- package/dist/Utils/DraftFunctions.js +1 -1
- package/dist/index.css +0 -7
- package/dist/main.d.ts +1 -1
- package/dist/main.js +1 -1
- package/package.json +33 -34
- package/dist/FormSteps/@StoryDecorators/FormStepDecorator.d.ts +0 -9
- package/dist/FormSteps/@StoryDecorators/FormStepDecorator.js +0 -86
|
@@ -47,11 +47,9 @@ export interface TextInput extends GSteps.GTextInput {
|
|
|
47
47
|
}
|
|
48
48
|
export interface DatePicker extends GSteps.GDatePicker {
|
|
49
49
|
type: FormStepTypes.DATEPICKER;
|
|
50
|
-
defaultValue?: string;
|
|
51
50
|
}
|
|
52
51
|
export interface DatePickerRange extends GSteps.GDatePickerRange {
|
|
53
52
|
type: FormStepTypes.DATEPICKER_RANGE;
|
|
54
|
-
defaultValue?: string[];
|
|
55
53
|
}
|
|
56
54
|
export interface Collapsible extends GSteps.GBaseStep {
|
|
57
55
|
type: FormStepTypes.COLLAPSIBLE;
|
|
@@ -62,10 +60,10 @@ export interface Collapsible extends GSteps.GBaseStep {
|
|
|
62
60
|
export interface FormSelector extends GSteps.GBaseStep {
|
|
63
61
|
type: FormStepTypes.SELECTOR;
|
|
64
62
|
label: string;
|
|
65
|
-
description: string
|
|
63
|
+
description: string;
|
|
66
64
|
required: boolean;
|
|
67
65
|
searchable: boolean;
|
|
68
|
-
options:
|
|
66
|
+
options: FormSelectorOption[];
|
|
69
67
|
size: 1 | 2 | 3 | 4;
|
|
70
68
|
maxSize?: number;
|
|
71
69
|
defaultValue?: string;
|
package/dist/App/AppHooks.js
CHANGED
|
@@ -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, (
|
|
61
|
-
const firstSection =
|
|
62
|
-
if (firstSection.steps === undefined &&
|
|
63
|
-
firstSection.steps =
|
|
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;
|
|
64
64
|
}
|
|
65
65
|
//If a rootStep is a mapper of type section
|
|
66
|
-
if (classifiers)
|
|
67
|
-
|
|
66
|
+
if (form && classifiers)
|
|
67
|
+
form.classifiers = classifiers;
|
|
68
68
|
/** Assign the idSection to all the forms steps */
|
|
69
|
-
for (const section of Object.values(
|
|
69
|
+
for (const section of Object.values(form.sections)) {
|
|
70
70
|
for (const idStep of section.steps) {
|
|
71
|
-
iterateNestedSteps(idStep,
|
|
71
|
+
iterateNestedSteps(idStep, form.steps, (step, path) => {
|
|
72
72
|
step.idSection = section.id;
|
|
73
73
|
step.stepPath = path;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
for (const idStep of
|
|
77
|
-
iterateNestedSteps(idStep,
|
|
76
|
+
for (const idStep of form.hiddenSteps ?? []) {
|
|
77
|
+
iterateNestedSteps(idStep, form.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 ?? {});
|
|
83
86
|
});
|
|
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,13 +46,11 @@ function ConfirmationDialog({ onClose, confirmation, customConfirmation }) {
|
|
|
46
46
|
fontSize: widthStats.isMobile ? '1rem' : '1.2rem',
|
|
47
47
|
}, children: confirmation.url })] }));
|
|
48
48
|
};
|
|
49
|
-
return (_jsx(Dialog, {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
boxSizing: 'content-box',
|
|
55
|
-
},
|
|
49
|
+
return (_jsx(Dialog, { PaperProps: {
|
|
50
|
+
style: {
|
|
51
|
+
borderRadius: '20px',
|
|
52
|
+
maxWidth: '100vw',
|
|
53
|
+
boxSizing: 'content-box',
|
|
56
54
|
},
|
|
57
55
|
}, open: true, children: _jsxs("div", { className: styles.confirmationContainer, style: {
|
|
58
56
|
color: '#293241',
|
|
@@ -44,11 +44,9 @@ function TermComponent({ term, tempError }) {
|
|
|
44
44
|
return parts;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
return (_jsxs(React.Fragment, { children: [_jsx(Dialog, {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
borderRadius: '20px',
|
|
51
|
-
},
|
|
47
|
+
return (_jsxs(React.Fragment, { children: [_jsx(Dialog, { PaperProps: {
|
|
48
|
+
style: {
|
|
49
|
+
borderRadius: '20px',
|
|
52
50
|
},
|
|
53
51
|
}, onClose: () => {
|
|
54
52
|
setShowDialog(false);
|
|
@@ -66,13 +66,11 @@ function CBRPropertyStepComponent(props) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
: undefined, getOptions: getInmueblesOptions }), showWarning !== undefined && (_jsx(Dialog, {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
boxSizing: 'content-box',
|
|
75
|
-
},
|
|
69
|
+
: undefined, getOptions: getInmueblesOptions }), showWarning !== undefined && (_jsx(Dialog, { PaperProps: {
|
|
70
|
+
style: {
|
|
71
|
+
borderRadius: '20px',
|
|
72
|
+
maxWidth: '100vw',
|
|
73
|
+
boxSizing: 'content-box',
|
|
76
74
|
},
|
|
77
75
|
}, open: true, children: _jsxs("div", { className: styles.confirmationContainer, style: { color: formStyle.textColor }, children: [_jsx("div", { className: styles.closeIcon, onClick: () => {
|
|
78
76
|
setShowWarning(undefined);
|
|
@@ -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:
|
|
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
|
|
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:
|
|
81
|
+
return (_jsx(SmartSelectStep, { ...props, step: props.step, 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 (
|
|
24
|
-
onChange(
|
|
23
|
+
if (start && end) {
|
|
24
|
+
onChange([start.toISOString(), end.toISOString()]);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
onChange(
|
|
27
|
+
onChange(null);
|
|
28
28
|
}
|
|
29
29
|
}, [onChange]);
|
|
30
30
|
const [minDate, maxDate] = [safeDate(step.minDate), safeDate(step.maxDate)];
|
|
@@ -18,13 +18,11 @@ 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, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
boxSizing: 'content-box',
|
|
27
|
-
},
|
|
21
|
+
return (_jsx(Dialog, { PaperProps: {
|
|
22
|
+
style: {
|
|
23
|
+
borderRadius: '20px',
|
|
24
|
+
maxWidth: '100vw',
|
|
25
|
+
boxSizing: 'content-box',
|
|
28
26
|
},
|
|
29
27
|
}, 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: {
|
|
30
28
|
color: type === 'INFO' ? formStyle.primaryColor : formStyle.errorColor,
|
|
@@ -64,6 +64,6 @@ function FileUploadComponent({ file, formStyle, error, editable, handleRemove, f
|
|
|
64
64
|
}
|
|
65
65
|
}, children: file.file?.name ?? file.fileName }), editable && (_jsx("div", { className: styles.deletBtn, onClick: () => {
|
|
66
66
|
handleRemove();
|
|
67
|
-
}, children: _jsx(CloseIcon, {
|
|
67
|
+
}, children: _jsx(CloseIcon, { size: 24 }) }))] }));
|
|
68
68
|
}
|
|
69
69
|
export default FileUploadComponent;
|
|
@@ -58,7 +58,7 @@ function FileUploadStep({ step, editable }) {
|
|
|
58
58
|
postFile(pFile.file, pFile.postInfo),
|
|
59
59
|
new Promise((resolve) => setTimeout(resolve, 1000)),
|
|
60
60
|
]);
|
|
61
|
-
setFileChange(
|
|
61
|
+
setFileChange([{ ...pFile, state: 'DONE', ...resp[0] }]);
|
|
62
62
|
}
|
|
63
63
|
catch (error) {
|
|
64
64
|
console.error(error);
|
|
@@ -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
|
|
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()] }));
|
|
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
|
|
486
|
+
if (!property || property.type !== condition.propertyType) {
|
|
487
487
|
return false;
|
|
488
488
|
}
|
|
489
489
|
const value = entityValue[condition.idProperty];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import ErkButton from './ErkButton';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
component: typeof ErkButton;
|
|
5
|
+
tags: string[];
|
|
6
|
+
args: {
|
|
7
|
+
text: string;
|
|
8
|
+
disabled: false;
|
|
9
|
+
onClick: import("vitest").Mock<(...args: any[]) => any>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story = StoryObj<typeof meta>;
|
|
14
|
+
export declare const Default: Story;
|
|
15
|
+
export declare const Disabled: Story;
|
|
16
|
+
export declare const DifferentColors: Story;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { fn } from 'storybook/test';
|
|
2
|
+
import ErkButton from './ErkButton';
|
|
3
|
+
const meta = {
|
|
4
|
+
component: ErkButton,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
args: {
|
|
7
|
+
text: 'Label',
|
|
8
|
+
disabled: false,
|
|
9
|
+
onClick: fn(),
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
export const Default = {
|
|
14
|
+
args: {
|
|
15
|
+
text: 'Label',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export const Disabled = {
|
|
19
|
+
args: {
|
|
20
|
+
text: 'Label',
|
|
21
|
+
disabled: true,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export const DifferentColors = {
|
|
25
|
+
args: {
|
|
26
|
+
text: 'Label',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -9,7 +9,6 @@ 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>;
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* 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,
|
|
21
|
-
return (_jsx(FormControl, { error: true, children: _jsx(StyledCheckbox, { ...others, error: +error, readOnly: readOnly, disabled: disabled,
|
|
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) }) }));
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import ErkCheckBox from './ErkCheckBox';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
component: typeof ErkCheckBox;
|
|
5
|
+
tags: string[];
|
|
6
|
+
};
|
|
7
|
+
export default meta;
|
|
8
|
+
type Story = StoryObj<typeof meta>;
|
|
9
|
+
export declare const Uncheked: Story;
|
|
10
|
+
export declare const Checked: Story;
|
|
11
|
+
export declare const Error: Story;
|
|
12
|
+
export declare const Disabled: Story;
|
|
13
|
+
export declare const ErrorColor: Story;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ErkCheckBox from './ErkCheckBox';
|
|
2
|
+
const meta = {
|
|
3
|
+
component: ErkCheckBox,
|
|
4
|
+
tags: ['autodocs'],
|
|
5
|
+
};
|
|
6
|
+
export default meta;
|
|
7
|
+
export const Uncheked = {
|
|
8
|
+
args: {
|
|
9
|
+
checked: false,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export const Checked = {
|
|
13
|
+
args: {
|
|
14
|
+
checked: true,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const Error = {
|
|
18
|
+
args: {
|
|
19
|
+
checked: false,
|
|
20
|
+
error: true,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const Disabled = {
|
|
24
|
+
args: {
|
|
25
|
+
checked: false,
|
|
26
|
+
disabled: true,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export const ErrorColor = {
|
|
30
|
+
args: {
|
|
31
|
+
checked: false,
|
|
32
|
+
error: true,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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';
|
|
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';
|
|
7
5
|
import { StyledTextField } from '../ErkTextField/ErkTextField';
|
|
8
6
|
import CalendarIcon from '../../Icons/CalendarIcon';
|
|
9
7
|
import { renderTimeViewClock } from '@mui/x-date-pickers/timeViewRenderers';
|
|
@@ -138,36 +136,17 @@ const StyledDay = styled(MuiPickerDay)(({ theme }) => ({
|
|
|
138
136
|
},
|
|
139
137
|
},
|
|
140
138
|
}));
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
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]);
|
|
139
|
+
// eslint-disable-next-line react/display-name
|
|
140
|
+
const CustomTextField = forwardRef((props, ref) => {
|
|
141
|
+
const pickerContext = usePickerContext();
|
|
155
142
|
const handleClick = () => {
|
|
156
|
-
if (!disabled && !readOnly) {
|
|
157
|
-
setOpen((prev) => !prev);
|
|
143
|
+
if (!props.disabled && !props.readOnly) {
|
|
144
|
+
pickerContext.setOpen((prev) => !prev);
|
|
158
145
|
}
|
|
159
146
|
};
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
fontSize: size === 'small' ? 18 : 20,
|
|
164
|
-
opacity: disabled || readOnly ? 0.5 : 1,
|
|
165
|
-
} }) })),
|
|
166
|
-
readOnly: true,
|
|
167
|
-
},
|
|
168
|
-
} }));
|
|
169
|
-
}
|
|
170
|
-
function CustomDatePicker({ error, required, disabled, readOnly, helperText, size = 'small', labelMargin = 5, pickTime = false, inputRef,
|
|
147
|
+
return _jsx(StyledTextField, { ...props, inputRef: ref, onClick: handleClick });
|
|
148
|
+
});
|
|
149
|
+
function CustomDatePicker({ error, required, disabled, readOnly, helperText, size = 'small', labelMargin = 5, pickTime = false,
|
|
171
150
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
172
151
|
orientation: _orientation, ...others }) {
|
|
173
152
|
if (pickTime) {
|
|
@@ -210,14 +189,18 @@ orientation: _orientation, ...others }) {
|
|
|
210
189
|
hidden: false,
|
|
211
190
|
toolbarPlaceholder: '– –',
|
|
212
191
|
},
|
|
213
|
-
|
|
192
|
+
textField: {
|
|
214
193
|
error,
|
|
215
|
-
required,
|
|
216
|
-
helperText,
|
|
217
194
|
size,
|
|
195
|
+
disabled,
|
|
196
|
+
readOnly: !disabled && readOnly,
|
|
197
|
+
helperText,
|
|
218
198
|
labelMargin,
|
|
199
|
+
placeholder: '',
|
|
219
200
|
fullWidth: true,
|
|
220
|
-
|
|
201
|
+
InputProps: {
|
|
202
|
+
readOnly: !disabled && readOnly,
|
|
203
|
+
},
|
|
221
204
|
},
|
|
222
205
|
}, viewRenderers: {
|
|
223
206
|
hours: renderTimeViewClock,
|
|
@@ -227,8 +210,9 @@ orientation: _orientation, ...others }) {
|
|
|
227
210
|
day: StyledDay,
|
|
228
211
|
dialog: StyledDialog,
|
|
229
212
|
toolbar: StyledDateTimeToolBar,
|
|
230
|
-
|
|
231
|
-
|
|
213
|
+
textField: CustomTextField,
|
|
214
|
+
openPickerIcon: CalendarIcon,
|
|
215
|
+
}, enableAccessibleFieldDOMStructure: false }));
|
|
232
216
|
}
|
|
233
217
|
else {
|
|
234
218
|
return (_jsx(StyledDatePicker, { ...others, size: size, reduceAnimations: true, readOnly: readOnly, disabled: disabled, defaultValue: required ? new Date() : undefined, showDaysOutsideCurrentMonth: true, views: ['year', 'month', 'day'], slotProps: {
|
|
@@ -260,21 +244,26 @@ orientation: _orientation, ...others }) {
|
|
|
260
244
|
hidden: false,
|
|
261
245
|
toolbarPlaceholder: '– –',
|
|
262
246
|
},
|
|
263
|
-
|
|
247
|
+
textField: {
|
|
248
|
+
size,
|
|
264
249
|
error,
|
|
265
|
-
|
|
250
|
+
disabled,
|
|
251
|
+
readOnly: !disabled && readOnly,
|
|
266
252
|
helperText,
|
|
267
|
-
size,
|
|
268
253
|
labelMargin,
|
|
269
254
|
fullWidth: true,
|
|
270
|
-
|
|
255
|
+
placeholder: '',
|
|
256
|
+
InputProps: {
|
|
257
|
+
readOnly: !disabled && readOnly,
|
|
258
|
+
},
|
|
271
259
|
},
|
|
272
260
|
}, slots: {
|
|
273
261
|
day: StyledDay,
|
|
274
262
|
dialog: StyledDialog,
|
|
275
263
|
toolbar: StyledDateToolBar,
|
|
276
|
-
|
|
277
|
-
|
|
264
|
+
textField: CustomTextField,
|
|
265
|
+
openPickerIcon: CalendarIcon,
|
|
266
|
+
}, enableAccessibleFieldDOMStructure: false }));
|
|
278
267
|
}
|
|
279
268
|
}
|
|
280
269
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import ErkDatePicker from './ErkDatePicker';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
component: typeof ErkDatePicker;
|
|
5
|
+
tags: string[];
|
|
6
|
+
args: {
|
|
7
|
+
readOnly: false;
|
|
8
|
+
};
|
|
9
|
+
parameters: {
|
|
10
|
+
date: Date;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
export declare const Empty: Story;
|
|
16
|
+
export declare const Default: Story;
|
|
17
|
+
export declare const ValueAndLabel: Story;
|
|
18
|
+
export declare const Full: Story;
|
|
19
|
+
export declare const FullDateTime: Story;
|
|
20
|
+
export declare const Error: Story;
|
|
21
|
+
export declare const Menu: Story;
|
|
22
|
+
export declare const DateTimeDateMenu: Story;
|
|
23
|
+
export declare const DateTimeTimeMenu: Story;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import ErkDatePicker from './ErkDatePicker';
|
|
3
|
+
import { useArgs } from 'storybook/internal/preview-api';
|
|
4
|
+
const meta = {
|
|
5
|
+
component: ErkDatePicker,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
args: {
|
|
8
|
+
readOnly: false,
|
|
9
|
+
},
|
|
10
|
+
parameters: {
|
|
11
|
+
date: new Date('07-21-2021'),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default meta;
|
|
15
|
+
export const Empty = {
|
|
16
|
+
args: {
|
|
17
|
+
value: null,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export const Default = {
|
|
21
|
+
args: {
|
|
22
|
+
label: 'Label',
|
|
23
|
+
value: new Date('07-21-2021'),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export const ValueAndLabel = {
|
|
27
|
+
args: {
|
|
28
|
+
label: 'Label',
|
|
29
|
+
value: null,
|
|
30
|
+
},
|
|
31
|
+
render: function Component(args) {
|
|
32
|
+
const [, setArgs] = useArgs();
|
|
33
|
+
const onValueChange = (value) => {
|
|
34
|
+
args.onChange?.(value);
|
|
35
|
+
setArgs({ value });
|
|
36
|
+
};
|
|
37
|
+
return _jsx(ErkDatePicker, { ...args, onChange: onValueChange });
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const Full = {
|
|
41
|
+
args: {
|
|
42
|
+
label: 'Label',
|
|
43
|
+
value: null,
|
|
44
|
+
helperText: 'Helper text',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export const FullDateTime = {
|
|
48
|
+
args: {
|
|
49
|
+
label: 'Label',
|
|
50
|
+
value: null,
|
|
51
|
+
helperText: 'Helper text',
|
|
52
|
+
pickTime: true,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export const Error = {
|
|
56
|
+
args: {
|
|
57
|
+
label: 'Label',
|
|
58
|
+
value: null,
|
|
59
|
+
helperText: 'Helper text',
|
|
60
|
+
error: true,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
export const Menu = {
|
|
64
|
+
args: {
|
|
65
|
+
label: 'Label',
|
|
66
|
+
value: null,
|
|
67
|
+
},
|
|
68
|
+
play: async ({ canvas, userEvent }) => {
|
|
69
|
+
const selector = canvas.getByTestId('date-picker');
|
|
70
|
+
await userEvent.click(selector);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
export const DateTimeDateMenu = {
|
|
74
|
+
args: {
|
|
75
|
+
label: 'Label',
|
|
76
|
+
value: null,
|
|
77
|
+
pickTime: true,
|
|
78
|
+
},
|
|
79
|
+
play: async ({ canvas, userEvent }) => {
|
|
80
|
+
const selector = canvas.getByTestId('date-picker');
|
|
81
|
+
await userEvent.click(selector);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
export const DateTimeTimeMenu = {
|
|
85
|
+
args: {
|
|
86
|
+
label: 'Label',
|
|
87
|
+
value: null,
|
|
88
|
+
pickTime: true,
|
|
89
|
+
},
|
|
90
|
+
play: async ({ canvas, userEvent }) => {
|
|
91
|
+
const selector = canvas.getByTestId('date-picker');
|
|
92
|
+
await userEvent.click(selector);
|
|
93
|
+
const time = canvas.getByText('12', {
|
|
94
|
+
selector: 'h3',
|
|
95
|
+
});
|
|
96
|
+
await userEvent.click(time);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
@@ -1,16 +1,13 @@
|
|
|
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';
|
|
5
4
|
import { ErkTextFieldProps } from '../ErkTextField/ErkTextField';
|
|
6
|
-
interface ErkDateRangePickerProps extends Omit<MuiDateRangePickerProps
|
|
5
|
+
interface ErkDateRangePickerProps extends Omit<MuiDateRangePickerProps<boolean>, 'ref' | 'onChange' | 'value' | 'slotProps'>, Pick<ErkTextFieldProps, 'error' | 'required' | 'helperText' | 'size'> {
|
|
7
6
|
onChange?: (dateRange: DateRange<Date>) => void;
|
|
8
7
|
value?: DateRange<Date>;
|
|
9
8
|
inputRef?: React.Ref<HTMLInputElement>;
|
|
10
9
|
/** labelMargin */
|
|
11
10
|
labelMargin?: number;
|
|
12
|
-
/** Shortcuts to display in the picker */
|
|
13
|
-
shortcuts?: PickersShortcutsItem<DateRange<Date>>[];
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* Generic datepicker with apps designs. Is class due to the use in the react-hook-forms library
|