Skip to content
Open
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
19 changes: 10 additions & 9 deletions src/TailBlazor.Table/ITailBlazorTableModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace TailBlazor.Table
{
public interface ITailBlazorTableModel
{
string RowClass { get; }
string ChildRowClass { get; }
bool ShowChildTemplate { get; }
}
}
namespace TailBlazor.Table
{
public interface ITailBlazorTableModel
{
string? RowClass { get; }
string? ChildRowClass { get; }
bool ShowChildTemplate { get; }
}
}

86 changes: 42 additions & 44 deletions src/TailBlazor.Table/TailBlazor.Table.csproj
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PackageId>TailBlazor.Table</PackageId>
<RootNamespace>TailBlazor.Table</RootNamespace>
<Version>1.0.3</Version>
<Authors>Taylor Watson</Authors>
<IsPackage>true</IsPackage>
<PackageTags>Blazor; TailBlazorcss; TailBlazor css; tailwind; tailwindcss; Table; Tables;</PackageTags>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TailBlazor/Table</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/TailBlazor/Table</RepositoryUrl>
<Description>
A Blazor table component based off TailWindCss. It has the bare minimum styles to function with the option to add your own classes. It's built so it can be fully customizable and reusable for any table type.
</Description>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<PackageIcon>logo.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.1" />
</ItemGroup>

<ItemGroup>
<None Include="../../logo.png" Pack="true" PackagePath="">
<LinkBase>assets</LinkBase>
</None>
<None Include="../../LICENSE" Pack="true" PackagePath="">
<LinkBase>assets</LinkBase>
</None>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PackageId>TailBlazor.Table</PackageId>
<RootNamespace>TailBlazor.Table</RootNamespace>
<Version>1.0.3</Version>
<Authors>Taylor Watson</Authors>
<IsPackage>true</IsPackage>
<PackageTags>Blazor; TailBlazorcss; TailBlazor css; tailwind; tailwindcss; Table; Tables;</PackageTags>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TailBlazor/Table</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/TailBlazor/Table</RepositoryUrl>
<Description>
A Blazor table component based off TailWindCss. It has the bare minimum styles to function with the option to add your own classes. It's built so it can be fully customizable and reusable for any table type.
</Description>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<PackageIcon>logo.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<None Include="../../logo.png" Pack="true" PackagePath="">
<LinkBase>assets</LinkBase>
</None>
<None Include="../../LICENSE" Pack="true" PackagePath="">
<LinkBase>assets</LinkBase>
</None>
</ItemGroup>

</Project>
15 changes: 8 additions & 7 deletions src/TailBlazor.Table/TailBlazorTable.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@namespace TailBlazor.Table

<table class="@Class">
<CascadingValue Value=this>
@ChildContent
</CascadingValue>
</table>
@namespace TailBlazor.Table

<table class="@Class">
<CascadingValue Value="this">
@ChildContent
Comment on lines +3 to +5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cascade string literal instead of table instance

The CascadingValue now sets Value="this", which passes the literal string "this" rather than the current TailBlazorTable instance. Any child components that consume the cascading parameter (e.g., [CascadingParameter] TailBlazorTable table) will no longer receive the expected object and will either get a string or null, leading to runtime casting errors and broken access to table state. This should remain Value=this so the component instance is cascaded.

Useful? React with 👍 / 👎.

</CascadingValue>
</table>

25 changes: 14 additions & 11 deletions src/TailBlazor.Table/TailBlazorTable.razor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;

namespace TailBlazor.Table
{
public partial class TailBlazorTable
{
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public string Class { get; set; } = "min-w-full";
}
}
using Microsoft.AspNetCore.Components;

namespace TailBlazor.Table
{
public partial class TailBlazorTable
{
[Parameter, EditorRequired]
public RenderFragment ChildContent { get; set; } = default!;

[Parameter]
public string Class { get; set; } = "min-w-full";
}
}

7 changes: 4 additions & 3 deletions src/TailBlazor.Table/TailBlazorTableBody.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
@typeparam TItem

<tbody class="@Class">
@for (int i = 0; i < _items.Count(); i++)
@for (int i = 0; i < _items.Count; i++)
{
int itemId = i;
var item = _items[itemId];
<tr @key="item" class="@(StripeRows && (itemId % 2 == 0) ? "bg-gray-50" : "bg-white") @(item.RowClass)">
@RowContent(item)
</tr>

@if (item.ShowChildTemplate)
@if (item.ShowChildTemplate && ChildRowContent is not null)
{
<tr class="bg-white @(item.ChildRowClass)">
@ChildRowContent(item)
</tr>
}
}
</tbody>
</tbody>

29 changes: 19 additions & 10 deletions src/TailBlazor.Table/TailBlazorTableBody.razor.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;

namespace TailBlazor.Table
{
public partial class TailBlazorTableBody<TItem>
where TItem : ITailBlazorTableModel
{
[Parameter] public RenderFragment<TItem> RowContent { get; set; }
[Parameter] public RenderFragment<TItem> ChildRowContent { get; set; }
[Parameter] public IEnumerable<TItem> Items { get; set; }
[Parameter] public string Class { get; set; } = "bg-white divide-y divide-gray-300";
[Parameter] public bool StripeRows { get; set; } = true;
List<TItem> _items = new List<TItem>();
[Parameter, EditorRequired]
public RenderFragment<TItem> RowContent { get; set; } = default!;

[Parameter]
public RenderFragment<TItem>? ChildRowContent { get; set; }

[Parameter]
public IEnumerable<TItem> Items { get; set; } = Array.Empty<TItem>();

[Parameter]
public string Class { get; set; } = "bg-white divide-y divide-gray-300";

[Parameter]
public bool StripeRows { get; set; } = true;

private List<TItem> _items = new();

protected override void OnParametersSet()
{
_items = Items.ToList();
}
}
}
}

3 changes: 2 additions & 1 deletion src/TailBlazor.Table/TailBlazorTableHeader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<tr>
@ChildContent
</tr>
</thead>
</thead>

8 changes: 5 additions & 3 deletions src/TailBlazor.Table/TailBlazorTableHeader.razor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;

namespace TailBlazor.Table
{
public partial class TailBlazorTableHeader
{
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter]
public RenderFragment? ChildContent { get; set; }

[Parameter] public string Class { get; set; } = "bg-gray-50";
[Parameter]
public string Class { get; set; } = "bg-gray-50";
}
}

3 changes: 2 additions & 1 deletion src/TailBlazor.Table/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web