1 | /**
|
2 | * @license
|
3 | * Copyright Akveo. All Rights Reserved.
|
4 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
5 | */
|
6 | import { ElementRef, QueryList, AfterViewInit, SimpleChanges, AfterContentInit, OnChanges } from '@angular/core';
|
7 | import { NbStatusService } from '../../services/status.service';
|
8 | import { NbComponentSize } from '../component-size';
|
9 | import { NbComponentOrCustomStatus } from '../component-status';
|
10 | import { NbBooleanInput } from '../helpers';
|
11 | import { NbChatFormComponent } from './chat-form.component';
|
12 | import { NbChatMessageComponent } from './chat-message.component';
|
13 | import { NbChatTitleDirective } from './chat-title.directive';
|
14 | import * as i0 from "@angular/core";
|
15 | /**
|
16 | * Conversational UI collection - a set of components for chat-like UI construction.
|
17 | *
|
18 | * Main features:
|
19 | * - different message types support (text, image, file, file group, map, etc)
|
20 | * - drag & drop for images and files with preview
|
21 | * - different UI styles
|
22 | * - custom action buttons (coming soon)
|
23 | *
|
24 | * Here's a complete example build in a bot-like app. Type `help` to be able to receive different message types.
|
25 | * Enjoy the conversation and the beautiful UI.
|
26 | * @stacked-example(Showcase, chat/chat-showcase.component)
|
27 | *
|
28 | * Basic chat configuration and usage:
|
29 | * ```ts
|
30 | * <nb-chat title="Nebular Conversational UI">
|
31 | * <nb-chat-message *ngFor="let msg of messages"
|
32 | * [type]="msg.type"
|
33 | * [message]="msg.text"
|
34 | * [reply]="msg.reply"
|
35 | * [sender]="msg.user.name"
|
36 | * [date]="msg.date"
|
37 | * [files]="msg.files"
|
38 | * [quote]="msg.quote"
|
39 | * [latitude]="msg.latitude"
|
40 | * [longitude]="msg.longitude"
|
41 | * [avatar]="msg.user.avatar">
|
42 | * </nb-chat-message>
|
43 | *
|
44 | * <nb-chat-form (send)="sendMessage($event)" [dropFiles]="true">
|
45 | * </nb-chat-form>
|
46 | * </nb-chat>
|
47 | * ```
|
48 | * ### Installation
|
49 | *
|
50 | * Import `NbChatModule` to your feature module.
|
51 | * ```ts
|
52 | * @NgModule({
|
53 | * imports: [
|
54 | * // ...
|
55 | * NbChatModule,
|
56 | * ],
|
57 | * })
|
58 | * export class PageModule { }
|
59 | * ```
|
60 | *
|
61 | * If you need to provide an API key for a `map` message type (which is required by Google Maps)
|
62 | * you may use `NbChatModule.forRoot({ ... })` call if this is a global app configuration
|
63 | * or `NbChatModule.forChild({ ... })` for a feature module configuration:
|
64 | *
|
65 | * ```ts
|
66 | * @NgModule({
|
67 | * imports: [
|
68 | * // ...
|
69 | * NbChatModule.forRoot({ messageGoogleMapKey: 'MAP_KEY' }),
|
70 | * ],
|
71 | * })
|
72 | * export class AppModule { }
|
73 | * ```
|
74 | *
|
75 | * ### Usage
|
76 | *
|
77 | * There are three main components:
|
78 | * ```ts
|
79 | * <nb-chat>
|
80 | * </nb-chat> // chat container
|
81 | *
|
82 | * <nb-chat-form>
|
83 | * </nb-chat-form> // chat form with drag&drop files feature
|
84 | *
|
85 | * <nb-chat-message>
|
86 | * </nb-chat-message> // chat message, available multiple types
|
87 | * ```
|
88 | *
|
89 | * You could provide a title template via the `nbChatTitle` directive. It overrides `title` input.
|
90 | * @stacked-example(Custom template as a title, chat/chat-template-title.component)
|
91 | *
|
92 | * Two users conversation showcase:
|
93 | * @stacked-example(Conversation, chat/chat-conversation-showcase.component)
|
94 | *
|
95 | * Chat UI is also available in different colors by specifying a `[status]` input:
|
96 | *
|
97 | * @stacked-example(Colored Chat, chat/chat-colors.component)
|
98 | *
|
99 | * Also it is possible to configure sizes through `[size]` input:
|
100 | *
|
101 | * @stacked-example(Chat Sizes, chat/chat-sizes.component)
|
102 | *
|
103 | * # Custom message types
|
104 | *
|
105 | * Besides built-in message types, you could provide custom ones with their own template to render.
|
106 | * As an example, let's add the `link` message type.
|
107 | * <br>
|
108 | * First, you need to provide a template for the `link` message type:
|
109 | * ```html
|
110 | * <nb-chat>
|
111 | * <a *nbCustomMessage="'link'" href="https://example.com">example.com</a>
|
112 | * </nb-chat>
|
113 | * ```
|
114 | * Then, add the `nb-chat-message` component with the `link` type:
|
115 | * ```html
|
116 | * <nb-chat>
|
117 | * <a *nbCustomMessage="'link'" href="https://example.com">example.com</a>
|
118 | * <nb-chat-message type="link"></nb-chat-message>
|
119 | * </nb-chat>
|
120 | * ```
|
121 | *
|
122 | * <div class="note note-warning">
|
123 | * <div class="note-title">Important!</div>
|
124 | * <div class="note-body">
|
125 | * Custom chat messages must be defined before the `nb-chat-message`.
|
126 | * </div>
|
127 | * </div>
|
128 | *
|
129 | * Custom message templates could have arbitrary data associated with them. Let's extract hardcoded link
|
130 | * href and text. To pass some data to the custom message template, use the `customMessageData` input
|
131 | * of the `nb-chat-message` component:
|
132 | * ```html
|
133 | * ...
|
134 | * <nb-chat-message type="link" [customMessageData]="{ href: 'https://example.com', text: 'example.com' }">
|
135 | * </nb-chat-message>
|
136 | * ...
|
137 | * ```
|
138 | * When `customMessageData` is set, this object would become a template context and you'll be able
|
139 | * to reference it via `let varName` syntax:
|
140 | * ```html
|
141 | * <a *nbCustomMessage="'link'; let data" [href]="data.href">{{ data.text }}</a>
|
142 | * ```
|
143 | *
|
144 | * That's it, full example will look like this:
|
145 | * ```html
|
146 | * <nb-chat title="Nebular Conversational UI">
|
147 | * <a *nbCustomMessage="'link'; let data" [href]="data.href">{{ data.text }}</a>
|
148 | * <nb-chat-message type="link" [customMessageData]="{ href: 'https://example.com', text: 'example.com' }">
|
149 | * </nb-chat-message>
|
150 | * </nb-chat>
|
151 | * ```
|
152 | *
|
153 | * If you want to style your custom template from the ground up you could turn off generic message styling
|
154 | * (such as round borders, color, background, etc.) via the `noStyles` input:
|
155 | * ```html
|
156 | * <div *nbCustomMessage="'my-custom-type'; noStyles: true">...</div>
|
157 | * ```
|
158 | * When you decide to use your own styles, the `isReply` property of the custom message template context
|
159 | * would come in handy. This property allows you to determine whether the message is a reply or not.
|
160 | * For example, to change link text color (as replies have a different background):
|
161 | * ```html
|
162 | * <a *nbCustomMessage="'link'; let data; let isReply=isReply"
|
163 | * [href]="data.href"
|
164 | * [class.link-control]="!isReply">
|
165 | * {{ data.label }}
|
166 | * </a>
|
167 | * ```
|
168 | *
|
169 | * Below, you could find a more complex example with multiple custom message types:
|
170 | * @stacked-example(Custom message, chat/chat-custom-message.component)
|
171 | *
|
172 | * @styles
|
173 | *
|
174 | * chat-background-color:
|
175 | * chat-border:
|
176 | * chat-border-radius:
|
177 | * chat-shadow:
|
178 | * chat-padding:
|
179 | * chat-scrollbar-color:
|
180 | * chat-scrollbar-background-color:
|
181 | * chat-scrollbar-width:
|
182 | * chat-text-color:
|
183 | * chat-text-font-family:
|
184 | * chat-text-font-size:
|
185 | * chat-text-font-weight:
|
186 | * chat-text-line-height:
|
187 | * chat-header-text-font-family:
|
188 | * chat-header-text-font-size:
|
189 | * chat-header-text-font-weight:
|
190 | * chat-header-text-line-height:
|
191 | * chat-tiny-height:
|
192 | * chat-small-height:
|
193 | * chat-medium-height:
|
194 | * chat-large-height:
|
195 | * chat-giant-height:
|
196 | * chat-basic-background-color:
|
197 | * chat-basic-text-color:
|
198 | * chat-primary-background-color:
|
199 | * chat-primary-text-color:
|
200 | * chat-success-background-color:
|
201 | * chat-success-text-color:
|
202 | * chat-info-background-color:
|
203 | * chat-info-text-color:
|
204 | * chat-warning-background-color:
|
205 | * chat-warning-text-color:
|
206 | * chat-danger-background-color:
|
207 | * chat-danger-text-color:
|
208 | * chat-control-background-color:
|
209 | * chat-control-text-color:
|
210 | * chat-divider-color:
|
211 | * chat-divider-style:
|
212 | * chat-divider-width:
|
213 | * chat-message-background:
|
214 | * chat-message-text-color:
|
215 | * chat-message-reply-background-color:
|
216 | * chat-message-reply-text-color:
|
217 | * chat-message-avatar-background-color:
|
218 | * chat-message-sender-text-color:
|
219 | * chat-message-quote-background-color:
|
220 | * chat-message-quote-text-color:
|
221 | * chat-message-file-text-color:
|
222 | * chat-message-file-background-color:
|
223 | */
|
224 | export declare class NbChatComponent implements OnChanges, AfterContentInit, AfterViewInit {
|
225 | protected statusService: NbStatusService;
|
226 | title: string;
|
227 | /**
|
228 | * Chat size, available sizes:
|
229 | * `tiny`, `small`, `medium`, `large`, `giant`
|
230 | */
|
231 | size: NbComponentSize;
|
232 | /**
|
233 | * Chat status color (adds specific styles):
|
234 | * `basic` (default), `primary`, `success`, `info`, `warning`, `danger`, `control`.
|
235 | */
|
236 | status: NbComponentOrCustomStatus;
|
237 | noMessagesPlaceholder: string;
|
238 | /**
|
239 | * Scroll chat to the bottom of the list when a new message arrives
|
240 | */
|
241 | get scrollBottom(): boolean;
|
242 | set scrollBottom(value: boolean);
|
243 | protected _scrollBottom: boolean;
|
244 | static ngAcceptInputType_scrollBottom: NbBooleanInput;
|
245 | scrollable: ElementRef;
|
246 | messages: QueryList<NbChatMessageComponent>;
|
247 | chatForm: NbChatFormComponent;
|
248 | titleTemplate: NbChatTitleDirective;
|
249 | constructor(statusService: NbStatusService);
|
250 | ngOnChanges(changes: SimpleChanges): void;
|
251 | ngAfterContentInit(): void;
|
252 | ngAfterViewInit(): void;
|
253 | updateView(): void;
|
254 | scrollListBottom(): void;
|
255 | protected updateFormStatus(): void;
|
256 | get tiny(): boolean;
|
257 | get small(): boolean;
|
258 | get medium(): boolean;
|
259 | get large(): boolean;
|
260 | get giant(): boolean;
|
261 | get primary(): boolean;
|
262 | get success(): boolean;
|
263 | get info(): boolean;
|
264 | get warning(): boolean;
|
265 | get danger(): boolean;
|
266 | get basic(): boolean;
|
267 | get control(): boolean;
|
268 | get additionalClasses(): string[];
|
269 | static ɵfac: i0.ɵɵFactoryDeclaration<NbChatComponent, never>;
|
270 | static ɵcmp: i0.ɵɵComponentDeclaration<NbChatComponent, "nb-chat", never, { "title": { "alias": "title"; "required": false; }; "size": { "alias": "size"; "required": false; }; "status": { "alias": "status"; "required": false; }; "noMessagesPlaceholder": { "alias": "noMessagesPlaceholder"; "required": false; }; "scrollBottom": { "alias": "scrollBottom"; "required": false; }; }, {}, ["chatForm", "titleTemplate", "messages"], ["nb-chat-message", "nb-chat-form"], false, never>;
|
271 | }
|