kamotive_ui 2.10.5 → 21.11.25
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/components/Comment/Comment.js +2 -2
- package/dist/components/Comment/Comment.module.css +1 -1
- package/dist/components/FileLoader/FileLoader.d.ts +3 -3
- package/dist/components/FileLoader/FileLoader.js +40 -11
- package/dist/components/IconButton/IconButton.module.css +1 -0
- package/dist/types/index.d.ts +6 -0
- package/package.json +1 -1
|
@@ -45,8 +45,8 @@ export const Comment = ({ id, value, style, className, username, avatar, creatio
|
|
|
45
45
|
React.createElement(Typography, { variant: "Body2-Medium", className: labelClasses }, username),
|
|
46
46
|
React.createElement(Typography, { variant: "Caption", className: styles.label, style: { color: '#8E8E93' } }, creationDate))),
|
|
47
47
|
canEdit && (React.createElement("div", { className: styles.iconsWrapper },
|
|
48
|
-
React.createElement(IconButton, { icon: React.createElement(IconPencilFilled, null), onClick: handleEditClick, size: "sm", style: { aspectRatio: 0 } }),
|
|
49
|
-
React.createElement(IconButton, { icon: React.createElement(IconDeleteFilled, null), onClick: handleDeleteClick, size: "sm", style: { aspectRatio: 0 } })))),
|
|
48
|
+
React.createElement(IconButton, { icon: React.createElement(IconPencilFilled, null), onClick: handleEditClick, size: "sm", style: { aspectRatio: 0, width: '30px', height: '30px' } }),
|
|
49
|
+
React.createElement(IconButton, { icon: React.createElement(IconDeleteFilled, null), onClick: handleDeleteClick, size: "sm", style: { aspectRatio: 0, width: '30px', height: '30px' } })))),
|
|
50
50
|
isEditMode ? (React.createElement(TextEditor, { defaultValue: commentText, onSubmit: handleSubmit, onChange: handleChange, error: error, helperText: helperText, files: attachedFiles, canAttachFiles: canAttachFiles })) : (React.createElement("div", { className: styles.commentWrapper },
|
|
51
51
|
attachedFiles.length > 0 && (React.createElement(AttachedFilesPreview, { files: attachedFiles, className: styles.attachedFilesContainer })),
|
|
52
52
|
React.createElement("div", { id: id, className: inputClassess, dangerouslySetInnerHTML: { __html: commentText || '' } }))),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FileLoaderProps } from '../../types';
|
|
3
|
-
export declare const FileLoader:
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileLoaderHandle, FileLoaderProps } from '../../types';
|
|
3
|
+
export declare const FileLoader: React.ForwardRefExoticComponent<FileLoaderProps & React.RefAttributes<FileLoaderHandle>>;
|
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
|
|
2
2
|
import { useDropzone } from 'react-dropzone';
|
|
3
3
|
import styles from './FileLoader.module.css';
|
|
4
4
|
import { Typography } from '../Typography/Typography';
|
|
5
5
|
import { IconUpload } from '../../Icons';
|
|
6
6
|
import { FileItem } from '../FileItem/FileItem';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
|
-
export const FileLoader = ({ maxFileSize = 2, maxFileCount = 10, acceptedFormats = {
|
|
8
|
+
export const FileLoader = forwardRef(({ maxFileSize = 2, maxFileCount = 10, acceptedFormats = {
|
|
9
9
|
'image/*': ['.png', '.gif', '.jpeg', '.jpg'],
|
|
10
10
|
'application/pdf': ['.pdf'],
|
|
11
|
-
'application/msword': ['.doc', '.docx'],
|
|
12
|
-
}, addedFiles, setAddedFiles, filesList = [], canAdd = true, lng = 'ru', className, style, fileValidator, progressBarWidth }) => {
|
|
11
|
+
'application/msword': ['.doc', '.docx', '.log', '.syslog', '.txt'],
|
|
12
|
+
}, rejectedFormats, addedFiles, setAddedFiles, filesList = [], canAdd = true, lng = 'ru', className, style, fileValidator, progressBarWidth }, ref) => {
|
|
13
13
|
const [isLoadingFiles, setIsLoadingFiles] = useState(false);
|
|
14
14
|
const [loadingFilesNames, setLoadingFilesNames] = useState([]);
|
|
15
15
|
const [errorFiles, setErrorFiles] = useState([]);
|
|
16
16
|
const [addedFilesFormated, setAddedFilesFormatted] = useState([]);
|
|
17
|
+
useImperativeHandle(ref, () => ({
|
|
18
|
+
clearErrorFiles: () => {
|
|
19
|
+
setErrorFiles([]);
|
|
20
|
+
},
|
|
21
|
+
clearAllFiles: () => {
|
|
22
|
+
setErrorFiles([]);
|
|
23
|
+
setAddedFiles([]);
|
|
24
|
+
setAddedFilesFormatted([]);
|
|
25
|
+
setLoadingFilesNames([]);
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
17
28
|
const fileValidatorInner = (file) => {
|
|
18
29
|
if (file.size > maxFileSize * 1024 * 1024 * 1024) {
|
|
19
30
|
return {
|
|
@@ -43,7 +54,7 @@ export const FileLoader = ({ maxFileSize = 2, maxFileCount = 10, acceptedFormats
|
|
|
43
54
|
message: lng === 'ru' || lng.includes('ru') ? `Максимальное количество файлов ${maxFileCount}` : `Maximum number of files ${maxFileCount}`,
|
|
44
55
|
};
|
|
45
56
|
}
|
|
46
|
-
if (acceptedFormats) {
|
|
57
|
+
if (acceptedFormats && !rejectedFormats) {
|
|
47
58
|
const acceptedExtensions = Object.values(acceptedFormats)
|
|
48
59
|
.reduce((acc, val) => acc.concat(val), []);
|
|
49
60
|
const fileParts = file.name.split('.');
|
|
@@ -59,6 +70,22 @@ export const FileLoader = ({ maxFileSize = 2, maxFileCount = 10, acceptedFormats
|
|
|
59
70
|
};
|
|
60
71
|
}
|
|
61
72
|
}
|
|
73
|
+
if (rejectedFormats) {
|
|
74
|
+
const rejectedExtensions = Object.values(rejectedFormats)
|
|
75
|
+
.reduce((acc, val) => acc.concat(val), []);
|
|
76
|
+
const fileParts = file.name.split('.');
|
|
77
|
+
const fileExtension = fileParts.length > 1
|
|
78
|
+
? `.${fileParts.pop().toLowerCase()}`
|
|
79
|
+
: '';
|
|
80
|
+
if (rejectedExtensions.includes(fileExtension)) {
|
|
81
|
+
return {
|
|
82
|
+
code: 'file-invalid-type',
|
|
83
|
+
message: lng === 'ru' || lng.includes('ru')
|
|
84
|
+
? `Файл не должен быть одного из следующих типов: ${getAcceptedFormatsString(rejectedFormats)}`
|
|
85
|
+
: `File must not be one of: ${getAcceptedFormatsString(rejectedFormats)}`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
62
89
|
if (fileValidator) {
|
|
63
90
|
const customValidationResult = fileValidator(file);
|
|
64
91
|
if (customValidationResult) {
|
|
@@ -149,13 +176,15 @@ export const FileLoader = ({ maxFileSize = 2, maxFileCount = 10, acceptedFormats
|
|
|
149
176
|
const fileRejectionItems = errorFiles.map(({ file, errors }) => (React.createElement(FileItem, { key: file.id, file: file, error: errors[0].message, onDelete: handleDeleteRejectedFile, isRejectedFile: true })));
|
|
150
177
|
// Функция для получения всех доступных форматов в виде строки
|
|
151
178
|
const getAcceptedFormatsString = (acceptedFormats) => {
|
|
152
|
-
const
|
|
179
|
+
const uniqueFormats = new Set();
|
|
153
180
|
for (const key in acceptedFormats) {
|
|
154
181
|
if (acceptedFormats.hasOwnProperty(key)) {
|
|
155
|
-
|
|
182
|
+
acceptedFormats[key].forEach((format) => {
|
|
183
|
+
uniqueFormats.add(format.replace('.', ''));
|
|
184
|
+
});
|
|
156
185
|
}
|
|
157
186
|
}
|
|
158
|
-
return
|
|
187
|
+
return Array.from(uniqueFormats).join(', ');
|
|
159
188
|
};
|
|
160
189
|
useEffect(() => {
|
|
161
190
|
if (addedFiles.length === 0) {
|
|
@@ -189,9 +218,9 @@ export const FileLoader = ({ maxFileSize = 2, maxFileCount = 10, acceptedFormats
|
|
|
189
218
|
React.createElement("br", null)))),
|
|
190
219
|
maxFileCount &&
|
|
191
220
|
(lng === 'ru' || lng.includes('ru') ? (React.createElement(Typography, { variant: "Body2", color: "var(--grey-medium)" }, `За раз можно загрузить ${maxFileCount} ${maxFileCount > 1 ? `файлов` : `файл`}`)) : (React.createElement(Typography, { variant: "Body2", color: "var(--grey-medium)" }, `You can upload ${maxFileCount} ${maxFileCount > 1 ? `files` : `file`}`))))),
|
|
192
|
-
acceptedFormats &&
|
|
193
|
-
|
|
221
|
+
acceptedFormats && !rejectedFormats && (React.createElement(Typography, { variant: "Body2", color: "var(--grey-medium)" }, `${lng === 'ru' || lng.includes('ru') ? 'Поддерживаемые форматы:' : 'Supported formats:'} ${getAcceptedFormatsString(acceptedFormats)}`)),
|
|
222
|
+
rejectedFormats && (React.createElement(Typography, { variant: "Body2", color: "var(--grey-medium)" }, `${lng === 'ru' || lng.includes('ru') ? 'Неподдерживаемые форматы:' : 'Unsupported formats:'} ${getAcceptedFormatsString(rejectedFormats)}`)),
|
|
194
223
|
(addedFiles === null || addedFiles === void 0 ? void 0 : addedFiles.length) > 0 || (errorFiles === null || errorFiles === void 0 ? void 0 : errorFiles.length) > 0 ? (React.createElement("div", { className: styles['addedFiles'] },
|
|
195
224
|
acceptedFileItems,
|
|
196
225
|
fileRejectionItems)) : lng === 'ru' || lng.includes('ru') ? (React.createElement(Typography, { variant: "Body2-SemiBold", color: "var(--grey-medium)", style: { marginTop: '5px' } }, "\u0424\u0430\u0439\u043B\u044B \u043D\u0435 \u0434\u043E\u0431\u0430\u0432\u043B\u0435\u043D\u044B")) : (React.createElement(Typography, { variant: "Body2-SemiBold", color: "var(--grey-medium)", style: { marginTop: '5px' } }, "Files not added"))));
|
|
197
|
-
};
|
|
226
|
+
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -461,6 +461,8 @@ export interface FileLoaderProps {
|
|
|
461
461
|
maxFileCount?: number;
|
|
462
462
|
/**Поддерживаемые форматы файлов */
|
|
463
463
|
acceptedFormats?: Accept;
|
|
464
|
+
/** Неподдерживаемые форматы файлов */
|
|
465
|
+
rejectedFormats?: Accept;
|
|
464
466
|
/**Добавленные файлы */
|
|
465
467
|
addedFiles: File[];
|
|
466
468
|
/**Сосотояние для добавления файлов */
|
|
@@ -480,6 +482,10 @@ export interface FileLoaderProps {
|
|
|
480
482
|
/** Ширина прогресс бара */
|
|
481
483
|
progressBarWidth?: string;
|
|
482
484
|
}
|
|
485
|
+
export interface FileLoaderHandle {
|
|
486
|
+
clearErrorFiles: () => void;
|
|
487
|
+
clearAllFiles: () => void;
|
|
488
|
+
}
|
|
483
489
|
export interface DialogProps {
|
|
484
490
|
/** Флаг открытия окна */
|
|
485
491
|
open: boolean;
|