Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat: add Customizations demo for Vue, React and Angular #28482

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
003758a
Initial React demo
nikkithelegendarypokemonster Dec 3, 2024
010e87a
Initial Angular demo
nikkithelegendarypokemonster Dec 3, 2024
07ab753
Initial Vue demo
nikkithelegendarypokemonster Dec 3, 2024
a06b9d9
Merge branch '24_2' of https://github.com/DevExpress/DevExtreme into …
nikkithelegendarypokemonster Dec 4, 2024
a40d776
refactor review comments
nikkithelegendarypokemonster Dec 4, 2024
9f2202f
refactor identation
nikkithelegendarypokemonster Dec 4, 2024
033e60b
add other framework for testing
nikkithelegendarypokemonster Dec 4, 2024
2419f7d
add react js demo
nikkithelegendarypokemonster Dec 4, 2024
fe67c1d
remove extra spaces and fix code arrangement as well
nikkithelegendarypokemonster Dec 4, 2024
bdc4308
update etalon files
nikkithelegendarypokemonster Dec 4, 2024
eac187c
rename class in test
nikkithelegendarypokemonster Dec 4, 2024
8878cbf
update scenario etalons
nikkithelegendarypokemonster Dec 4, 2024
37c8016
refactor review comments
nikkithelegendarypokemonster Dec 4, 2024
fed53ae
fix testcafe test to be compatible with other frameworks as well
nikkithelegendarypokemonster Dec 4, 2024
130b332
test fix
nikkithelegendarypokemonster Dec 5, 2024
3f9ad9a
refactor react
EugeniyKiyashko Dec 5, 2024
f9bc200
Merge branch '24_2' into 24_2-chat-customization-demo-frameworks
EugeniyKiyashko Dec 5, 2024
516719c
Testcafe scenarios tests: skip unstable tests
EugeniyKiyashko Dec 5, 2024
3135449
fix small remarks after review
EugeniyKiyashko Dec 5, 2024
a849a68
fix lint
EugeniyKiyashko Dec 5, 2024
3be9aef
fix text in Vue
EugeniyKiyashko Dec 5, 2024
03d5bc0
revert excess change
EugeniyKiyashko Dec 5, 2024
08c1877
regenerate reactjs
EugeniyKiyashko Dec 5, 2024
47630e4
fix scenario tests
EugeniyKiyashko Dec 5, 2024
bd83b4d
revert lint changes
EugeniyKiyashko Dec 5, 2024
ab74b2e
fix
EugeniyKiyashko Dec 5, 2024
17db75e
fix indentions
EugeniyKiyashko Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/demos/Demos/Chat/Customization/Angular/app/app.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.demo-container {
min-width: 720px;
display: flex;
gap: 20px;
}

::ng-deep .chat-container {
display: flex;
flex-grow: 1;
align-items: center;
justify-content: center;
}

::ng-deep .options {
padding: 20px;
display: flex;
flex-direction: column;
min-width: 280px;
background-color: rgba(191, 191, 191, 0.15);
gap: 16px;
}

::ng-deep .dx-chat {
max-width: 480px;
}

::ng-deep .caption {
font-size: var(--dx-font-size-sm);
font-weight: 500;
}

::ng-deep .option-separator {
border-bottom: 1px solid var(--dx-color-border);
}

::ng-deep .dx-avatar {
border: 1px solid var(--dx-color-border);
}
79 changes: 79 additions & 0 deletions apps/demos/Demos/Chat/Customization/Angular/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<div class="demo-container">
<div class="chat-container">
<dx-chat
#chat
[height]="710"
[user]="currentUser"
nikkithelegendarypokemonster marked this conversation as resolved.
Show resolved Hide resolved
[items]="messages$ | async"
[showAvatar]="true"
[showUserName]="true"
[showDayHeaders]="true"
[showMessageTimestamp]="true"
[dayHeaderFormat]="dayHeaderFormats[0]"
[messageTimestampFormat]="messageTimestampFormats[0]"
[disabled]="false"
(onMessageEntered)="onMessageEntered($event)"
>
</dx-chat>
</div>

<div class="options">
<div class="caption">Options</div>

<div class="option">
<dx-check-box text="Avatar" [(value)]="chat.showAvatar"></dx-check-box>
</div>

<div class="option">
<dx-check-box
text="User Name"
[(value)]="chat.showUserName"
></dx-check-box>
</div>

<div class="option-separator"></div>

<div class="option">
<dx-check-box
text="Day Headers"
[(value)]="chat.showDayHeaders"
></dx-check-box>
</div>

<div class="option">
<span>Day Header Format:</span>
<dx-select-box
[items]="dayHeaderFormats"
[(value)]="chat.dayHeaderFormat"
[inputAttr]="dayHeaderLabel"
></dx-select-box>
</div>

<div class="option-separator"></div>

<div class="option">
<dx-check-box
text="Message Timestamp"
[(value)]="chat.showMessageTimestamp"
></dx-check-box>
</div>

<div class="option">
<span>Message Timestamp Format:</span>
<dx-select-box
[items]="messageTimestampFormats"
[(value)]="chat.messageTimestampFormat"
[inputAttr]="messageTimestampLabel"
></dx-select-box>
</div>

<div class="option-separator"></div>

<div class="option">
<dx-check-box
text="Disable Chat"
[(value)]="chat.disabled"
></dx-check-box>
</div>
</div>
</div>
63 changes: 63 additions & 0 deletions apps/demos/Demos/Chat/Customization/Angular/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { NgModule, Component, enableProdMode } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { DxChatModule, DxCheckBoxModule, DxSelectBoxModule } from 'devextreme-angular';
import { User, Message, MessageEnteredEvent } from 'devextreme/ui/chat';
import { Observable } from 'rxjs';
import { AppService } from './app.service';

if (!/localhost/.test(document.location.host)) {
enableProdMode();
}

let modulePrefix = '';
// @ts-ignore
if (window && window.config.packageConfigPaths) {
modulePrefix = '/app';
}

@Component({
selector: 'demo-app',
templateUrl: `.${modulePrefix}/app.component.html`,
styleUrls: [`.${modulePrefix}/app.component.css`],
})
export class AppComponent {
currentUser: User;

supportAgent: User;

messages$: Observable<Message[]>;

dayHeaderFormats = this.appService.dayHeaderFormats;

messageTimestampFormats = this.appService.messageTimestampFormats;

dayHeaderLabel = this.appService.dayHeaderLabel;

messageTimestampLabel = this.appService.messageTimestampLabel;

constructor(private readonly appService: AppService) {
[this.currentUser, this.supportAgent] = this.appService.getUsers();
this.messages$ = this.appService.messages$;
}

onMessageEntered(event: MessageEnteredEvent) {
this.appService.onMessageEntered(event);
}
}

@NgModule({
imports: [
BrowserModule,
DxChatModule,
DxCheckBoxModule,
DxSelectBoxModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [AppService],
})
export class AppModule { }

platformBrowserDynamic().bootstrapModule(AppModule);
90 changes: 90 additions & 0 deletions apps/demos/Demos/Chat/Customization/Angular/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { User, Message, MessageEnteredEvent } from 'devextreme/ui/chat';

@Injectable({
providedIn: 'root',
})
export class AppService {
date: Date;

currentUser: User = {
id: 'c94c0e76-fb49-4b9b-8f07-9f93ed93b4f3',
name: 'John Doe',
};

supportAgent: User = {
id: 'd16d1a4c-5c67-4e20-b70e-2991c22747c3',
name: 'Support Agent',
avatarUrl: '../../../../images/petersmith.png',
nikkithelegendarypokemonster marked this conversation as resolved.
Show resolved Hide resolved
};

dayHeaderFormats = ['dd/MM/yyyy', 'dd.MM.yyyy', 'MMMM dd, yyyy', 'EEEE, MMMM dd'];

messageTimestampFormats = ['hh:mm a', 'hh:mm:ss a', 'HH:mm', 'HH:mm:ss'];

messageTimestampLabel = { 'aria-label': 'Message Timestamp Format' };

dayHeaderLabel = { 'aria-label': 'Day Header Format' };

messages: Message[] = [];

messagesSubject: BehaviorSubject<Message[]> = new BehaviorSubject([]);

constructor() {
this.date = new Date();
this.date.setHours(0, 0, 0, 0);

this.messages = [
{
timestamp: this.getTimestamp(this.date, -9),
author: this.supportAgent,
text: 'Hello, John!\nHow can I assist you today?',
},
{
timestamp: this.getTimestamp(this.date, -7),
author: this.currentUser,
text: 'Hi, I\'m having trouble accessing my account.',
},
{
timestamp: this.getTimestamp(this.date, -7),
author: this.currentUser,
text: 'It says my password is incorrect.',
},
{
timestamp: this.getTimestamp(this.date, -7),
author: this.supportAgent,
text: 'I can help you with that. Can you please confirm your UserID for security purposes?',
},
{
timestamp: this.getTimestamp(this.date, 1),
author: this.currentUser,
text: 'john.doe1357',
},
{
timestamp: this.getTimestamp(this.date, 1),
author: this.supportAgent,
text: '✅ Instructions to restore access have been sent to the email address associated with your account.',
},
];

this.messagesSubject.next(this.messages);
}

get messages$(): Observable<Message[]> {
return this.messagesSubject.asObservable();
}

getUsers(): User[] {
return [this.currentUser, this.supportAgent];
}

getTimestamp(date: Date, offsetMinutes = 0): number {
return date.getTime() + offsetMinutes * 60000;
}

onMessageEntered(event: MessageEnteredEvent) {
this.messages = [...this.messages, event.message];
this.messagesSubject.next(this.messages);
}
}
26 changes: 26 additions & 0 deletions apps/demos/Demos/Chat/Customization/Angular/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<link rel="stylesheet" type="text/css" href="../../../../node_modules/devextreme-dist/css/dx.light.css" />

<script src="../../../../node_modules/core-js/client/shim.min.js"></script>
<script src="../../../../node_modules/zone.js/bundles/zone.umd.js"></script>
<script src="../../../../node_modules/reflect-metadata/Reflect.js"></script>
<script src="../../../../node_modules/systemjs/dist/system.js"></script>

<script src="config.js"></script>
<script>
System.import("app").catch(console.error.bind(console));
</script>
</head>

<body class="dx-viewport">
<div class="demo-container">
<demo-app>Loading...</demo-app>
</div>
</body>
</html>
Loading
Loading