Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/bitfoundation/bitplatform
Browse files Browse the repository at this point in the history
…into 7338-boilerplates-app-insights-is-not-working-in-server
  • Loading branch information
ysmoradi committed Apr 8, 2024
2 parents 02ef7c0 + 63a33c7 commit f7062a9
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 35 deletions.
69 changes: 48 additions & 21 deletions src/BlazorUI/Bit.BlazorUI/Components/Nav/BitNav.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace Bit.BlazorUI;

public partial class BitNav<TItem> : IDisposable where TItem : class
{
private bool SelectedItemHasBeenSet;
private TItem? selectedItem;


private bool SelectedItemHasBeenSet;

private bool _disposed;
private IEnumerable<TItem>? _oldItems;

internal TItem? _currentItem;
internal List<TItem> _items = [];
private IEnumerable<TItem>? _oldItems = default!;
internal Dictionary<TItem, bool> _itemExpandStates = [];


Expand Down Expand Up @@ -45,6 +45,21 @@ public partial class BitNav<TItem> : IDisposable where TItem : class
/// </summary>
[Parameter] public BitNavItemTemplateRenderMode HeaderTemplateRenderMode { get; set; } = BitNavItemTemplateRenderMode.Normal;

/// <summary>
/// The indentation value in px for each level of depth of child item.
/// </summary>
[Parameter] public int IndentValue { get; set; } = 16;

/// <summary>
/// The indentation padding in px for items without children (compensation space for chevron icon).
/// </summary>
[Parameter] public int IndentPadding { get; set; } = 27;

/// <summary>
/// The indentation padding in px for items in reversed mode.
/// </summary>
[Parameter] public int IndentReversedPadding { get; set; } = 4;

/// <summary>
/// A collection of item to display in the navigation bar.
/// </summary>
Expand Down Expand Up @@ -101,7 +116,7 @@ public partial class BitNav<TItem> : IDisposable where TItem : class
[Parameter] public bool ReversedChevron { get; set; }

/// <summary>
/// Selected item to show in Nav.
/// Selected item to show in the BitNav.
/// </summary>
[Parameter]
public TItem? SelectedItem
Expand All @@ -116,12 +131,17 @@ public TItem? SelectedItem

if (value is not null)
{
ExpandParents(_items);
ToggleItemAndParents(_items, value, true);
}
}
}
[Parameter] public EventCallback<TItem> SelectedItemChanged { get; set; }

/// <summary>
/// Enables the single-expand mode in the BitNav.
/// </summary>
[Parameter] public bool SingleExpand { get; set; }

/// <summary>
/// Custom CSS styles for different parts of the BitNav component.
/// </summary>
Expand Down Expand Up @@ -611,6 +631,7 @@ internal void SetItemExpanded(TItem item, bool value)
{
_itemExpandStates.Add(item, value);
}

}

internal bool GetItemExpanded(TItem item)
Expand Down Expand Up @@ -643,12 +664,32 @@ internal void UnregisterOption(BitNavOption option)
_items.Remove((option as TItem)!);
StateHasChanged();
}

internal string GetItemKey(TItem item)
{
return GetKey(item) ?? Guid.NewGuid().ToString();
}

internal bool ToggleItemAndParents(IList<TItem> items, TItem item, bool isExpanded)
{
foreach (var parent in items)
{
var childItems = GetChildItems(parent);
if (parent == item || (childItems.Any() && ToggleItemAndParents(childItems, item, isExpanded)))
{
SetItemExpanded(parent, isExpanded);
return true;
}
}

return false;
}

internal void Refresh()
{
StateHasChanged();
}



protected override string RootElementClass => "bit-nav";
Expand Down Expand Up @@ -726,20 +767,6 @@ private void SetSelectedItemByCurrentUrl()
}
}

private bool ExpandParents(IList<TItem> items)
{
foreach (var parent in items)
{
if (parent == SelectedItem || (GetChildItems(parent).Any() && ExpandParents(GetChildItems(parent))))
{
SetItemExpanded(parent, true);
return true;
}
}

return false;
}

private void SetIsExpanded(TItem item, bool value)
{
if (item is BitNavItem navItem)
Expand Down
6 changes: 5 additions & 1 deletion src/BlazorUI/Bit.BlazorUI/Components/Nav/_BitNavChild.razor
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@
}
else
{
var padding = childItems.Any()
? (Depth * Nav.IndentValue + (Nav.ReversedChevron ? Nav.IndentReversedPadding : 0))
: (Depth * Nav.IndentValue + (Nav.ReversedChevron ? Nav.IndentReversedPadding : Nav.IndentPadding));

<div name="@text"
class="bit-nav-ict @GetItemContainerClasses()"
style="padding-inline-start:@(childItems.Any() ? (Depth * 16 + (Nav.ReversedChevron ? 4 : 0)) : (Depth * 16 + (Nav.ReversedChevron ? 4 : 27)))px; @GetItemContainerStyles()">
style="padding-inline-start:@(padding)px; @GetItemContainerStyles()">

<div class="bit-nav-mct" style="@(Nav.ReversedChevron ? "flex-flow:row-reverse" : null)">
@if (childItems.Any())
Expand Down
29 changes: 28 additions & 1 deletion src/BlazorUI/Bit.BlazorUI/Components/Nav/_BitNavChild.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,34 @@ private async Task ToggleItem()

if (Nav.GetIsEnabled(Item) is false || Nav.GetChildItems(Item).Count is 0) return;

Nav.SetItemExpanded(Item, Nav.GetItemExpanded(Item) is false);
var isExpanded = Nav.GetItemExpanded(Item) is false;

if (Nav.SingleExpand)
{
if (isExpanded)
{
if (Nav._currentItem is not null)
{
Nav.ToggleItemAndParents(Nav._items, Nav._currentItem, false);
}
}

if (isExpanded)
{
Nav.ToggleItemAndParents(Nav._items, Item, isExpanded);
}
else
{
Nav.SetItemExpanded(Item, isExpanded);
}

Nav.Refresh();
Nav._currentItem = Item;
}
else
{
Nav.SetItemExpanded(Item, isExpanded);
}

await Nav.OnItemToggle.InvokeAsync(Item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public partial class BitNavDemo
{
private readonly List<ComponentParameter> componentParameters = new()
{
private readonly List<ComponentParameter> componentParameters =
[
new()
{
Name = "ChildContent",
Expand Down Expand Up @@ -35,6 +35,34 @@ public partial class BitNavDemo
Description = "Used to customize how content inside the group header is rendered."
},
new()
{
Name = "HeaderTemplateRenderMode",
Type = "BitNavItemTemplateRenderMode",
DefaultValue = "BitNavItemTemplateRenderMode.Normal",
Description = "The render mode of the custom HeaderTemplate."
},
new()
{
Name = "IndentValue",
Type = "int",
DefaultValue = "16",
Description = "The indentation value in px for each level of depth of child item."
},
new()
{
Name = "IndentPadding",
Type = "int",
DefaultValue = "27",
Description = "The indentation padding in px for items without children (compensation space for chevron icon)."
},
new()
{
Name = "IndentReversedPadding",
Type = "int",
DefaultValue = "4",
Description = "The indentation padding in px for items in reversed mode."
},
new()
{
Name = "Items",
Type = "IList<TItem>",
Expand Down Expand Up @@ -116,7 +144,14 @@ public partial class BitNavDemo
Name = "SelectedItem",
Type = "TItem?",
DefaultValue = "null",
Description = "Selected item to show in Nav."
Description = "Selected item to show in the BitNav."
},
new()
{
Name = "SingleExpand",
Type = "bool",
DefaultValue = "false",
Description = "Enables the single-expand mode in the BitNav."
},
new()
{
Expand All @@ -127,10 +162,9 @@ public partial class BitNavDemo
Href = "#nav-class-styles",
LinkType = LinkType.Link
}
};

private readonly List<ComponentSubClass> componentSubClasses = new()
{
];
private readonly List<ComponentSubClass> componentSubClasses =
[
new()
{
Id = "nav-item",
Expand Down Expand Up @@ -678,10 +712,9 @@ public partial class BitNavDemo
},
}
}
};

private readonly List<ComponentSubEnum> componentSubEnums = new()
{
];
private readonly List<ComponentSubEnum> componentSubEnums =
[
new()
{
Id = "nav-mode-enum",
Expand Down Expand Up @@ -779,5 +812,5 @@ public partial class BitNavDemo
}
]
},
};
];
}

0 comments on commit f7062a9

Please sign in to comment.