tp-react-elements 1.0.1 → 1.0.3
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/_virtual/index.esm12.js +2 -2
- package/dist/_virtual/index.esm14.js +2 -2
- package/dist/_virtual/index.esm5.js +2 -2
- package/dist/_virtual/index.esm6.js +2 -2
- package/dist/components/Form/Form.styles.esm.js +1 -1
- package/dist/components/FormComponents/FileUpload/FormRenderFileUpload.esm.js +34 -8
- package/dist/components/FormComponents/FileUpload/FormRenderMultiFileUpload.esm.js +42 -25
- package/dist/components/FormComponents/FileUpload/MultiFileWithPreview.esm.js +41 -21
- package/dist/node_modules/react-date-range/dist/components/Calendar/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/DefinedRange/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/InputRangeField/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/Month/index.esm.js +1 -1
- package/dist/utils/Interface/FormInterface.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var InputRangeField = {};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { InputRangeField as __exports };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Month = {};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Month as __exports };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var DefinedRange = {};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { DefinedRange as __exports };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Calendar = {};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Calendar as __exports };
|
|
@@ -29,7 +29,7 @@ const Formitem = styled(Grid, {
|
|
|
29
29
|
paddingRight: '15px',
|
|
30
30
|
marginBottom: theme.spacing(1),
|
|
31
31
|
[theme.breakpoints.down('md')]: {
|
|
32
|
-
width:
|
|
32
|
+
width: `calc(100%/${noOfColumn})`,
|
|
33
33
|
},
|
|
34
34
|
}));
|
|
35
35
|
const ErrorMessageComponent = styled(Box)(({ theme }) => ({
|
|
@@ -25,9 +25,38 @@ const FormRenderFileUpload = ({ props, variant, }) => {
|
|
|
25
25
|
document: ['doc', 'docx', 'pdf'],
|
|
26
26
|
all: ['pdf', 'jpg', 'jpeg', 'png', 'xls', 'xlsx', 'doc', 'docx', 'zip'],
|
|
27
27
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const getValidExtensions = () => {
|
|
29
|
+
const fileType = props.item.fileType;
|
|
30
|
+
if (!fileType) {
|
|
31
|
+
return extensionMap.all;
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(fileType)) {
|
|
34
|
+
// Check if array contains predefined keys (like 'image', 'pdf') or actual extensions
|
|
35
|
+
const hasPredefinedKeys = fileType.some((item) => extensionMap[item]);
|
|
36
|
+
if (hasPredefinedKeys) {
|
|
37
|
+
// Merge extensions from all predefined keys
|
|
38
|
+
const extensions = new Set();
|
|
39
|
+
fileType.forEach((item) => {
|
|
40
|
+
if (extensionMap[item]) {
|
|
41
|
+
extensionMap[item].forEach((ext) => extensions.add(ext));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Treat as direct extension
|
|
45
|
+
extensions.add(item);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return Array.from(extensions);
|
|
49
|
+
}
|
|
50
|
+
// All items are direct extensions
|
|
51
|
+
return fileType;
|
|
52
|
+
}
|
|
53
|
+
return extensionMap[fileType] || extensionMap.all;
|
|
54
|
+
};
|
|
55
|
+
const getAcceptString = () => {
|
|
56
|
+
const extensions = getValidExtensions();
|
|
57
|
+
return extensions.map((ext) => `.${ext}`).join(',');
|
|
58
|
+
};
|
|
59
|
+
const accept = getAcceptString();
|
|
31
60
|
return (jsxs(Fragment, { children: [jsxs(Box, { paddingLeft: '4px', sx: { ...props.item.sx }, children: [props.item?.label && (jsx(Box, { sx: { fontSize: '10px;' }, children: renderLabel(variant, props, true) })), jsx(TextField, { type: "file", id: props.item.name, error: isShowBorderError, inputRef: inputRef, inputProps: {
|
|
32
61
|
accept,
|
|
33
62
|
'aria-labelledby': `${props.item.name}-label`,
|
|
@@ -36,14 +65,11 @@ const FormRenderFileUpload = ({ props, variant, }) => {
|
|
|
36
65
|
}, onChange: (event) => {
|
|
37
66
|
const file = event.target?.files[0];
|
|
38
67
|
const fileName = file ? file.name : null;
|
|
39
|
-
const allowedExtensions = extensionMap;
|
|
40
68
|
const fileExtension = fileName ? fileName.split('.').pop().toLowerCase() : null;
|
|
41
|
-
const validExtensions =
|
|
42
|
-
? allowedExtensions[props.item.fileType]
|
|
43
|
-
: allowedExtensions.all;
|
|
69
|
+
const validExtensions = getValidExtensions();
|
|
44
70
|
if (props.item?.fileType && fileExtension && !validExtensions.includes(fileExtension)) {
|
|
45
71
|
props.item?.handleFileError &&
|
|
46
|
-
props.item?.handleFileError(`Please upload ${
|
|
72
|
+
props.item?.handleFileError(`Please upload ${validExtensions.join(', ')} files only`);
|
|
47
73
|
event.target.value = ''; // Clear the file input\
|
|
48
74
|
props.setValue(props.item?.name, null);
|
|
49
75
|
props.setValue(props.item?.name + 'Name', '');
|
|
@@ -18,17 +18,48 @@ const FormRenderMultiFileUpload = ({ props, variant, }) => {
|
|
|
18
18
|
}, [watched]);
|
|
19
19
|
const isError = !!props.errors?.[props.item.name];
|
|
20
20
|
const isShowBorderError = isError;
|
|
21
|
+
const extensionMap = {
|
|
22
|
+
excel: ['xls', 'xlsx'],
|
|
23
|
+
pdf: ['pdf'],
|
|
24
|
+
zip: ['zip'],
|
|
25
|
+
image: ['jpg', 'jpeg', 'png'],
|
|
26
|
+
document: ['doc', 'docx', 'pdf'],
|
|
27
|
+
all: ['pdf', 'jpg', 'jpeg', 'png', 'xls', 'xlsx', 'doc', 'docx', 'zip'],
|
|
28
|
+
};
|
|
29
|
+
const getValidExtensions = () => {
|
|
30
|
+
const fileType = props.item.fileType;
|
|
31
|
+
if (!fileType) {
|
|
32
|
+
return extensionMap.all;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(fileType)) {
|
|
35
|
+
// Check if array contains predefined keys (like 'image', 'pdf') or actual extensions
|
|
36
|
+
const hasPredefinedKeys = fileType.some((item) => extensionMap[item]);
|
|
37
|
+
if (hasPredefinedKeys) {
|
|
38
|
+
// Merge extensions from all predefined keys
|
|
39
|
+
const extensions = new Set();
|
|
40
|
+
fileType.forEach((item) => {
|
|
41
|
+
if (extensionMap[item]) {
|
|
42
|
+
extensionMap[item].forEach((ext) => extensions.add(ext));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Treat as direct extension
|
|
46
|
+
extensions.add(item);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return Array.from(extensions);
|
|
50
|
+
}
|
|
51
|
+
// All items are direct extensions
|
|
52
|
+
return fileType;
|
|
53
|
+
}
|
|
54
|
+
return extensionMap[fileType] || extensionMap.all;
|
|
55
|
+
};
|
|
56
|
+
const getAcceptString = () => {
|
|
57
|
+
const extensions = getValidExtensions();
|
|
58
|
+
return extensions.map((ext) => `.${ext}`).join(',');
|
|
59
|
+
};
|
|
21
60
|
return (jsxs(Fragment, { children: [jsxs(Box, { paddingLeft: '4px', sx: { ...props.item.sx }, children: [props.item?.label && (jsx(Box, { sx: { fontSize: '10px;' }, children: renderLabel(variant, props, true) })), jsx(TextField, { type: "file", id: props.item.name, error: isShowBorderError, inputRef: inputRef, inputProps: {
|
|
22
61
|
multiple: true,
|
|
23
|
-
accept:
|
|
24
|
-
? '.xls,.xlsx'
|
|
25
|
-
: props.item.fileType === 'pdf'
|
|
26
|
-
? '.pdf'
|
|
27
|
-
: props.item.fileType === 'image'
|
|
28
|
-
? '.jpg,.jpeg,.png'
|
|
29
|
-
: props.item.fileType === 'all'
|
|
30
|
-
? '.pdf,.jpg,.jpeg,.png,.xls,.xlsx,.doc,.docx'
|
|
31
|
-
: '',
|
|
62
|
+
accept: getAcceptString(),
|
|
32
63
|
'aria-labelledby': `${props.item.name}-label`,
|
|
33
64
|
'aria-describedby': `${props.item.name}-helper ${props.item.name}-error`,
|
|
34
65
|
'aria-required': props.item.required ? true : undefined,
|
|
@@ -39,14 +70,6 @@ const FormRenderMultiFileUpload = ({ props, variant, }) => {
|
|
|
39
70
|
.map((item) => item.name)
|
|
40
71
|
.join(',')
|
|
41
72
|
: null;
|
|
42
|
-
const allowedExtensions = {
|
|
43
|
-
excel: ['xls', 'xlsx'],
|
|
44
|
-
pdf: ['pdf'],
|
|
45
|
-
image: ['jpg', 'jpeg', 'png'],
|
|
46
|
-
all: ['pdf', 'jpg', 'jpeg', 'png', 'xls', 'xlsx', 'doc', 'docx', 'zip'],
|
|
47
|
-
zip: ['zip'],
|
|
48
|
-
document: ['doc', 'docx', 'pdf'],
|
|
49
|
-
};
|
|
50
73
|
let fileExtension = null;
|
|
51
74
|
if (fileName) {
|
|
52
75
|
const ext = fileName.split('.').pop();
|
|
@@ -54,16 +77,10 @@ const FormRenderMultiFileUpload = ({ props, variant, }) => {
|
|
|
54
77
|
fileExtension = ext.toLowerCase();
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
|
-
const validExtensions =
|
|
58
|
-
? allowedExtensions.excel
|
|
59
|
-
: props.item.fileType === 'pdf'
|
|
60
|
-
? allowedExtensions.pdf
|
|
61
|
-
: props.item.fileType === 'image'
|
|
62
|
-
? allowedExtensions.image
|
|
63
|
-
: allowedExtensions.all;
|
|
80
|
+
const validExtensions = getValidExtensions();
|
|
64
81
|
if (props.item?.fileType && fileExtension && !validExtensions.includes(fileExtension)) {
|
|
65
82
|
props.item?.handleFileError &&
|
|
66
|
-
props.item?.handleFileError(`Please upload ${
|
|
83
|
+
props.item?.handleFileError(`Please upload ${validExtensions.join(', ')} files only`);
|
|
67
84
|
event.target.value = ''; // Clear the file input\
|
|
68
85
|
props.setValue(props.item?.name, null);
|
|
69
86
|
props.setValue(props.item?.name + 'Name', '');
|
|
@@ -73,23 +73,51 @@ const MultiFileWithPreview = ({ props, variant, }) => {
|
|
|
73
73
|
}
|
|
74
74
|
}, [watched]);
|
|
75
75
|
const isError = !!props.errors?.[props.item.name];
|
|
76
|
+
const extensionMap = {
|
|
77
|
+
excel: ['xls', 'xlsx'],
|
|
78
|
+
pdf: ['pdf'],
|
|
79
|
+
image: ['jpg', 'jpeg', 'png'],
|
|
80
|
+
all: ['pdf', 'jpg', 'jpeg', 'png', 'xls', 'xlsx', 'doc', 'docx', 'zip'],
|
|
81
|
+
zip: ['zip'],
|
|
82
|
+
document: ['doc', 'docx', 'pdf'],
|
|
83
|
+
};
|
|
84
|
+
const getValidExtensions = () => {
|
|
85
|
+
const fileType = props.item.fileType;
|
|
86
|
+
if (!fileType) {
|
|
87
|
+
return extensionMap.all;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(fileType)) {
|
|
90
|
+
// Check if array contains predefined keys (like 'image', 'pdf') or actual extensions
|
|
91
|
+
const hasPredefinedKeys = fileType.some((item) => extensionMap[item]);
|
|
92
|
+
if (hasPredefinedKeys) {
|
|
93
|
+
// Merge extensions from all predefined keys
|
|
94
|
+
const extensions = new Set();
|
|
95
|
+
fileType.forEach((item) => {
|
|
96
|
+
if (extensionMap[item]) {
|
|
97
|
+
extensionMap[item].forEach((ext) => extensions.add(ext));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Treat as direct extension
|
|
101
|
+
extensions.add(item);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return Array.from(extensions);
|
|
105
|
+
}
|
|
106
|
+
// All items are direct extensions
|
|
107
|
+
return fileType;
|
|
108
|
+
}
|
|
109
|
+
return extensionMap[fileType] || extensionMap.all;
|
|
110
|
+
};
|
|
111
|
+
const getAcceptString = () => {
|
|
112
|
+
const extensions = getValidExtensions();
|
|
113
|
+
return extensions.map((ext) => `.${ext}`).join(',');
|
|
114
|
+
};
|
|
76
115
|
const handleFileChange = (event) => {
|
|
77
116
|
const files = event.target.files;
|
|
78
117
|
if (!files)
|
|
79
118
|
return;
|
|
80
119
|
const fileArray = Array.from(files);
|
|
81
|
-
const
|
|
82
|
-
excel: ['xls', 'xlsx'],
|
|
83
|
-
pdf: ['pdf'],
|
|
84
|
-
image: ['jpg', 'jpeg', 'png'],
|
|
85
|
-
all: ['pdf', 'jpg', 'jpeg', 'png', 'xls', 'xlsx', 'doc', 'docx', 'zip']};
|
|
86
|
-
const validExtensions = props.item.fileType === 'excel'
|
|
87
|
-
? allowedExtensions.excel
|
|
88
|
-
: props.item.fileType === 'pdf'
|
|
89
|
-
? allowedExtensions.pdf
|
|
90
|
-
: props.item.fileType === 'image'
|
|
91
|
-
? allowedExtensions.image
|
|
92
|
-
: allowedExtensions.all;
|
|
120
|
+
const validExtensions = getValidExtensions();
|
|
93
121
|
const invalidFile = fileArray.find((file) => {
|
|
94
122
|
const ext = file.name.split('.').pop()?.toLowerCase();
|
|
95
123
|
return !ext || !validExtensions.includes(ext);
|
|
@@ -208,15 +236,7 @@ const MultiFileWithPreview = ({ props, variant, }) => {
|
|
|
208
236
|
: `${selectedFiles.length} file(s) selected`
|
|
209
237
|
: isSingleFileMode
|
|
210
238
|
? 'Upload File'
|
|
211
|
-
: 'Upload Files', jsx("input", { type: "file", hidden: true, multiple: !isSingleFileMode, accept: props.item.
|
|
212
|
-
? '.xls,.xlsx'
|
|
213
|
-
: props.item.fileType === 'pdf'
|
|
214
|
-
? '.pdf'
|
|
215
|
-
: props.item.fileType === 'image'
|
|
216
|
-
? '.jpg,.jpeg,.png'
|
|
217
|
-
: props.item.fileType === 'all'
|
|
218
|
-
? '.pdf,.jpg,.jpeg,.png,.xls,.xlsx,.doc,.docx'
|
|
219
|
-
: '', ref: inputRef, onChange: handleFileChange })] }), jsx(Box, { sx: { width: 36, display: 'flex', justifyContent: 'center' }, children: props.item.showFileCarousel && selectedFiles.length > 0 ? (jsx(IconButton, { onClick: handlePreviewClick, color: "primary", size: "small", "aria-label": "preview selected files", children: jsx(VisibilityIcon, {}) })) : null })] })] }), jsx(FormBottomField, { ...props }), jsx(Modal, { open: open, onClose: handleClose, children: jsxs(Box, { sx: {
|
|
239
|
+
: 'Upload Files', jsx("input", { type: "file", hidden: true, multiple: !isSingleFileMode, accept: getAcceptString(), ref: inputRef, onChange: handleFileChange })] }), jsx(Box, { sx: { width: 36, display: 'flex', justifyContent: 'center' }, children: props.item.showFileCarousel && selectedFiles.length > 0 ? (jsx(IconButton, { onClick: handlePreviewClick, color: "primary", size: "small", "aria-label": "preview selected files", children: jsx(VisibilityIcon, {}) })) : null })] })] }), jsx(FormBottomField, { ...props }), jsx(Modal, { open: open, onClose: handleClose, children: jsxs(Box, { sx: {
|
|
220
240
|
position: 'absolute',
|
|
221
241
|
top: '50%',
|
|
222
242
|
left: '50%',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as Calendar } from '../../../../../_virtual/index.
|
|
1
|
+
import { __exports as Calendar } from '../../../../../_virtual/index.esm6.js';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
|
|
4
4
|
import { __require as requireDayCell } from '../DayCell/index.esm.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as DefinedRange } from '../../../../../_virtual/index.
|
|
1
|
+
import { __exports as DefinedRange } from '../../../../../_virtual/index.esm5.js';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
|
|
4
4
|
import { __require as requireStyles } from '../../styles.esm.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as InputRangeField } from '../../../../../_virtual/index.
|
|
1
|
+
import { __exports as InputRangeField } from '../../../../../_virtual/index.esm12.js';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as Month } from '../../../../../_virtual/index.
|
|
1
|
+
import { __exports as Month } from '../../../../../_virtual/index.esm14.js';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { __require as requirePropTypes } from '../../../../prop-types/index.esm.js';
|
|
4
4
|
import { __require as requireDayCell } from '../DayCell/index.esm.js';
|
|
@@ -41,7 +41,7 @@ export interface FormSectionPropsItem {
|
|
|
41
41
|
sx?: SxProps<Theme>;
|
|
42
42
|
donotAllowSpace?: boolean;
|
|
43
43
|
onInputProps?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
44
|
-
fileType?: 'excel' | 'pdf' | 'all' | 'zip' | 'image' | 'document' | '';
|
|
44
|
+
fileType?: 'excel' | 'pdf' | 'all' | 'zip' | 'image' | 'document' | '' | string[];
|
|
45
45
|
handleFileError?: (message: string) => void;
|
|
46
46
|
onCloseMenu?: () => void;
|
|
47
47
|
doNotAllowPaste?: boolean;
|