-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #681 from GetStream/message-text-component
feat: create message-text component
- Loading branch information
Showing
21 changed files
with
791 additions
and
476 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
projects/customizations-example/src/app/message-text/message-text.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<ng-container *ngIf="isQuoted; else regularMessageText"> | ||
<!-- Quoted message are clamped by default, so need there --> | ||
<stream-message-text | ||
[message]="message" | ||
[shouldTranslate]="shouldTranslate" | ||
[isQuoted]="isQuoted" | ||
></stream-message-text> | ||
</ng-container> | ||
<ng-template #regularMessageText> | ||
<div class="message-text" [class.message-text-expanded]="isExpanded" #text> | ||
<stream-message-text | ||
[message]="message" | ||
[shouldTranslate]="shouldTranslate" | ||
[isQuoted]="isQuoted" | ||
></stream-message-text> | ||
</div> | ||
<!-- 5px diff is due to Firefox issue --> | ||
<button | ||
[class.visible]="text.scrollHeight - text.clientHeight > 5 || isExpanded" | ||
(click)="isExpanded = !isExpanded" | ||
> | ||
{{ "Show" + (isExpanded ? " less" : " more") }} | ||
</button> | ||
</ng-template> |
19 changes: 19 additions & 0 deletions
19
projects/customizations-example/src/app/message-text/message-text.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.message-text { | ||
overflow: hidden; | ||
display: -webkit-box; | ||
-webkit-line-clamp: 5; | ||
line-clamp: 5; | ||
-webkit-box-orient: vertical; | ||
} | ||
|
||
.message-text.message-text-expanded { | ||
display: block; | ||
} | ||
|
||
button { | ||
display: none; | ||
|
||
&.visible { | ||
display: block; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
projects/customizations-example/src/app/message-text/message-text.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { MessageResponseBase } from 'stream-chat'; | ||
import { DefaultStreamChatGenerics, StreamMessage } from 'stream-chat-angular'; | ||
|
||
@Component({ | ||
selector: 'app-message-text', | ||
templateUrl: './message-text.component.html', | ||
styleUrls: ['./message-text.component.scss'], | ||
}) | ||
export class MessageTextComponent { | ||
@Input() message: | ||
| StreamMessage<DefaultStreamChatGenerics> | ||
| undefined | ||
| MessageResponseBase<DefaultStreamChatGenerics>; | ||
@Input() isQuoted: boolean = false; | ||
@Input() shouldTranslate: boolean = false; | ||
isExpanded = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
projects/stream-chat-angular/src/lib/message-text/message-text.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<p | ||
[class.str-chat__quoted-message-text-value]="isQuoted" | ||
[class.str-chat__message-text-value]="!isQuoted" | ||
*ngIf="message?.text" | ||
data-testid="text" | ||
> | ||
<ng-container *ngIf="messageTextParts; else defaultContent"> | ||
<!-- eslint-disable-next-line @angular-eslint/template/use-track-by-function --> | ||
<ng-container *ngFor="let part of messageTextParts"> | ||
<span | ||
*ngIf="part.type === 'text'; else mention" | ||
[innerHTML]="part.content" | ||
></span> | ||
<ng-template #mention> | ||
<ng-template #defaultMention let-content="content"> | ||
<span class="str-chat__message-mention">{{ content }}</span> | ||
</ng-template> | ||
<ng-container | ||
*ngTemplateOutlet=" | ||
(customTemplatesService.mentionTemplate$ | async) || defaultMention; | ||
context: getMentionContext(part) | ||
" | ||
></ng-container> | ||
</ng-template> | ||
</ng-container> | ||
</ng-container> | ||
<ng-template #defaultContent> | ||
<ng-container *ngIf="displayAs === 'text'; else asHTML"> | ||
{{ messageText || "" }} | ||
</ng-container> | ||
<ng-template #asHTML | ||
><span data-testid="html-content" [innerHTML]="messageText"></span | ||
></ng-template> | ||
</ng-template> | ||
</p> |
Oops, something went wrong.