Skip to content

Commit 45057f8

Browse files
committed
feat: 增加组件脚本
1 parent 46cab2d commit 45057f8

4 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@namespace BootstrapBlazor.Components
2+
@inherits PopoverSelectBase<string>
3+
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Region.razor.js", JSObjectReference = true)]
4+
5+
@if (IsShowLabel)
6+
{
7+
<BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
8+
}
9+
<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString">
10+
<div data-bs-toggle="bb.dropdown" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString">
11+
<input type="text" id="@InputId" disabled="@Disabled" readonly placeholder="@PlaceHolder" class="@InputClassString" value="@CurrentValue" />
12+
<span class="@AppendClassString"><i class="@DropdownIcon"></i></span>
13+
</div>
14+
@if (GetClearable())
15+
{
16+
<span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span>
17+
}
18+
</div>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
using Microsoft.AspNetCore.Components;
6+
7+
namespace BootstrapBlazor.Components;
8+
9+
/// <summary>
10+
/// Region 组件
11+
/// </summary>
12+
public partial class Region
13+
{
14+
private string? ClassString => CssBuilder.Default("select bb-region")
15+
.AddClassFromAttributes(AdditionalAttributes)
16+
.Build();
17+
18+
private string? InputId => $"{Id}_input";
19+
20+
private string? InputClassString => CssBuilder.Default("form-select form-control")
21+
.AddClass($"border-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue)
22+
.AddClass($"border-success", IsValid.HasValue && IsValid.Value)
23+
.AddClass($"border-danger", IsValid.HasValue && !IsValid.Value)
24+
.AddClass(CssClass).AddClass(ValidCss)
25+
.Build();
26+
27+
private string? AppendClassString => CssBuilder.Default("form-select-append")
28+
.AddClass($"text-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue)
29+
.AddClass($"text-success", IsValid.HasValue && IsValid.Value)
30+
.AddClass($"text-danger", IsValid.HasValue && !IsValid.Value)
31+
.Build();
32+
33+
/// <summary>
34+
/// Gets or sets the placeholder text.
35+
/// </summary>
36+
[Parameter]
37+
public string? PlaceHolder { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the color. The default is <see cref="Color.None"/> (no color).
41+
/// </summary>
42+
[Parameter]
43+
public Color Color { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the dropdown icon. The default is "fa-solid fa-angle-up".
47+
/// </summary>
48+
[Parameter]
49+
[NotNull]
50+
public string? DropdownIcon { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the callback method when the clear button is clicked. Default is null.
54+
/// </summary>
55+
[Parameter]
56+
public Func<Task>? OnClearAsync { get; set; }
57+
58+
/// <summary>
59+
/// Gets or sets the right-side clear icon. Default is fa-solid fa-angle-up.
60+
/// </summary>
61+
[Parameter]
62+
[NotNull]
63+
public string? ClearIcon { get; set; }
64+
65+
/// <summary>
66+
/// Gets or sets whether the select component is clearable. Default is false.
67+
/// </summary>
68+
[Parameter]
69+
public bool IsClearable { get; set; }
70+
71+
/// <summary>
72+
/// Gets or sets the <see cref="IIconTheme"/> service instance.
73+
/// </summary>
74+
[Inject]
75+
[NotNull]
76+
protected IIconTheme? IconTheme { get; set; }
77+
78+
private bool GetClearable() => IsClearable && !IsDisabled;
79+
80+
private string? ClearClassString => CssBuilder.Default("clear-icon")
81+
.AddClass($"text-{Color.ToDescriptionString()}", Color != Color.None)
82+
.AddClass($"text-success", IsValid.HasValue && IsValid.Value)
83+
.AddClass($"text-danger", IsValid.HasValue && !IsValid.Value)
84+
.Build();
85+
86+
/// <summary>
87+
/// <inheritdoc/>
88+
/// </summary>
89+
protected override void OnParametersSet()
90+
{
91+
base.OnParametersSet();
92+
93+
DropdownIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectDropdownIcon);
94+
ClearIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectClearIcon);
95+
}
96+
97+
private void OnClearValue()
98+
{
99+
CurrentValue = "";
100+
}
101+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bb-region {
2+
position: relative;
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function init(id) {
2+
3+
}
4+
5+
export function dispose(id) {
6+
7+
}

0 commit comments

Comments
 (0)