@snack-uikit/attachment 0.0.1-preview-8b6f4393.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 +5 -0
- package/LICENSE +201 -0
- package/README.md +51 -0
- package/dist/components/Attachment/Attachment.d.ts +2 -0
- package/dist/components/Attachment/Attachment.js +28 -0
- package/dist/components/Attachment/components/Emblem/Emblem.d.ts +5 -0
- package/dist/components/Attachment/components/Emblem/Emblem.js +20 -0
- package/dist/components/Attachment/components/Emblem/index.d.ts +1 -0
- package/dist/components/Attachment/components/Emblem/index.js +1 -0
- package/dist/components/Attachment/components/Emblem/styled.module.css +15 -0
- package/dist/components/Attachment/components/index.d.ts +1 -0
- package/dist/components/Attachment/components/index.js +1 -0
- package/dist/components/Attachment/index.d.ts +1 -0
- package/dist/components/Attachment/index.js +1 -0
- package/dist/components/Attachment/styles.module.css +15 -0
- package/dist/components/AttachmentSquare/AttachmentSquare.d.ts +2 -0
- package/dist/components/AttachmentSquare/AttachmentSquare.js +27 -0
- package/dist/components/AttachmentSquare/components/HoverContent/HoverContent.d.ts +4 -0
- package/dist/components/AttachmentSquare/components/HoverContent/HoverContent.js +11 -0
- package/dist/components/AttachmentSquare/components/HoverContent/index.d.ts +1 -0
- package/dist/components/AttachmentSquare/components/HoverContent/index.js +1 -0
- package/dist/components/AttachmentSquare/components/LoadingContent/LoadingContent.d.ts +1 -0
- package/dist/components/AttachmentSquare/components/LoadingContent/LoadingContent.js +8 -0
- package/dist/components/AttachmentSquare/components/LoadingContent/index.d.ts +1 -0
- package/dist/components/AttachmentSquare/components/LoadingContent/index.js +1 -0
- package/dist/components/AttachmentSquare/components/MainContent/MainContent.d.ts +6 -0
- package/dist/components/AttachmentSquare/components/MainContent/MainContent.js +19 -0
- package/dist/components/AttachmentSquare/components/MainContent/index.d.ts +1 -0
- package/dist/components/AttachmentSquare/components/MainContent/index.js +1 -0
- package/dist/components/AttachmentSquare/components/index.d.ts +3 -0
- package/dist/components/AttachmentSquare/components/index.js +3 -0
- package/dist/components/AttachmentSquare/components/styles.module.css +12 -0
- package/dist/components/AttachmentSquare/index.d.ts +1 -0
- package/dist/components/AttachmentSquare/index.js +1 -0
- package/dist/components/AttachmentSquare/styles.module.css +16 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/contexts.d.ts +5 -0
- package/dist/contexts.js +5 -0
- package/dist/helperComponents/Actions/Actions.d.ts +6 -0
- package/dist/helperComponents/Actions/Actions.js +20 -0
- package/dist/helperComponents/Actions/index.d.ts +1 -0
- package/dist/helperComponents/Actions/index.js +1 -0
- package/dist/helperComponents/Actions/styles.module.css +5 -0
- package/dist/helperComponents/Text/Text.d.ts +5 -0
- package/dist/helperComponents/Text/Text.js +10 -0
- package/dist/helperComponents/Text/index.d.ts +1 -0
- package/dist/helperComponents/Text/index.js +1 -0
- package/dist/helperComponents/Text/styles.module.css +16 -0
- package/dist/helperComponents/TextBlock/TextBlock.d.ts +5 -0
- package/dist/helperComponents/TextBlock/TextBlock.js +9 -0
- package/dist/helperComponents/TextBlock/index.d.ts +1 -0
- package/dist/helperComponents/TextBlock/index.js +1 -0
- package/dist/helperComponents/TextBlock/styles.module.css +68 -0
- package/dist/helperComponents/index.d.ts +2 -0
- package/dist/helperComponents/index.js +2 -0
- package/dist/helpers.d.ts +3 -0
- package/dist/helpers.js +18 -0
- package/dist/hooks.d.ts +4 -0
- package/dist/hooks.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +1 -0
- package/package.json +45 -0
- package/src/components/Attachment/Attachment.tsx +55 -0
- package/src/components/Attachment/components/Emblem/Emblem.tsx +47 -0
- package/src/components/Attachment/components/Emblem/index.ts +1 -0
- package/src/components/Attachment/components/Emblem/styled.module.scss +16 -0
- package/src/components/Attachment/components/index.ts +1 -0
- package/src/components/Attachment/index.ts +1 -0
- package/src/components/Attachment/styles.module.scss +20 -0
- package/src/components/AttachmentSquare/AttachmentSquare.tsx +56 -0
- package/src/components/AttachmentSquare/components/HoverContent/HoverContent.tsx +24 -0
- package/src/components/AttachmentSquare/components/HoverContent/index.ts +1 -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/MainContent/MainContent.tsx +44 -0
- package/src/components/AttachmentSquare/components/MainContent/index.ts +1 -0
- package/src/components/AttachmentSquare/components/index.ts +3 -0
- package/src/components/AttachmentSquare/components/styles.module.scss +17 -0
- package/src/components/AttachmentSquare/index.ts +1 -0
- package/src/components/AttachmentSquare/styles.module.scss +25 -0
- package/src/components/index.ts +2 -0
- package/src/contexts.ts +14 -0
- package/src/helperComponents/Actions/Actions.tsx +48 -0
- package/src/helperComponents/Actions/index.ts +1 -0
- package/src/helperComponents/Actions/styles.module.scss +8 -0
- package/src/helperComponents/Text/Text.tsx +22 -0
- package/src/helperComponents/Text/index.ts +1 -0
- package/src/helperComponents/Text/styles.module.scss +24 -0
- package/src/helperComponents/TextBlock/TextBlock.tsx +22 -0
- package/src/helperComponents/TextBlock/index.ts +1 -0
- package/src/helperComponents/TextBlock/styles.module.scss +63 -0
- package/src/helperComponents/index.ts +2 -0
- package/src/helpers.ts +21 -0
- package/src/hooks.ts +33 -0
- package/src/index.ts +3 -0
- package/src/types.ts +47 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ButtonFunction } from '@snack-uikit/button';
|
|
2
|
+
import { DownloadSVG, TrashSVG } from '@snack-uikit/icons';
|
|
3
|
+
|
|
4
|
+
import { useAttachmentContext } from '../../contexts';
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
|
|
7
|
+
type ActionsProps = {
|
|
8
|
+
hideDownload?: boolean;
|
|
9
|
+
hideDelete?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function Actions({ hideDelete, hideDownload }: ActionsProps) {
|
|
13
|
+
const { onDelete, onDownload, file, disabled } = useAttachmentContext();
|
|
14
|
+
|
|
15
|
+
const showDownload = onDownload && !hideDownload;
|
|
16
|
+
const showDelete = onDelete && !hideDelete;
|
|
17
|
+
|
|
18
|
+
if (!showDownload && !showDelete) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div className={styles.actions}>
|
|
24
|
+
{showDownload && (
|
|
25
|
+
<ButtonFunction
|
|
26
|
+
disabled={disabled}
|
|
27
|
+
size='xs'
|
|
28
|
+
icon={<DownloadSVG />}
|
|
29
|
+
onClick={e => {
|
|
30
|
+
onDownload(file);
|
|
31
|
+
e.stopPropagation();
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
{showDelete && (
|
|
36
|
+
<ButtonFunction
|
|
37
|
+
disabled={disabled}
|
|
38
|
+
size='xs'
|
|
39
|
+
icon={<TrashSVG />}
|
|
40
|
+
onClick={e => {
|
|
41
|
+
onDelete(file);
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
)}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Actions';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
2
|
+
|
|
3
|
+
import { useAttachmentContext } from '../../contexts';
|
|
4
|
+
|
|
5
|
+
export type TextProps = {
|
|
6
|
+
text?: string;
|
|
7
|
+
className: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function Text({ text, className }: TextProps) {
|
|
11
|
+
const { truncateVariant } = useAttachmentContext();
|
|
12
|
+
|
|
13
|
+
if (!text) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className={className}>
|
|
19
|
+
<TruncateString text={text} maxLines={1} variant={truncateVariant} />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Text';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-attachment';
|
|
2
|
+
|
|
3
|
+
.wrapper {
|
|
4
|
+
@include composite-var($attachment-container-square);
|
|
5
|
+
|
|
6
|
+
.main {
|
|
7
|
+
display: flex;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.hover {
|
|
11
|
+
display: none;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&:hover,
|
|
15
|
+
&:focus-visible {
|
|
16
|
+
.hover {
|
|
17
|
+
display: flex;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.main {
|
|
21
|
+
display: none;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
|
|
3
|
+
import { useAttachmentContext } from '../../contexts';
|
|
4
|
+
import { AttachmentProps } from '../../types';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import styles from './styles.module.scss';
|
|
7
|
+
|
|
8
|
+
export type TextBlockProps = Pick<AttachmentProps, 'title' | 'description' | 'error' | 'className'> & {
|
|
9
|
+
align?: 'center' | 'left';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function TextBlock({ title, description, error, className, align = 'left' }: TextBlockProps) {
|
|
13
|
+
const { size } = useAttachmentContext();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div className={cn(styles.content, className)} data-size={size} data-align={align}>
|
|
17
|
+
<Text className={styles.title} text={title} />
|
|
18
|
+
<Text className={styles.description} text={description} />
|
|
19
|
+
<Text className={styles.error} text={error} />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TextBlock';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-attachment';
|
|
2
|
+
|
|
3
|
+
$sizes: 's', 'm';
|
|
4
|
+
|
|
5
|
+
$title: (
|
|
6
|
+
's': $sans-label-m,
|
|
7
|
+
'm': $sans-label-l,
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
$description: (
|
|
11
|
+
's': $sans-body-s,
|
|
12
|
+
'm': $sans-body-m,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
.content {
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
display: flex;
|
|
18
|
+
flex: 1;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
align-items: flex-start;
|
|
21
|
+
justify-content: flex-start;
|
|
22
|
+
|
|
23
|
+
&[data-align='left'] {
|
|
24
|
+
text-align: left;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&[data-align='center'] {
|
|
28
|
+
max-width: 100%;
|
|
29
|
+
text-align: center;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@each $size in $sizes {
|
|
33
|
+
&[data-size='#{$size}'] {
|
|
34
|
+
.title {
|
|
35
|
+
@include composite-var($title, $size);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.description,
|
|
39
|
+
.error {
|
|
40
|
+
@include composite-var($description, $size);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.title,
|
|
47
|
+
.description,
|
|
48
|
+
.error {
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
width: 100%;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.title {
|
|
54
|
+
color: $sys-neutral-text-main;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.description {
|
|
58
|
+
color: $sys-neutral-text-light;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.error {
|
|
62
|
+
color: $sys-red-text-support;
|
|
63
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getBaseFileName(fileName?: string) {
|
|
2
|
+
if (!fileName) {
|
|
3
|
+
return fileName;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const parts = fileName.split('.');
|
|
7
|
+
parts.pop();
|
|
8
|
+
|
|
9
|
+
// Для отображения названия файлов без имени (например, .bashrc, .gitignore)
|
|
10
|
+
if (parts.length === 1 && parts[0] === '') return fileName;
|
|
11
|
+
|
|
12
|
+
return parts.join('.');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getFileExtension(fileName?: string) {
|
|
16
|
+
return fileName?.split('.').pop()?.toLocaleUpperCase();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isFileImage(file: File) {
|
|
20
|
+
return file.type.match(/image\/(png|jpg|jpeg|gif|webp|bmp|svg)/i);
|
|
21
|
+
}
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { isFileImage } from './helpers';
|
|
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
|
+
const reader = new FileReader();
|
|
12
|
+
|
|
13
|
+
reader.onloadstart = () => {
|
|
14
|
+
setIsLoading(true);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
reader.onloadend = () => {
|
|
18
|
+
setIsLoading(false);
|
|
19
|
+
|
|
20
|
+
const { result } = reader;
|
|
21
|
+
if (result) {
|
|
22
|
+
setImageData(result.toString());
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
reader.readAsDataURL(file);
|
|
27
|
+
} else {
|
|
28
|
+
setImageData(undefined);
|
|
29
|
+
}
|
|
30
|
+
}, [file]);
|
|
31
|
+
|
|
32
|
+
return { imageData, loading };
|
|
33
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CardProps } from '@snack-uikit/card';
|
|
2
|
+
import { IconPredefinedProps } from '@snack-uikit/icon-predefined';
|
|
3
|
+
import { TruncateStringProps } from '@snack-uikit/truncate-string';
|
|
4
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
5
|
+
|
|
6
|
+
export type Size = 's' | 'm';
|
|
7
|
+
|
|
8
|
+
export type AttachmentCommonProps = WithSupportProps<{
|
|
9
|
+
/** Файл */
|
|
10
|
+
file?: File;
|
|
11
|
+
/** Колбек на клик по кнопке скачивания */
|
|
12
|
+
onDownload?(file?: File | undefined): void;
|
|
13
|
+
/** Колбек на клик по кнопке удаления */
|
|
14
|
+
onDelete?(file?: File | undefined): void;
|
|
15
|
+
/**
|
|
16
|
+
* Заголовок
|
|
17
|
+
* @default file.name
|
|
18
|
+
*/
|
|
19
|
+
title?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Описание
|
|
22
|
+
* @default file.type
|
|
23
|
+
*/
|
|
24
|
+
description?: string;
|
|
25
|
+
/** Сообщение об ошибке */
|
|
26
|
+
error?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Вариант обрезания строки:
|
|
29
|
+
* <br> - `End` - с конца;
|
|
30
|
+
* <br> - `Middle` - по середине
|
|
31
|
+
* */
|
|
32
|
+
truncateVariant?: TruncateStringProps['variant'];
|
|
33
|
+
/** Управление состоянием загрузки */
|
|
34
|
+
loading?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Объект сопоставления расширения файла и отображаемой иконки
|
|
37
|
+
* @defaultIcon FileSVG
|
|
38
|
+
*/
|
|
39
|
+
extension2Icon?: Record<string, IconPredefinedProps['icon']>;
|
|
40
|
+
}> &
|
|
41
|
+
Pick<CardProps, 'checked' | 'disabled' | 'multipleSelection' | 'onClick' | 'className'>;
|
|
42
|
+
|
|
43
|
+
export type AttachmentSquareProps = AttachmentCommonProps;
|
|
44
|
+
export type AttachmentProps = AttachmentCommonProps & {
|
|
45
|
+
/** Размер */
|
|
46
|
+
size?: Size;
|
|
47
|
+
};
|