-
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 #159 from GetStream/mention-enhancement
Mention enhancement
- Loading branch information
Showing
19 changed files
with
364 additions
and
111 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 @@ | ||
{ | ||
"label": "Code examples", | ||
"position": 6 | ||
} |
138 changes: 138 additions & 0 deletions
138
docusaurus/docs/Angular/code-examples/mention-actions.mdx
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,138 @@ | ||
--- | ||
id: mention-actions | ||
sidebar_position: 1 | ||
title: Mention actions | ||
--- | ||
|
||
import Screenshot from "../assets/mention-screenshot.png"; | ||
|
||
In this example, we will demonstrate how to create custom mention actions if a user clicks on or hovers over a mention in a message. | ||
|
||
## Custom mention template | ||
|
||
You can provide a custom message template to the `MessageList` component: | ||
|
||
```html | ||
<div id="root"> | ||
<stream-channel-list></stream-channel-list> | ||
<stream-channel> | ||
<stream-channel-header></stream-channel-header> | ||
<stream-message-list | ||
[mentionTemplate]="mentionTemplate" | ||
></stream-message-list> | ||
<stream-notification-list></stream-notification-list> | ||
<stream-message-input></stream-message-input> | ||
</stream-channel> | ||
</div> | ||
|
||
<ng-template #mentionTemplate let-user="user"> | ||
<b>@{{ user.name || user.id }}</b> | ||
</ng-template> | ||
``` | ||
|
||
The `MessageList` component will provide the mentioned user in a variable called `user`, the object has a [`UserResponse`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts) type and you can use it to display information about the user. | ||
|
||
This template looks and works like the default mention template, however you can add interactions to this element. | ||
|
||
## Display user information on click | ||
|
||
In this step we will create a popover with additional user information that will be displayed if the user clicks on a mention. We are using the [`ngx-popperjs`](https://www.npmjs.com/package/ngx-popperjs) library for the popover, but you can use a different library as well. | ||
|
||
### Install `ngx-popperjs` | ||
|
||
Let's install the necessary dependencies: | ||
|
||
```bash | ||
npm install @popperjs/core ngx-popperjs --save | ||
``` | ||
|
||
### Import the `NgxPopperjsModule` module | ||
|
||
```typescript | ||
import {NgxPopperjsModule} from 'ngx-popperjs'; | ||
|
||
@NgModule({ | ||
// ... | ||
imports: [ | ||
// ... | ||
NgxPopperjsModule | ||
] | ||
}) | ||
``` | ||
|
||
### Import SCSS | ||
|
||
Add this to your `styles.scss`: | ||
|
||
```scss | ||
@import "~ngx-popperjs/scss/theme-white"; | ||
``` | ||
|
||
[CSS is also supported.](https://www.npmjs.com/package/ngx-popperjs) | ||
|
||
### Create the popover | ||
|
||
```html | ||
<ng-template #mentionTemplate let-user="user"> | ||
<span | ||
style="cursor: pointer" | ||
[popper]="popperContent" | ||
[popperPositionFixed]="true" | ||
> | ||
<b>@{{ user.name || user.id }}</b> | ||
</span> | ||
<popper-content #popperContent style="display: inline"> | ||
<div style="display: flex; align-items: center"> | ||
<stream-avatar | ||
[imageUrl]="user.image" | ||
[name]="user.name || user.id" | ||
></stream-avatar> | ||
<b>{{ user.name || user.id }}</b> | ||
<span> {{ user.online ? "online" : "offline" }}</span> | ||
</div> | ||
</popper-content> | ||
</ng-template> | ||
``` | ||
|
||
This is the popover that is displayed if we click on a mention in a message: | ||
|
||
<img src={Screenshot} width="500" /> | ||
|
||
[`ngx-popperjs`](https://www.npmjs.com/package/ngx-popperjs) has a lot of other configuration options, feel free to explore those. | ||
|
||
## Display user information on hover | ||
|
||
Let's modify our solution and display the popover on hover instead of click: | ||
|
||
We need to add a variable to our component class: | ||
|
||
```typescript | ||
import { NgxPopperjsTriggers } from "ngx-popperjs"; | ||
|
||
popoverTrigger = NgxPopperjsTriggers.hover; | ||
``` | ||
|
||
And modify our template: | ||
|
||
```html | ||
<ng-template #mentionTemplate let-user="user"> | ||
<span | ||
style="cursor: pointer" | ||
[popper]="popperContent" | ||
[popperPositionFixed]="true" | ||
[popperTrigger]="popoverTrigger" | ||
> | ||
<b>@{{ user.name || user.id }}</b> | ||
</span> | ||
<popper-content #popperContent style="display: inline"> | ||
<div style="display: flex; align-items: center"> | ||
<stream-avatar | ||
[imageUrl]="user.image" | ||
[name]="user.name || user.id" | ||
></stream-avatar> | ||
<b>{{ user.name || user.id }}</b> | ||
<span> {{ user.online ? "online" : "offline" }}</span> | ||
</div> | ||
</popper-content> | ||
</ng-template> | ||
``` |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
14 changes: 0 additions & 14 deletions
14
projects/stream-chat-angular/src/lib/message/highlight-mentions.pipe.spec.ts
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
projects/stream-chat-angular/src/lib/message/highlight-mentions.pipe.ts
This file was deleted.
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
Oops, something went wrong.