-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(Dropdown): add ItemsTemplate parameter #7046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4075538
feat: 增加 DropdownItem 组件
ArgoZhang 3de958e
feat: 增加 IDropdownItem 接口
ArgoZhang 7eba918
feat: 增加 DropdownItem 组件
ArgoZhang 5afb43a
feat: 增加 DropdownDivider 组件
ArgoZhang d733524
feat: 实现 ItemsTemplate 模板功能
ArgoZhang 17dc844
refactor: 代码格式化
ArgoZhang e7cc51b
feat: 移除 IDropdownItem 接口
ArgoZhang 59bf6e3
doc: 更新示例
ArgoZhang 42c4f59
doc: 增加 ItemsTemplate 示例
ArgoZhang 9531164
doc: 增加多语言
ArgoZhang bfcf6d0
refactor: 移除 DropdownDivider 组件
ArgoZhang 0e8d5a3
refactor: 精简代码
ArgoZhang 6e5bcfa
refactor: 更新示例
ArgoZhang 3b531e9
refactor: 更改属性名
ArgoZhang e7230de
test: 增加单元测试
ArgoZhang 31ee7c1
refactor: 代码格式化
ArgoZhang 3ef7af2
doc: 代码格式化
ArgoZhang 248d341
refactor: 移除变量
ArgoZhang e60b187
refactor: 增加条件渲染
ArgoZhang 12a6c59
refactor: 增加 ButtonText 判断
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,3 +9,9 @@ | |
| margin-inline-start: 0.25rem; | ||
| } | ||
| } | ||
|
|
||
| .dropdown-menu { | ||
| .divider { | ||
| margin: 0.25rem 0; | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor
This file contains hidden or 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,22 @@ | ||
| @namespace BootstrapBlazor.Components | ||
|
|
||
| @if (ChildContent != null) | ||
| { | ||
| <div class="@ItemClassString"> | ||
| @ChildContent | ||
| </div> | ||
| } | ||
| else | ||
| { | ||
| <DynamicElement class="@ItemClassString" | ||
| TriggerClick="!IsDisabled" OnClick="OnClickItem"> | ||
| @if (!string.IsNullOrEmpty(ItemIconString)) | ||
| { | ||
| <i class="@ItemIconString"></i> | ||
| } | ||
| @if (!string.IsNullOrEmpty(Text)) | ||
| { | ||
| <span>@Text</span> | ||
| } | ||
| </DynamicElement> | ||
| } |
66 changes: 66 additions & 0 deletions
66
src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor.cs
This file contains hidden or 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,66 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
||
| /// <summary> | ||
| /// DropdownItem 组件 | ||
| /// </summary> | ||
| public partial class DropdownItem | ||
| { | ||
| /// <summary> | ||
| /// 获得/设置 显示文本 | ||
| /// </summary> | ||
| [Parameter] | ||
| public string? Text { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 图标 | ||
| /// </summary> | ||
| [Parameter] | ||
| public string? Icon { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 是否被禁用 默认 false 优先级低于 <see cref="OnDisabledCallback"/> | ||
| /// </summary> | ||
| [Parameter] | ||
| public bool Disabled { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 是否被禁用回调方法 默认 null 优先级高于 <see cref="Disabled"/> | ||
| /// </summary> | ||
| [Parameter] | ||
| public Func<bool>? OnDisabledCallback { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 点击回调方法 默认 null | ||
| /// </summary> | ||
| [Parameter] | ||
| public Func<Task>? OnClick { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 组件内容 | ||
| /// </summary> | ||
| [Parameter] | ||
| public RenderFragment? ChildContent { get; set; } | ||
|
|
||
| private string? ItemIconString => CssBuilder.Default("dropdown-item-icon") | ||
| .AddClass(Icon, !string.IsNullOrEmpty(Icon)) | ||
| .Build(); | ||
|
|
||
| private string? ItemClassString => CssBuilder.Default("dropdown-item") | ||
| .AddClass("disabled", IsDisabled) | ||
| .Build(); | ||
|
|
||
| private bool IsDisabled => OnDisabledCallback?.Invoke() ?? Disabled; | ||
|
|
||
| private async Task OnClickItem() | ||
| { | ||
| if (OnClick != null) | ||
| { | ||
| await OnClick(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.