-
-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module: mentions): Add ability to customize the rendering (#3178)
* feat(module: mentions): Add ability to customize the rendering of the textarea. This allows using the TextArea component if you want its extended functionality. Add tests. Update demos. * fix test * fix test --------- Co-authored-by: James Yeung <shunjiey@hotmail.com>
- Loading branch information
1 parent
ab3e3c0
commit 9c69ef4
Showing
11 changed files
with
266 additions
and
52 deletions.
There are no files selected for viewing
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 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,15 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Web; | ||
|
||
namespace AntDesign | ||
{ | ||
public class MentionsTextareaTemplateOptions | ||
{ | ||
public string Value { get; set; } | ||
public ForwardRef RefBack { get; set; } | ||
public Action<KeyboardEventArgs> OnKeyDown { get; set; } | ||
public Func<ChangeEventArgs, Task> OnInput { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
@import '../../input/style/mixin'; | ||
|
||
.ant-mention-dropdown { | ||
top: 100%; | ||
left: 0; | ||
position: relative; | ||
width: 100%; | ||
margin-top: 4px; | ||
margin-bottom: 4px; | ||
top: 100%; | ||
left: 0; | ||
position: relative; | ||
width: 100%; | ||
margin-top: 4px; | ||
margin-bottom: 4px; | ||
} | ||
|
||
.ant-mentions { | ||
border: none; | ||
} | ||
|
||
.ant-mentions .rc-textarea { | ||
.input(); | ||
} |
81 changes: 55 additions & 26 deletions
81
site/AntDesign.Docs/Demos/Components/Mentions/demo/Form.razor
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 |
---|---|---|
@@ -1,35 +1,64 @@ | ||
<div> | ||
To do | ||
@* <div style="margin-bottom: 10px"> | ||
<Mentions> | ||
<MentionsOption Value="afc163">afc163</MentionsOption> | ||
<MentionsOption Value="zombieJ">zombieJ</MentionsOption> | ||
<MentionsOption Value="yesmeck">yesmeck</MentionsOption> | ||
</Mentions> | ||
</div> | ||
@using System.ComponentModel.DataAnnotations; | ||
@using System.Text.Json; | ||
@using System.ComponentModel | ||
|
||
<div style="margin-bottom: 10px"> | ||
<Mentions Rows="6" Placeholder="You can use to ref user here"> | ||
<!-- TODO: Make work with validation visuals. Submission will work though. --> | ||
<AntDesign.Form Model="@model" | ||
OnFinish="OnFinish" | ||
OnFinishFailed="OnFinishFailed" | ||
LabelColSpan="8" | ||
WrapperColSpan="16"> | ||
<FormItem Label="Comment"> | ||
<Mentions @bind-Value=@model.Comment> | ||
<MentionsOption Value="afc163">afc163</MentionsOption> | ||
<MentionsOption Value="zombieJ">zombieJ</MentionsOption> | ||
<MentionsOption Value="yesmeck">yesmeck</MentionsOption> | ||
</Mentions> | ||
</div> | ||
|
||
<Button Type="primary">Submit</Button> | ||
<Button>Reset</Button>*@ | ||
</div> | ||
|
||
|
||
@code{ | ||
</FormItem> | ||
<FormItem Label="Another Comment"> | ||
<Mentions @bind-Value=@model.AnotherComment> | ||
<ChildContent> | ||
<MentionsOption Value="afc163">afc163</MentionsOption> | ||
<MentionsOption Value="zombieJ">zombieJ</MentionsOption> | ||
<MentionsOption Value="yesmeck">yesmeck</MentionsOption> | ||
</ChildContent> | ||
<TextareaTemplate Context="mentionsContext"> | ||
<TextArea RefBack=@mentionsContext.RefBack | ||
OnInput=@mentionsContext.OnInput | ||
BindOnInput=false | ||
OnkeyDown=@mentionsContext.OnKeyDown | ||
Value=@mentionsContext.Value | ||
ShowCount=true | ||
MaxLength="200" /> | ||
</TextareaTemplate> | ||
</Mentions> | ||
</FormItem> | ||
<FormItem WrapperColOffset="8" WrapperColSpan="16"> | ||
<Button Type="@ButtonType.Primary" HtmlType="submit"> | ||
Submit | ||
</Button> | ||
</FormItem> | ||
</AntDesign.Form> | ||
@code | ||
{ | ||
public class Model | ||
{ | ||
[Required] | ||
public string Comment { get; set; } | ||
|
||
//private class FormData | ||
//{ | ||
// public string data1 { get; set; } | ||
// public string data2 { get; set; } | ||
//} | ||
[Required] | ||
public string AnotherComment{ get; set; } | ||
} | ||
|
||
private Model model = new Model(); | ||
|
||
//private FormData frmData = new FormData(); | ||
private void OnFinish(EditContext editContext) | ||
{ | ||
Console.WriteLine($"Success:{JsonSerializer.Serialize(model)}"); | ||
} | ||
|
||
} | ||
private void OnFinishFailed(EditContext editContext) | ||
{ | ||
Console.WriteLine($"Failed:{JsonSerializer.Serialize(model)}"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
site/AntDesign.Docs/Demos/Components/Mentions/demo/TextareaTemplate.razor
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,20 @@ | ||
<Mentions> | ||
<ChildContent> | ||
<MentionsOption Value="afc163">afc163</MentionsOption> | ||
<MentionsOption Value="zombieJ">zombieJ</MentionsOption> | ||
<MentionsOption Value="yesmeck">yesmeck</MentionsOption> | ||
</ChildContent> | ||
<TextareaTemplate> | ||
<TextArea RefBack=@context.RefBack | ||
OnInput=@context.OnInput | ||
BindOnInput=false | ||
OnkeyDown=@context.OnKeyDown | ||
Value=@context.Value | ||
ShowCount=true | ||
MaxLength="200" /> | ||
</TextareaTemplate> | ||
</Mentions> | ||
|
||
@code { | ||
string value { get; set; } | ||
} |
14 changes: 14 additions & 0 deletions
14
site/AntDesign.Docs/Demos/Components/Mentions/demo/textareatemplate.md
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,14 @@ | ||
--- | ||
order: 6 | ||
title: | ||
zh-CN: 文本区域模板 | ||
en-US: Textarea Template | ||
--- | ||
|
||
## zh-CN | ||
|
||
自定义文本区域的呈现。最常见的用例是使用 TextArea 组件。 | ||
|
||
## en-US | ||
|
||
Customize the rendering of the textarea. Most common usecase will be to use the TextArea component. |
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.