@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,127 @@
|
|
|
1
|
+
import { Card } from '@cloud-ru/ds-card';
|
|
2
|
+
import { BACKGROUND_PREDEFINED_FILL } from '@cloud-ru/ds-materials';
|
|
3
|
+
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { KeyboardEvent, MouseEvent, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { AttachmentContext, AttachmentFocusActionsContext } from '../../context';
|
|
8
|
+
import { useImage } from '../../hooks';
|
|
9
|
+
import { AttachmentSquareProps } from '../../types';
|
|
10
|
+
import { getBaseFileName, getFileExtension } from '../../utils';
|
|
11
|
+
import { HoverContent } from './components/HoverContent';
|
|
12
|
+
import { LoadingContent } from './components/LoadingContent';
|
|
13
|
+
import { MainContent } from './components/MainContent';
|
|
14
|
+
import styles from './styles.module.scss';
|
|
15
|
+
|
|
16
|
+
export function AttachmentSquare({
|
|
17
|
+
file,
|
|
18
|
+
loading,
|
|
19
|
+
icon,
|
|
20
|
+
title: titleProp,
|
|
21
|
+
description: descriptionProp,
|
|
22
|
+
error,
|
|
23
|
+
disabled,
|
|
24
|
+
truncateVariant,
|
|
25
|
+
checked,
|
|
26
|
+
onDownload,
|
|
27
|
+
onDelete,
|
|
28
|
+
onClick,
|
|
29
|
+
onRetry,
|
|
30
|
+
size = 's',
|
|
31
|
+
className,
|
|
32
|
+
...rest
|
|
33
|
+
}: AttachmentSquareProps) {
|
|
34
|
+
const { loading: loadingImage, imageData } = useImage(file);
|
|
35
|
+
const isLoading = loading || loadingImage;
|
|
36
|
+
|
|
37
|
+
const title = titleProp || getBaseFileName(file?.name);
|
|
38
|
+
const description = descriptionProp || getFileExtension(file?.name);
|
|
39
|
+
|
|
40
|
+
const [hasFocusedActions, setHasFocusedActions] = useState<boolean>(false);
|
|
41
|
+
|
|
42
|
+
const interactive = !isLoading && !disabled && Boolean(onClick);
|
|
43
|
+
const hasError = Boolean(error);
|
|
44
|
+
const hasActions = Boolean(onDownload || onDelete || onRetry);
|
|
45
|
+
const isChecked = !loading && !error && checked;
|
|
46
|
+
const isDisabled = !loading && disabled;
|
|
47
|
+
|
|
48
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
49
|
+
if (!interactive || !onClick) return;
|
|
50
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
onClick(event as unknown as MouseEvent<HTMLDivElement>);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Card
|
|
58
|
+
{...extractSupportProps(rest)}
|
|
59
|
+
view='outline'
|
|
60
|
+
radius={size === 's' ? 's' : 'm'}
|
|
61
|
+
backgroundPredefined={
|
|
62
|
+
hasError ? BACKGROUND_PREDEFINED_FILL.RedBackground : BACKGROUND_PREDEFINED_FILL.NeutralBackground1Level
|
|
63
|
+
}
|
|
64
|
+
disabled={isDisabled}
|
|
65
|
+
checked={isChecked}
|
|
66
|
+
multiSelect
|
|
67
|
+
interactive={interactive}
|
|
68
|
+
className={cn(styles.root, className)}
|
|
69
|
+
data-attachment-error={hasError || undefined}
|
|
70
|
+
aria-busy={isLoading || undefined}
|
|
71
|
+
>
|
|
72
|
+
<AttachmentContext.Provider
|
|
73
|
+
value={{
|
|
74
|
+
file,
|
|
75
|
+
truncateVariant,
|
|
76
|
+
onDelete,
|
|
77
|
+
onDownload,
|
|
78
|
+
onRetry,
|
|
79
|
+
disabled,
|
|
80
|
+
size,
|
|
81
|
+
truncate: { title: 1, description: 1, error: 1 },
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<AttachmentFocusActionsContext.Provider
|
|
85
|
+
value={{ focused: hasFocusedActions, setFocused: setHasFocusedActions }}
|
|
86
|
+
>
|
|
87
|
+
<div
|
|
88
|
+
className={cn(styles.composition, {
|
|
89
|
+
[styles.hasFocusedActions]: hasFocusedActions,
|
|
90
|
+
})}
|
|
91
|
+
data-size={size}
|
|
92
|
+
data-loading={isLoading || undefined}
|
|
93
|
+
data-error={hasError || undefined}
|
|
94
|
+
data-has-actions={hasActions || undefined}
|
|
95
|
+
onClick={interactive ? onClick : undefined}
|
|
96
|
+
onKeyDown={interactive ? handleKeyDown : undefined}
|
|
97
|
+
role={interactive ? 'button' : undefined}
|
|
98
|
+
// Card-корень уже фокусируется (tabIndex={0}); внутренний wrapper забирает только обработчики.
|
|
99
|
+
tabIndex={-1}
|
|
100
|
+
>
|
|
101
|
+
{!isLoading && !hasError && (
|
|
102
|
+
<MainContent
|
|
103
|
+
title={title}
|
|
104
|
+
description={description}
|
|
105
|
+
icon={icon}
|
|
106
|
+
imageData={imageData}
|
|
107
|
+
className={styles.main}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
|
|
111
|
+
{!isLoading && !disabled && (
|
|
112
|
+
<HoverContent
|
|
113
|
+
title={title}
|
|
114
|
+
description={description}
|
|
115
|
+
error={error}
|
|
116
|
+
hasImage={Boolean(imageData)}
|
|
117
|
+
className={styles.hover}
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
{isLoading && <LoadingContent />}
|
|
122
|
+
</div>
|
|
123
|
+
</AttachmentFocusActionsContext.Provider>
|
|
124
|
+
</AttachmentContext.Provider>
|
|
125
|
+
</Card>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
|
|
3
|
+
import { useAttachmentContext } from '../../../../context';
|
|
4
|
+
import { Actions, TextBlock } from '../../../../helperComponents';
|
|
5
|
+
import { AttachmentProps } from '../../../../types';
|
|
6
|
+
import styles from './styles.module.scss';
|
|
7
|
+
|
|
8
|
+
type HoverContentProps = Pick<AttachmentProps, 'title' | 'description' | 'error' | 'className'> & {
|
|
9
|
+
/** image-mode → overlay даёт title/description/actions поверх `<img>`; icon-mode → только actions поверх иконки. */
|
|
10
|
+
hasImage?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function HoverContent({ title, description, error, hasImage, className }: HoverContentProps) {
|
|
14
|
+
const { size } = useAttachmentContext();
|
|
15
|
+
const hasError = Boolean(error);
|
|
16
|
+
|
|
17
|
+
const showOnHoverOnly = !hasError;
|
|
18
|
+
// Дублировать TextBlock из MainContent нельзя: два absolute-слоя того же текста дают визуальный bold.
|
|
19
|
+
const showText = hasImage || hasError;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
className={cn(styles.overlay, showOnHoverOnly && className)}
|
|
24
|
+
data-size={size}
|
|
25
|
+
data-error={hasError || undefined}
|
|
26
|
+
data-mode={hasImage ? 'image' : 'icon'}
|
|
27
|
+
>
|
|
28
|
+
{showText && (
|
|
29
|
+
<TextBlock title={title} error={error} description={!hasError ? description : undefined} align='center' />
|
|
30
|
+
)}
|
|
31
|
+
<Actions hideDownload={hasError} hideRetry={!hasError} />
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './HoverContent';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/components/attachment.module' as att;
|
|
3
|
+
|
|
4
|
+
$sizes: 's', 'm';
|
|
5
|
+
|
|
6
|
+
.overlay {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: 0;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
|
|
13
|
+
width: 100%;
|
|
14
|
+
height: 100%;
|
|
15
|
+
|
|
16
|
+
color: base.$sn-theme-color-available-version-textMain;
|
|
17
|
+
|
|
18
|
+
// Overlay прозрачный во всех режимах: image-mode скрывает `<img>` на hover (см.
|
|
19
|
+
// AttachmentSquare/styles.module.scss) и под HoverContent'ом просвечивает
|
|
20
|
+
// Card.stateLayer; icon-mode никогда не закрывает MainContent; error-mode
|
|
21
|
+
// показывает RedBackground от Card.
|
|
22
|
+
background-color: transparent;
|
|
23
|
+
|
|
24
|
+
// Icon-mode: MainContent держит текст наверху, overlay подменяет иконку Actions'ами в нижнем слоте.
|
|
25
|
+
&[data-mode='icon']:not([data-error]) {
|
|
26
|
+
justify-content: flex-end;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@each $size in $sizes {
|
|
30
|
+
&[data-size='#{$size}'] {
|
|
31
|
+
padding: base.simple-var(att.$attachment, 'anatomy', 'size', $size, 'container', 'content', 'padding');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Spinner } from '@cloud-ru/ds-loader';
|
|
2
|
+
|
|
3
|
+
import { TEST_IDS } from '../../../../constants';
|
|
4
|
+
import { Actions } from '../../../../helperComponents';
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
|
|
7
|
+
export function LoadingContent() {
|
|
8
|
+
return (
|
|
9
|
+
<div className={styles.composition} data-test-id={TEST_IDS.loadingSquare}>
|
|
10
|
+
<Spinner />
|
|
11
|
+
<Actions hideDownload hideRetry />
|
|
12
|
+
</div>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LoadingContent';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
|
|
3
|
+
.composition {
|
|
4
|
+
position: absolute;
|
|
5
|
+
inset: 0;
|
|
6
|
+
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
|
|
12
|
+
color: base.$sn-theme-color-neutral-text;
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IconPredefined } from '@cloud-ru/ds-icon-predefined';
|
|
2
|
+
import { FileSVG } from '@cloud-ru/ds-icons/interface/system';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
|
|
5
|
+
import { TEST_IDS } from '../../../../constants';
|
|
6
|
+
import { useAttachmentContext } from '../../../../context';
|
|
7
|
+
import { TextBlock } from '../../../../helperComponents';
|
|
8
|
+
import { AttachmentProps } from '../../../../types';
|
|
9
|
+
import { EMBLEM_ICON_SIZE } from '../../../../utils';
|
|
10
|
+
import styles from './styles.module.scss';
|
|
11
|
+
|
|
12
|
+
type MainContentProps = {
|
|
13
|
+
imageData?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
} & Pick<AttachmentProps, 'title' | 'icon' | 'className'>;
|
|
16
|
+
|
|
17
|
+
export function MainContent({ title, description, icon, imageData, className }: MainContentProps) {
|
|
18
|
+
const { file, size = 's' } = useAttachmentContext();
|
|
19
|
+
|
|
20
|
+
if (imageData) {
|
|
21
|
+
return (
|
|
22
|
+
<div className={cn(styles.composition, styles.image, className)} data-attachment-image=''>
|
|
23
|
+
<img src={imageData} alt={file?.name ?? title ?? 'file'} data-test-id={TEST_IDS.image} className={styles.img} />
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className={cn(styles.composition, styles.iconMode, className)} data-size={size}>
|
|
30
|
+
<TextBlock title={title} description={description} align='center' />
|
|
31
|
+
<div className={styles.iconSlot} data-attachment-icon-slot=''>
|
|
32
|
+
<IconPredefined
|
|
33
|
+
size={EMBLEM_ICON_SIZE[size]}
|
|
34
|
+
icon={icon ?? FileSVG}
|
|
35
|
+
background
|
|
36
|
+
appearance='neutral'
|
|
37
|
+
shape='squared'
|
|
38
|
+
data-test-id={TEST_IDS.icon}
|
|
39
|
+
/>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MainContent';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/components/attachment.module' as att;
|
|
3
|
+
|
|
4
|
+
$sizes: 's', 'm';
|
|
5
|
+
|
|
6
|
+
.composition {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Не `space-between` — иначе текст прижимается к верху и съезжает под check-badge Card.
|
|
16
|
+
.iconMode {
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: 0;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
|
|
22
|
+
@each $size in $sizes {
|
|
23
|
+
&[data-size='#{$size}'] {
|
|
24
|
+
padding: base.simple-var(att.$attachment, 'anatomy', 'size', $size, 'container', 'content', 'padding');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.iconSlot {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.image {
|
|
36
|
+
padding: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.img {
|
|
40
|
+
display: block;
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: 100%;
|
|
43
|
+
object-fit: cover;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AttachmentSquare';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/components/attachment.module' as att;
|
|
3
|
+
|
|
4
|
+
$sizes: 's', 'm';
|
|
5
|
+
|
|
6
|
+
.root {
|
|
7
|
+
isolation: isolate;
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
|
|
11
|
+
@each $size in $sizes {
|
|
12
|
+
&:has(> div > [data-size='#{$size}']) {
|
|
13
|
+
width: base.simple-var(att.$attachment, 'anatomy', 'size', $size, 'container', 'width');
|
|
14
|
+
height: base.simple-var(att.$attachment, 'anatomy', 'size', $size, 'container', 'height');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Card.content — full-bleed image/иконке нужна вся высота. Card-корень рендерит
|
|
19
|
+
// ровно один div-ребёнок (`.content`); остальные дети (`acrylic`, `stateLayer`,
|
|
20
|
+
// `outlineBorder`, `checkWrapper`) — span. `:last-child` использовать нельзя:
|
|
21
|
+
// outlineBorder/checkWrapper идут в DOM после content'а ради paint order'а
|
|
22
|
+
// (см. Card.tsx комменты).
|
|
23
|
+
> div {
|
|
24
|
+
flex: 1;
|
|
25
|
+
min-height: 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.composition {
|
|
30
|
+
position: relative;
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 100%;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.main {
|
|
36
|
+
position: absolute;
|
|
37
|
+
inset: 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.hover {
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
position: absolute;
|
|
43
|
+
inset: 0;
|
|
44
|
+
opacity: 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* stylelint-disable no-descending-specificity -- независимые правила раскрытия hover-оверлея. */
|
|
48
|
+
.hasFocusedActions .hover,
|
|
49
|
+
.composition:hover .hover[data-mode='image'],
|
|
50
|
+
.composition[data-has-actions]:hover .hover,
|
|
51
|
+
.root:focus-visible .hover[data-mode='image'],
|
|
52
|
+
.root:focus-visible .composition[data-has-actions] .hover {
|
|
53
|
+
opacity: 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Error-state overlay (RedBackground + hint) показываем всегда, даже без actions.
|
|
57
|
+
.composition[data-error] .hover {
|
|
58
|
+
opacity: 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// pointer-events на .hover оставляем none по умолчанию, иначе оверлей перехватывает
|
|
62
|
+
// события у TextBlock из MainContent в icon-mode (TruncateString-тултип перестаёт
|
|
63
|
+
// срабатывать). Сами actions внутри overlay'я нативно интерактивны через свой
|
|
64
|
+
// data-атрибут.
|
|
65
|
+
.hover [data-attachment-actions] {
|
|
66
|
+
pointer-events: auto;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Image-mode и error-state рендерят собственный TextBlock внутри overlay'я — на
|
|
70
|
+
// нём нужен hover, чтобы сработал тултип TruncateString. Underlying слой в этих
|
|
71
|
+
// режимах — `<img>` или RedBackground без текста, перекрытие безопасно. Icon-mode
|
|
72
|
+
// остаётся pointer-events: none, чтобы события доходили до TextBlock в MainContent.
|
|
73
|
+
.hover[data-mode='image'],
|
|
74
|
+
.hover[data-error] {
|
|
75
|
+
pointer-events: auto;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Иконка скрывается на hover/focus, потому что её место занимает Actions из HoverContent.
|
|
79
|
+
// В disabled HoverContent не рендерится (actions отключены) — без `:not([data-disabled])`
|
|
80
|
+
// hover скрывал бы иконку и оставлял пустой слот вместо неё.
|
|
81
|
+
.root:not([data-disabled]) .composition[data-has-actions]:hover [data-attachment-icon-slot],
|
|
82
|
+
.root:not([data-disabled]) .hasFocusedActions [data-attachment-icon-slot],
|
|
83
|
+
.root:not([data-disabled]):focus-visible .composition[data-has-actions] [data-attachment-icon-slot] {
|
|
84
|
+
opacity: 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Image-mode: на hover/focus убираем `<img>` из визуала, чтобы под HoverContent'ом
|
|
88
|
+
// просвечивал Card.stateLayer (regular-hovered-filled / activated-hovered-filled
|
|
89
|
+
// для selected). Без этого overlay рисовался с белым фоном и stateLayer прятался.
|
|
90
|
+
.root:not([data-disabled]) .composition:hover [data-attachment-image],
|
|
91
|
+
.root:not([data-disabled]) .hasFocusedActions [data-attachment-image],
|
|
92
|
+
.root:not([data-disabled]):focus-visible .composition [data-attachment-image] {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
/* stylelint-enable no-descending-specificity */
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const SIZE = {
|
|
2
|
+
S: 's',
|
|
3
|
+
M: 'm',
|
|
4
|
+
} as const;
|
|
5
|
+
|
|
6
|
+
const PREFIX = 'attachment';
|
|
7
|
+
|
|
8
|
+
export const TEST_IDS = {
|
|
9
|
+
root: PREFIX,
|
|
10
|
+
rootSquare: `${PREFIX}-square`,
|
|
11
|
+
icon: `${PREFIX}__icon`,
|
|
12
|
+
image: `${PREFIX}__image`,
|
|
13
|
+
loading: `${PREFIX}__loading`,
|
|
14
|
+
loadingSquare: `${PREFIX}-square__loading`,
|
|
15
|
+
retryAction: `${PREFIX}__retry-action`,
|
|
16
|
+
deleteAction: `${PREFIX}__delete-action`,
|
|
17
|
+
downloadAction: `${PREFIX}__download-action`,
|
|
18
|
+
title: `${PREFIX}__title`,
|
|
19
|
+
description: `${PREFIX}__description`,
|
|
20
|
+
error: `${PREFIX}__error`,
|
|
21
|
+
} as const;
|
package/src/context.tsx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import { AttachmentProps } from './types';
|
|
4
|
+
|
|
5
|
+
export type AttachmentContextType = Pick<
|
|
6
|
+
AttachmentProps,
|
|
7
|
+
'size' | 'file' | 'truncateVariant' | 'onDownload' | 'onDelete' | 'onRetry' | 'disabled' | 'truncate'
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
export const AttachmentContext = createContext<AttachmentContextType>({});
|
|
11
|
+
|
|
12
|
+
export function useAttachmentContext() {
|
|
13
|
+
return useContext(AttachmentContext);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type AttachmentFocusActionsContextType = {
|
|
17
|
+
focused: boolean;
|
|
18
|
+
setFocused(focused: boolean): void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const AttachmentFocusActionsContext = createContext<AttachmentFocusActionsContextType>({
|
|
22
|
+
focused: false,
|
|
23
|
+
setFocused: () => {},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export function useAttachmentFocusActionsContext() {
|
|
27
|
+
return useContext(AttachmentFocusActionsContext);
|
|
28
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
2
|
+
import { DownloadSVG, TrashSVG, UpdateSVG } from '@cloud-ru/ds-icons/interface/system';
|
|
3
|
+
import { MouseEvent } from 'react';
|
|
4
|
+
|
|
5
|
+
import { TEST_IDS } from '../../constants';
|
|
6
|
+
import { useAttachmentContext, useAttachmentFocusActionsContext } from '../../context';
|
|
7
|
+
import styles from './styles.module.scss';
|
|
8
|
+
|
|
9
|
+
type ActionsProps = {
|
|
10
|
+
hideDownload?: boolean;
|
|
11
|
+
hideDelete?: boolean;
|
|
12
|
+
hideRetry?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const noop = () => {};
|
|
16
|
+
|
|
17
|
+
export function Actions({ hideDelete, hideDownload, hideRetry }: ActionsProps) {
|
|
18
|
+
const { onDelete, onDownload, file, disabled, onRetry } = useAttachmentContext();
|
|
19
|
+
const { setFocused = noop } = useAttachmentFocusActionsContext();
|
|
20
|
+
|
|
21
|
+
const showDownload = onDownload && !hideDownload;
|
|
22
|
+
const showDelete = onDelete && !hideDelete;
|
|
23
|
+
const showRetry = onRetry && !hideRetry;
|
|
24
|
+
|
|
25
|
+
const handleFocus = () => setFocused(true);
|
|
26
|
+
const handleBlur = () => setFocused(false);
|
|
27
|
+
|
|
28
|
+
const handleRetry = (e: MouseEvent<HTMLButtonElement>) => {
|
|
29
|
+
onRetry?.();
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const handleDownload = (e: MouseEvent<HTMLButtonElement>) => {
|
|
34
|
+
onDownload?.(file);
|
|
35
|
+
e.stopPropagation();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const handleDelete = (e: MouseEvent<HTMLButtonElement>) => {
|
|
39
|
+
onDelete?.(file);
|
|
40
|
+
e.stopPropagation();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (!showDownload && !showDelete && !showRetry) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className={styles.actions} data-attachment-actions=''>
|
|
49
|
+
{showDownload && (
|
|
50
|
+
<Button
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
view='function'
|
|
53
|
+
appearance='neutral'
|
|
54
|
+
size='m'
|
|
55
|
+
icon={<DownloadSVG />}
|
|
56
|
+
onClick={handleDownload}
|
|
57
|
+
onFocus={handleFocus}
|
|
58
|
+
onBlur={handleBlur}
|
|
59
|
+
data-test-id={TEST_IDS.downloadAction}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
{showRetry && (
|
|
63
|
+
<Button
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
view='function'
|
|
66
|
+
appearance='neutral'
|
|
67
|
+
size='m'
|
|
68
|
+
icon={<UpdateSVG />}
|
|
69
|
+
onClick={handleRetry}
|
|
70
|
+
onFocus={handleFocus}
|
|
71
|
+
onBlur={handleBlur}
|
|
72
|
+
data-test-id={TEST_IDS.retryAction}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
{showDelete && (
|
|
76
|
+
<Button
|
|
77
|
+
disabled={disabled}
|
|
78
|
+
view='function'
|
|
79
|
+
appearance='neutral'
|
|
80
|
+
size='m'
|
|
81
|
+
icon={<TrashSVG />}
|
|
82
|
+
onClick={handleDelete}
|
|
83
|
+
onFocus={handleFocus}
|
|
84
|
+
onBlur={handleBlur}
|
|
85
|
+
data-test-id={TEST_IDS.deleteAction}
|
|
86
|
+
/>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Actions';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TruncateString } from '@cloud-ru/ds-truncate-string';
|
|
2
|
+
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
|
|
4
|
+
import { useAttachmentContext } from '../../context';
|
|
5
|
+
|
|
6
|
+
export type TextProps = {
|
|
7
|
+
text?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
maxLines?: number;
|
|
10
|
+
'data-test-id'?: string;
|
|
11
|
+
/** Только на wrapper-div для typography token-mapping; в TruncateString не пробрасывается. */
|
|
12
|
+
'data-size'?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function Text({ text, className, maxLines = 1, ...rest }: TextProps) {
|
|
16
|
+
const { truncateVariant } = useAttachmentContext();
|
|
17
|
+
|
|
18
|
+
if (!text) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { 'data-size': dataSize, ...support } = rest;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className={className} data-size={dataSize}>
|
|
26
|
+
<TruncateString text={text} maxLines={maxLines} variant={truncateVariant} {...extractSupportProps(support)} />
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Text';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Hint } from '@cloud-ru/ds-field-decorator';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
|
|
4
|
+
import { TEST_IDS } from '../../constants';
|
|
5
|
+
import { useAttachmentContext } from '../../context';
|
|
6
|
+
import { AttachmentProps } from '../../types';
|
|
7
|
+
import { Text } from '../Text';
|
|
8
|
+
import styles from './styles.module.scss';
|
|
9
|
+
|
|
10
|
+
export type TextBlockProps = Pick<AttachmentProps, 'title' | 'description' | 'error' | 'className'> & {
|
|
11
|
+
align?: 'center' | 'left';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function TextBlock({ title, description, error, className, align = 'left' }: TextBlockProps) {
|
|
15
|
+
const { size = 's', truncate = {} } = useAttachmentContext();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className={cn(styles.content, className)} data-size={size} data-align={align}>
|
|
19
|
+
<Text
|
|
20
|
+
className={styles.title}
|
|
21
|
+
text={title}
|
|
22
|
+
data-test-id={TEST_IDS.title}
|
|
23
|
+
maxLines={truncate?.title}
|
|
24
|
+
data-size={size}
|
|
25
|
+
/>
|
|
26
|
+
<Text
|
|
27
|
+
className={styles.description}
|
|
28
|
+
text={description}
|
|
29
|
+
data-test-id={TEST_IDS.description}
|
|
30
|
+
maxLines={truncate?.description}
|
|
31
|
+
data-size={size}
|
|
32
|
+
/>
|
|
33
|
+
{error && (
|
|
34
|
+
<Hint error={error} showHintIcon size={size} maxLines={truncate?.error} data-test-id={TEST_IDS.error} />
|
|
35
|
+
)}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TextBlock';
|