Skip to content

Commit 7eba918

Browse files
committed
feat: 增加 DropdownItem 组件
1 parent 3de958e commit 7eba918

File tree

2 files changed

+83
-39
lines changed

2 files changed

+83
-39
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// DropdownItem 组件
10+
/// </summary>
11+
public class DropdownItem : ComponentBase, IDropdownItem, IDisposable
12+
{
13+
/// <summary>
14+
/// 获得/设置 显示文本
15+
/// </summary>
16+
[Parameter]
17+
public string? Text { get; set; }
18+
19+
/// <summary>
20+
/// 获得/设置 图标
21+
/// </summary>
22+
[Parameter]
23+
public string? Icon { get; set; }
24+
25+
/// <summary>
26+
/// 获得/设置 是否被禁用 默认 false 优先级低于 <see cref="OnDisabledCallback"/>
27+
/// </summary>
28+
[Parameter]
29+
public bool Disabled { get; set; }
30+
31+
/// <summary>
32+
/// 获得/设置 是否被禁用回调方法 默认 null 优先级高于 <see cref="Disabled"/>
33+
/// </summary>
34+
[Parameter]
35+
public Func<DropdownItem, bool>? OnDisabledCallback { get; set; }
36+
37+
/// <summary>
38+
/// 获得/设置 点击回调方法 默认 null
39+
/// </summary>
40+
[Parameter]
41+
public Func<Task>? OnClick { get; set; }
42+
43+
[CascadingParameter]
44+
[NotNull]
45+
private List<IDropdownItem>? Items { get; set; }
46+
47+
/// <summary>
48+
/// <inheritdoc/>
49+
/// </summary>
50+
protected override void OnInitialized()
51+
{
52+
base.OnInitialized();
53+
54+
Items.Add(this);
55+
}
56+
57+
private bool disposedValue;
58+
59+
/// <summary>
60+
/// 释放资源方法
61+
/// </summary>
62+
/// <param name="disposing"></param>
63+
protected virtual void Dispose(bool disposing)
64+
{
65+
if (!disposedValue)
66+
{
67+
if (disposing)
68+
{
69+
Items.Remove(this);
70+
}
71+
disposedValue = true;
72+
}
73+
}
74+
75+
/// <summary>
76+
/// <inheritdoc/>
77+
/// </summary>
78+
public void Dispose()
79+
{
80+
Dispose(true);
81+
GC.SuppressFinalize(this);
82+
}
83+
}

src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)