-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSelectProvince.razor.cs
More file actions
60 lines (51 loc) · 1.73 KB
/
SelectProvince.razor.cs
File metadata and controls
60 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Components;
/// <summary>
/// <para lang="zh">SelectProvince 组件</para>
/// <para lang="en">SelectProvince component</para>
/// </summary>
public partial class SelectProvince
{
/// <summary>
/// <para lang="zh">获得/设置 是否可多选,默认 false 单选</para>
/// <para lang="en">Gets or sets whether multiple selection is enabled. Default is false (single selection)</para>
/// </summary>
[Parameter]
public bool IsMultiple { get; set; }
private string? ClassString => CssBuilder.Default("select bb-province")
.AddClass("disabled", IsDisabled)
.AddClassFromAttributes(AdditionalAttributes)
.Build();
private readonly HashSet<string> _values = [];
private string? GetActiveClass(string item) => _values.Contains(item) || CurrentValue == item ? "active" : null;
private async Task OnClearValue()
{
if (IsMultiple)
{
_values.Clear();
}
CurrentValue = "";
if (OnClearAsync != null)
{
await OnClearAsync();
}
}
private void OnSelectProvince(string item)
{
if (IsMultiple)
{
if (!_values.Remove(item))
{
_values.Add(item);
}
CurrentValue = string.Join(",", _values);
}
else
{
CurrentValue = item;
}
}
private HashSet<string> GetProvinces() => RegionService.GetProvinces();
}