Skip to content

Commit af49a16

Browse files
author
Ruslan Farkhutdinov
committed
Chat FU: Add display flex to message bubble & refactor
1 parent 0e85dea commit af49a16

File tree

13 files changed

+80
-41
lines changed

13 files changed

+80
-41
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@
4949

5050
@mixin chat-fileview(
5151
$chat-file-view-items-gap,
52-
$chat-file-view-margin-top,
5352
$chat-file-container-width,
5453
) {
5554
.dx-chat-file-view {
5655
gap: $chat-file-view-items-gap;
57-
margin-top: $chat-file-view-margin-top;
5856
grid-template-columns: repeat(auto-fit, $chat-file-container-width);
5957
}
6058
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ $chat-messagebubble-max-height-image: 400px !default;
99
}
1010

1111
.dx-chat-messagebubble {
12+
display: flex;
13+
flex-direction: column;
1214
width: auto;
1315
word-break: break-word;
1416
white-space: break-spaces;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
$bubble-container-gap,
99
$bubble-delete-gap,
1010
$bubble-delete-icon-size,
11+
$chat-bubble-gap,
1112
) {
1213
.dx-chat-messagegroup-content {
1314
row-gap: $bubble-container-gap;
@@ -16,6 +17,7 @@
1617
.dx-chat-messagebubble {
1718
padding: $padding;
1819
border-radius: $border-radius;
20+
gap: $chat-bubble-gap;
1921

2022
&.dx-chat-messagebubble-deleted {
2123
.dx-chat-messagebubble-content {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
);
3131
@include chat-fileview(
3232
$chat-file-view-items-gap,
33-
$chat-file-view-margin-top,
3433
$chat-file-container-width,
3534
);
3635
@include chat-alertlist(
@@ -58,6 +57,7 @@
5857
$chat-bubble-container-gap,
5958
$chat-bubble-delete-gap,
6059
$chat-bubble-delete-icon-size,
60+
$chat-bubble-gap,
6161
);
6262
@include chat-messagegroup(
6363
$chat-messagegroup-gap,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $chat-file-secondary-font-size: 10px !default;
7474
$chat-file-base-section-gap: 4px !default;
7575
$chat-file-file-size-max-width: 4em !default;
7676
$chat-file-view-items-gap: 8px !default;
77-
$chat-file-view-margin-top: 8px !default;
77+
$chat-bubble-gap: 8px !default;
7878

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
);
3434
@include chat-fileview(
3535
$chat-file-view-items-gap,
36-
$chat-file-view-margin-top,
3736
$chat-file-container-width,
3837
);
3938
@include chat-alertlist(
@@ -61,6 +60,7 @@
6160
$chat-bubble-container-gap,
6261
$chat-bubble-delete-gap,
6362
$chat-bubble-delete-icon-size,
63+
$chat-bubble-gap,
6464
);
6565
@include chat-messagegroup(
6666
$chat-messagegroup-gap,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $chat-file-secondary-font-size: 10px !default;
7373
$chat-file-base-section-gap: 4px !default;
7474
$chat-file-file-size-max-width: 4em !default;
7575
$chat-file-view-items-gap: 8px !default;
76-
$chat-file-view-margin-top: 8px !default;
76+
$chat-bubble-gap: 8px !default;
7777

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
);
3232
@include chat-fileview(
3333
$chat-file-view-items-gap,
34-
$chat-file-view-margin-top,
3534
$chat-file-container-width,
3635
);
3736
@include chat-alertlist(
@@ -59,6 +58,7 @@
5958
$chat-bubble-container-gap,
6059
$chat-bubble-delete-gap,
6160
$chat-bubble-delete-icon-size,
61+
$chat-bubble-gap,
6262
);
6363
@include chat-messagegroup(
6464
$chat-messagegroup-gap,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $chat-file-secondary-font-size: 10px !default;
7171
$chat-file-base-section-gap: 4px !default;
7272
$chat-file-file-size-max-width: 4em !default;
7373
$chat-file-view-items-gap: 8px !default;
74-
$chat-file-view-margin-top: 8px !default;
74+
$chat-bubble-gap: 8px !default;
7575

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

packages/devextreme/js/__internal/ui/chat/messagebubble.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import type { WidgetOptions } from '@js/ui/widget/ui.widget';
77
import { ICON_CLASS } from '@ts/core/utils/m_icon';
88
import type { OptionChanged } from '@ts/core/widget/types';
99
import Widget from '@ts/core/widget/widget';
10-
11-
import FileView from './file_view/file_view';
10+
import FileView from '@ts/ui/chat/file_view/file_view';
1211

1312
export const CHAT_MESSAGEBUBBLE_CLASS = 'dx-chat-messagebubble';
1413
export const CHAT_MESSAGEBUBBLE_DELETED_CLASS = 'dx-chat-messagebubble-deleted';
1514
export const CHAT_MESSAGEBUBBLE_CONTENT_CLASS = 'dx-chat-messagebubble-content';
16-
export const CHAT_MESSAGEBUBBLE_ATTACHMENTS_CLASS = 'dx-chat-messagebubble-attachments';
1715
export const CHAT_MESSAGEBUBBLE_ICON_PROHIBITION_CLASS = `${ICON_CLASS}-cursorprohibition`;
1816
export const CHAT_MESSAGEBUBBLE_HAS_IMAGE_CLASS = 'dx-has-image';
1917
export const CHAT_MESSAGEBUBBLE_IMAGE_CLASS = 'dx-chat-messagebubble-image';
@@ -35,7 +33,7 @@ export interface Properties extends WidgetOptions<MessageBubble> {
3533
class MessageBubble extends Widget<Properties> {
3634
_$content!: dxElementWrapper;
3735

38-
_$attachmentsContainer!: dxElementWrapper;
36+
_$attachments?: dxElementWrapper;
3937

4038
_getDefaultOptions(): Properties {
4139
return {
@@ -68,9 +66,14 @@ class MessageBubble extends Widget<Properties> {
6866
}
6967

7068
_renderAttachmentsContainer(): void {
71-
this._$attachmentsContainer = $('<div>')
72-
.addClass(CHAT_MESSAGEBUBBLE_ATTACHMENTS_CLASS)
73-
.appendTo(this.$element());
69+
const { attachments, isDeleted } = this.option();
70+
71+
this._$attachments?.remove();
72+
this._$attachments = undefined;
73+
74+
if (attachments?.length && !isDeleted) {
75+
this._$attachments = $('<div>').appendTo(this.$element());
76+
}
7477
}
7578

7679
_updateContent(): void {
@@ -83,8 +86,9 @@ class MessageBubble extends Widget<Properties> {
8386
isDeleted = false,
8487
} = this.option();
8588

86-
this.$element().removeClass(CHAT_MESSAGEBUBBLE_DELETED_CLASS);
87-
this.$element().removeClass(CHAT_MESSAGEBUBBLE_HAS_IMAGE_CLASS);
89+
this.$element()
90+
.removeClass(CHAT_MESSAGEBUBBLE_DELETED_CLASS)
91+
.removeClass(CHAT_MESSAGEBUBBLE_HAS_IMAGE_CLASS);
8892

8993
this._$content.empty();
9094

@@ -130,27 +134,27 @@ class MessageBubble extends Widget<Properties> {
130134

131135
_renderAttachments(): void {
132136
const {
133-
isDeleted,
134137
attachments,
135138
activeStateEnabled,
136139
focusStateEnabled,
137140
hoverStateEnabled,
138141
onAttachmentDownload,
139142
} = this.option();
140143

141-
this._$attachmentsContainer.empty();
144+
if (!this._$attachments) {
145+
return;
146+
}
142147

143-
if (attachments?.length && !isDeleted) {
144-
const $fileView = $('<div>');
145-
this._createComponent($fileView, FileView, {
146-
files: attachments,
147-
onDownload: onAttachmentDownload,
148+
this._$attachments.empty();
149+
150+
if (attachments?.length) {
151+
this._createComponent(this._$attachments, FileView, {
148152
activeStateEnabled,
149153
focusStateEnabled,
150154
hoverStateEnabled,
155+
files: attachments,
156+
onDownload: onAttachmentDownload,
151157
});
152-
153-
this._$attachmentsContainer.append($fileView);
154158
}
155159
}
156160

@@ -171,7 +175,11 @@ class MessageBubble extends Widget<Properties> {
171175
case 'isDeleted':
172176
this._updateMessageData(name, value);
173177
this._updateContent();
174-
this._renderAttachments();
178+
this._renderAttachmentsContainer();
179+
break;
180+
case 'type':
181+
this._updateContent();
182+
this._renderAttachmentsContainer();
175183
break;
176184
case 'template':
177185
this._updateContent();
@@ -181,6 +189,7 @@ class MessageBubble extends Widget<Properties> {
181189
break;
182190
case 'onAttachmentDownload':
183191
case 'attachments':
192+
this._renderAttachmentsContainer();
184193
this._renderAttachments();
185194
break;
186195
default:

0 commit comments

Comments
 (0)