Skip to content
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

feat(ListView): use grid layout instead of flex #5409

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions src/BootstrapBlazor.Server/Components/Samples/ListViews.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<BodyTemplate>
<Card>
<BodyTemplate>
<img src="@context.ImageUrl" />
<img class="lv-demo-img" src="@context.ImageUrl" />
<div class="lv-demo-desc">@context.Description</div>
</BodyTemplate>
</Card>
Expand All @@ -42,7 +42,7 @@
<BodyTemplate>
<Card>
<BodyTemplate>
<img src="@context.ImageUrl" />
<img class="lv-demo-img" src="@context.ImageUrl" />
<div class="lv-demo-desc">@context.Description</div>
</BodyTemplate>
</Card>
Expand All @@ -60,7 +60,7 @@
<BodyTemplate>
<Card>
<BodyTemplate>
<img src="@context.ImageUrl" />
<img class="lv-demo-img" src="@context.ImageUrl" />
<div class="lv-demo-desc">@context.Description</div>
</BodyTemplate>
</Card>
Expand All @@ -78,7 +78,7 @@
<BodyTemplate>
<Card>
<BodyTemplate>
<img src="@context.ImageUrl" />
<img class="lv-demo-img" src="@context.ImageUrl" />
<div class="lv-demo-desc">@context.Description</div>
</BodyTemplate>
</Card>
Expand All @@ -96,7 +96,7 @@
<BodyTemplate>
<Card>
<BodyTemplate>
<img src="@context.ImageUrl" />
<img class="lv-demo-img" src="@context.ImageUrl" />
<div class="lv-demo-desc">@context.Description</div>
</BodyTemplate>
</Card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
img {
margin-bottom: 1rem;
.lv-demo-img {
width: 100%;
border-radius: var(--bs-border-radius);
}

Expand Down
25 changes: 10 additions & 15 deletions src/BootstrapBlazor/Components/ListView/ListView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
{
if (GroupName == null)
{
foreach (var item in Rows)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
@BodyTemplate(item)
</div>
}
@RenderGroup(Rows)
}
else if (Collapsible)
{
Expand All @@ -38,12 +33,7 @@
<div @key="@key.GroupName" class="accordion-item">
<div class="accordion-header">@key.GroupName</div>
<div class="accordion-body">
@foreach (var item in key.Items)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
@BodyTemplate(item)
</div>
}
@RenderGroup(key.Items)
</div>
</div>
}
Expand Down Expand Up @@ -77,14 +67,19 @@
@code {
RenderFragment RenderItem((object? GroupName, IOrderedEnumerable<TItem> Items) key, int index) =>
@<CollapseItem Text="@GetGroupName(key.GroupName)" IsCollapsed="IsCollapsed(index, key.GroupName)">
@foreach (var item in key.Items)
@RenderGroup(key.Items)
</CollapseItem>;

RenderFragment<IEnumerable<TItem>> RenderGroup => items =>
@<div class="listview-item-group">
@foreach (var item in items)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
<div @key="item" class="listview-item" @onclick="@(e => OnClick(item))">
@if(BodyTemplate != null)
{
@BodyTemplate(item)
}
</div>
}
</CollapseItem>;
</div>;
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/ListView/ListView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class ListView<TItem> : BootstrapComponentBase
.AddClassFromAttributes(AdditionalAttributes)
.Build();

private string? BodyClassString => CssBuilder.Default("listview-body")
private string? BodyClassString => CssBuilder.Default("listview-body scroll")
.AddClass("is-group", GroupName != null)
.Build();

Expand Down
33 changes: 8 additions & 25 deletions src/BootstrapBlazor/Components/ListView/ListView.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
--bb-lv-item-border-hover-color: #{$bb-lv-item-border-hover-color};
--bb-lv-item-shadow: #{$bb-lv-item-shadow};
--bb-lv-body-padding: #{$bb-lv-body-padding};
--bb-lv-body-item-margin: #{$bb-lv-body-item-margin};
--bb-lv-body-item-gap: #{$bb-lv-body-item-gap};
--bb-lv-footer-padding: #{$bb-lv-footer-padding};
border: 1px solid var(--bb-lv-border-color);
border-radius: var(--bs-border-radius);
Expand All @@ -29,24 +29,17 @@
.listview .listview-body {
padding: var(--bb-lv-body-padding);
position: relative;
overflow: auto;
display: flex;
flex-flow: row wrap;
flex: 1;
align-content: flex-start;
height: 1%;
min-height: 0;
height: 1%;
}

.listview .listview-body.is-group {
padding: 0;
}

.listview .listview-body .listview-item {
margin: var(--bb-lv-body-item-margin);
}

.listview .listview-body .listview-item .card {
box-shadow: var(--bb-lv-item-shadow);
transition: var(--bb-lv-item-trans);
}

Expand All @@ -55,15 +48,11 @@
border: 1px solid var(--bb-lv-item-border-hover-color);
}

.listview .listview-body .listview-item .card {
box-shadow: var(--bb-lv-item-shadow);
}

.listview .listview-body .listview-item-group {
flex-basis: 100%;
margin: 1rem 0;
font-weight: bold;
position: relative;
.listview .listview-item-group {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: var(--bb-lv-body-item-gap);
align-items: start;
}

.listview .listview-body .accordion {
Expand All @@ -82,15 +71,9 @@
}

.listview .listview-body .accordion-body {
display: flex;
flex-wrap: wrap;
padding: var(--bb-lv-body-padding);
}

.listview .listview-body .accordion-item {
width: 100%;
}

.listview .listview-body .accordion-item:last-child .accordion-header {
border-bottom: 1px solid var(--bb-lv-border-color);
}
Expand Down
6 changes: 3 additions & 3 deletions src/BootstrapBlazor/wwwroot/scss/theme/bootstrapblazor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ $bb-lv-border-color: var(--bs-border-color);
$bb-lv-item-trans: border .3s linear;
$bb-lv-item-border-hover-color: #409eff;
$bb-lv-item-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
$bb-lv-body-padding: 1rem 0 0 1rem;
$bb-lv-body-item-margin: 0 1rem 1rem 0;
$bb-lv-footer-padding: 1rem;
$bb-lv-body-padding: 0.5rem;
$bb-lv-body-item-gap: 0.5rem;
$bb-lv-footer-padding: 0.5rem;

// Logout
$bb-logout-avatar-width: 42px;
Expand Down