-
Notifications
You must be signed in to change notification settings - Fork 4
Add toolbar dropdown support #107
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
7 commits
Select commit
Hold shift + click to select a range
5248314
add dropdown item to toolbar (#99)
albx f4b07bf
#99 - add tests for toolbar dropdown
albx 45aa11b
#99 - add stories and sample for toolbard dropdown support
albx 37047e6
#99 - reafactor BitToolbarItem to inherit from a base class
albx 9890c1c
#99 - update toolbar documentation
albx 40d4f88
#99 - apply suggestions from review
albx 5fe955e
#99 - fix documentation based on PR review
albx 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
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
39 changes: 39 additions & 0 deletions
39
src/BitBlazor/Components/Toolbar/BitToolbarDropdownItem.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,39 @@ | ||
| @namespace BitBlazor.Components | ||
|
|
||
| @inherits BitToolbarItemBase | ||
|
|
||
| <li> | ||
| <BitDropdown ActivatorId="@Id" ActivatorLabel="@Label"> | ||
| <ActivatorTemplate> | ||
| <button class="@ComputeActivatorCssClass()" type="button" id="@context.ActivatorId" @ref="context.ActivatorRef" @attributes="ComputeActivatorAttributes(context)" disabled="@Disabled" @onclick="@(() => HandleActivatorClick(context))" @onkeydown="@(args => HandleActivatorKeyDownAsync(context, args))"> | ||
| @if (HasBadge) | ||
| { | ||
| <div class="badge-wrapper"> | ||
| <span class="toolbar-badge"> | ||
| @if (IsToolbarSizeDefault) | ||
| { | ||
| @BadgeCount | ||
| } | ||
| </span> | ||
| @if (Parent.Size is ToolbarSize.Medium or ToolbarSize.Small && HasBadgeLabel) | ||
| { | ||
| @RenderBadgeLabel() | ||
| } | ||
| </div> | ||
| } | ||
|
|
||
| <BitIcon IconName="@IconName" /> | ||
| <span class="@ComputeLabelCssClass()"> | ||
| @context.ActivatorLabel | ||
| @if (Parent.Size is ToolbarSize.Default && HasBadgeLabel) | ||
| { | ||
| @RenderBadgeLabel() | ||
| } | ||
| </span> | ||
| </button> | ||
| </ActivatorTemplate> | ||
| <ChildContent> | ||
| @ChildContent | ||
| </ChildContent> | ||
| </BitDropdown> | ||
| </li> |
76 changes: 76 additions & 0 deletions
76
src/BitBlazor/Components/Toolbar/BitToolbarDropdownItem.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,76 @@ | ||
| using BitBlazor.Core; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.Components.Web; | ||
|
|
||
| namespace BitBlazor.Components; | ||
|
|
||
| /// <summary> | ||
| /// Represents a dropdown item that can be used within a <see cref="BitToolbar"/> component. | ||
| /// It provides a way to include dropdown functionality in a toolbar, allowing users to select from a list of options or actions. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Rendered with <see cref="BitDropdown"/>, which requires an interactive render mode (Server, WebAssembly, or Auto) to open and close. | ||
| /// Under static SSR (no circuit/WASM runtime attached) the activator cannot be toggled, so the dropdown menu can never be opened. | ||
| /// </remarks> | ||
| public partial class BitToolbarDropdownItem : BitToolbarItemBase | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the content to be rendered inside the dropdown item. | ||
| /// </summary> | ||
| [Parameter] | ||
| [EditorRequired] | ||
| public RenderFragment ChildContent { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the unique identifier for the dropdown item. | ||
| /// This ID is used to associate the item with its corresponding dropdown menu for accessibility purposes. | ||
| /// </summary> | ||
| [Parameter] | ||
| [EditorRequired] | ||
| public string Id { get; set; } = string.Empty; | ||
|
|
||
| private string ComputeActivatorCssClass() | ||
| { | ||
| var builder = new CssClassBuilder("btn", "btn-dropdown", "dropdown-toggle"); | ||
|
|
||
| if (Disabled) | ||
| { | ||
| builder.Add("disabled"); | ||
| } | ||
|
|
||
| return builder.Build(); | ||
| } | ||
|
|
||
| // Merges the ActivatorContext's dropdown-managed attributes with the aria-disabled state set by SetDisabled(). | ||
| private IDictionary<string, object> ComputeActivatorAttributes(ActivatorContext context) | ||
| { | ||
| var attributes = new Dictionary<string, object>(context.Attributes); | ||
|
|
||
| foreach (var attribute in AdditionalAttributes) | ||
| { | ||
| attributes[attribute.Key] = attribute.Value; | ||
| } | ||
|
|
||
| return attributes; | ||
| } | ||
|
|
||
| private void HandleActivatorClick(ActivatorContext context) | ||
| { | ||
| if (Disabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| context.ToggleDropdown(); | ||
| } | ||
|
|
||
| private async Task HandleActivatorKeyDownAsync(ActivatorContext context, KeyboardEventArgs args) | ||
| { | ||
| if (Disabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| await context.HandleKeyDownAsync(args); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.