@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.
Files changed (163) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +201 -0
  3. package/README.md +312 -0
  4. package/dist/cjs/components/Attachment/Attachment.d.ts +2 -0
  5. package/dist/cjs/components/Attachment/Attachment.js +29 -0
  6. package/dist/cjs/components/Attachment/components/Emblem/Emblem.d.ts +5 -0
  7. package/dist/cjs/components/Attachment/components/Emblem/Emblem.js +30 -0
  8. package/dist/cjs/components/Attachment/components/Emblem/index.d.ts +1 -0
  9. package/dist/cjs/components/Attachment/components/Emblem/index.js +17 -0
  10. package/dist/cjs/components/Attachment/components/Emblem/styles.module.css +32 -0
  11. package/dist/cjs/components/Attachment/index.d.ts +1 -0
  12. package/dist/cjs/components/Attachment/index.js +17 -0
  13. package/dist/cjs/components/Attachment/styles.module.css +23 -0
  14. package/dist/cjs/components/AttachmentSquare/AttachmentSquare.d.ts +2 -0
  15. package/dist/cjs/components/AttachmentSquare/AttachmentSquare.js +53 -0
  16. package/dist/cjs/components/AttachmentSquare/components/HoverContent/HoverContent.d.ts +7 -0
  17. package/dist/cjs/components/AttachmentSquare/components/HoverContent/HoverContent.js +19 -0
  18. package/dist/cjs/components/AttachmentSquare/components/HoverContent/index.d.ts +1 -0
  19. package/dist/cjs/components/AttachmentSquare/components/HoverContent/index.js +17 -0
  20. package/dist/cjs/components/AttachmentSquare/components/HoverContent/styles.module.css +20 -0
  21. package/dist/cjs/components/AttachmentSquare/components/LoadingContent/LoadingContent.d.ts +1 -0
  22. package/dist/cjs/components/AttachmentSquare/components/LoadingContent/LoadingContent.js +14 -0
  23. package/dist/cjs/components/AttachmentSquare/components/LoadingContent/index.d.ts +1 -0
  24. package/dist/cjs/components/AttachmentSquare/components/LoadingContent/index.js +17 -0
  25. package/dist/cjs/components/AttachmentSquare/components/LoadingContent/styles.module.css +9 -0
  26. package/dist/cjs/components/AttachmentSquare/components/MainContent/MainContent.d.ts +7 -0
  27. package/dist/cjs/components/AttachmentSquare/components/MainContent/MainContent.js +22 -0
  28. package/dist/cjs/components/AttachmentSquare/components/MainContent/index.d.ts +1 -0
  29. package/dist/cjs/components/AttachmentSquare/components/MainContent/index.js +17 -0
  30. package/dist/cjs/components/AttachmentSquare/components/MainContent/styles.module.css +38 -0
  31. package/dist/cjs/components/AttachmentSquare/index.d.ts +1 -0
  32. package/dist/cjs/components/AttachmentSquare/index.js +17 -0
  33. package/dist/cjs/components/AttachmentSquare/styles.module.css +68 -0
  34. package/dist/cjs/components/index.d.ts +2 -0
  35. package/dist/cjs/components/index.js +18 -0
  36. package/dist/cjs/constants.d.ts +18 -0
  37. package/dist/cjs/constants.js +22 -0
  38. package/dist/cjs/context.d.ts +10 -0
  39. package/dist/cjs/context.js +17 -0
  40. package/dist/cjs/helperComponents/Actions/Actions.d.ts +7 -0
  41. package/dist/cjs/helperComponents/Actions/Actions.js +38 -0
  42. package/dist/cjs/helperComponents/Actions/index.d.ts +1 -0
  43. package/dist/cjs/helperComponents/Actions/index.js +17 -0
  44. package/dist/cjs/helperComponents/Actions/styles.module.css +4 -0
  45. package/dist/cjs/helperComponents/Text/Text.d.ts +9 -0
  46. package/dist/cjs/helperComponents/Text/Text.js +15 -0
  47. package/dist/cjs/helperComponents/Text/index.d.ts +1 -0
  48. package/dist/cjs/helperComponents/Text/index.js +17 -0
  49. package/dist/cjs/helperComponents/TextBlock/TextBlock.d.ts +5 -0
  50. package/dist/cjs/helperComponents/TextBlock/TextBlock.js +17 -0
  51. package/dist/cjs/helperComponents/TextBlock/index.d.ts +1 -0
  52. package/dist/cjs/helperComponents/TextBlock/index.js +17 -0
  53. package/dist/cjs/helperComponents/TextBlock/styles.module.css +56 -0
  54. package/dist/cjs/helperComponents/index.d.ts +3 -0
  55. package/dist/cjs/helperComponents/index.js +19 -0
  56. package/dist/cjs/hooks.d.ts +4 -0
  57. package/dist/cjs/hooks.js +37 -0
  58. package/dist/cjs/index.d.ts +3 -0
  59. package/dist/cjs/index.js +19 -0
  60. package/dist/cjs/package.json +3 -0
  61. package/dist/cjs/style.css +250 -0
  62. package/dist/cjs/types.d.ts +70 -0
  63. package/dist/cjs/types.js +2 -0
  64. package/dist/cjs/utils.d.ts +6 -0
  65. package/dist/cjs/utils.js +28 -0
  66. package/dist/esm/components/Attachment/Attachment.d.ts +2 -0
  67. package/dist/esm/components/Attachment/Attachment.js +23 -0
  68. package/dist/esm/components/Attachment/components/Emblem/Emblem.d.ts +5 -0
  69. package/dist/esm/components/Attachment/components/Emblem/Emblem.js +24 -0
  70. package/dist/esm/components/Attachment/components/Emblem/index.d.ts +1 -0
  71. package/dist/esm/components/Attachment/components/Emblem/index.js +1 -0
  72. package/dist/esm/components/Attachment/components/Emblem/styles.module.css +32 -0
  73. package/dist/esm/components/Attachment/index.d.ts +1 -0
  74. package/dist/esm/components/Attachment/index.js +1 -0
  75. package/dist/esm/components/Attachment/styles.module.css +23 -0
  76. package/dist/esm/components/AttachmentSquare/AttachmentSquare.d.ts +2 -0
  77. package/dist/esm/components/AttachmentSquare/AttachmentSquare.js +47 -0
  78. package/dist/esm/components/AttachmentSquare/components/HoverContent/HoverContent.d.ts +7 -0
  79. package/dist/esm/components/AttachmentSquare/components/HoverContent/HoverContent.js +13 -0
  80. package/dist/esm/components/AttachmentSquare/components/HoverContent/index.d.ts +1 -0
  81. package/dist/esm/components/AttachmentSquare/components/HoverContent/index.js +1 -0
  82. package/dist/esm/components/AttachmentSquare/components/HoverContent/styles.module.css +20 -0
  83. package/dist/esm/components/AttachmentSquare/components/LoadingContent/LoadingContent.d.ts +1 -0
  84. package/dist/esm/components/AttachmentSquare/components/LoadingContent/LoadingContent.js +8 -0
  85. package/dist/esm/components/AttachmentSquare/components/LoadingContent/index.d.ts +1 -0
  86. package/dist/esm/components/AttachmentSquare/components/LoadingContent/index.js +1 -0
  87. package/dist/esm/components/AttachmentSquare/components/LoadingContent/styles.module.css +9 -0
  88. package/dist/esm/components/AttachmentSquare/components/MainContent/MainContent.d.ts +7 -0
  89. package/dist/esm/components/AttachmentSquare/components/MainContent/MainContent.js +16 -0
  90. package/dist/esm/components/AttachmentSquare/components/MainContent/index.d.ts +1 -0
  91. package/dist/esm/components/AttachmentSquare/components/MainContent/index.js +1 -0
  92. package/dist/esm/components/AttachmentSquare/components/MainContent/styles.module.css +38 -0
  93. package/dist/esm/components/AttachmentSquare/index.d.ts +1 -0
  94. package/dist/esm/components/AttachmentSquare/index.js +1 -0
  95. package/dist/esm/components/AttachmentSquare/styles.module.css +68 -0
  96. package/dist/esm/components/index.d.ts +2 -0
  97. package/dist/esm/components/index.js +2 -0
  98. package/dist/esm/constants.d.ts +18 -0
  99. package/dist/esm/constants.js +19 -0
  100. package/dist/esm/context.d.ts +10 -0
  101. package/dist/esm/context.js +12 -0
  102. package/dist/esm/helperComponents/Actions/Actions.d.ts +7 -0
  103. package/dist/esm/helperComponents/Actions/Actions.js +32 -0
  104. package/dist/esm/helperComponents/Actions/index.d.ts +1 -0
  105. package/dist/esm/helperComponents/Actions/index.js +1 -0
  106. package/dist/esm/helperComponents/Actions/styles.module.css +4 -0
  107. package/dist/esm/helperComponents/Text/Text.d.ts +9 -0
  108. package/dist/esm/helperComponents/Text/Text.js +12 -0
  109. package/dist/esm/helperComponents/Text/index.d.ts +1 -0
  110. package/dist/esm/helperComponents/Text/index.js +1 -0
  111. package/dist/esm/helperComponents/TextBlock/TextBlock.d.ts +5 -0
  112. package/dist/esm/helperComponents/TextBlock/TextBlock.js +11 -0
  113. package/dist/esm/helperComponents/TextBlock/index.d.ts +1 -0
  114. package/dist/esm/helperComponents/TextBlock/index.js +1 -0
  115. package/dist/esm/helperComponents/TextBlock/styles.module.css +56 -0
  116. package/dist/esm/helperComponents/index.d.ts +3 -0
  117. package/dist/esm/helperComponents/index.js +3 -0
  118. package/dist/esm/hooks.d.ts +4 -0
  119. package/dist/esm/hooks.js +34 -0
  120. package/dist/esm/index.d.ts +3 -0
  121. package/dist/esm/index.js +3 -0
  122. package/dist/esm/style.css +250 -0
  123. package/dist/esm/types.d.ts +70 -0
  124. package/dist/esm/types.js +1 -0
  125. package/dist/esm/utils.d.ts +6 -0
  126. package/dist/esm/utils.js +22 -0
  127. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  128. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  129. package/package.json +50 -0
  130. package/src/components/Attachment/Attachment.tsx +79 -0
  131. package/src/components/Attachment/components/Emblem/Emblem.tsx +56 -0
  132. package/src/components/Attachment/components/Emblem/index.ts +1 -0
  133. package/src/components/Attachment/components/Emblem/styles.module.scss +34 -0
  134. package/src/components/Attachment/index.ts +1 -0
  135. package/src/components/Attachment/styles.module.scss +28 -0
  136. package/src/components/AttachmentSquare/AttachmentSquare.tsx +127 -0
  137. package/src/components/AttachmentSquare/components/HoverContent/HoverContent.tsx +34 -0
  138. package/src/components/AttachmentSquare/components/HoverContent/index.ts +1 -0
  139. package/src/components/AttachmentSquare/components/HoverContent/styles.module.scss +34 -0
  140. package/src/components/AttachmentSquare/components/LoadingContent/LoadingContent.tsx +14 -0
  141. package/src/components/AttachmentSquare/components/LoadingContent/index.ts +1 -0
  142. package/src/components/AttachmentSquare/components/LoadingContent/styles.module.scss +13 -0
  143. package/src/components/AttachmentSquare/components/MainContent/MainContent.tsx +43 -0
  144. package/src/components/AttachmentSquare/components/MainContent/index.ts +1 -0
  145. package/src/components/AttachmentSquare/components/MainContent/styles.module.scss +44 -0
  146. package/src/components/AttachmentSquare/index.ts +1 -0
  147. package/src/components/AttachmentSquare/styles.module.scss +95 -0
  148. package/src/components/index.ts +2 -0
  149. package/src/constants.ts +21 -0
  150. package/src/context.tsx +28 -0
  151. package/src/helperComponents/Actions/Actions.tsx +90 -0
  152. package/src/helperComponents/Actions/index.ts +1 -0
  153. package/src/helperComponents/Actions/styles.module.scss +4 -0
  154. package/src/helperComponents/Text/Text.tsx +29 -0
  155. package/src/helperComponents/Text/index.ts +1 -0
  156. package/src/helperComponents/TextBlock/TextBlock.tsx +38 -0
  157. package/src/helperComponents/TextBlock/index.ts +1 -0
  158. package/src/helperComponents/TextBlock/styles.module.scss +53 -0
  159. package/src/helperComponents/index.ts +3 -0
  160. package/src/hooks.ts +40 -0
  161. package/src/index.ts +3 -0
  162. package/src/types.ts +74 -0
  163. 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
+
@@ -0,0 +1,3 @@
1
+ export * from './Actions';
2
+ export * from './Text';
3
+ export * from './TextBlock';
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
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export * from './constants';
3
+ export * from './types';
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
+ }