@cloud-ru/ds-attachment 1.0.0
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/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +312 -0
- package/dist/cjs/components/Attachment/Attachment.d.ts +2 -0
- package/dist/cjs/components/Attachment/Attachment.js +29 -0
- package/dist/cjs/components/Attachment/components/Emblem/Emblem.d.ts +5 -0
- package/dist/cjs/components/Attachment/components/Emblem/Emblem.js +30 -0
- package/dist/cjs/components/Attachment/components/Emblem/index.d.ts +1 -0
- package/dist/cjs/components/Attachment/components/Emblem/index.js +17 -0
- package/dist/cjs/components/Attachment/components/Emblem/styles.module.css +32 -0
- package/dist/cjs/components/Attachment/index.d.ts +1 -0
- package/dist/cjs/components/Attachment/index.js +17 -0
- package/dist/cjs/components/Attachment/styles.module.css +23 -0
- package/dist/cjs/components/AttachmentSquare/AttachmentSquare.d.ts +2 -0
- package/dist/cjs/components/AttachmentSquare/AttachmentSquare.js +53 -0
- package/dist/cjs/components/AttachmentSquare/components/HoverContent/HoverContent.d.ts +7 -0
- package/dist/cjs/components/AttachmentSquare/components/HoverContent/HoverContent.js +19 -0
- package/dist/cjs/components/AttachmentSquare/components/HoverContent/index.d.ts +1 -0
- package/dist/cjs/components/AttachmentSquare/components/HoverContent/index.js +17 -0
- package/dist/cjs/components/AttachmentSquare/components/HoverContent/styles.module.css +20 -0
- package/dist/cjs/components/AttachmentSquare/components/LoadingContent/LoadingContent.d.ts +1 -0
- package/dist/cjs/components/AttachmentSquare/components/LoadingContent/LoadingContent.js +14 -0
- package/dist/cjs/components/AttachmentSquare/components/LoadingContent/index.d.ts +1 -0
- package/dist/cjs/components/AttachmentSquare/components/LoadingContent/index.js +17 -0
- package/dist/cjs/components/AttachmentSquare/components/LoadingContent/styles.module.css +9 -0
- package/dist/cjs/components/AttachmentSquare/components/MainContent/MainContent.d.ts +7 -0
- package/dist/cjs/components/AttachmentSquare/components/MainContent/MainContent.js +22 -0
- package/dist/cjs/components/AttachmentSquare/components/MainContent/index.d.ts +1 -0
- package/dist/cjs/components/AttachmentSquare/components/MainContent/index.js +17 -0
- package/dist/cjs/components/AttachmentSquare/components/MainContent/styles.module.css +38 -0
- package/dist/cjs/components/AttachmentSquare/index.d.ts +1 -0
- package/dist/cjs/components/AttachmentSquare/index.js +17 -0
- package/dist/cjs/components/AttachmentSquare/styles.module.css +68 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/constants.d.ts +18 -0
- package/dist/cjs/constants.js +22 -0
- package/dist/cjs/context.d.ts +10 -0
- package/dist/cjs/context.js +17 -0
- package/dist/cjs/helperComponents/Actions/Actions.d.ts +7 -0
- package/dist/cjs/helperComponents/Actions/Actions.js +38 -0
- package/dist/cjs/helperComponents/Actions/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Actions/index.js +17 -0
- package/dist/cjs/helperComponents/Actions/styles.module.css +4 -0
- package/dist/cjs/helperComponents/Text/Text.d.ts +9 -0
- package/dist/cjs/helperComponents/Text/Text.js +15 -0
- package/dist/cjs/helperComponents/Text/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Text/index.js +17 -0
- package/dist/cjs/helperComponents/TextBlock/TextBlock.d.ts +5 -0
- package/dist/cjs/helperComponents/TextBlock/TextBlock.js +17 -0
- package/dist/cjs/helperComponents/TextBlock/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TextBlock/index.js +17 -0
- package/dist/cjs/helperComponents/TextBlock/styles.module.css +56 -0
- package/dist/cjs/helperComponents/index.d.ts +3 -0
- package/dist/cjs/helperComponents/index.js +19 -0
- package/dist/cjs/hooks.d.ts +4 -0
- package/dist/cjs/hooks.js +37 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +250 -0
- package/dist/cjs/types.d.ts +70 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +6 -0
- package/dist/cjs/utils.js +28 -0
- package/dist/esm/components/Attachment/Attachment.d.ts +2 -0
- package/dist/esm/components/Attachment/Attachment.js +23 -0
- package/dist/esm/components/Attachment/components/Emblem/Emblem.d.ts +5 -0
- package/dist/esm/components/Attachment/components/Emblem/Emblem.js +24 -0
- package/dist/esm/components/Attachment/components/Emblem/index.d.ts +1 -0
- package/dist/esm/components/Attachment/components/Emblem/index.js +1 -0
- package/dist/esm/components/Attachment/components/Emblem/styles.module.css +32 -0
- package/dist/esm/components/Attachment/index.d.ts +1 -0
- package/dist/esm/components/Attachment/index.js +1 -0
- package/dist/esm/components/Attachment/styles.module.css +23 -0
- package/dist/esm/components/AttachmentSquare/AttachmentSquare.d.ts +2 -0
- package/dist/esm/components/AttachmentSquare/AttachmentSquare.js +47 -0
- package/dist/esm/components/AttachmentSquare/components/HoverContent/HoverContent.d.ts +7 -0
- package/dist/esm/components/AttachmentSquare/components/HoverContent/HoverContent.js +13 -0
- package/dist/esm/components/AttachmentSquare/components/HoverContent/index.d.ts +1 -0
- package/dist/esm/components/AttachmentSquare/components/HoverContent/index.js +1 -0
- package/dist/esm/components/AttachmentSquare/components/HoverContent/styles.module.css +20 -0
- package/dist/esm/components/AttachmentSquare/components/LoadingContent/LoadingContent.d.ts +1 -0
- package/dist/esm/components/AttachmentSquare/components/LoadingContent/LoadingContent.js +8 -0
- package/dist/esm/components/AttachmentSquare/components/LoadingContent/index.d.ts +1 -0
- package/dist/esm/components/AttachmentSquare/components/LoadingContent/index.js +1 -0
- package/dist/esm/components/AttachmentSquare/components/LoadingContent/styles.module.css +9 -0
- package/dist/esm/components/AttachmentSquare/components/MainContent/MainContent.d.ts +7 -0
- package/dist/esm/components/AttachmentSquare/components/MainContent/MainContent.js +16 -0
- package/dist/esm/components/AttachmentSquare/components/MainContent/index.d.ts +1 -0
- package/dist/esm/components/AttachmentSquare/components/MainContent/index.js +1 -0
- package/dist/esm/components/AttachmentSquare/components/MainContent/styles.module.css +38 -0
- package/dist/esm/components/AttachmentSquare/index.d.ts +1 -0
- package/dist/esm/components/AttachmentSquare/index.js +1 -0
- package/dist/esm/components/AttachmentSquare/styles.module.css +68 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/constants.d.ts +18 -0
- package/dist/esm/constants.js +19 -0
- package/dist/esm/context.d.ts +10 -0
- package/dist/esm/context.js +12 -0
- package/dist/esm/helperComponents/Actions/Actions.d.ts +7 -0
- package/dist/esm/helperComponents/Actions/Actions.js +32 -0
- package/dist/esm/helperComponents/Actions/index.d.ts +1 -0
- package/dist/esm/helperComponents/Actions/index.js +1 -0
- package/dist/esm/helperComponents/Actions/styles.module.css +4 -0
- package/dist/esm/helperComponents/Text/Text.d.ts +9 -0
- package/dist/esm/helperComponents/Text/Text.js +12 -0
- package/dist/esm/helperComponents/Text/index.d.ts +1 -0
- package/dist/esm/helperComponents/Text/index.js +1 -0
- package/dist/esm/helperComponents/TextBlock/TextBlock.d.ts +5 -0
- package/dist/esm/helperComponents/TextBlock/TextBlock.js +11 -0
- package/dist/esm/helperComponents/TextBlock/index.d.ts +1 -0
- package/dist/esm/helperComponents/TextBlock/index.js +1 -0
- package/dist/esm/helperComponents/TextBlock/styles.module.css +56 -0
- package/dist/esm/helperComponents/index.d.ts +3 -0
- package/dist/esm/helperComponents/index.js +3 -0
- package/dist/esm/hooks.d.ts +4 -0
- package/dist/esm/hooks.js +34 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/style.css +250 -0
- package/dist/esm/types.d.ts +70 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +6 -0
- package/dist/esm/utils.js +22 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +50 -0
- package/src/components/Attachment/Attachment.tsx +79 -0
- package/src/components/Attachment/components/Emblem/Emblem.tsx +56 -0
- package/src/components/Attachment/components/Emblem/index.ts +1 -0
- package/src/components/Attachment/components/Emblem/styles.module.scss +34 -0
- package/src/components/Attachment/index.ts +1 -0
- package/src/components/Attachment/styles.module.scss +28 -0
- package/src/components/AttachmentSquare/AttachmentSquare.tsx +127 -0
- package/src/components/AttachmentSquare/components/HoverContent/HoverContent.tsx +34 -0
- package/src/components/AttachmentSquare/components/HoverContent/index.ts +1 -0
- package/src/components/AttachmentSquare/components/HoverContent/styles.module.scss +34 -0
- package/src/components/AttachmentSquare/components/LoadingContent/LoadingContent.tsx +14 -0
- package/src/components/AttachmentSquare/components/LoadingContent/index.ts +1 -0
- package/src/components/AttachmentSquare/components/LoadingContent/styles.module.scss +13 -0
- package/src/components/AttachmentSquare/components/MainContent/MainContent.tsx +43 -0
- package/src/components/AttachmentSquare/components/MainContent/index.ts +1 -0
- package/src/components/AttachmentSquare/components/MainContent/styles.module.scss +44 -0
- package/src/components/AttachmentSquare/index.ts +1 -0
- package/src/components/AttachmentSquare/styles.module.scss +95 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +21 -0
- package/src/context.tsx +28 -0
- package/src/helperComponents/Actions/Actions.tsx +90 -0
- package/src/helperComponents/Actions/index.ts +1 -0
- package/src/helperComponents/Actions/styles.module.scss +4 -0
- package/src/helperComponents/Text/Text.tsx +29 -0
- package/src/helperComponents/Text/index.ts +1 -0
- package/src/helperComponents/TextBlock/TextBlock.tsx +38 -0
- package/src/helperComponents/TextBlock/index.ts +1 -0
- package/src/helperComponents/TextBlock/styles.module.scss +53 -0
- package/src/helperComponents/index.ts +3 -0
- package/src/hooks.ts +40 -0
- package/src/index.ts +3 -0
- package/src/types.ts +74 -0
- package/src/utils.ts +30 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
|
|
3
|
+
$sizes: 's', 'm';
|
|
4
|
+
$title-typo: (
|
|
5
|
+
's': base.$sn-regular-label-m,
|
|
6
|
+
'm': base.$sn-regular-label-l,
|
|
7
|
+
);
|
|
8
|
+
$body-typo: (
|
|
9
|
+
's': base.$sn-regular-body-s,
|
|
10
|
+
'm': base.$sn-regular-body-m,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
// width:100% + min-width:0 — без них в column-flex с `align-items: center` (Square overlay)
|
|
14
|
+
// TruncateString берёт натуральную ширину текста и обходит truncate.
|
|
15
|
+
.content {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex: 1;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
|
|
20
|
+
width: 100%;
|
|
21
|
+
min-width: 0;
|
|
22
|
+
|
|
23
|
+
&[data-align='center'] {
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
text-align: center;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.title {
|
|
31
|
+
width: 100%;
|
|
32
|
+
min-width: 0;
|
|
33
|
+
color: base.$sn-theme-color-available-version-textMain;
|
|
34
|
+
|
|
35
|
+
@each $size in $sizes {
|
|
36
|
+
&[data-size='#{$size}'] {
|
|
37
|
+
@include base.composite-var($title-typo, $size);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.description {
|
|
43
|
+
width: 100%;
|
|
44
|
+
min-width: 0;
|
|
45
|
+
color: base.$sn-theme-color-available-version-textSecondary;
|
|
46
|
+
|
|
47
|
+
@each $size in $sizes {
|
|
48
|
+
&[data-size='#{$size}'] {
|
|
49
|
+
@include base.composite-var($body-typo, $size);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { isFileImage } from './utils';
|
|
4
|
+
|
|
5
|
+
export function useImage(file?: File) {
|
|
6
|
+
const [imageData, setImageData] = useState<string | undefined>(undefined);
|
|
7
|
+
const [loading, setIsLoading] = useState<boolean>(false);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!file || !isFileImage(file)) {
|
|
11
|
+
setImageData(undefined);
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const reader = new FileReader();
|
|
16
|
+
let aborted = false;
|
|
17
|
+
|
|
18
|
+
reader.onloadstart = () => {
|
|
19
|
+
if (!aborted) setIsLoading(true);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
reader.onloadend = () => {
|
|
23
|
+
if (aborted) return;
|
|
24
|
+
setIsLoading(false);
|
|
25
|
+
const { result } = reader;
|
|
26
|
+
if (result) setImageData(result.toString());
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
reader.readAsDataURL(file);
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
aborted = true;
|
|
33
|
+
if (reader.readyState === FileReader.LOADING) {
|
|
34
|
+
reader.abort();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, [file]);
|
|
38
|
+
|
|
39
|
+
return { imageData, loading };
|
|
40
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IconPredefinedProps } from '@cloud-ru/ds-icon-predefined';
|
|
2
|
+
import { TruncateStringProps } from '@cloud-ru/ds-truncate-string';
|
|
3
|
+
import { ValueOf, WithSupportProps } from '@cloud-ru/ds-utils';
|
|
4
|
+
import { MouseEvent } from 'react';
|
|
5
|
+
|
|
6
|
+
import { SIZE } from './constants';
|
|
7
|
+
|
|
8
|
+
export type Size = ValueOf<typeof SIZE>;
|
|
9
|
+
|
|
10
|
+
export type AttachmentSquareProps = WithSupportProps<{
|
|
11
|
+
/** Файл */
|
|
12
|
+
file?: File;
|
|
13
|
+
/** Колбек на клик по кнопке скачивания */
|
|
14
|
+
onDownload?(file?: File | undefined): void;
|
|
15
|
+
/** Колбек на клик по кнопке удаления */
|
|
16
|
+
onDelete?(file?: File | undefined): void;
|
|
17
|
+
/** Колбек на клик по кнопке повторения */
|
|
18
|
+
onRetry?(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Заголовок
|
|
21
|
+
* @default fileName
|
|
22
|
+
*/
|
|
23
|
+
title?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Описание
|
|
26
|
+
* @default fileExtension
|
|
27
|
+
*/
|
|
28
|
+
description?: string;
|
|
29
|
+
/** Сообщение об ошибке */
|
|
30
|
+
error?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Вариант обрезания строки:
|
|
33
|
+
* <br> - `end` — с конца;
|
|
34
|
+
* <br> - `middle` — по середине
|
|
35
|
+
*/
|
|
36
|
+
truncateVariant?: TruncateStringProps['variant'];
|
|
37
|
+
/** Управление состоянием загрузки */
|
|
38
|
+
loading?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Иконка для файла
|
|
41
|
+
* @defaultIcon FileSVG
|
|
42
|
+
*/
|
|
43
|
+
icon?: IconPredefinedProps['icon'];
|
|
44
|
+
/** Размер */
|
|
45
|
+
size?: Size;
|
|
46
|
+
/** Состояние «выбран» (множественный выбор) */
|
|
47
|
+
checked?: boolean;
|
|
48
|
+
/** Заблокировано */
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** Клик по карточке */
|
|
51
|
+
onClick?(event: MouseEvent<HTMLDivElement>): void;
|
|
52
|
+
/** CSS-класс корня */
|
|
53
|
+
className?: string;
|
|
54
|
+
}>;
|
|
55
|
+
|
|
56
|
+
export type AttachmentProps = AttachmentSquareProps & {
|
|
57
|
+
truncate?: {
|
|
58
|
+
/**
|
|
59
|
+
* Максимальное кол-во строк заголовка
|
|
60
|
+
* @default 1
|
|
61
|
+
*/
|
|
62
|
+
title?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Максимальное кол-во строк описания
|
|
65
|
+
* @default 1
|
|
66
|
+
*/
|
|
67
|
+
description?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Максимальное кол-во строк ошибки
|
|
70
|
+
* @default 1
|
|
71
|
+
*/
|
|
72
|
+
error?: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IconPredefinedProps, SIZE as IP_SIZE } from '@cloud-ru/ds-icon-predefined';
|
|
2
|
+
|
|
3
|
+
import { Size } from './types';
|
|
4
|
+
|
|
5
|
+
export const EMBLEM_ICON_SIZE: Record<Size, IconPredefinedProps['size']> = {
|
|
6
|
+
s: IP_SIZE.M,
|
|
7
|
+
m: IP_SIZE.L,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function getBaseFileName(fileName?: string) {
|
|
11
|
+
if (!fileName) {
|
|
12
|
+
return fileName;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const parts = fileName.split('.');
|
|
16
|
+
parts.pop();
|
|
17
|
+
|
|
18
|
+
// Файлы без имени (.bashrc, .gitignore) — возвращаем исходное имя.
|
|
19
|
+
if (parts.length === 1 && parts[0] === '') return fileName;
|
|
20
|
+
|
|
21
|
+
return parts.join('.');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getFileExtension(fileName?: string) {
|
|
25
|
+
return fileName?.split('.').pop()?.toLocaleUpperCase();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isFileImage(file: File) {
|
|
29
|
+
return Boolean(file.type.match(/image\/(png|jpg|jpeg|gif|webp|bmp|svg)/i));
|
|
30
|
+
}
|