Skip to content

Commit d92568b

Browse files
authored
feat(module:mention): support nzVariant (#9379)
1 parent 15d1550 commit d92568b

8 files changed

Lines changed: 216 additions & 32 deletions

File tree

‎components/mention/demo/variant.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 12
3+
title:
4+
zh-CN: 形态变体
5+
en-US: Variants
6+
---
7+
8+
## zh-CN
9+
10+
Mentions 形态变体,可选 `outlined` `filled` `borderless` `underlined` 四种形态。
11+
12+
## en-US
13+
14+
Variants of Mentions, there are four variants: `outlined` `filled` `borderless` and `underlined`.

‎components/mention/demo/variant.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, model } from '@angular/core';
2+
import { FormsModule } from '@angular/forms';
3+
4+
import { NzVariant } from 'ng-zorro-antd/core/types';
5+
import { NzInputModule } from 'ng-zorro-antd/input';
6+
import { NzMentionModule } from 'ng-zorro-antd/mention';
7+
import { NzSegmentedModule } from 'ng-zorro-antd/segmented';
8+
9+
@Component({
10+
selector: 'nz-demo-mention-variant',
11+
imports: [FormsModule, NzInputModule, NzMentionModule, NzSegmentedModule],
12+
template: `
13+
<nz-segmented [nzOptions]="variants" [(ngModel)]="variant" />
14+
<nz-mention [nzSuggestions]="suggestions" (nzOnSelect)="onSelect($event)" [nzVariant]="variant()">
15+
<textarea rows="1" placeholder="input here" nzMentionTrigger nz-input [(ngModel)]="inputValue"></textarea>
16+
</nz-mention>
17+
`,
18+
styles: `
19+
nz-segmented {
20+
margin-bottom: 1rem;
21+
}
22+
`
23+
})
24+
export class NzDemoMentionVariantComponent {
25+
inputValue = model('@afc163');
26+
suggestions = ['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご'];
27+
variant = model<NzVariant>('outlined');
28+
variants = [
29+
{ label: 'Outlined', value: 'outlined' },
30+
{ label: 'Filled', value: 'filled' },
31+
{ label: 'Borderless', value: 'borderless' },
32+
{ label: 'Underlined', value: 'underlined' }
33+
];
34+
35+
onSelect(value: string): void {
36+
console.log(value);
37+
}
38+
}

‎components/mention/doc/index.en-US.md‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ When need to mention someone or something.
2020

2121
### nz-mention
2222

23-
| Property | Description | Type | Default |
24-
| ----------------------- | ----------------------------------------------------------------------------------------- | ---------------------------------------------- | -------------------------------- |
25-
| `[nzMentionTrigger]` | Trigger element **(required)** | `HTMLTextAreaElement \| HTMLInputElement` | - |
26-
| `[nzMentionSuggestion]` | Customize the suggestion template | `TemplateRef<any>` | - |
27-
| `[nzLoading]` | Loading mode | `boolean` | `false` |
28-
| `[nzNotFoundContent]` | Suggestion when suggestions empty | `string` | `'无匹配结果,轻敲空格完成输入'` |
29-
| `[nzPlacement]` | The position of the suggestion relative to the target, which can be one of top and bottom | `'button' \| 'top'` | `'bottom'` |
30-
| `[nzPrefix]` | Character which will trigger Mention to show mention list | `string \| string[]` | `'@'` |
31-
| `[nzSuggestions]` | Suggestion content | `any[]` | `[]` |
32-
| `[nzStatus]` | Set validation status | `'error' \| 'warning'` | - |
33-
| `[nzValueWith]` | Function that maps an suggestion's value | `(any) => string \| (value: string) => string` |
34-
| `(nzOnSelect)` | Callback function called when select from suggestions | `EventEmitter<any>` | - |
35-
| `(nzOnSearchChange)` | Callback function called when search content changes | `EventEmitter<MentionOnSearchTypes>` | - |
23+
| Property | Description | Type | Default |
24+
| ----------------------- | ----------------------------------------------------------------------------------------- | -------------------------------------------------------- | -------------------------------- |
25+
| `[nzMentionTrigger]` | Trigger element **(required)** | `HTMLTextAreaElement \| HTMLInputElement` | - |
26+
| `[nzMentionSuggestion]` | Customize the suggestion template | `TemplateRef<any>` | - |
27+
| `[nzLoading]` | Loading mode | `boolean` | `false` |
28+
| `[nzNotFoundContent]` | Suggestion when suggestions empty | `string` | `'无匹配结果,轻敲空格完成输入'` |
29+
| `[nzPlacement]` | The position of the suggestion relative to the target, which can be one of top and bottom | `'button' \| 'top'` | `'bottom'` |
30+
| `[nzPrefix]` | Character which will trigger Mention to show mention list | `string \| string[]` | `'@'` |
31+
| `[nzSuggestions]` | Suggestion content | `any[]` | `[]` |
32+
| `[nzStatus]` | Set validation status | `'error' \| 'warning'` | - |
33+
| `[nzVariant]` | Variants of Input | `'outlined' \| 'filled' \| 'borderless' \| 'underlined'` | `'outlined'` |
34+
| `[nzValueWith]` | Function that maps an suggestion's value | `(any) => string \| (value: string) => string` |
35+
| `(nzOnSelect)` | Callback function called when select from suggestions | `EventEmitter<any>` | - |
36+
| `(nzOnSearchChange)` | Callback function called when search content changes | `EventEmitter<MentionOnSearchTypes>` | - |
3637

3738
#### Methods
3839

‎components/mention/doc/index.zh-CN.md‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ description: 用于在输入中提及某人或某事。
2121

2222
### nz-mention
2323

24-
| 参数 | 说明 | 类型 | 默认值 |
25-
| ----------------------- | --------------------------------- | ---------------------------------------------- | -------------------------------- |
26-
| `[nzMentionTrigger]` | 用于指定提及的触发元素 **(必须)** | `HTMLTextAreaElement \| HTMLInputElement` | - |
27-
| `[nzMentionSuggestion]` | 自定义建议渲染模板 | `TemplateRef<any>` | - |
28-
| `[nzLoading]` | 加载中 | `boolean` | `false` |
29-
| `[nzNotFoundContent]` | 未找到时的内容 | `string` | `'无匹配结果,轻敲空格完成输入'` |
30-
| `[nzPlacement]` | 建议框位置 | `'bottom' \| 'top'` | `'bottom'` |
31-
| `[nzPrefix]` | 触发弹出下拉框的字符 | `string \| string[]` | `'@'` |
32-
| `[nzSuggestions]` | 建议内容 | `any[]` | `[]` |
33-
| `[nzStatus]` | 设置校验状态 | `'error' \| 'warning'` | - |
34-
| `[nzValueWith]` | 建议选项的取值方法 | `(any) => string \| (value: string) => string` |
35-
| `(nzOnSelect)` | 下拉框选择建议时回调 | `EventEmitter<any>` | - |
36-
| `(nzOnSearchChange)` | 输入框中 @ 变化时回调 | `EventEmitter<MentionOnSearchTypes>` | - |
24+
| 参数 | 说明 | 类型 | 默认值 |
25+
| ----------------------- | --------------------------------- | -------------------------------------------------------- | -------------------------------- |
26+
| `[nzMentionTrigger]` | 用于指定提及的触发元素 **(必须)** | `HTMLTextAreaElement \| HTMLInputElement` | - |
27+
| `[nzMentionSuggestion]` | 自定义建议渲染模板 | `TemplateRef<any>` | - |
28+
| `[nzLoading]` | 加载中 | `boolean` | `false` |
29+
| `[nzNotFoundContent]` | 未找到时的内容 | `string` | `'无匹配结果,轻敲空格完成输入'` |
30+
| `[nzPlacement]` | 建议框位置 | `'bottom' \| 'top'` | `'bottom'` |
31+
| `[nzPrefix]` | 触发弹出下拉框的字符 | `string \| string[]` | `'@'` |
32+
| `[nzSuggestions]` | 建议内容 | `any[]` | `[]` |
33+
| `[nzStatus]` | 设置校验状态 | `'error' \| 'warning'` | - |
34+
| `[nzVariant]` | 形态变体 | `'outlined' \| 'filled' \| 'borderless' \| 'underlined'` | `'outlined'` |
35+
| `[nzValueWith]` | 建议选项的取值方法 | `(any) => string \| (value: string) => string` |
36+
| `(nzOnSelect)` | 下拉框选择建议时回调 | `EventEmitter<any>` | - |
37+
| `(nzOnSearchChange)` | 输入框中 @ 变化时回调 | `EventEmitter<MentionOnSearchTypes>` | - |
3738

3839
#### 方法
3940

‎components/mention/mention-trigger.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
forwardRef,
1515
inject,
1616
NgZone,
17-
Output
17+
Output,
18+
signal
1819
} from '@angular/core';
1920
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2021
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
@@ -62,6 +63,8 @@ export class NzMentionTriggerDirective implements ControlValueAccessor {
6263
@Output() readonly onClick = new EventEmitter<MouseEvent>();
6364
value?: string;
6465

66+
readonly disabled = signal(false);
67+
6568
constructor() {
6669
this.destroyRef.onDestroy(() => {
6770
this.completeEvents();
@@ -122,6 +125,10 @@ export class NzMentionTriggerDirective implements ControlValueAccessor {
122125
this.onTouched = fn;
123126
}
124127

128+
setDisabledState(isDisabled: boolean): void {
129+
this.disabled.set(isDisabled);
130+
}
131+
125132
private setupEventListener<TEvent extends Event>(eventName: string, eventEmitter: EventEmitter<TEvent>): void {
126133
fromEventOutsideAngular<TEvent>(this.elementRef.nativeElement, eventName)
127134
.pipe(takeUntilDestroyed(this.destroyRef))

‎components/mention/mention.component.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ChangeDetectionStrategy,
2222
ChangeDetectorRef,
2323
Component,
24+
computed,
2425
contentChild,
2526
ContentChild,
2627
DestroyRef,
@@ -36,6 +37,7 @@ import {
3637
Output,
3738
QueryList,
3839
Renderer2,
40+
signal,
3941
SimpleChanges,
4042
TemplateRef,
4143
ViewChild,
@@ -48,7 +50,7 @@ import { distinctUntilChanged, map, startWith, switchMap, withLatestFrom } from
4850

4951
import { NzFormItemFeedbackIconComponent, NzFormNoStatusService, NzFormStatusService } from 'ng-zorro-antd/core/form';
5052
import { DEFAULT_MENTION_BOTTOM_POSITIONS, DEFAULT_MENTION_TOP_POSITIONS } from 'ng-zorro-antd/core/overlay';
51-
import { NgClassInterface, NzSafeAny, NzStatus, NzValidateStatus } from 'ng-zorro-antd/core/types';
53+
import { NgClassInterface, NzSafeAny, NzStatus, NzValidateStatus, NzVariant } from 'ng-zorro-antd/core/types';
5254
import {
5355
fromEventOutsideAngular,
5456
getCaretCoordinates,
@@ -122,7 +124,12 @@ export type MentionPlacement = 'top' | 'bottom';
122124
changeDetection: ChangeDetectionStrategy.OnPush,
123125
host: {
124126
class: 'ant-mentions',
125-
'[class.ant-mentions-rtl]': `dir === 'rtl'`
127+
'[class.ant-mentions-rtl]': `dir === 'rtl'`,
128+
'[class.ant-mentions-borderless]': `nzVariant === 'borderless'`,
129+
'[class.ant-mentions-filled]': `nzVariant === 'filled'`,
130+
'[class.ant-mentions-underlined]': `nzVariant === 'underlined'`,
131+
'[class.ant-mentions-focused]': `focused()`,
132+
'[class.ant-mentions-disabled]': `disabled()`
126133
},
127134
imports: [NgTemplateOutlet, NzIconModule, NzEmptyModule, NzFormItemFeedbackIconComponent]
128135
})
@@ -142,6 +149,7 @@ export class NzMentionComponent implements OnInit, AfterViewInit, OnChanges {
142149
@Input() nzPlacement: MentionPlacement = 'bottom';
143150
@Input() nzSuggestions: NzSafeAny[] = [];
144151
@Input() nzStatus: NzStatus = '';
152+
@Input() nzVariant: NzVariant = 'outlined';
145153
@Output() readonly nzOnSelect = new EventEmitter<NzSafeAny>();
146154
@Output() readonly nzOnSearchChange = new EventEmitter<MentionOnSearchTypes>();
147155

@@ -168,6 +176,11 @@ export class NzMentionComponent implements OnInit, AfterViewInit, OnChanges {
168176
statusCls: NgClassInterface = {};
169177
status: NzValidateStatus = '';
170178
hasFeedback: boolean = false;
179+
readonly focused = signal(false);
180+
181+
readonly disabled = computed(() => {
182+
return this.trigger().disabled();
183+
});
171184

172185
private previousValue: string | null = null;
173186
private cursorMention: string | null = null;
@@ -327,6 +340,8 @@ export class NzMentionComponent implements OnInit, AfterViewInit, OnChanges {
327340
}
328341

329342
private bindTriggerEvents(): void {
343+
this.trigger().onFocusin.subscribe(() => this.focused.set(true));
344+
this.trigger().onBlur.subscribe(() => this.focused.set(false));
330345
this.trigger().onInput.subscribe((e: KeyboardEvent) => this.handleInput(e));
331346
this.trigger().onKeydown.subscribe((e: KeyboardEvent) => this.handleKeydown(e));
332347
this.trigger().onClick.subscribe(() => this.handleClick());

0 commit comments

Comments
 (0)