@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,32 @@
1
+ .loader{
2
+ display:inline-flex;
3
+ flex-shrink:0;
4
+ align-items:center;
5
+ justify-content:center;
6
+ color:var(--sn-theme-color-neutral-text, var(--sn-brand-color-neutral-45, var(--sn-primitive-color-gray-45, #81869c)));
7
+ }
8
+ .loader[data-size=s]{
9
+ width:var(--sn-attachment-anatomy-size-s-container-content-image-width, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
10
+ height:var(--sn-attachment-anatomy-size-s-container-content-image-height, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
11
+ }
12
+ .loader[data-size=m]{
13
+ width:var(--sn-attachment-anatomy-size-m-container-content-image-width, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
14
+ height:var(--sn-attachment-anatomy-size-m-container-content-image-height, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
15
+ }
16
+
17
+ .image{
18
+ display:block;
19
+ flex-shrink:0;
20
+ -o-object-fit:cover;
21
+ object-fit:cover;
22
+ }
23
+ .image[data-size=s]{
24
+ width:var(--sn-attachment-anatomy-size-s-container-content-image-width, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
25
+ height:var(--sn-attachment-anatomy-size-s-container-content-image-height, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
26
+ border-radius:var(--sn-attachment-anatomy-size-s-container-content-image-borderRadius, var(--sn-density-radius-xs, var(--sn-primitive-dimension-10, 10px)));
27
+ }
28
+ .image[data-size=m]{
29
+ width:var(--sn-attachment-anatomy-size-m-container-content-image-width, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
30
+ height:var(--sn-attachment-anatomy-size-m-container-content-image-height, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
31
+ border-radius:var(--sn-attachment-anatomy-size-m-container-content-image-borderRadius, var(--sn-density-radius-s, var(--sn-primitive-dimension-16, 16px)));
32
+ }
@@ -0,0 +1 @@
1
+ export * from './Attachment.js';
@@ -0,0 +1 @@
1
+ export * from './Attachment.js';
@@ -0,0 +1,23 @@
1
+ .root{
2
+ isolation:isolate;
3
+ display:inline-block;
4
+ width:-moz-fit-content;
5
+ width:fit-content;
6
+ max-width:100%;
7
+ }
8
+
9
+ .composition{
10
+ display:flex;
11
+ align-items:flex-start;
12
+ box-sizing:border-box;
13
+ width:100%;
14
+ min-width:0;
15
+ }
16
+ .composition[data-size=s]{
17
+ gap:var(--sn-attachment-anatomy-size-s-container-gap, var(--sn-primitive-dimension-8, 8px));
18
+ padding:var(--sn-attachment-anatomy-size-s-container-content-padding, var(--sn-primitive-dimension-8, 8px));
19
+ }
20
+ .composition[data-size=m]{
21
+ gap:var(--sn-attachment-anatomy-size-m-container-gap, var(--sn-primitive-dimension-8, 8px));
22
+ padding:var(--sn-attachment-anatomy-size-m-container-content-padding, var(--sn-primitive-dimension-16, 16px));
23
+ }
@@ -0,0 +1,2 @@
1
+ import { AttachmentSquareProps } from '../../types.js';
2
+ export declare function AttachmentSquare({ file, loading, icon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, onDownload, onDelete, onClick, onRetry, size, className, ...rest }: AttachmentSquareProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Card } from '@cloud-ru/ds-card';
3
+ import { BACKGROUND_PREDEFINED_FILL } from '@cloud-ru/ds-materials';
4
+ import { extractSupportProps } from '@cloud-ru/ds-utils';
5
+ import cn from 'classnames';
6
+ import { useState } from 'react';
7
+ import { AttachmentContext, AttachmentFocusActionsContext } from '../../context.js';
8
+ import { useImage } from '../../hooks.js';
9
+ import { getBaseFileName, getFileExtension } from '../../utils.js';
10
+ import { HoverContent } from './components/HoverContent/index.js';
11
+ import { LoadingContent } from './components/LoadingContent/index.js';
12
+ import { MainContent } from './components/MainContent/index.js';
13
+ import styles from './styles.module.css';
14
+ export function AttachmentSquare({ file, loading, icon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, onDownload, onDelete, onClick, onRetry, size = 's', className, ...rest }) {
15
+ const { loading: loadingImage, imageData } = useImage(file);
16
+ const isLoading = loading || loadingImage;
17
+ const title = titleProp || getBaseFileName(file?.name);
18
+ const description = descriptionProp || getFileExtension(file?.name);
19
+ const [hasFocusedActions, setHasFocusedActions] = useState(false);
20
+ const interactive = !isLoading && !disabled && Boolean(onClick);
21
+ const hasError = Boolean(error);
22
+ const hasActions = Boolean(onDownload || onDelete || onRetry);
23
+ const isChecked = !loading && !error && checked;
24
+ const isDisabled = !loading && disabled;
25
+ const handleKeyDown = (event) => {
26
+ if (!interactive || !onClick)
27
+ return;
28
+ if (event.key === 'Enter' || event.key === ' ') {
29
+ event.preventDefault();
30
+ onClick(event);
31
+ }
32
+ };
33
+ return (_jsx(Card, { ...extractSupportProps(rest), view: 'outline', radius: size === 's' ? 's' : 'm', backgroundPredefined: hasError ? BACKGROUND_PREDEFINED_FILL.RedBackground : BACKGROUND_PREDEFINED_FILL.NeutralBackground1Level, disabled: isDisabled, checked: isChecked, multiSelect: true, interactive: interactive, className: cn(styles.root, className), "data-attachment-error": hasError || undefined, "aria-busy": isLoading || undefined, children: _jsx(AttachmentContext.Provider, { value: {
34
+ file,
35
+ truncateVariant,
36
+ onDelete,
37
+ onDownload,
38
+ onRetry,
39
+ disabled,
40
+ size,
41
+ truncate: { title: 1, description: 1, error: 1 },
42
+ }, children: _jsx(AttachmentFocusActionsContext.Provider, { value: { focused: hasFocusedActions, setFocused: setHasFocusedActions }, children: _jsxs("div", { className: cn(styles.composition, {
43
+ [styles.hasFocusedActions]: hasFocusedActions,
44
+ }), "data-size": size, "data-loading": isLoading || undefined, "data-error": hasError || undefined, "data-has-actions": hasActions || undefined, onClick: interactive ? onClick : undefined, onKeyDown: interactive ? handleKeyDown : undefined, role: interactive ? 'button' : undefined,
45
+ // Card-корень уже фокусируется (tabIndex={0}); внутренний wrapper забирает только обработчики.
46
+ tabIndex: -1, children: [!isLoading && !hasError && (_jsx(MainContent, { title: title, description: description, icon: icon, imageData: imageData, className: styles.main })), !isLoading && !disabled && (_jsx(HoverContent, { title: title, description: description, error: error, hasImage: Boolean(imageData), className: styles.hover })), isLoading && _jsx(LoadingContent, {})] }) }) }) }));
47
+ }
@@ -0,0 +1,7 @@
1
+ import { AttachmentProps } from '../../../../types.js';
2
+ type HoverContentProps = Pick<AttachmentProps, 'title' | 'description' | 'error' | 'className'> & {
3
+ /** image-mode → overlay даёт title/description/actions поверх `<img>`; icon-mode → только actions поверх иконки. */
4
+ hasImage?: boolean;
5
+ };
6
+ export declare function HoverContent({ title, description, error, hasImage, className }: HoverContentProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import cn from 'classnames';
3
+ import { useAttachmentContext } from '../../../../context.js';
4
+ import { Actions, TextBlock } from '../../../../helperComponents/index.js';
5
+ import styles from './styles.module.css';
6
+ export function HoverContent({ title, description, error, hasImage, className }) {
7
+ const { size } = useAttachmentContext();
8
+ const hasError = Boolean(error);
9
+ const showOnHoverOnly = !hasError;
10
+ // Дублировать TextBlock из MainContent нельзя: два absolute-слоя того же текста дают визуальный bold.
11
+ const showText = hasImage || hasError;
12
+ return (_jsxs("div", { className: cn(styles.overlay, showOnHoverOnly && className), "data-size": size, "data-error": hasError || undefined, "data-mode": hasImage ? 'image' : 'icon', children: [showText && (_jsx(TextBlock, { title: title, error: error, description: !hasError ? description : undefined, align: 'center' })), _jsx(Actions, { hideDownload: hasError, hideRetry: !hasError })] }));
13
+ }
@@ -0,0 +1 @@
1
+ export * from './HoverContent.js';
@@ -0,0 +1 @@
1
+ export * from './HoverContent.js';
@@ -0,0 +1,20 @@
1
+ .overlay{
2
+ display:flex;
3
+ flex-direction:column;
4
+ gap:0;
5
+ align-items:center;
6
+ justify-content:center;
7
+ width:100%;
8
+ height:100%;
9
+ color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
10
+ background-color:transparent;
11
+ }
12
+ .overlay[data-mode=icon]:not([data-error]){
13
+ justify-content:flex-end;
14
+ }
15
+ .overlay[data-size=s]{
16
+ padding:var(--sn-attachment-anatomy-size-s-container-content-padding, var(--sn-primitive-dimension-8, 8px));
17
+ }
18
+ .overlay[data-size=m]{
19
+ padding:var(--sn-attachment-anatomy-size-m-container-content-padding, var(--sn-primitive-dimension-16, 16px));
20
+ }
@@ -0,0 +1 @@
1
+ export declare function LoadingContent(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Spinner } from '@cloud-ru/ds-loader';
3
+ import { TEST_IDS } from '../../../../constants.js';
4
+ import { Actions } from '../../../../helperComponents/index.js';
5
+ import styles from './styles.module.css';
6
+ export function LoadingContent() {
7
+ return (_jsxs("div", { className: styles.composition, "data-test-id": TEST_IDS.loadingSquare, children: [_jsx(Spinner, {}), _jsx(Actions, { hideDownload: true, hideRetry: true })] }));
8
+ }
@@ -0,0 +1 @@
1
+ export * from './LoadingContent.js';
@@ -0,0 +1 @@
1
+ export * from './LoadingContent.js';
@@ -0,0 +1,9 @@
1
+ .composition{
2
+ position:absolute;
3
+ inset:0;
4
+ display:flex;
5
+ flex-direction:column;
6
+ align-items:center;
7
+ justify-content:center;
8
+ color:var(--sn-theme-color-neutral-text, var(--sn-brand-color-neutral-45, var(--sn-primitive-color-gray-45, #81869c)));
9
+ }
@@ -0,0 +1,7 @@
1
+ import { AttachmentProps } from '../../../../types.js';
2
+ type MainContentProps = {
3
+ imageData?: string;
4
+ description?: string;
5
+ } & Pick<AttachmentProps, 'title' | 'icon' | 'className'>;
6
+ export declare function MainContent({ title, description, icon, imageData, className }: MainContentProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { IconPredefined } from '@cloud-ru/ds-icon-predefined';
3
+ import { FileSVG } from '@cloud-ru/ds-icons/interface/system';
4
+ import cn from 'classnames';
5
+ import { TEST_IDS } from '../../../../constants.js';
6
+ import { useAttachmentContext } from '../../../../context.js';
7
+ import { TextBlock } from '../../../../helperComponents/index.js';
8
+ import { EMBLEM_ICON_SIZE } from '../../../../utils.js';
9
+ import styles from './styles.module.css';
10
+ export function MainContent({ title, description, icon, imageData, className }) {
11
+ const { file, size = 's' } = useAttachmentContext();
12
+ if (imageData) {
13
+ return (_jsx("div", { className: cn(styles.composition, styles.image, className), "data-attachment-image": '', children: _jsx("img", { src: imageData, alt: file?.name ?? title ?? 'file', "data-test-id": TEST_IDS.image, className: styles.img }) }));
14
+ }
15
+ return (_jsxs("div", { className: cn(styles.composition, styles.iconMode, className), "data-size": size, children: [_jsx(TextBlock, { title: title, description: description, align: 'center' }), _jsx("div", { className: styles.iconSlot, "data-attachment-icon-slot": '', children: _jsx(IconPredefined, { size: EMBLEM_ICON_SIZE[size], icon: icon ?? FileSVG, background: true, appearance: 'neutral', shape: 'squared', "data-test-id": TEST_IDS.icon }) })] }));
16
+ }
@@ -0,0 +1 @@
1
+ export * from './MainContent.js';
@@ -0,0 +1 @@
1
+ export * from './MainContent.js';
@@ -0,0 +1,38 @@
1
+ .composition{
2
+ display:flex;
3
+ align-items:center;
4
+ justify-content:center;
5
+ width:100%;
6
+ height:100%;
7
+ }
8
+
9
+ .iconMode{
10
+ flex-direction:column;
11
+ gap:0;
12
+ align-items:center;
13
+ justify-content:center;
14
+ }
15
+ .iconMode[data-size=s]{
16
+ padding:var(--sn-attachment-anatomy-size-s-container-content-padding, var(--sn-primitive-dimension-8, 8px));
17
+ }
18
+ .iconMode[data-size=m]{
19
+ padding:var(--sn-attachment-anatomy-size-m-container-content-padding, var(--sn-primitive-dimension-16, 16px));
20
+ }
21
+
22
+ .iconSlot{
23
+ display:flex;
24
+ align-items:center;
25
+ justify-content:center;
26
+ }
27
+
28
+ .image{
29
+ padding:0;
30
+ }
31
+
32
+ .img{
33
+ display:block;
34
+ width:100%;
35
+ height:100%;
36
+ -o-object-fit:cover;
37
+ object-fit:cover;
38
+ }
@@ -0,0 +1 @@
1
+ export * from './AttachmentSquare.js';
@@ -0,0 +1 @@
1
+ export * from './AttachmentSquare.js';
@@ -0,0 +1,68 @@
1
+ @charset "UTF-8";
2
+ .root{
3
+ isolation:isolate;
4
+ display:inline-flex;
5
+ flex-direction:column;
6
+ }
7
+ .root:has(> div > [data-size=s]){
8
+ width:var(--sn-attachment-anatomy-size-s-container-width, var(--sn-density-size-5xl, var(--sn-primitive-dimension-104, 104px)));
9
+ height:var(--sn-attachment-anatomy-size-s-container-height, var(--sn-density-size-5xl, var(--sn-primitive-dimension-104, 104px)));
10
+ }
11
+ .root:has(> div > [data-size=m]){
12
+ width:var(--sn-attachment-anatomy-size-m-container-width, var(--sn-density-size-8xl, var(--sn-primitive-dimension-128, 128px)));
13
+ height:var(--sn-attachment-anatomy-size-m-container-height, var(--sn-density-size-8xl, var(--sn-primitive-dimension-128, 128px)));
14
+ }
15
+ .root > div{
16
+ flex:1;
17
+ min-height:0;
18
+ }
19
+
20
+ .composition{
21
+ position:relative;
22
+ width:100%;
23
+ height:100%;
24
+ }
25
+
26
+ .main{
27
+ position:absolute;
28
+ inset:0;
29
+ }
30
+
31
+ .hover{
32
+ pointer-events:none;
33
+ position:absolute;
34
+ inset:0;
35
+ opacity:0;
36
+ }
37
+ .hasFocusedActions .hover,
38
+ .composition:hover .hover[data-mode=image],
39
+ .composition[data-has-actions]:hover .hover,
40
+ .root:focus-visible .hover[data-mode=image],
41
+ .root:focus-visible .composition[data-has-actions] .hover{
42
+ opacity:1;
43
+ }
44
+
45
+ .composition[data-error] .hover{
46
+ opacity:1;
47
+ }
48
+
49
+ .hover [data-attachment-actions]{
50
+ pointer-events:auto;
51
+ }
52
+
53
+ .hover[data-mode=image],
54
+ .hover[data-error]{
55
+ pointer-events:auto;
56
+ }
57
+
58
+ .root:not([data-disabled]) .composition[data-has-actions]:hover [data-attachment-icon-slot],
59
+ .root:not([data-disabled]) .hasFocusedActions [data-attachment-icon-slot],
60
+ .root:not([data-disabled]):focus-visible .composition[data-has-actions] [data-attachment-icon-slot]{
61
+ opacity:0;
62
+ }
63
+
64
+ .root:not([data-disabled]) .composition:hover [data-attachment-image],
65
+ .root:not([data-disabled]) .hasFocusedActions [data-attachment-image],
66
+ .root:not([data-disabled]):focus-visible .composition [data-attachment-image]{
67
+ display:none;
68
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Attachment/index.js';
2
+ export * from './AttachmentSquare/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './Attachment/index.js';
2
+ export * from './AttachmentSquare/index.js';
@@ -0,0 +1,18 @@
1
+ export declare const SIZE: {
2
+ readonly S: "s";
3
+ readonly M: "m";
4
+ };
5
+ export declare const TEST_IDS: {
6
+ readonly root: "attachment";
7
+ readonly rootSquare: "attachment-square";
8
+ readonly icon: "attachment__icon";
9
+ readonly image: "attachment__image";
10
+ readonly loading: "attachment__loading";
11
+ readonly loadingSquare: "attachment-square__loading";
12
+ readonly retryAction: "attachment__retry-action";
13
+ readonly deleteAction: "attachment__delete-action";
14
+ readonly downloadAction: "attachment__download-action";
15
+ readonly title: "attachment__title";
16
+ readonly description: "attachment__description";
17
+ readonly error: "attachment__error";
18
+ };
@@ -0,0 +1,19 @@
1
+ export const SIZE = {
2
+ S: 's',
3
+ M: 'm',
4
+ };
5
+ const PREFIX = 'attachment';
6
+ export const TEST_IDS = {
7
+ root: PREFIX,
8
+ rootSquare: `${PREFIX}-square`,
9
+ icon: `${PREFIX}__icon`,
10
+ image: `${PREFIX}__image`,
11
+ loading: `${PREFIX}__loading`,
12
+ loadingSquare: `${PREFIX}-square__loading`,
13
+ retryAction: `${PREFIX}__retry-action`,
14
+ deleteAction: `${PREFIX}__delete-action`,
15
+ downloadAction: `${PREFIX}__download-action`,
16
+ title: `${PREFIX}__title`,
17
+ description: `${PREFIX}__description`,
18
+ error: `${PREFIX}__error`,
19
+ };
@@ -0,0 +1,10 @@
1
+ import { AttachmentProps } from './types.js';
2
+ export type AttachmentContextType = Pick<AttachmentProps, 'size' | 'file' | 'truncateVariant' | 'onDownload' | 'onDelete' | 'onRetry' | 'disabled' | 'truncate'>;
3
+ export declare const AttachmentContext: import("react").Context<AttachmentContextType>;
4
+ export declare function useAttachmentContext(): AttachmentContextType;
5
+ export type AttachmentFocusActionsContextType = {
6
+ focused: boolean;
7
+ setFocused(focused: boolean): void;
8
+ };
9
+ export declare const AttachmentFocusActionsContext: import("react").Context<AttachmentFocusActionsContextType>;
10
+ export declare function useAttachmentFocusActionsContext(): AttachmentFocusActionsContextType;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const AttachmentContext = createContext({});
3
+ export function useAttachmentContext() {
4
+ return useContext(AttachmentContext);
5
+ }
6
+ export const AttachmentFocusActionsContext = createContext({
7
+ focused: false,
8
+ setFocused: () => { },
9
+ });
10
+ export function useAttachmentFocusActionsContext() {
11
+ return useContext(AttachmentFocusActionsContext);
12
+ }
@@ -0,0 +1,7 @@
1
+ type ActionsProps = {
2
+ hideDownload?: boolean;
3
+ hideDelete?: boolean;
4
+ hideRetry?: boolean;
5
+ };
6
+ export declare function Actions({ hideDelete, hideDownload, hideRetry }: ActionsProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export {};
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from '@cloud-ru/ds-button';
3
+ import { DownloadSVG, TrashSVG, UpdateSVG } from '@cloud-ru/ds-icons/interface/system';
4
+ import { TEST_IDS } from '../../constants.js';
5
+ import { useAttachmentContext, useAttachmentFocusActionsContext } from '../../context.js';
6
+ import styles from './styles.module.css';
7
+ const noop = () => { };
8
+ export function Actions({ hideDelete, hideDownload, hideRetry }) {
9
+ const { onDelete, onDownload, file, disabled, onRetry } = useAttachmentContext();
10
+ const { setFocused = noop } = useAttachmentFocusActionsContext();
11
+ const showDownload = onDownload && !hideDownload;
12
+ const showDelete = onDelete && !hideDelete;
13
+ const showRetry = onRetry && !hideRetry;
14
+ const handleFocus = () => setFocused(true);
15
+ const handleBlur = () => setFocused(false);
16
+ const handleRetry = (e) => {
17
+ onRetry?.();
18
+ e.stopPropagation();
19
+ };
20
+ const handleDownload = (e) => {
21
+ onDownload?.(file);
22
+ e.stopPropagation();
23
+ };
24
+ const handleDelete = (e) => {
25
+ onDelete?.(file);
26
+ e.stopPropagation();
27
+ };
28
+ if (!showDownload && !showDelete && !showRetry) {
29
+ return null;
30
+ }
31
+ return (_jsxs("div", { className: styles.actions, "data-attachment-actions": '', children: [showDownload && (_jsx(Button, { disabled: disabled, view: 'function', appearance: 'neutral', size: 'm', icon: _jsx(DownloadSVG, {}), onClick: handleDownload, onFocus: handleFocus, onBlur: handleBlur, "data-test-id": TEST_IDS.downloadAction })), showRetry && (_jsx(Button, { disabled: disabled, view: 'function', appearance: 'neutral', size: 'm', icon: _jsx(UpdateSVG, {}), onClick: handleRetry, onFocus: handleFocus, onBlur: handleBlur, "data-test-id": TEST_IDS.retryAction })), showDelete && (_jsx(Button, { disabled: disabled, view: 'function', appearance: 'neutral', size: 'm', icon: _jsx(TrashSVG, {}), onClick: handleDelete, onFocus: handleFocus, onBlur: handleBlur, "data-test-id": TEST_IDS.deleteAction }))] }));
32
+ }
@@ -0,0 +1 @@
1
+ export * from './Actions.js';
@@ -0,0 +1 @@
1
+ export * from './Actions.js';
@@ -0,0 +1,4 @@
1
+ .actions{
2
+ display:inline-flex;
3
+ align-items:center;
4
+ }
@@ -0,0 +1,9 @@
1
+ export type TextProps = {
2
+ text?: string;
3
+ className?: string;
4
+ maxLines?: number;
5
+ 'data-test-id'?: string;
6
+ /** Только на wrapper-div для typography token-mapping; в TruncateString не пробрасывается. */
7
+ 'data-size'?: string;
8
+ };
9
+ export declare function Text({ text, className, maxLines, ...rest }: TextProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TruncateString } from '@cloud-ru/ds-truncate-string';
3
+ import { extractSupportProps } from '@cloud-ru/ds-utils';
4
+ import { useAttachmentContext } from '../../context.js';
5
+ export function Text({ text, className, maxLines = 1, ...rest }) {
6
+ const { truncateVariant } = useAttachmentContext();
7
+ if (!text) {
8
+ return null;
9
+ }
10
+ const { 'data-size': dataSize, ...support } = rest;
11
+ return (_jsx("div", { className: className, "data-size": dataSize, children: _jsx(TruncateString, { text: text, maxLines: maxLines, variant: truncateVariant, ...extractSupportProps(support) }) }));
12
+ }
@@ -0,0 +1 @@
1
+ export * from './Text.js';
@@ -0,0 +1 @@
1
+ export * from './Text.js';
@@ -0,0 +1,5 @@
1
+ import { AttachmentProps } from '../../types.js';
2
+ export type TextBlockProps = Pick<AttachmentProps, 'title' | 'description' | 'error' | 'className'> & {
3
+ align?: 'center' | 'left';
4
+ };
5
+ export declare function TextBlock({ title, description, error, className, align }: TextBlockProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Hint } from '@cloud-ru/ds-field-decorator';
3
+ import cn from 'classnames';
4
+ import { TEST_IDS } from '../../constants.js';
5
+ import { useAttachmentContext } from '../../context.js';
6
+ import { Text } from '../Text/index.js';
7
+ import styles from './styles.module.css';
8
+ export function TextBlock({ title, description, error, className, align = 'left' }) {
9
+ const { size = 's', truncate = {} } = useAttachmentContext();
10
+ return (_jsxs("div", { className: cn(styles.content, className), "data-size": size, "data-align": align, children: [_jsx(Text, { className: styles.title, text: title, "data-test-id": TEST_IDS.title, maxLines: truncate?.title, "data-size": size }), _jsx(Text, { className: styles.description, text: description, "data-test-id": TEST_IDS.description, maxLines: truncate?.description, "data-size": size }), error && (_jsx(Hint, { error: error, showHintIcon: true, size: size, maxLines: truncate?.error, "data-test-id": TEST_IDS.error }))] }));
11
+ }
@@ -0,0 +1 @@
1
+ export * from './TextBlock.js';
@@ -0,0 +1 @@
1
+ export * from './TextBlock.js';
@@ -0,0 +1,56 @@
1
+ .content{
2
+ display:flex;
3
+ flex:1;
4
+ flex-direction:column;
5
+ width:100%;
6
+ min-width:0;
7
+ }
8
+ .content[data-align=center]{
9
+ align-items:center;
10
+ justify-content:center;
11
+ text-align:center;
12
+ }
13
+
14
+ .title{
15
+ width:100%;
16
+ min-width:0;
17
+ color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
18
+ }
19
+ .title[data-size=s]{
20
+ font-family:var(--sn-regular-label-m-fontFamily, var(--sn-brand-font-fontFamily-regular-label, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
21
+ font-weight:var(--sn-regular-label-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-label-m, var(--sn-brand-font-fontWeight-light-regular-label-m, var(--sn-primitive-font-fontWeightValue-550, 550))));
22
+ line-height:var(--sn-regular-label-m-lineHeight, var(--sn-density-typography-roleLabel-lineHeightM, var(--sn-primitive-font-lineHeight-by16, 24px)));
23
+ font-size:var(--sn-regular-label-m-fontSize, var(--sn-density-typography-roleLabel-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px)));
24
+ letter-spacing:var(--sn-regular-label-m-letterSpacing, var(--sn-primitive-font-letterSpacing-s, 0px));
25
+ paragraph-spacing:var(--sn-regular-label-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize12, 6px));
26
+ }
27
+ .title[data-size=m]{
28
+ font-family:var(--sn-regular-label-l-fontFamily, var(--sn-brand-font-fontFamily-regular-label, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
29
+ font-weight:var(--sn-regular-label-l-fontWeight, var(--sn-theme-typography-fontWeight-regular-label-l, var(--sn-brand-font-fontWeight-light-regular-label-l, var(--sn-primitive-font-fontWeightValue-550, 550))));
30
+ line-height:var(--sn-regular-label-l-lineHeight, var(--sn-density-typography-roleLabel-lineHeightL, var(--sn-primitive-font-lineHeight-by20, 28px)));
31
+ font-size:var(--sn-regular-label-l-fontSize, var(--sn-density-typography-roleLabel-fontSizeL, var(--sn-primitive-font-fontSize-20, 20px)));
32
+ letter-spacing:var(--sn-regular-label-l-letterSpacing, var(--sn-primitive-font-letterSpacing-s, 0px));
33
+ paragraph-spacing:var(--sn-regular-label-l-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize14, 7px));
34
+ }
35
+
36
+ .description{
37
+ width:100%;
38
+ min-width:0;
39
+ color:var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8)));
40
+ }
41
+ .description[data-size=s]{
42
+ font-family:var(--sn-regular-body-s-fontFamily, var(--sn-brand-font-fontFamily-regular-body, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
43
+ font-weight:var(--sn-regular-body-s-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-s, var(--sn-brand-font-fontWeight-light-regular-body-s, var(--sn-primitive-font-fontWeightValue-400, 400))));
44
+ line-height:var(--sn-regular-body-s-lineHeight, var(--sn-density-typography-roleBody-lineHeightS, var(--sn-primitive-font-lineHeight-by14, 20px)));
45
+ font-size:var(--sn-regular-body-s-fontSize, var(--sn-density-typography-roleBody-fontSizeS, var(--sn-primitive-font-fontSize-14, 14px)));
46
+ letter-spacing:var(--sn-regular-body-s-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
47
+ paragraph-spacing:var(--sn-regular-body-s-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize12, 6px));
48
+ }
49
+ .description[data-size=m]{
50
+ font-family:var(--sn-regular-body-m-fontFamily, var(--sn-brand-font-fontFamily-regular-body, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
51
+ font-weight:var(--sn-regular-body-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-m, var(--sn-brand-font-fontWeight-light-regular-body-m, var(--sn-primitive-font-fontWeightValue-400, 400))));
52
+ line-height:var(--sn-regular-body-m-lineHeight, var(--sn-density-typography-roleBody-lineHeightM, var(--sn-primitive-font-lineHeight-by16, 24px)));
53
+ font-size:var(--sn-regular-body-m-fontSize, var(--sn-density-typography-roleBody-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px)));
54
+ letter-spacing:var(--sn-regular-body-m-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
55
+ paragraph-spacing:var(--sn-regular-body-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize14, 7px));
56
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Actions/index.js';
2
+ export * from './Text/index.js';
3
+ export * from './TextBlock/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './Actions/index.js';
2
+ export * from './Text/index.js';
3
+ export * from './TextBlock/index.js';
@@ -0,0 +1,4 @@
1
+ export declare function useImage(file?: File): {
2
+ imageData: string | undefined;
3
+ loading: boolean;
4
+ };