Skip to content

Commit

Permalink
Add improvements to the MultiComboBox component
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeatstariongroup authored and Robbware committed Oct 3, 2023
1 parent e528d3b commit e3a0adf
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 12 deletions.
1 change: 0 additions & 1 deletion COMET.Web.Common/Components/BookEditor/InputEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<MultiComboBox TItem="Category"
Values="@categorizableThing.Category"
Data="@this.AvailableCategories"
ShowCheckBoxes="true"
ValuesChanged="@this.OnCategoryChange">
<RowTemplate>
<span>@context.Name</span>
Expand Down
20 changes: 16 additions & 4 deletions COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace COMET.Web.Common.Components.BookEditor
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Model;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Utilities;

using Microsoft.AspNetCore.Components;
Expand All @@ -46,20 +47,26 @@ public partial class InputEditor<TItem>
/// Gets or sets the <see cref="ILogger"/>
/// </summary>
[Inject]
ILogger<InputEditor<TItem>> Logger { get; set; }
public ILogger<InputEditor<TItem>> Logger { get; set; }

/// <summary>
/// Gets or sets the <see cref="HttpClient"/>
/// </summary>
[Inject]
HttpClient HttpClient { get; set; }
public HttpClient HttpClient { get; set; }

/// <summary>
/// Gets or sets the <see cref="IOptions{GlobalOptions}"/>
/// <summary>
/// Gets or sets the <see cref="IOptions{GlobalOptions}"/>
/// </summary>
[Inject]
public IOptions<GlobalOptions> Options { get; set; }

/// <summary>
/// Gets or sets the <see cref="ISessionService"/>
/// </summary>
[Inject]
public ISessionService SessionService { get; set; }

/// <summary>
/// Gets or sets the item for which the input is being provided
/// </summary>
Expand Down Expand Up @@ -117,6 +124,11 @@ protected override async Task OnInitializedAsync()
{
this.showShortName = showShortNameValue;
}

if (this.Item is IOwnedThing ownedThing)
{
ownedThing.Owner = this.SessionService.Session.ActivePerson.DefaultDomain;
}
}
catch (Exception e)
{
Expand Down
18 changes: 14 additions & 4 deletions COMET.Web.Common/Components/MultiComboBox.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
Data="@this.Data"
ValueChanged="@this.ItemSelected"
Enabled="@this.Enabled"
Value="@this.lastSelectedValue"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
CssClass="w-100">
<ItemTemplate>
<div class="multi-combo-item-template">
Expand All @@ -47,12 +49,12 @@
</ItemTemplate>

<EditBoxTemplate>
@if(this.Values.Count <= 2)
@if(this.Values.Count <= this.MaxNumberOfChips)
{
<div class="chips-container">
@foreach(var value in this.Values)
{
<button class="chip" @onclick="@(() => this.ItemSelected(value))">
<div class="chip">
@if (this.RowTemplate != null)
{
@this.RowTemplate(value)
Expand All @@ -61,13 +63,21 @@
{
@value
}
</button>
<button class="chip-button icon icon-close" @onclick="@(() => this.ItemSelected(value))"></button>
</div>
}
</div>
}
else
{
<div>@(this.Values.Count) items are selected</div>
if (this.EditorTextTemplate != null)
{
@this.EditorTextTemplate
}
else
{
<div>@(this.Values.Count) items are selected</div>
}
}
</EditBoxTemplate>
</DxComboBox>
21 changes: 20 additions & 1 deletion COMET.Web.Common/Components/MultiComboBox.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,35 @@ namespace COMET.Web.Common.Components
/// </summary>
public partial class MultiComboBox<TItem>
{
/// <summary>
/// The last selected value of the combobox
/// </summary>
private TItem lastSelectedValue;

/// <summary>
/// Gets or sets the maximum number of chips that the combo should show
/// </summary>
[Parameter]
public int MaxNumberOfChips { get; set; } = 3;

/// <summary>
/// Gets or sets if the checkboxes for the selected items should be drawn
/// </summary>
[Parameter]
public bool ShowCheckBoxes { get; set; }
public bool ShowCheckBoxes { get; set; } = true;

/// <summary>
/// Gets or sets the item template for the selected items
/// </summary>
[Parameter]
public RenderFragment<TItem> RowTemplate { get; set; }

/// <summary>
/// Gets or sets item template to show when the number of selected items is greater or equal to the <see cref="MaxNumberOfChips"/>
/// </summary>
[Parameter]
public RenderFragment EditorTextTemplate { get; set; }

/// <summary>
/// Gets or sets the data of the combobox
/// </summary>
Expand Down Expand Up @@ -63,6 +80,8 @@ public partial class MultiComboBox<TItem>
/// <returns>an asynchronous operation</returns>
private async Task ItemSelected(TItem newValue)
{
this.lastSelectedValue = default;

if(this.Values.Contains(newValue))
{
this.Values.Remove(newValue);
Expand Down
20 changes: 18 additions & 2 deletions COMET.Web.Common/Components/MultiComboBox.razor.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
::deep.chip {
border: 0;
background-color: #EEEEEE;
border-radius: 15px;
padding: 2.5% 5%;
border-radius: 30px;
padding: 2%;
box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.2);
color: #555;
display: flex;
align-items:center;
justify-content:center;
column-gap: 5px;
}

::deep.chip-button {
border: 0;
border-radius: 30px;
}

::deep.chip-button:hover {
box-shadow: 0px 0px 0px 2px rgba(0,0,0,0.2);
}

::deep.chips-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
row-gap: 5px;
column-gap: 5px;
width: 100%;
height: 100%;
}

::deep.dxbl-listbox-item{
Expand Down
1 change: 1 addition & 0 deletions COMET.Web.Common/wwwroot/css/SVG/icons/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions COMET.Web.Common/wwwroot/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
background-image: url(SVG/icons/trash.svg)
}

.icon-close {
background-image: url(SVG/icons/close.svg)
}

.logo-size {
max-width: 95px;
height: auto;
Expand Down

0 comments on commit e3a0adf

Please sign in to comment.