Skip to content

Commit 0a69269

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
Chat FU: Create FileView component (#31428)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 40f6f7f commit 0a69269

File tree

14 files changed

+363
-10
lines changed

14 files changed

+363
-10
lines changed

packages/devextreme-scss/scss/widgets/base/chat/layout/chat-fileview/_index.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@use "../../../mixins" as *;
22

33
.dx-chat-file {
4-
flex: 1 1 30%;
54
display: flex;
65
align-items: center;
6+
flex-shrink: 0;
77
}
88

99
.dx-chat-file-icon-container {
@@ -37,3 +37,9 @@
3737
flex-grow: 0;
3838
flex-shrink: 0;
3939
}
40+
41+
.dx-chat-file-view {
42+
display: flex;
43+
flex-wrap: wrap;
44+
width: 100%;
45+
}

packages/devextreme-scss/scss/widgets/base/chat/layout/chat-fileview/_mixins.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@mixin chat-file(
2-
$chat-file-container-min-width,
2+
$chat-file-container-width,
33
$chat-file-container-padding,
44
$chat-file-container-background-color,
55
$chat-file-container-border-radius,
@@ -11,7 +11,7 @@
1111
$chat-file-file-size-max-width
1212
) {
1313
.dx-chat-file {
14-
min-width: $chat-file-container-min-width;
14+
width: $chat-file-container-width;
1515
padding: $chat-file-container-padding;
1616
background-color: $chat-file-container-background-color;
1717
border-radius: $chat-file-container-border-radius;
@@ -46,3 +46,11 @@
4646
flex-basis: $chat-file-button-size;
4747
}
4848
}
49+
50+
@mixin chat-fileview(
51+
$chat-file-view-items-gap,
52+
) {
53+
.dx-chat-file-view {
54+
gap: $chat-file-view-items-gap;
55+
}
56+
}

packages/devextreme-scss/scss/widgets/fluent/chat/_index.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$chat-avatar-background-color,
1717
);
1818
@include chat-file(
19-
$chat-file-container-min-width,
19+
$chat-file-container-width,
2020
$chat-file-container-padding,
2121
$chat-file-container-background-color,
2222
$chat-file-container-border-radius,
@@ -27,6 +27,9 @@
2727
$chat-file-base-section-gap,
2828
$chat-file-file-size-max-width,
2929
);
30+
@include chat-fileview(
31+
$chat-file-view-items-gap
32+
);
3033
@include chat-alertlist(
3134
$chat-alertlist-color,
3235
$chat-alerts-padding-block,

packages/devextreme-scss/scss/widgets/fluent/chat/_sizes.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ $chat-confirmation-popup-toolbar-padding-block: $fluent-popup-content-withtitle-
6666
$chat-confirmation-popup-toolbar-padding-inline: $fluent-popup-content-withtitle-top-padding !default;
6767
$chat-confirmation-popup-toolbar-gap: null !default;
6868

69-
$chat-file-container-min-width: 17.14em !default;
69+
$chat-file-container-width: 17.14em !default;
7070
$chat-file-container-padding: 7px 8px !default;
7171
$chat-file-container-border-radius: $fluent-base-border-radius !default;
7272
$chat-file-button-size: $fluent-button-height !default;
7373
$chat-file-secondary-font-size: 10px !default;
7474
$chat-file-base-section-gap: 4px !default;
7575
$chat-file-file-size-max-width: 4em !default;
76+
$chat-file-view-items-gap: 8px !default;
7677

7778
@if $size == "default" {
7879
$chat-bubble-border-radius: $fluent-base-border-radius * 3 !default;

packages/devextreme-scss/scss/widgets/generic/chat/_index.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$chat-avatar-background-color,
2020
);
2121
@include chat-file(
22-
$chat-file-container-min-width,
22+
$chat-file-container-width,
2323
$chat-file-container-padding,
2424
$chat-file-container-background-color,
2525
$chat-file-container-border-radius,
@@ -30,6 +30,9 @@
3030
$chat-file-base-section-gap,
3131
$chat-file-file-size-max-width,
3232
);
33+
@include chat-fileview(
34+
$chat-file-view-items-gap
35+
);
3336
@include chat-alertlist(
3437
$chat-alertlist-color,
3538
$chat-alerts-padding-block,

packages/devextreme-scss/scss/widgets/generic/chat/_sizes.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ $chat-confirmation-popup-toolbar-padding-block: $generic-popup-toolbarbottom-pad
6565
$chat-confirmation-popup-toolbar-padding-inline: $generic-popup-toolbarbottom-padding !default;
6666
$chat-confirmation-popup-toolbar-gap: null !default;
6767

68-
$chat-file-container-min-width: 17.14em !default;
68+
$chat-file-container-width: 17.14em !default;
6969
$chat-file-container-padding: 7px 8px !default;
7070
$chat-file-container-border-radius: $base-border-radius !default;
7171
$chat-file-button-size: null !default;
7272
$chat-file-secondary-font-size: 10px !default;
7373
$chat-file-base-section-gap: 4px !default;
7474
$chat-file-file-size-max-width: 4em !default;
75+
$chat-file-view-items-gap: 8px !default;
7576

7677
@if $size == "default" {
7778
$chat-bubble-padding: 8px 12px !default;

packages/devextreme-scss/scss/widgets/material/chat/_index.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$chat-avatar-background-color,
1818
);
1919
@include chat-file(
20-
$chat-file-container-min-width,
20+
$chat-file-container-width,
2121
$chat-file-container-padding,
2222
$chat-file-container-background-color,
2323
$chat-file-container-border-radius,
@@ -28,6 +28,9 @@
2828
$chat-file-base-section-gap,
2929
$chat-file-file-size-max-width,
3030
);
31+
@include chat-fileview(
32+
$chat-file-view-items-gap
33+
);
3134
@include chat-alertlist(
3235
$chat-alertlist-color,
3336
$chat-alerts-padding-block,

packages/devextreme-scss/scss/widgets/material/chat/_sizes.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ $chat-confirmation-popup-toolbar-padding-block: null !default;
6363
$chat-confirmation-popup-toolbar-padding-inline: null !default;
6464
$chat-confirmation-popup-toolbar-gap: null !default;
6565

66-
$chat-file-container-min-width: 17.14em !default;
66+
$chat-file-container-width: 17.14em !default;
6767
$chat-file-container-padding: 7px 8px !default;
6868
$chat-file-container-border-radius: $material-base-border-radius !default;
6969
$chat-file-button-size: $material-button-height !default;
7070
$chat-file-secondary-font-size: 10px !default;
7171
$chat-file-base-section-gap: 4px !default;
7272
$chat-file-file-size-max-width: 4em !default;
73+
$chat-file-view-items-gap: 8px !default;
7374

7475
@if $size == "default" {
7576
$chat-bubble-border-radius: 8px !default;

packages/devextreme/js/__internal/ui/chat/file_view/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type Properties = DOMComponentProperties<File> & {
2525
onDownload?: (e: AttachmentDownloadEvent) => void;
2626
};
2727

28-
const CHAT_FILE_CLASS = 'dx-chat-file';
28+
export const CHAT_FILE_CLASS = 'dx-chat-file';
2929
const CHAT_FILE_ICON_CONTAINER_CLASS = 'dx-chat-file-icon-container';
3030
const CHAT_FILE_NAME_CLASS = 'dx-chat-file-name';
3131
const CHAT_FILE_SIZE_CLASS = 'dx-chat-file-size';
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import $ from '@js/core/renderer';
2+
import type { Attachment, AttachmentDownloadEvent } from '@js/ui/chat';
3+
import type { DOMComponentProperties } from '@ts/core/widget/dom_component';
4+
import DOMComponent from '@ts/core/widget/dom_component';
5+
import type { OptionChanged } from '@ts/core/widget/types';
6+
import type { Properties as FileProperties } from '@ts/ui/chat/file_view/file';
7+
import File from '@ts/ui/chat/file_view/file';
8+
9+
export interface FileViewProperties extends DOMComponentProperties<FileView> {
10+
activeStateEnabled?: boolean;
11+
12+
focusStateEnabled?: boolean;
13+
14+
hoverStateEnabled?: boolean;
15+
16+
files?: Attachment[];
17+
18+
onDownload?: (e: AttachmentDownloadEvent) => void;
19+
}
20+
21+
export const CHAT_FILE_VIEW_CLASS = 'dx-chat-file-view';
22+
export const CHAT_FILE_VIEW_ITEM_CLASS = 'dx-chat-file-view-item';
23+
24+
class FileView extends DOMComponent<FileView, FileViewProperties> {
25+
private _fileInstances: File[] = [];
26+
27+
private _downloadAction?: (e: Partial<AttachmentDownloadEvent>) => void;
28+
29+
_getDefaultOptions(): FileViewProperties {
30+
return {
31+
...super._getDefaultOptions(),
32+
files: [],
33+
activeStateEnabled: true,
34+
focusStateEnabled: true,
35+
hoverStateEnabled: true,
36+
};
37+
}
38+
39+
_init(): void {
40+
super._init();
41+
42+
this._createDownloadAction();
43+
}
44+
45+
_createDownloadAction(): void {
46+
this._downloadAction = this._createActionByOption(
47+
'onDownload',
48+
{ excludeValidators: ['disabled'] },
49+
);
50+
}
51+
52+
_initMarkup(): void {
53+
this.$element().addClass(CHAT_FILE_VIEW_CLASS);
54+
super._initMarkup();
55+
56+
this._renderItems();
57+
}
58+
59+
_renderItems(): void {
60+
const { files = [] } = this.option();
61+
62+
this._clearFileInstances();
63+
64+
files.forEach((file) => {
65+
this._renderItem(file);
66+
});
67+
}
68+
69+
_renderItem(data: Attachment): void {
70+
const $file = $('<div>');
71+
72+
const fileInstance = this._createComponent($file, File, this._getFileConfig(data));
73+
74+
this.$element().append($file);
75+
76+
this._fileInstances.push(fileInstance);
77+
}
78+
79+
_getFileConfig(data: Attachment): FileProperties {
80+
const { activeStateEnabled, focusStateEnabled, hoverStateEnabled } = this.option();
81+
82+
const configuration: FileProperties = {
83+
data,
84+
activeStateEnabled,
85+
focusStateEnabled,
86+
hoverStateEnabled,
87+
onDownload: (event) => {
88+
this._downloadAction?.(event);
89+
},
90+
};
91+
92+
return configuration;
93+
}
94+
95+
_clearFileInstances(): void {
96+
this._fileInstances?.forEach((instance) => { instance.dispose(); });
97+
this._fileInstances = [];
98+
this.$element().empty();
99+
}
100+
101+
_dispose(): void {
102+
this._clearFileInstances();
103+
super._dispose();
104+
}
105+
106+
_optionChanged(args: OptionChanged<FileViewProperties>): void {
107+
const { name } = args;
108+
109+
switch (name) {
110+
case 'activeStateEnabled':
111+
case 'focusStateEnabled':
112+
case 'hoverStateEnabled':
113+
case 'files':
114+
this._renderItems();
115+
break;
116+
117+
case 'onDownload':
118+
this._createDownloadAction();
119+
break;
120+
121+
default:
122+
super._optionChanged(args);
123+
}
124+
}
125+
}
126+
127+
export default FileView;

0 commit comments

Comments
 (0)