From f212a639e1ff62077613419d3a7dd6f73e465dcc Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 20 Feb 2026 16:46:56 +0800 Subject: [PATCH] Refactor TableColumn width property to string type and implement BlaoriseFluentSizingParse for dynamic sizing in DataGrid columns --- .../Extensibility/TableColumns/TableColumn.cs | 5 +- .../BlaoriseFluentSizingParse.cs | 87 +++++++++++++++++++ .../Components/AbpExtensibleDataGrid.razor | 10 +-- .../TimeExtensionProperty.razor | 2 +- 4 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 framework/src/Volo.Abp.BlazoriseUI/BlaoriseFluentSizingParse.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumn.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumn.cs index 5152ce2a22..000e4e7703 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumn.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumn.cs @@ -11,10 +11,7 @@ public class TableColumn public string Data { get; set; } = default!; - /// - /// px - /// - public double Width { get; set; } = default!; + public string Width { get; set; } = default!; public string PropertyName { get; set; } = default!; diff --git a/framework/src/Volo.Abp.BlazoriseUI/BlaoriseFluentSizingParse.cs b/framework/src/Volo.Abp.BlazoriseUI/BlaoriseFluentSizingParse.cs new file mode 100644 index 0000000000..95063a58f4 --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/BlaoriseFluentSizingParse.cs @@ -0,0 +1,87 @@ +using Blazorise; +using System; +using System.Globalization; +using System.Text.RegularExpressions; + +namespace Volo.Abp.BlazoriseUI; + +public static class BlaoriseFluentSizingParse +{ + private static readonly Regex SizingPattern = new Regex( + @"^(\d+(?:\.\d+)?)(px|rem|em|ch|vw|vh|%)$", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + /// + /// Parses a CSS size string into an IFluentSizingStyle. + /// Supported formats (based on Blazorise FluentSizing source): + /// Fixed units : 10px, 10rem, 10em, 10ch + /// Viewport units : 10vw, 10vh + /// Percentage : 25%, 33%, 50%, 66%, 75%, 100% -> maps to SizingSize enum (CSS class) + /// other % values -> inline style + /// Keyword : auto -> SizingSize.Auto + /// CSS variable : var(--my-var), --my-var, or my-var (all handled by WithVariable) + /// + public static IFluentSizingStyle Parse(string value, SizingType sizingType = SizingType.None) + { + var fluentSizing = new FluentSizing(sizingType); + + if (string.IsNullOrWhiteSpace(value)) + { + return fluentSizing; + } + + value = value.Trim(); + + // "auto" -> SizingSize.Auto + if (value.Equals("auto", StringComparison.OrdinalIgnoreCase)) + { + return (IFluentSizingStyle)fluentSizing.WithSize(SizingSize.Auto); + } + + // CSS variable: + // "var(--my-var)" -> used as-is + // "--my-var" -> wrapped as var(--my-var) + // "my-var" -> prepended "--" and wrapped as var(--my-var) + // All three cases are handled correctly by Blazorise's GetCssVariableValue. + if (value.StartsWith("var(", StringComparison.Ordinal) || value.StartsWith("--", StringComparison.Ordinal)) + { + return fluentSizing.WithVariable(value); + } + + var match = SizingPattern.Match(value); + + if (!match.Success) + { + return fluentSizing; + } + + var number = double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture); + var unit = match.Groups[2].Value.ToLowerInvariant(); + + if (unit == "%") + { + // Standard percentages map to SizingSize enum (generates CSS class via class provider) + var sizingSize = number switch + { + 25 => SizingSize.Is25, + 33 => SizingSize.Is33, + 50 => SizingSize.Is50, + 66 => SizingSize.Is66, + 75 => SizingSize.Is75, + 100 => SizingSize.Is100, + _ => SizingSize.Default + }; + + if (sizingSize != SizingSize.Default) + { + return (IFluentSizingStyle)fluentSizing.WithSize(sizingSize); + } + + // Non-standard percentage falls back to inline style + return fluentSizing.WithSize("%", number); + } + + // px, rem, em, ch, vw, vh -> inline style via WithSize(unit, size) + return fluentSizing.WithSize(unit, number); + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor index 47315154a5..b52d40bdc0 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor @@ -73,7 +73,7 @@ { @if (column.ValueConverter == null) { - + @RenderCustomTableColumnComponent(column.Component, context.Item!) @@ -81,7 +81,7 @@ } else { - + @RenderCustomTableColumnComponent(column.Component, context.Item!) @@ -96,7 +96,7 @@ { @@ -119,7 +119,7 @@ } else { - + @{ var entity = context as IHasExtraProperties; diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor index 1ee93159d5..a0b2333714 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor @@ -7,7 +7,7 @@ { - @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)--> + @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)