Skip to content

Commit 202371f

Browse files
committed
doc: 增加方法示例
1 parent de76d81 commit 202371f

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

src/BootstrapBlazor.Server/Components/Samples/Vditors.razor

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
@page "/vditors"
22
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
33

4-
<h3>@Localizer["Header"]</h3>
5-
<h4>@Localizer["Tip"]</h4>
4+
<h3>@Localizer["VditorTitle"]</h3>
5+
6+
<h4>@Localizer["VditorSubTitle"]</h4>
67

78
<PackageTips Name="BootstrapBlazor.Vditor" />
89

910
<p>@((MarkupString)Localizer["MarkdownsNote"].Value)</p>
1011

1112
<Pre class="no-highlight">builder.Services.Configure&lt;HubOptions&gt;(option => option.MaximumReceiveMessageSize = null);</Pre>
1213

13-
<DemoBlock Title="@Localizer["NormalTitle"]" Introduction="@Localizer["NormalIntro"]" Name="Normal">
14-
<section ignore>
15-
<BootstrapInputGroup>
16-
<BootstrapInputGroupLabel DisplayText="Mode"></BootstrapInputGroupLabel>
17-
<Segmented Value="_mode" OnValueChanged="OnModeChanged">
18-
@foreach (var item in Enum.GetValues(typeof(VditorMode)).Cast<VditorMode>())
19-
{
20-
<SegmentedItem Value="@item" Text="@item.ToString()" />
21-
}
22-
</Segmented>
23-
</BootstrapInputGroup>
14+
<DemoBlock Title="@Localizer["BaseUsageTitle"]" Introduction="@Localizer["BaseUsageIntro"]" Name="Normal">
15+
<section ignore class="row g-3">
16+
<div class="col-12">
17+
<BootstrapInputGroup>
18+
<BootstrapInputGroupLabel DisplayText="Mode"></BootstrapInputGroupLabel>
19+
<Segmented Value="_mode" OnValueChanged="OnModeChanged">
20+
@foreach (var item in Enum.GetValues(typeof(VditorMode)).Cast<VditorMode>())
21+
{
22+
<SegmentedItem Value="@item" Text="@item.ToString()" />
23+
}
24+
</Segmented>
25+
</BootstrapInputGroup>
26+
</div>
27+
<div class="col-12">
28+
<Button Text="GetValue" OnClick="OnTriggerGetValueAsync"></Button>
29+
<Button Text="InsertValue" OnClick="OnTriggerInsertValueAsync"></Button>
30+
<Button Text="GetHtml" OnClick="OnTriggerGetHtmlAsync"></Button>
31+
<Button Text="GetSelection" OnClick="OnTriggerGetSelectionAsync"></Button>
32+
<Button Text="Enable" OnClick="OnTriggerEnableAsync"></Button>
33+
<Button Text="Disable" OnClick="OnTriggerDisableAsync"></Button>
34+
<Button Text="Focus" OnClick="OnTriggerFocusAsync"></Button>
35+
<Button Text="Blur" OnClick="OnTriggerBlurAsync"></Button>
36+
</div>
2437
</section>
2538
<Vditor Value="@_vditorValueString" Options="_vditorOptions" @ref="_vditor"
2639
OnRenderedAsync="OnRenderAsync"

src/BootstrapBlazor.Server/Components/Samples/Vditors.razor.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ private async Task OnBlurAsync(string value)
6363
_vditorValueString = value;
6464
_logger.Log($"Trigger OnBlurAsync");
6565

66-
// 手动获取 HTML 代码
6766
_htmlString = await _vditor.GetHtmlAsync();
6867
StateHasChanged();
6968
}
@@ -98,6 +97,47 @@ private async Task OnCtrlEnterAsync(string value)
9897
StateHasChanged();
9998
}
10099

100+
private async Task OnTriggerGetValueAsync()
101+
{
102+
_vditorValueString = await _vditor.GetValueAsync() ?? "";
103+
}
104+
105+
private async Task OnTriggerInsertValueAsync()
106+
{
107+
await _vditor.InsertValueAsync("光标处插入当前值");
108+
}
109+
110+
private async Task OnTriggerGetHtmlAsync()
111+
{
112+
_htmlString = await _vditor.GetHtmlAsync();
113+
}
114+
115+
private async Task OnTriggerGetSelectionAsync()
116+
{
117+
var selection = await _vditor.GetSelectionAsync() ?? "";
118+
_logger.Log($"Trigger OnTriggerGetSelectionAsync: {selection}");
119+
}
120+
121+
private async Task OnTriggerEnableAsync()
122+
{
123+
await _vditor.EnableAsync();
124+
}
125+
126+
private async Task OnTriggerDisableAsync()
127+
{
128+
await _vditor.DisableAsync();
129+
}
130+
131+
private async Task OnTriggerFocusAsync()
132+
{
133+
await _vditor.FocusAsync();
134+
}
135+
136+
private async Task OnTriggerBlurAsync()
137+
{
138+
await _vditor.BlurAsync();
139+
}
140+
101141
private static AttributeItem[] GetAttributes() =>
102142
[
103143
new()

0 commit comments

Comments
 (0)