Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.1.3-beta07</Version>
<Version>9.1.3-beta08</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/BootstrapBlazor/Components/SelectGeneric/ISelectGeneric.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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>
/// ISelect 接口
/// </summary>
public interface ISelectGeneric<TValue>
{
/// <summary>
/// 增加 SelectedItem 项方法
/// </summary>
/// <param name="item"></param>
void Add(SelectedItem<TValue> item);
}
115 changes: 115 additions & 0 deletions src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@namespace BootstrapBlazor.Components
@using Microsoft.AspNetCore.Components.Web.Virtualization
@typeparam TValue
@inherits SelectBase<TValue>
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor/Components/Select/Select.razor.js", JSObjectReference = true)]

@if (IsShowLabel)
{
<BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString">
<CascadingValue Value="this" IsFixed="true">
@Options
</CascadingValue>
<RenderTemplate>
<div class="dropdown-toggle" data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString">
@if (DisplayTemplate != null)
{
<div id="@InputId" class="@InputClassString" tabindex="0">
@DisplayTemplate(SelectedRow)
</div>
}
else
{
<input type="text" id="@InputId" disabled="@Disabled" placeholder="@PlaceHolder" class="@InputClassString" value="@SelectedRow.Text" @onchange="OnChange" readonly="@ReadonlyString" />
}
<span class="@AppendClassString"><i class="@DropdownIcon"></i></span>
</div>
@if (GetClearable())
{
<span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span>
}
<div class="dropdown-menu">
@if (IsVirtualize)
{
@if (ShowSearch)
{
<div class="@SearchClassString">
<input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" @oninput="EventCallback.Factory.CreateBinder<string>(this, async v => await SearchTextChanged(v), SearchText)" aria-label="Search">
<i class="@SearchIconString"></i>
</div>
}
<div class="dropdown-virtual">
@if (OnQueryAsync == null)
{
<Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" Items="@GetVirtualItems()" ChildContent="RenderRow" />
}
else
{
<Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" ItemsProvider="LoadItems" Placeholder="RenderPlaceHolderRow" ItemContent="RenderRow" @ref="VirtualizeElement" />
}
</div>
}
else
{
@if (ShowSearch)
{
<div class="@SearchClassString">
<input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" @oninput="EventCallback.Factory.CreateBinder<string>(this, async v => await SearchTextChanged(v), SearchText)" aria-label="Search">
<i class="@SearchIconString"></i>
</div>
}
@foreach (var itemGroup in Rows.GroupBy(i => i.GroupName))
{
if (!string.IsNullOrEmpty(itemGroup.Key))
{
if (GroupItemTemplate != null)
{
@GroupItemTemplate(itemGroup.Key)
}
else
{
<Divider Text="@itemGroup.Key" />
}
}
@foreach (var item in itemGroup)
{
@RenderRow(item)
}
}
@if (Rows.Count == 0)
{
<div class="dropdown-item">@NoSearchDataText</div>
}
}
</div>
@if (!IsPopover)
{
<div class="dropdown-menu-arrow"></div>
}
</RenderTemplate>
</div>

@code {
RenderFragment<SelectedItem<TValue>> RenderRow => item =>
@<div class="@ActiveItem(item)" @onclick="() => OnClickItem(item)">
@if (ItemTemplate != null)
{
@ItemTemplate(item)
}
else if (IsMarkupString)
{
@((MarkupString)item.Text)
}
else
{
@item.Text
}
</div>;

RenderFragment<PlaceholderContext> RenderPlaceHolderRow => context =>
@<div class="dropdown-item">
<div class="is-ph"></div>
</div>;
}
Loading
Loading