Skip to content

Commit

Permalink
Chat: implement day headers (#28160)
Browse files Browse the repository at this point in the history
Signed-off-by: EugeniyKiyashko <[email protected]>
Co-authored-by: EugeniyKiyashko <[email protected]>
  • Loading branch information
Zedwag and EugeniyKiyashko authored Oct 16, 2024
1 parent 5933228 commit ad8f0c8
Show file tree
Hide file tree
Showing 90 changed files with 520 additions and 27 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions e2e/testcafe-devextreme/tests/chat/messageList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ test('Messagelist appearance with scrollbar', async (t) => {
user: userSecond,
width: 400,
height: 600,
showDayHeaders: false,
onMessageSend: (e) => {
const { component, message } = e;

Expand Down Expand Up @@ -150,3 +151,48 @@ test('Messagelist should scrolled to the latest messages after being rendered in
}],
});
});

test('Messagelist with date headers', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

await testScreenshot(t, takeScreenshot, 'Messagelist with date headers.png', { element: '#container' });

await t
.expect(compareResults.isValid())
.ok(compareResults.errorMessages());
}).before(async () => {
const userFirst = createUser(1, 'First');
const userSecond = createUser(2, 'Second');
const msInDay = 86400000;
const today = new Date().setHours(7, 22, 0, 0);
const yesterday = today - msInDay;

const items = [{
timestamp: new Date('05.01.2024'),
author: userFirst,
text: 'AAA',
}, {
timestamp: new Date('06.01.2024'),
author: userFirst,
text: 'BBB',
}, {
timestamp: new Date('06.01.2024'),
author: userSecond,
text: 'CCC',
}, {
timestamp: yesterday,
author: userSecond,
text: 'DDD',
}, {
timestamp: today,
author: userFirst,
text: 'EEE',
}];

return createWidget('dxChat', {
items,
user: userSecond,
width: 400,
height: 600,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@
border-radius: 999em;
}

.dx-chat-messagelist-day-header {
text-align: center;
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
@use "sass:math";

@mixin chat-messagelist($padding) {
@mixin chat-messagelist(
$padding,
$day-header-color,
$day-header-padding-bottom,
$day-header-first-padding-top,
) {
.dx-chat-messagelist {
.dx-scrollable-content {
padding-inline: $padding;
}
}

.dx-chat-messagelist-day-header {
padding-bottom: $day-header-padding-bottom;
color: $day-header-color;

&:first-child {
padding-top: $day-header-first-padding-top;
}
}
}

@mixin chat-messagelist-empty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ $chat-bubble-background-color-primary: null !default;
$chat-bubble-background-color-secondary: $base-border-color !default;
$chat-information-color: null !default;

$chat-messagelist-day-header-color: null !default;
$chat-messagelist-empty-icon-color: null !default;
$chat-messagelist-empty-icon-background-color: null !default;
$chat-messagelist-empty-message-color: $base-text-color !default;
$chat-messagelist-empty-prompt-color: null !default;

@if $mode == "light" {
$chat-information-color: darken($base-bg, 56.08) !default;
$chat-messagelist-day-header-color: darken($base-bg, 56.08) !default;
$chat-messagelist-empty-icon-color: lighten($base-icon-color, 32.16) !default;
$chat-messagelist-empty-icon-background-color: darken($base-bg, 3.92) !default;
$chat-messagelist-empty-prompt-color: darken($base-label-color, 5.88) !default;
Expand All @@ -39,7 +41,8 @@ $chat-messagelist-empty-prompt-color: null !default;
@if $mode == "dark" {
$chat-bubble-background-color-primary: darken(desaturate(adjust-hue($base-accent, 356.3), 14.7), 49.4) !default;
$chat-information-color: lighten($base-bg, 43.92) !default;


$chat-messagelist-day-header-color: lighten($base-bg, 43.92) !default;
$chat-messagelist-empty-icon-color: darken($base-icon-color, 25.88) !default;
$chat-messagelist-empty-icon-background-color: lighten($base-bg, 7.84) !default;
$chat-messagelist-empty-prompt-color: lighten($base-label-color, 7.84) !default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@
$chat-messagelist-empty-prompt-font-size,
$chat-messagelist-empty-prompt-color,
);
@include chat-messagelist($chat-messagelist-padding);
@include chat-messagelist(
$chat-messagelist-padding,
$chat-messagelist-day-header-color,
$chat-messagelist-day-header-padding-bottom,
$chat-messagelist-day-header-first-padding-top,
);
2 changes: 2 additions & 0 deletions packages/devextreme-scss/scss/widgets/fluent/chat/_sizes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $chat-messagelist-empty-icon-margin-bottom: null !default;
$chat-messagelist-empty-row-gap: null !default;
$chat-messagelist-empty-message-font-size: null !default;
$chat-messagelist-empty-prompt-font-size: null !default;
$chat-messagelist-day-header-padding-bottom: 12px !default;
$chat-messagelist-day-header-first-padding-top: 20px !default;

@if $size == "default" {
$chat-bubble-border-radius: $fluent-base-border-radius * 3 !default;
Expand Down
24 changes: 16 additions & 8 deletions packages/devextreme-scss/scss/widgets/generic/chat/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ $chat-background-color: $base-bg !default;
$chat-border-color: $base-border-color !default;
$chat-avatar-color: null !default;
$chat-messagebox-border-color: $base-border-color !default;
$chat-avatar-background-color: null !default;
$chat-bubble-color-primary: null !default;
$chat-bubble-background-color-primary: null !default;
$chat-bubble-background-color-secondary: null !default;
$chat-information-color: null !default;

$chat-messagelist-day-header-color: null !default;
$chat-messagelist-empty-icon-color: null !default;
$chat-messagelist-empty-icon-background-color: null !default;
$chat-messagelist-empty-message-color: null !default;
Expand All @@ -28,6 +28,7 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-secondary: darken($base-element-bg, 4%) !default;
$chat-information-color: darken($base-bg, 41.57) !default;

$chat-messagelist-day-header-color: darken($base-bg, 41.57) !default;
$chat-messagelist-empty-icon-color: lighten($base-icon-color, 46.67) !default;
$chat-messagelist-empty-icon-background-color: darken($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: darken($base-text-color, 6.67) !default;
Expand All @@ -40,7 +41,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: color.change(darken($base-accent, 5%), $alpha: 0.1) !default;
$chat-bubble-background-color-secondary: lighten($base-element-bg, 4%) !default;
$chat-information-color: lighten($base-bg, 32.55) !default;


$chat-messagelist-day-header-color: lighten($base-bg, 32.55) !default;
$chat-messagelist-empty-icon-color: darken($base-icon-color, 37.25) !default;
$chat-messagelist-empty-icon-background-color: lighten($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: lighten($base-text-color, 12.94) !default;
Expand All @@ -53,7 +55,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: color.change(darken($base-accent, 5%), $alpha: 0.1) !default;
$chat-bubble-background-color-secondary: darken($base-element-bg, 4%) !default;
$chat-information-color: darken($base-bg, 41.57) !default;


$chat-messagelist-day-header-color: darken($base-bg, 41.57) !default;
$chat-messagelist-empty-icon-color: $base-icon-color !default;
$chat-messagelist-empty-icon-background-color: darken($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: $base-text-color !default;
Expand All @@ -66,7 +69,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: $base-inverted-bg !default;
$chat-bubble-background-color-secondary: $base-hover-color !default;
$chat-information-color: $base-text-color !default;


$chat-messagelist-day-header-color: $base-text-color !default;
$chat-messagelist-empty-icon-color: $base-bg !default;
$chat-messagelist-empty-icon-background-color: $base-inverted-bg !default;
$chat-messagelist-empty-message-color: $base-text-color !default;
Expand All @@ -79,7 +83,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: color.change(darken($base-accent, 5%), $alpha: 0.1) !default;
$chat-bubble-background-color-secondary: lighten($base-element-bg, 4%) !default;
$chat-information-color: lighten($base-bg, 32.55) !default;


$chat-messagelist-day-header-color: lighten($base-bg, 32.55) !default;
$chat-messagelist-empty-icon-color: $base-icon-color !default;
$chat-messagelist-empty-icon-background-color: darken($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: $base-text-color !default;
Expand All @@ -92,7 +97,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: color.change(darken($base-accent, 5%), $alpha: 0.1) !default;
$chat-bubble-background-color-secondary: lighten($base-element-bg, 4%) !default;
$chat-information-color: lighten($base-bg, 32.55) !default;


$chat-messagelist-day-header-color: lighten($base-bg, 32.55) !default;
$chat-messagelist-empty-icon-color: darken($base-icon-color, 37.25) !default;
$chat-messagelist-empty-icon-background-color: lighten($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: lighten($base-text-color, 12.94) !default;
Expand All @@ -104,7 +110,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: color.change(darken($base-accent, 5%), $alpha: 0.1) !default;
$chat-bubble-background-color-secondary: darken($base-element-bg, 4%) !default;
$chat-information-color: darken($base-bg, 41.57) !default;


$chat-messagelist-day-header-color: darken($base-bg, 41.57) !default;
$chat-messagelist-empty-icon-color: $base-icon-color !default;
$chat-messagelist-empty-icon-background-color: darken($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: $base-text-color !default;
Expand All @@ -117,7 +124,8 @@ $chat-avatar-background-color: $base-border-color !default;
$chat-bubble-background-color-primary: color.change(darken($base-accent, 5%), $alpha: 0.1) !default;
$chat-bubble-background-color-secondary: darken($base-element-bg, 4%) !default;
$chat-information-color: darken($base-bg, 41.57) !default;


$chat-messagelist-day-header-color: darken($base-bg, 41.57) !default;
$chat-messagelist-empty-icon-color: $base-icon-color !default;
$chat-messagelist-empty-icon-background-color: darken($base-bg, 7.84) !default;
$chat-messagelist-empty-message-color: $base-text-color !default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@
$chat-messagelist-empty-prompt-font-size,
$chat-messagelist-empty-prompt-color,
);
@include chat-messagelist($chat-messagelist-padding);
@include chat-messagelist(
$chat-messagelist-padding,
$chat-messagelist-day-header-color,
$chat-messagelist-day-header-padding-bottom,
$chat-messagelist-day-header-first-padding-top,
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ $chat-messagelist-empty-icon-margin-bottom: null !default;
$chat-messagelist-empty-row-gap: null !default;
$chat-messagelist-empty-message-font-size: null !default;
$chat-messagelist-empty-prompt-font-size: null !default;
$chat-messagelist-day-header-padding-bottom: 12px !default;
$chat-messagelist-day-header-first-padding-top: 20px !default;

@if $size == "default" {
$chat-bubble-padding: 8px 12px !default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $chat-bubble-background-color-primary: null !default;
$chat-bubble-background-color-secondary: null !default;
$chat-information-color: null !default;

$chat-messagelist-day-header-color: null !default;
$chat-messagelist-empty-icon-color: rgba($base-inverted-bg, 0.38) !default;
$chat-messagelist-empty-icon-background-color: rgba($base-inverted-bg, 0.08) !default;
$chat-messagelist-empty-message-color: rgba($base-inverted-bg, 0.87) !default;
Expand All @@ -23,10 +24,12 @@ $chat-messagelist-empty-prompt-color: rgba($base-inverted-bg, 0.6) !default;
$chat-bubble-background-color-primary: rgba($base-accent, 0.08) !default;
$chat-bubble-background-color-secondary: rgba($base-inverted-bg, 0.08) !default;
$chat-information-color: rgba(darken($base-bg, 100.00), 0.6) !default;
$chat-messagelist-day-header-color: rgba(darken($base-bg, 100.00), 0.6) !default;
}

@else if $mode == "dark" {
$chat-bubble-background-color-primary: rgba(lighten($base-accent, 19.22), 0.08) !default;
$chat-bubble-background-color-secondary: rgba(lighten(desaturate(adjust-hue($base-bg, -240), 8.47), 76.86), 0.08) !default;
$chat-information-color: rgba(lighten(desaturate(adjust-hue($base-bg, -240), 8.47), 76.86), 0.6) !default;
$chat-messagelist-day-header-color: rgba(lighten(desaturate(adjust-hue($base-bg, -240), 8.47), 76.86), 0.6) !default;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@
$chat-messagelist-empty-prompt-font-size,
$chat-messagelist-empty-prompt-color,
);
@include chat-messagelist($chat-messagelist-padding);
@include chat-messagelist(
$chat-messagelist-padding,
$chat-messagelist-day-header-color,
$chat-messagelist-day-header-padding-bottom,
$chat-messagelist-day-header-first-padding-top,
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ $chat-messagelist-empty-icon-margin-bottom: null !default;
$chat-messagelist-empty-row-gap: null !default;
$chat-messagelist-empty-message-font-size: null !default;
$chat-messagelist-empty-prompt-font-size: null !default;
$chat-messagelist-day-header-padding-bottom: 12px !default;
$chat-messagelist-day-header-first-padding-top: 20px !default;

@if $size == "default" {
$chat-messagebox-buton-gap: 10px !default;
Expand Down
9 changes: 7 additions & 2 deletions packages/devextreme/js/__internal/ui/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import MessageList from './messagelist';
const CHAT_CLASS = 'dx-chat';
const TEXTEDITOR_INPUT_CLASS = 'dx-texteditor-input';

type Properties = ChatProperties & { title: string };
type Properties = ChatProperties & { title: string; showDayHeaders: boolean };

class Chat extends Widget<Properties> {
_chatHeader?: ChatHeader;
Expand All @@ -43,6 +43,7 @@ class Chat extends Widget<Properties> {
dataSource: null,
user: { id: new Guid().toString() },
onMessageSend: undefined,
showDayHeaders: true,
};
}

Expand Down Expand Up @@ -98,7 +99,7 @@ class Chat extends Widget<Properties> {
}

_renderMessageList(): void {
const { items = [], user } = this.option();
const { items = [], user, showDayHeaders } = this.option();

const currentUserId = user?.id;
const $messageList = $('<div>');
Expand All @@ -108,6 +109,7 @@ class Chat extends Widget<Properties> {
this._messageList = this._createComponent($messageList, MessageList, {
items,
currentUserId,
showDayHeaders,
});
}

Expand Down Expand Up @@ -214,6 +216,9 @@ class Chat extends Widget<Properties> {
case 'onMessageSend':
this._createMessageSendAction();
break;
case 'showDayHeaders':
this._messageList.option(name, value);
break;
default:
super._optionChanged(args);
}
Expand Down
Loading

0 comments on commit ad8f0c8

Please sign in to comment.