Skip to content

Commit 19a50f0

Browse files
authored
Merge pull request #158 from GetStream/custom-message-edit-input
feat: Add support for custom message input in MessageActionsBox #134
2 parents a68a682 + 8861620 commit 19a50f0

File tree

10 files changed

+74
-17
lines changed

10 files changed

+74
-17
lines changed

docusaurus/docs/Angular/components/message-actions.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ export class CustomMessageComponent {
4747
}
4848
```
4949

50-
:::important
51-
Currently it is not possible to provide a custom component for message edit.
52-
:::
53-
5450
:::important
5551
The `MessageActionBox` component doesn't check if the user has the necessary capabilities to perform a given aciton, it is done by the [`MessageList`](./message-list.mdx/#enabledmessageactions) component.
5652
:::
@@ -87,6 +83,14 @@ The list of actions that are enabled. To disable all actions, provide an empty a
8783
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
8884
| [`MessageAction`](https://github.com/GetStream/stream-chat-angular/tree/master/projects/stream-chat-angular/src/lib/message-actions-box/message-actions-box.component.ts)[] | [] |
8985

86+
### messageInputTemplate
87+
88+
The input used for message edit. By default, the [default message input component](./message-input.mdx) is used. To change the input for message edit, provide [your own custom template](./message-input.mdx/#customization).
89+
90+
| Type |
91+
| ----------- |
92+
| TemplateRef |
93+
9094
## Outputs
9195

9296
### isEditing

docusaurus/docs/Angular/components/message-input.mdx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,26 @@ If you want to create your own message input, here is how to use it:
1818
<stream-channel-list></stream-channel-list>
1919
<stream-channel>
2020
<stream-channel-header></stream-channel-header>
21-
<stream-message-list></stream-message-list>
21+
<stream-message-list
22+
[messageInputTemplate]="customMessageInput"
23+
></stream-message-list>
2224
<custom-message-input></custom-message-input>
2325
</stream-channel>
26+
27+
<ng-template
28+
#customMessageInput
29+
let-message="message"
30+
let-messageUpdateHandler="messageUpdateHandler"
31+
>
32+
<custom-message-input
33+
[message]="message"
34+
(messageUpdate)="messageUpdateHandler($event)"
35+
></custom-message-input>
36+
</ng-template>
2437
```
2538

39+
The default chat UI uses the message input in two different places: at the bottom of the channel to send new message, and in the message list to edit a message.
40+
2641
:::note
2742
If you want to create your own message input, you can use the following building blocks:
2843

@@ -51,10 +66,6 @@ You can use the [`Textarea`](./textarea.mdx) or the [`AutocompleteTextarea`](./a
5166

5267
:::
5368

54-
:::important
55-
Currently it is not possible to provide a custom component for message edit in the [`MessageActionsBox`](./message-actions.mdx) component. Please consider this limitation when creating your own custom message input.
56-
:::
57-
5869
## Inputs
5970

6071
### isFileUploadEnabled

docusaurus/docs/Angular/components/message-list.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ By default, the [default message component](./message.mdx) is used. To change th
5959
| ----------- |
6060
| TemplateRef |
6161

62+
### messageInputTemplate
63+
64+
The input used for message edit. By default, the [default message input component](./message-input.mdx) is used. To change the input for message edit, provide [your own custom template](./message-input.mdx/#customization).
65+
66+
| Type |
67+
| ----------- |
68+
| TemplateRef |
69+
6270
### areReactionsEnabled
6371

6472
If true, the message reactions are displayed. Users can also react to messages if they have the necessary [channel capability](https://getstream.io/chat/docs/javascript/channel_capabilities/?language=javascript).

docusaurus/docs/Angular/components/message.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,11 @@ If `true`, the message status (sending, sent, who read the message) is displayed
149149
| Type |
150150
| ------- |
151151
| boolean |
152+
153+
### messageInputTemplate
154+
155+
The input used for message edit. By default, the [default message input component](./message-input.mdx) is used. To change the input for message edit, provide [your own custom template](./message-input.mdx/#customization).
156+
157+
| Type |
158+
| ----------- |
159+
| TemplateRef |

projects/stream-chat-angular/src/lib/message-actions-box/message-actions-box.component.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,23 @@
7171
"
7272
>
7373
<div class="str-chat__edit-message-form" *ngIf="isEditModalOpen">
74-
<stream-message-input
75-
[message]="message"
76-
(messageUpdate)="modalClosed()"
77-
></stream-message-input>
74+
<ng-container *ngIf="messageInputTemplate; else defaultInput">
75+
<ng-container
76+
*ngTemplateOutlet="
77+
messageInputTemplate;
78+
context: {
79+
message: message,
80+
messageUpdateHandler: modalClosed
81+
}
82+
"
83+
></ng-container>
84+
</ng-container>
85+
<ng-template #defaultInput>
86+
<stream-message-input
87+
[message]="message"
88+
(messageUpdate)="modalClosed()"
89+
></stream-message-input>
90+
</ng-template>
7891
<stream-notification-list></stream-notification-list>
7992
<div class="str-chat__message-team-form-footer">
8093
<div></div>

projects/stream-chat-angular/src/lib/message-actions-box/message-actions-box.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
OnChanges,
66
Output,
77
SimpleChanges,
8+
TemplateRef,
89
ViewChild,
910
} from '@angular/core';
1011
import { ChannelService } from '../channel.service';
@@ -29,6 +30,7 @@ export type MessageActions =
2930
styles: [],
3031
})
3132
export class MessageActionsBoxComponent implements OnChanges {
33+
@Input() messageInputTemplate: TemplateRef<any> | undefined;
3234
@Input() isOpen = false;
3335
@Input() isMine = false;
3436
@Input() message: StreamMessage | undefined;
@@ -136,10 +138,10 @@ export class MessageActionsBoxComponent implements OnChanges {
136138
this.messageInput?.messageSent();
137139
}
138140

139-
modalClosed() {
141+
modalClosed = () => {
140142
this.isEditModalOpen = false;
141143
this.isEditing.emit(false);
142-
}
144+
};
143145

144146
async deleteClicked() {
145147
try {

projects/stream-chat-angular/src/lib/message-list/message-list.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
lastSentMessageId: !!(
2727
lastSentMessageId && message?.id === lastSentMessageId
2828
),
29-
canReceiveReadEvents: canReceiveReadEvents
29+
canReceiveReadEvents: canReceiveReadEvents,
30+
messageInputTemplate: messageInputTemplate
3031
}
3132
"
3233
></ng-container>
@@ -41,6 +42,7 @@
4142
"
4243
[enabledMessageActions]="enabledMessageActions"
4344
[canReceiveReadEvents]="canReceiveReadEvents"
45+
[messageInputTemplate]="messageInputTemplate"
4446
></stream-message>
4547
</ng-template>
4648
</li>

projects/stream-chat-angular/src/lib/message-list/message-list.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { MessageActions } from '../message-actions-box/message-actions-box.compo
2424
})
2525
export class MessageListComponent implements AfterViewChecked, OnChanges {
2626
@Input() messageTemplate: TemplateRef<any> | undefined;
27+
@Input() messageInputTemplate: TemplateRef<any> | undefined;
2728
@Input() areReactionsEnabled = true;
2829
/* eslint-disable-next-line @angular-eslint/no-input-rename */
2930
@Input('enabledMessageActions') enabledMessageActionsInput: MessageActions[] =

projects/stream-chat-angular/src/lib/message/message.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
[message]="message"
6767
(displayedActionsCount)="visibleMessageActionsCount = $event"
6868
(isEditing)="isEditing = $event; isActionBoxOpen = !isEditing"
69+
[messageInputTemplate]="messageInputTemplate"
6970
></stream-message-actions-box>
7071
<stream-icon
7172
*ngIf="visibleMessageActionsCount > 0"

projects/stream-chat-angular/src/lib/message/message.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, ElementRef, Input, ViewChild } from '@angular/core';
1+
import {
2+
Component,
3+
ElementRef,
4+
Input,
5+
TemplateRef,
6+
ViewChild,
7+
} from '@angular/core';
28
import { UserResponse } from 'stream-chat';
39
import { ChannelService } from '../channel.service';
410
import { ChatClientService } from '../chat-client.service';
@@ -14,6 +20,7 @@ import { getReadByText } from './read-by-text';
1420
styles: [],
1521
})
1622
export class MessageComponent {
23+
@Input() messageInputTemplate: TemplateRef<any> | undefined;
1724
@Input() message: StreamMessage | undefined;
1825
@Input() enabledMessageActions: MessageActions[] = [];
1926
@Input() areReactionsEnabled: boolean | undefined;

0 commit comments

Comments
 (0)