From d3dc34aa7f77e47404668b49309ce4ac39f809a1 Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Sat, 8 Jun 2024 16:54:29 +0530 Subject: [PATCH 1/4] Code improvements --- .../BarCharts/BarChart_Demo_01_Examples.razor | 2 +- ...BarChart_Demo_02_Horizontal_BarChart.razor | 4 +- .../BarChart_Demo_03_Stacked_BarChart.razor | 2 +- .../BarCharts/BarChart_Demo_04_Locale.razor | 2 +- ..._05_Stacked_BarChart_with_Datalabels.razor | 2 +- .../Charts/Charts_Demo_00_Examples.razor | 18 +++---- .../DoughnutChart_Demo_01_Examples.razor | 2 +- .../DoughnutChart_Demo_02_Datalabels.razor | 2 +- .../LineChart_Demo_01_A_Examples.razor | 2 +- .../LineChart_Demo_01_B_Examples.razor | 2 +- .../LineCharts/LineChart_Demo_02_Locale.razor | 2 +- .../LineChart_Demo_04_Datalabels.razor | 2 +- .../PieCharts/PieChart_Demo_01_Examples.razor | 2 +- .../PieChart_Demo_02_Datalabels.razor | 2 +- ...Chart_Demo_03_Change_Legend_Position.razor | 2 +- .../Components/Accordion/Accordion.razor.cs | 7 ++- .../Accordion/AccordionItem.razor.cs | 8 ++- .../Components/Alert/Alert.razor.cs | 9 ++-- .../Components/Badge/Badge.razor.cs | 15 +++--- .../Components/Button/Button.razor.cs | 21 ++++---- .../Components/Callout/Callout.razor.cs | 7 ++- blazorbootstrap/Components/Card/Card.razor.cs | 9 ++-- .../Components/Card/CardBody.razor.cs | 4 +- .../Components/Card/CardFooter.razor.cs | 4 +- .../Components/Card/CardGroup.razor.cs | 4 +- .../Components/Card/CardHeader.razor.cs | 7 ++- .../Components/Card/CardLink.razor.cs | 7 ++- .../Components/Card/CardSubTitle.razor.cs | 4 +- .../Components/Card/CardText.razor.cs | 4 +- .../Components/Card/CardTitle.razor.cs | 4 +- .../Components/Collapse/Collapse.razor.cs | 7 ++- .../ConfirmDialog/ConfirmDialog.razor.cs | 16 +++--- .../Core/BlazorBootstrapComponentBase.cs | 53 ++++++++++++++++--- .../Components/Dropdown/Dropdown.razor.cs | 7 ++- .../Dropdown/DropdownActionButton.razor.cs | 9 ++-- .../Dropdown/DropdownDivider.razor.cs | 4 +- .../Dropdown/DropdownHeader.razor.cs | 4 +- .../Components/Dropdown/DropdownItem.razor.cs | 9 ++-- .../Components/Dropdown/DropdownMenu.razor.cs | 7 ++- .../Dropdown/DropdownToggleButton.razor.cs | 13 +++-- .../Form/AutoComplete/AutoComplete.razor.cs | 7 ++- .../Form/CurrencyInput/CurrencyInput.razor.cs | 7 ++- .../Form/DateInput/DateInput.razor.cs | 4 +- .../Form/NumberInput/NumberInput.razor.cs | 7 ++- .../Form/RangeInput/RangeInput.razor.cs | 4 +- .../Components/Form/Switch/Switch.razor.cs | 9 ++-- .../Form/TimeInput/TimeInput.razor.cs | 4 +- blazorbootstrap/Components/Grid/Grid.razor.cs | 13 +++-- .../Components/Grid/GridColumn.razor.cs | 2 +- .../Components/Grid/GridColumnFilter.razor.cs | 6 +-- blazorbootstrap/Components/Icon/Icon.razor.cs | 13 +++-- .../Components/Modals/Modal.razor.cs | 7 ++- .../Components/Offcanvas/Offcanvas.razor.cs | 9 ++-- .../Components/Pagination/Pagination.razor.cs | 9 ++-- .../Pagination/PaginationItem.razor.cs | 9 ++-- .../Pagination/PaginationLink.razor.cs | 4 +- .../Placeholders/Placeholder.razor.cs | 11 ++-- .../PlaceholderContainer.razor.cs | 4 +- .../Components/Preload/Preload.razor.cs | 18 +++---- .../Components/Progress/Progress.razor.cs | 8 +-- .../Components/Progress/ProgressBar.razor.cs | 16 +++--- .../Components/Ribbon/Ribbon.razor.cs | 13 +++-- .../Components/Ribbon/RibbonGroup.razor.cs | 11 ++-- .../Components/Ribbon/RibbonItem.razor.cs | 19 ++++--- .../Ribbon/RibbonItemGroup.razor.cs | 15 +++--- .../Components/Ribbon/RibbonTab.razor.cs | 2 +- .../Components/Sidebar/Sidebar.razor.cs | 9 ++-- .../Components/Sidebar/SidebarItem.razor.cs | 9 ++-- .../Sidebar/SidebarItemGroup.razor.cs | 4 +- .../Components/Sidebar2/Sidebar2.razor.cs | 9 ++-- .../Components/Sidebar2/Sidebar2Item.razor.cs | 11 ++-- .../Sidebar2/Sidebar2ItemGroup.razor.cs | 4 +- .../SortableList/SortableList.razor.cs | 4 +- .../Components/Spinner/Spinner.razor.cs | 9 ++-- blazorbootstrap/Components/Tabs/Tab.razor.cs | 2 +- blazorbootstrap/Components/Tabs/Tabs.razor.cs | 13 +++-- .../Components/Toasts/SimpleToast.razor.cs | 9 ++-- .../Components/Toasts/Toast.razor.cs | 7 ++- .../Components/Toasts/Toasts.razor.cs | 9 ++-- blazorbootstrap/Config.cs | 2 - blazorbootstrap/Utilities/CssClassBuilder.cs | 45 ---------------- blazorbootstrap/Utilities/CssStyleBuilder.cs | 45 ---------------- .../BootstrapIconUtility.cs} | 2 +- .../ColorBuilder.cs => Utils/ColorUtility.cs} | 2 +- .../FilterOperatorUtility.cs} | 2 +- .../IdGenerator.cs => Utils/IdUtility.cs} | 21 ++------ 86 files changed, 291 insertions(+), 449 deletions(-) delete mode 100644 blazorbootstrap/Utilities/CssClassBuilder.cs delete mode 100644 blazorbootstrap/Utilities/CssStyleBuilder.cs rename blazorbootstrap/{Utilities/BootstrapIconProvider.cs => Utils/BootstrapIconUtility.cs} (99%) rename blazorbootstrap/{Utilities/ColorBuilder.cs => Utils/ColorUtility.cs} (96%) rename blazorbootstrap/{Utilities/FilterOperatorHelper.cs => Utils/FilterOperatorUtility.cs} (99%) rename blazorbootstrap/{Utilities/IdGenerator.cs => Utils/IdUtility.cs} (80%) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_01_Examples.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_01_Examples.razor index 11281a949..e5c6247c7 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_01_Examples.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_01_Examples.razor @@ -120,7 +120,7 @@ private BarChartDataset GetRandomBarChartDataset() { - var c = ColorBuilder.CategoricalTwelveColors[datasetsCount].ToColor(); + var c = ColorUtility.CategoricalTwelveColors[datasetsCount].ToColor(); datasetsCount += 1; diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_02_Horizontal_BarChart.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_02_Horizontal_BarChart.razor index 2437c404a..0c4dbf5a1 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_02_Horizontal_BarChart.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_02_Horizontal_BarChart.razor @@ -13,8 +13,8 @@ var dataset1 = new BarChartDataset() { Data = new List { 55000, 15000, 18000, 21000 }, - BackgroundColor = new List { ColorBuilder.CategoricalTwelveColors[0] }, - BorderColor = new List { ColorBuilder.CategoricalTwelveColors[0] }, + BackgroundColor = new List { ColorUtility.CategoricalTwelveColors[0] }, + BorderColor = new List { ColorUtility.CategoricalTwelveColors[0] }, BorderWidth = new List { 0 }, }; datasets.Add(dataset1); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_03_Stacked_BarChart.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_03_Stacked_BarChart.razor index f0d3fc46f..f0b9d2d2f 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_03_Stacked_BarChart.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_03_Stacked_BarChart.razor @@ -7,7 +7,7 @@ protected override void OnInitialized() { - var colors = ColorBuilder.CategoricalTwelveColors; + var colors = ColorUtility.CategoricalTwelveColors; var labels = new List { "Chrome", "Firefox", "Safari", "Edge" }; var datasets = new List(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_04_Locale.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_04_Locale.razor index 2053f6089..caacaee0e 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_04_Locale.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_04_Locale.razor @@ -7,7 +7,7 @@ protected override void OnInitialized() { - var colors = ColorBuilder.CategoricalTwelveColors; + var colors = ColorUtility.CategoricalTwelveColors; var labels = new List { "Chrome", "Firefox", "Safari", "Edge" }; var datasets = new List(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_05_Stacked_BarChart_with_Datalabels.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_05_Stacked_BarChart_with_Datalabels.razor index 1af8890fb..0565edc3e 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_05_Stacked_BarChart_with_Datalabels.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/BarCharts/BarChart_Demo_05_Stacked_BarChart_with_Datalabels.razor @@ -7,7 +7,7 @@ protected override void OnInitialized() { - var colors = ColorBuilder.CategoricalTwelveColors; + var colors = ColorUtility.CategoricalTwelveColors; var labels = new List { "Chrome", "Firefox", "Safari", "Edge" }; var datasets = new List(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/Charts_Demo_00_Examples.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/Charts_Demo_00_Examples.razor index 74204466c..7748b6671 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/Charts_Demo_00_Examples.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/Charts_Demo_00_Examples.razor @@ -48,15 +48,12 @@ options.Plugins.Title!.Text = "MANHATTAN"; options.Plugins.Title.Display = true; - options.Plugins.Title.Font!.Size = 20; + options.Plugins.Title.Font = new ChartFont { Size = 20 }; options.Responsive = true; - options.Scales.X!.Title!.Text = "Overs"; - options.Scales.X.Title.Display = true; - - options.Scales.Y!.Title!.Text = "Runs"; - options.Scales.Y.Title.Display = true; + options.Scales.X!.Title = new ChartAxesTitle { Text = "Overs", Display = true }; + options.Scales.Y!.Title = new ChartAxesTitle { Text = "Runs", Display = true }; await barChart.InitializeAsync(data, options); } @@ -103,15 +100,12 @@ options.Plugins.Title!.Text = "WORM"; options.Plugins.Title.Display = true; - options.Plugins.Title.Font!.Size = 20; + options.Plugins.Title.Font = new ChartFont { Size = 20 }; options.Responsive = true; - options.Scales.X!.Title!.Text = "Overs"; - options.Scales.X.Title.Display = true; - - options.Scales.Y!.Title!.Text = "Runs"; - options.Scales.Y.Title.Display = true; + options.Scales.X!.Title = new ChartAxesTitle { Text = "Overs", Display = true }; + options.Scales.Y!.Title = new ChartAxesTitle { Text = "Runs", Display = true }; await lineChart.InitializeAsync(data, options); } diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_01_Examples.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_01_Examples.razor index 3cd985ab7..ab810b6d0 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_01_Examples.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_01_Examples.razor @@ -19,7 +19,7 @@ protected override void OnInitialized() { - backgroundColors = ColorBuilder.CategoricalTwelveColors; + backgroundColors = ColorUtility.CategoricalTwelveColors; chartData = new ChartData { Labels = GetDefaultDataLabels(4), Datasets = GetDefaultDataSets(1) }; doughnutChartOptions = new(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_02_Datalabels.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_02_Datalabels.razor index 7e559ae29..977dcae96 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_02_Datalabels.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/DoughnutCharts/DoughnutChart_Demo_02_Datalabels.razor @@ -18,7 +18,7 @@ protected override void OnInitialized() { - backgroundColors = ColorBuilder.CategoricalTwelveColors; + backgroundColors = ColorUtility.CategoricalTwelveColors; chartData = new ChartData { Labels = GetDefaultDataLabels(4), Datasets = GetDefaultDataSets(3) }; doughnutChartOptions = new(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_A_Examples.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_A_Examples.razor index 2731ba2f3..8a440de14 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_A_Examples.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_A_Examples.razor @@ -114,7 +114,7 @@ private LineChartDataset GetRandomLineChartDataset() { - var c = ColorBuilder.CategoricalTwelveColors[datasetsCount].ToColor(); + var c = ColorUtility.CategoricalTwelveColors[datasetsCount].ToColor(); datasetsCount += 1; diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_B_Examples.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_B_Examples.razor index 4393673a7..34cad3aa6 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_B_Examples.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_01_B_Examples.razor @@ -7,7 +7,7 @@ protected override void OnInitialized() { - var colors = ColorBuilder.CategoricalTwelveColors; + var colors = ColorUtility.CategoricalTwelveColors; var labels = new List { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; var datasets = new List(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_02_Locale.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_02_Locale.razor index 67c43862f..c83762196 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_02_Locale.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_02_Locale.razor @@ -7,7 +7,7 @@ protected override void OnInitialized() { - var colors = ColorBuilder.CategoricalTwelveColors; + var colors = ColorUtility.CategoricalTwelveColors; var labels = new List { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; var datasets = new List(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_04_Datalabels.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_04_Datalabels.razor index d423aa076..a553b515b 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_04_Datalabels.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_04_Datalabels.razor @@ -7,7 +7,7 @@ protected override void OnInitialized() { - var colors = ColorBuilder.CategoricalTwelveColors; + var colors = ColorUtility.CategoricalTwelveColors; var labels = new List { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; var datasets = new List(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_01_Examples.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_01_Examples.razor index 07a206dac..9681c4722 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_01_Examples.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_01_Examples.razor @@ -19,7 +19,7 @@ protected override void OnInitialized() { - backgroundColors = ColorBuilder.CategoricalTwelveColors; + backgroundColors = ColorUtility.CategoricalTwelveColors; chartData = new ChartData { Labels = GetDefaultDataLabels(4), Datasets = GetDefaultDataSets(1) }; pieChartOptions = new(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_02_Datalabels.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_02_Datalabels.razor index 267b4fff6..83bee0027 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_02_Datalabels.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_02_Datalabels.razor @@ -18,7 +18,7 @@ protected override void OnInitialized() { - backgroundColors = ColorBuilder.CategoricalTwelveColors; + backgroundColors = ColorUtility.CategoricalTwelveColors; chartData = new ChartData { Labels = GetDefaultDataLabels(4), Datasets = GetDefaultDataSets(3) }; pieChartOptions = new(); diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_03_Change_Legend_Position.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_03_Change_Legend_Position.razor index 817f43704..3ab7f6e51 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_03_Change_Legend_Position.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/PieCharts/PieChart_Demo_03_Change_Legend_Position.razor @@ -20,7 +20,7 @@ protected override void OnInitialized() { - backgroundColors = ColorBuilder.CategoricalTwelveColors; + backgroundColors = ColorUtility.CategoricalTwelveColors; chartData = new ChartData { Labels = GetDefaultDataLabels(4), Datasets = GetDefaultDataSets(1) }; pieChartOptions = new(); diff --git a/blazorbootstrap/Components/Accordion/Accordion.razor.cs b/blazorbootstrap/Components/Accordion/Accordion.razor.cs index 38f3fe919..8fe07966b 100644 --- a/blazorbootstrap/Components/Accordion/Accordion.razor.cs +++ b/blazorbootstrap/Components/Accordion/Accordion.razor.cs @@ -173,10 +173,9 @@ internal void Add(AccordionItem accordionItem) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Accordion) - .AddClass(BootstrapClass.AccordionFlush, Flush) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Accordion, true), + (BootstrapClass.AccordionFlush, Flush)); /// /// If , accordion items stay open when another item is opened. diff --git a/blazorbootstrap/Components/Accordion/AccordionItem.razor.cs b/blazorbootstrap/Components/Accordion/AccordionItem.razor.cs index 5e3ecd038..b691486ac 100644 --- a/blazorbootstrap/Components/Accordion/AccordionItem.razor.cs +++ b/blazorbootstrap/Components/Accordion/AccordionItem.razor.cs @@ -14,7 +14,7 @@ public partial class AccordionItem : BlazorBootstrapComponentBase protected override void OnInitialized() { - Id = IdGenerator.GetNextId(); // This is required + Id = IdUtility.GetNextId(); // This is required Parent.Add(this); } @@ -61,10 +61,8 @@ private async Task OnCollapseShownAsync() #region Properties, Indexers - protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.AccordionItem) - .Build(); + protected override string? ClassNames => + BuildClassNames(Class, (BootstrapClass.AccordionItem, true)); /// /// Gets or sets the active state. diff --git a/blazorbootstrap/Components/Alert/Alert.razor.cs b/blazorbootstrap/Components/Alert/Alert.razor.cs index 563ead7c2..392f4888a 100644 --- a/blazorbootstrap/Components/Alert/Alert.razor.cs +++ b/blazorbootstrap/Components/Alert/Alert.razor.cs @@ -62,11 +62,10 @@ protected override async Task OnInitializedAsync() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Alert) - .AddClass(Color.ToAlertColorClass(), Color != AlertColor.None) - .AddClass(BootstrapClass.AlertDismisable, Dismissable) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Alert, true), + (Color.ToAlertColorClass(), Color != AlertColor.None), + (BootstrapClass.AlertDismisable, Dismissable)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Badge/Badge.razor.cs b/blazorbootstrap/Components/Badge/Badge.razor.cs index d4193f243..c2f6185f8 100644 --- a/blazorbootstrap/Components/Badge/Badge.razor.cs +++ b/blazorbootstrap/Components/Badge/Badge.razor.cs @@ -5,14 +5,13 @@ public partial class Badge : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Badge) - .AddClass(Color.ToBadgeColorClass(), Color != BadgeColor.None) - .AddClass(IndicatorType.ToBadgeIndicatorClass(), IndicatorType != BadgeIndicatorType.None) - .AddClass(Position.ToPositionClass(), Position != Position.None) - .AddClass(Placement.ToBadgePlacementClass(), Placement != BadgePlacement.None) - .AddClass("p-2", ChildContent is null) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Badge, true), + (Color.ToBadgeColorClass(), Color != BadgeColor.None), + (IndicatorType.ToBadgeIndicatorClass(), IndicatorType != BadgeIndicatorType.None), + (Position.ToPositionClass(), Position != Position.None), + (Placement.ToBadgePlacementClass(), Placement != BadgePlacement.None), + ("p-2", ChildContent is null)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Button/Button.razor.cs b/blazorbootstrap/Components/Button/Button.razor.cs index c1bce3306..151931a8e 100644 --- a/blazorbootstrap/Components/Button/Button.razor.cs +++ b/blazorbootstrap/Components/Button/Button.razor.cs @@ -283,17 +283,16 @@ private void SetAttributes() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Button) - .AddClass(Color.ToButtonColorClass(), Color != ButtonColor.None && !Outline) - .AddClass(Color.ToButtonOutlineColorClass(), Color != ButtonColor.None && Outline) - .AddClass(Size.ToButtonSizeClass(), Size != ButtonSize.None) - .AddClass(BootstrapClass.ButtonDisabled, Disabled && Type == ButtonType.Link) - .AddClass(BootstrapClass.ButtonActive, Active) - .AddClass(BootstrapClass.ButtonBlock, Block) - .AddClass(BootstrapClass.ButtonLoading!, Loading && LoadingTemplate is not null) - .AddClass(Position.ToPositionClass(), Position != Position.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Button, true), + (Color.ToButtonColorClass(), Color != ButtonColor.None && !Outline), + (Color.ToButtonOutlineColorClass(), Color != ButtonColor.None && Outline), + (Size.ToButtonSizeClass(), Size != ButtonSize.None), + (BootstrapClass.ButtonDisabled, Disabled && Type == ButtonType.Link), + (BootstrapClass.ButtonActive, Active), + (BootstrapClass.ButtonBlock, Block), + (BootstrapClass.ButtonLoading!, Loading && LoadingTemplate is not null), + (Position.ToPositionClass(), Position != Position.None)); /// /// Gets or sets the button active state. diff --git a/blazorbootstrap/Components/Callout/Callout.razor.cs b/blazorbootstrap/Components/Callout/Callout.razor.cs index e04328976..ba887cc60 100644 --- a/blazorbootstrap/Components/Callout/Callout.razor.cs +++ b/blazorbootstrap/Components/Callout/Callout.razor.cs @@ -36,10 +36,9 @@ private IconName GetIconName() => #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Callout) - .AddClass(Color.ToCalloutColorClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Callout, true), + (Color.ToCalloutColorClass(), true)); private string CalloutHeadingCssClass => BootstrapClass.CalloutHeading; diff --git a/blazorbootstrap/Components/Card/Card.razor.cs b/blazorbootstrap/Components/Card/Card.razor.cs index 804cac501..5a70e24d4 100644 --- a/blazorbootstrap/Components/Card/Card.razor.cs +++ b/blazorbootstrap/Components/Card/Card.razor.cs @@ -5,11 +5,10 @@ public partial class Card : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Card) - .AddClass(TextAlignment.ToTextAlignmentClass()) - .AddClass(Color.ToCardColorClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Card, true), + (TextAlignment.ToTextAlignmentClass(), true), + (Color.ToCardColorClass(), true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardBody.razor.cs b/blazorbootstrap/Components/Card/CardBody.razor.cs index 81fe42725..7a51b799e 100644 --- a/blazorbootstrap/Components/Card/CardBody.razor.cs +++ b/blazorbootstrap/Components/Card/CardBody.razor.cs @@ -5,9 +5,7 @@ public partial class CardBody : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardBody) - .Build(); + BuildClassNames(Class, (BootstrapClass.CardBody, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardFooter.razor.cs b/blazorbootstrap/Components/Card/CardFooter.razor.cs index 4a024f94d..44164ddc4 100644 --- a/blazorbootstrap/Components/Card/CardFooter.razor.cs +++ b/blazorbootstrap/Components/Card/CardFooter.razor.cs @@ -5,9 +5,7 @@ public partial class CardFooter : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardFooter) - .Build(); + BuildClassNames(Class, (BootstrapClass.CardFooter, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardGroup.razor.cs b/blazorbootstrap/Components/Card/CardGroup.razor.cs index 9f4bb4c31..c9c2c0b9c 100644 --- a/blazorbootstrap/Components/Card/CardGroup.razor.cs +++ b/blazorbootstrap/Components/Card/CardGroup.razor.cs @@ -5,9 +5,7 @@ public partial class CardGroup : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardGroup) - .Build(); + BuildClassNames(Class, (BootstrapClass.CardGroup, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardHeader.razor.cs b/blazorbootstrap/Components/Card/CardHeader.razor.cs index 2a01acaea..33721e8af 100644 --- a/blazorbootstrap/Components/Card/CardHeader.razor.cs +++ b/blazorbootstrap/Components/Card/CardHeader.razor.cs @@ -5,10 +5,9 @@ public partial class CardHeader : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardHeader) - .AddClass(Color.ToCardColorClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.CardHeader, true), + (Color.ToCardColorClass(), true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardLink.razor.cs b/blazorbootstrap/Components/Card/CardLink.razor.cs index c19c3eb7f..fb5c509e0 100644 --- a/blazorbootstrap/Components/Card/CardLink.razor.cs +++ b/blazorbootstrap/Components/Card/CardLink.razor.cs @@ -107,10 +107,9 @@ private void SetAttributes() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardLink) - .AddClass(BootstrapClass.Disabled, Disabled) - .Build(); + BuildClassNames(Class, + (BootstrapClass.CardLink, true), + (BootstrapClass.Disabled, Disabled)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardSubTitle.razor.cs b/blazorbootstrap/Components/Card/CardSubTitle.razor.cs index 42812fed7..4dd642cb5 100644 --- a/blazorbootstrap/Components/Card/CardSubTitle.razor.cs +++ b/blazorbootstrap/Components/Card/CardSubTitle.razor.cs @@ -5,9 +5,7 @@ public partial class CardSubTitle : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardSubTitle) - .Build(); + BuildClassNames(Class, (BootstrapClass.CardSubTitle, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardText.razor.cs b/blazorbootstrap/Components/Card/CardText.razor.cs index e6c4fc66e..1e83a8a3e 100644 --- a/blazorbootstrap/Components/Card/CardText.razor.cs +++ b/blazorbootstrap/Components/Card/CardText.razor.cs @@ -5,9 +5,7 @@ public partial class CardText : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardText) - .Build(); + BuildClassNames(Class, (BootstrapClass.CardText, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Card/CardTitle.razor.cs b/blazorbootstrap/Components/Card/CardTitle.razor.cs index 0965fe25c..724bca063 100644 --- a/blazorbootstrap/Components/Card/CardTitle.razor.cs +++ b/blazorbootstrap/Components/Card/CardTitle.razor.cs @@ -5,9 +5,7 @@ public partial class CardTitle : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.CardTitle) - .Build(); + BuildClassNames(Class, (BootstrapClass.CardTitle, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Collapse/Collapse.razor.cs b/blazorbootstrap/Components/Collapse/Collapse.razor.cs index 0dc579bfc..68ee3e78f 100644 --- a/blazorbootstrap/Components/Collapse/Collapse.razor.cs +++ b/blazorbootstrap/Components/Collapse/Collapse.razor.cs @@ -78,10 +78,9 @@ protected override async Task OnInitializedAsync() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Collapse) - .AddClass(BootstrapClass.CollapseHorizontal, Horizontal) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Collapse, true), + (BootstrapClass.CollapseHorizontal, Horizontal)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/ConfirmDialog/ConfirmDialog.razor.cs b/blazorbootstrap/Components/ConfirmDialog/ConfirmDialog.razor.cs index a6ab9dca2..163ff00cb 100644 --- a/blazorbootstrap/Components/ConfirmDialog/ConfirmDialog.razor.cs +++ b/blazorbootstrap/Components/ConfirmDialog/ConfirmDialog.razor.cs @@ -126,17 +126,15 @@ private Task Show(string title, string? message1, string? message2, Type? #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Modal) - .AddClass(BootstrapClass.ConfirmationModal) - .AddClass(BootstrapClass.ModalFade) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Modal, true), + (BootstrapClass.ConfirmationModal, true), + (BootstrapClass.ModalFade, true)); protected override string? StyleNames => - new CssStyleBuilder(Style) - .AddStyle("display:block", showBackdrop) - .AddStyle("display:none", !showBackdrop) - .Build(); + BuildStyleNames(Style, + ("display:block", showBackdrop), + ("display:none", !showBackdrop)); #endregion } diff --git a/blazorbootstrap/Components/Core/BlazorBootstrapComponentBase.cs b/blazorbootstrap/Components/Core/BlazorBootstrapComponentBase.cs index aada72c6a..6ba3754cb 100644 --- a/blazorbootstrap/Components/Core/BlazorBootstrapComponentBase.cs +++ b/blazorbootstrap/Components/Core/BlazorBootstrapComponentBase.cs @@ -23,13 +23,53 @@ protected override async Task OnAfterRenderAsync(bool firstRender) /// protected override void OnInitialized() { - Id ??= IdGenerator.GetNextId(); + Id ??= IdUtility.GetNextId(); base.OnInitialized(); } + public static string BuildClassNames(string? userDefinedCssClass, params (string? cssClass, bool when)[] cssClassList) + { + var list = new HashSet(); + + if (cssClassList is not null && cssClassList.Any()) + foreach (var (cssClass, when) in cssClassList) + { + if (!string.IsNullOrWhiteSpace(cssClass) && when) + list.Add(cssClass); + } + + if (!string.IsNullOrWhiteSpace(userDefinedCssClass)) + list.Add(userDefinedCssClass.Trim()); + + if (list.Any()) + return string.Join(" ", list); + else + return string.Empty; + } + + public static string BuildStyleNames(string? userDefinedCssStyle, params (string? cssStyle, bool when)[] cssStyleList) + { + var list = new HashSet(); + + if (cssStyleList is not null && cssStyleList.Any()) + foreach (var (cssStyle, when) in cssStyleList) + { + if (!string.IsNullOrWhiteSpace(cssStyle) && when) + list.Add(cssStyle); + } + + if (!string.IsNullOrWhiteSpace(userDefinedCssStyle)) + list.Add(userDefinedCssStyle.Trim()); + + if (list.Any()) + return string.Join(';', list); + else + return string.Empty; + } + /// - /// + /// public void Dispose() { Dispose(true); @@ -37,8 +77,7 @@ public void Dispose() } /// - /// + /// public async ValueTask DisposeAsync() { await DisposeAsyncCore(true).ConfigureAwait(false); @@ -83,21 +122,19 @@ protected virtual ValueTask DisposeAsyncCore(bool disposing) [Parameter] public string? Class { get; set; } - protected virtual string? ClassNames => new CssClassBuilder(Class).Build(); + protected virtual string? ClassNames => Class; public ElementReference Element { get; set; } [Parameter] public string? Id { get; set; } - [Inject] protected IIdGenerator IdGenerator { get; set; } = default!; - protected bool IsRenderComplete { get; private set; } [Inject] protected IJSRuntime JSRuntime { get; set; } = default!; [Parameter] public string? Style { get; set; } - protected virtual string? StyleNames => new CssStyleBuilder(Style).Build(); + protected virtual string? StyleNames => Style; #endregion diff --git a/blazorbootstrap/Components/Dropdown/Dropdown.razor.cs b/blazorbootstrap/Components/Dropdown/Dropdown.razor.cs index 769311315..054956aea 100644 --- a/blazorbootstrap/Components/Dropdown/Dropdown.razor.cs +++ b/blazorbootstrap/Components/Dropdown/Dropdown.razor.cs @@ -87,10 +87,9 @@ protected override void OnInitialized() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.ButtonGroup) - .AddClass(Direction.ToDropdownDirectionClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.ButtonGroup, true), + (Direction.ToDropdownDirectionClass(), true)); /// /// If , enables the auto close. diff --git a/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs index f9f847834..1e7bd7296 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs @@ -19,11 +19,10 @@ protected override void OnInitialized() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Button) - .AddClass(Color.ToDropdownButtonColorClass(), Color != DropdownColor.None) - .AddClass(Size.ToDropdownButtonSizeClass(), Size != DropdownSize.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Button, true), + (Color.ToDropdownButtonColorClass(), Color != DropdownColor.None), + (Size.ToDropdownButtonSizeClass(), Size != DropdownSize.None)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs index c728765d9..5b191bc38 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs @@ -5,9 +5,7 @@ public partial class DropdownDivider : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.DropdownDivider) - .Build(); + BuildClassNames(Class, (BootstrapClass.DropdownDivider, true)); #endregion } diff --git a/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs index 4b654eeb9..b97de1cb4 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs @@ -5,9 +5,7 @@ public partial class DropdownHeader : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.DropdownHeader) - .Build(); + BuildClassNames(Class, (BootstrapClass.DropdownHeader, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs index c55a9bfb0..16c470bc7 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs @@ -164,11 +164,10 @@ private void SetAttributes() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.DropdownItem) - .AddClass(BootstrapClass.Active, Active) - .AddClass(BootstrapClass.Disabled, Disabled) - .Build(); + BuildClassNames(Class, + (BootstrapClass.DropdownItem, true), + (BootstrapClass.Active, Active), + (BootstrapClass.Disabled, Disabled)); /// /// Gets or sets the dropdown item active state. diff --git a/blazorbootstrap/Components/Dropdown/DropdownMenu.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownMenu.razor.cs index e70e7d070..4b5bc9d62 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownMenu.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownMenu.razor.cs @@ -5,10 +5,9 @@ public partial class DropdownMenu : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.DropdownMenu) - .AddClass(Position.ToDropdownMenuPositionClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.DropdownMenu, true), + (Position.ToDropdownMenuPositionClass(), true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Dropdown/DropdownToggleButton.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownToggleButton.razor.cs index 1df6d14d3..bf7f823fc 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownToggleButton.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownToggleButton.razor.cs @@ -41,13 +41,12 @@ protected override void OnInitialized() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Button) - .AddClass(Color.ToDropdownButtonColorClass(), Color != DropdownColor.None) - .AddClass(Size.ToDropdownButtonSizeClass(), Size != DropdownSize.None) - .AddClass(BootstrapClass.DropdownToggle) - .AddClass(BootstrapClass.DropdownToggleSplit, Split) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Button, true), + (Color.ToDropdownButtonColorClass(), Color != DropdownColor.None), + (Size.ToDropdownButtonSizeClass(), Size != DropdownSize.None), + (BootstrapClass.DropdownToggle, true), + (BootstrapClass.DropdownToggleSplit, Split)); /// /// If , enables the auto close. diff --git a/blazorbootstrap/Components/Form/AutoComplete/AutoComplete.razor.cs b/blazorbootstrap/Components/Form/AutoComplete/AutoComplete.razor.cs index 8a2fb0826..d98eeca0b 100644 --- a/blazorbootstrap/Components/Form/AutoComplete/AutoComplete.razor.cs +++ b/blazorbootstrap/Components/Form/AutoComplete/AutoComplete.razor.cs @@ -288,10 +288,9 @@ private async Task ShowAsync() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormControl) - .AddClass(Size.ToAutoCompleteSizeClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.FormControl, true), + (Size.ToAutoCompleteSizeClass(), true)); /// /// Gets or sets the data provider. diff --git a/blazorbootstrap/Components/Form/CurrencyInput/CurrencyInput.razor.cs b/blazorbootstrap/Components/Form/CurrencyInput/CurrencyInput.razor.cs index 7a823ead1..99881011d 100644 --- a/blazorbootstrap/Components/Form/CurrencyInput/CurrencyInput.razor.cs +++ b/blazorbootstrap/Components/Form/CurrencyInput/CurrencyInput.razor.cs @@ -395,10 +395,9 @@ private bool TryParseValue(object value, out TValue newValue) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormControl) - .AddClass(TextAlignment.ToTextAlignmentClass(), TextAlignment != Alignment.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.FormControl, true), + (TextAlignment.ToTextAlignmentClass(), TextAlignment != Alignment.None)); /// /// If , allows negative numbers. diff --git a/blazorbootstrap/Components/Form/DateInput/DateInput.razor.cs b/blazorbootstrap/Components/Form/DateInput/DateInput.razor.cs index 69e87b9c8..181d4239b 100644 --- a/blazorbootstrap/Components/Form/DateInput/DateInput.razor.cs +++ b/blazorbootstrap/Components/Form/DateInput/DateInput.razor.cs @@ -281,9 +281,7 @@ private bool TryParseValue(object value, out TValue newValue) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormControl) - .Build(); + BuildClassNames(Class, (BootstrapClass.FormControl, true)); private string autoComplete => AutoComplete ? "true" : "false"; diff --git a/blazorbootstrap/Components/Form/NumberInput/NumberInput.razor.cs b/blazorbootstrap/Components/Form/NumberInput/NumberInput.razor.cs index 1bf08e2f3..74c2ca9a9 100644 --- a/blazorbootstrap/Components/Form/NumberInput/NumberInput.razor.cs +++ b/blazorbootstrap/Components/Form/NumberInput/NumberInput.razor.cs @@ -346,10 +346,9 @@ private bool TryParseValue(object value, out TValue newValue) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormControl) - .AddClass(TextAlignment.ToTextAlignmentClass(), TextAlignment != Alignment.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.FormControl, true), + (TextAlignment.ToTextAlignmentClass(), TextAlignment != Alignment.None)); /// /// If , allows negative numbers. diff --git a/blazorbootstrap/Components/Form/RangeInput/RangeInput.razor.cs b/blazorbootstrap/Components/Form/RangeInput/RangeInput.razor.cs index 6df7c75ac..f112e4511 100644 --- a/blazorbootstrap/Components/Form/RangeInput/RangeInput.razor.cs +++ b/blazorbootstrap/Components/Form/RangeInput/RangeInput.razor.cs @@ -369,9 +369,7 @@ private bool TryParseValue(object value, out TValue newValue) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormRange) - .Build(); + BuildClassNames(Class, (BootstrapClass.FormRange, true)); /// /// Gets or sets the disabled state. diff --git a/blazorbootstrap/Components/Form/Switch/Switch.razor.cs b/blazorbootstrap/Components/Form/Switch/Switch.razor.cs index 4ac785bb8..38483c0bf 100644 --- a/blazorbootstrap/Components/Form/Switch/Switch.razor.cs +++ b/blazorbootstrap/Components/Form/Switch/Switch.razor.cs @@ -66,11 +66,10 @@ private async Task OnChange(ChangeEventArgs args) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormCheck) - .AddClass(BootstrapClass.FormSwitch) - .AddClass(BootstrapClass.FormCheckReverse, Reverse) - .Build(); + BuildClassNames(Class, + (BootstrapClass.FormCheck, true), + (BootstrapClass.FormSwitch, true), + (BootstrapClass.FormCheckReverse, Reverse)); /// /// Gets or sets the disabled state. diff --git a/blazorbootstrap/Components/Form/TimeInput/TimeInput.razor.cs b/blazorbootstrap/Components/Form/TimeInput/TimeInput.razor.cs index 83169c0d3..ca48872d4 100644 --- a/blazorbootstrap/Components/Form/TimeInput/TimeInput.razor.cs +++ b/blazorbootstrap/Components/Form/TimeInput/TimeInput.razor.cs @@ -246,9 +246,7 @@ private bool TryParseValue(object value, out TValue newValue) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FormControl) - .Build(); + BuildClassNames(Class, (BootstrapClass.FormControl, true)); private string autoComplete => AutoComplete ? "true" : "false"; diff --git a/blazorbootstrap/Components/Grid/Grid.razor.cs b/blazorbootstrap/Components/Grid/Grid.razor.cs index 258313454..0200db23b 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor.cs +++ b/blazorbootstrap/Components/Grid/Grid.razor.cs @@ -54,7 +54,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) protected override void OnInitialized() { - headerCheckboxId = IdGenerator.GetNextId(); + headerCheckboxId = IdUtility.GetNextId(); pageSize = PageSize; @@ -441,7 +441,7 @@ private void PrepareCheckboxIds() if (currentLength < itemsCount) for (var i = currentLength; i < itemsCount; i++) - checkboxIds[i] = IdGenerator.GetNextId(); + checkboxIds[i] = IdUtility.GetNextId(); } /// @@ -506,7 +506,7 @@ private void SetFilters(IEnumerable filterItems) if (column != null) { - var allowedFilterOperators = FilterOperatorHelper.GetFilterOperators(column.GetPropertyTypeName()); + var allowedFilterOperators = FilterOperatorUtility.GetFilterOperators(column.GetPropertyTypeName()); if (allowedFilterOperators != null && allowedFilterOperators.Any(x => x.FilterOperator == item.Operator)) { @@ -522,10 +522,9 @@ private void SetFilters(IEnumerable filterItems) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("bb-table") - .AddClass(BootstrapClass.TableSticky, FixedHeader) - .Build(); + BuildClassNames(Class, + ("bb-table", true), + (BootstrapClass.TableSticky, FixedHeader)); /// /// Gets or sets the grid delete. diff --git a/blazorbootstrap/Components/Grid/GridColumn.razor.cs b/blazorbootstrap/Components/Grid/GridColumn.razor.cs index 84d8c0fc2..825f03384 100644 --- a/blazorbootstrap/Components/Grid/GridColumn.razor.cs +++ b/blazorbootstrap/Components/Grid/GridColumn.razor.cs @@ -22,7 +22,7 @@ public partial class GridColumn : BlazorBootstrapComponentBase protected override async Task OnInitializedAsync() { - Id = IdGenerator.GetNextId(); // Required + Id = IdUtility.GetNextId(); // Required filterOperator = FilterOperator; filterValue = FilterValue; diff --git a/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs b/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs index da5617b4a..aed938940 100644 --- a/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs +++ b/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs @@ -75,14 +75,14 @@ or StringConstants.PropertyTypeNameDecimal private async Task> GetFilterOperatorsAsync(string propertyTypeName) { if (FiltersTranslationProvider is null) - return FilterOperatorHelper.GetFilterOperators(PropertyTypeName!); + return FilterOperatorUtility.GetFilterOperators(PropertyTypeName!); var filters = await FiltersTranslationProvider.Invoke(); if (!(filters?.Any() ?? false)) - return FilterOperatorHelper.GetFilterOperators(PropertyTypeName!); + return FilterOperatorUtility.GetFilterOperators(PropertyTypeName!); - return FilterOperatorHelper.GetFilterOperators(PropertyTypeName!, filters!); + return FilterOperatorUtility.GetFilterOperators(PropertyTypeName!, filters!); } private async Task OnEnumFilterValueChangedAsync(object enumValue) diff --git a/blazorbootstrap/Components/Icon/Icon.razor.cs b/blazorbootstrap/Components/Icon/Icon.razor.cs index 934012e74..98e095140 100644 --- a/blazorbootstrap/Components/Icon/Icon.razor.cs +++ b/blazorbootstrap/Components/Icon/Icon.razor.cs @@ -5,13 +5,12 @@ public partial class Icon : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapIconProvider.Icon(), string.IsNullOrWhiteSpace(CustomIconName)) - .AddClass(BootstrapIconProvider.Icon(Name), string.IsNullOrWhiteSpace(CustomIconName)) - .AddClass(CustomIconName!, !string.IsNullOrWhiteSpace(CustomIconName)) - .AddClass(BootstrapIconProvider.IconSize(Size)!, Size != IconSize.None) - .AddClass(Color.ToIconColorClass(), Color != IconColor.None) - .Build(); + BuildClassNames(Class, + (BootstrapIconUtility.Icon(), string.IsNullOrWhiteSpace(CustomIconName)), + (BootstrapIconUtility.Icon(Name), string.IsNullOrWhiteSpace(CustomIconName)), + (CustomIconName!, !string.IsNullOrWhiteSpace(CustomIconName)), + (BootstrapIconUtility.IconSize(Size)!, Size != IconSize.None), + (Color.ToIconColorClass(), Color != IconColor.None)); /// /// Gets or sets the icon color. diff --git a/blazorbootstrap/Components/Modals/Modal.razor.cs b/blazorbootstrap/Components/Modals/Modal.razor.cs index 71c651f04..2183d9506 100644 --- a/blazorbootstrap/Components/Modals/Modal.razor.cs +++ b/blazorbootstrap/Components/Modals/Modal.razor.cs @@ -158,10 +158,9 @@ private async Task ShowAsync(string? title, string? message, Type? type, Diction #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Modal) - .AddClass(BootstrapClass.ModalFade) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Modal, true), + (BootstrapClass.ModalFade, true)); /// /// Gets or sets the body CSS class. diff --git a/blazorbootstrap/Components/Offcanvas/Offcanvas.razor.cs b/blazorbootstrap/Components/Offcanvas/Offcanvas.razor.cs index ff71f5150..7c3d705c6 100644 --- a/blazorbootstrap/Components/Offcanvas/Offcanvas.razor.cs +++ b/blazorbootstrap/Components/Offcanvas/Offcanvas.razor.cs @@ -100,11 +100,10 @@ private async Task ShowAsync(string? title, Type? type, Dictionary - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Offcanvas) - .AddClass(Placement.ToOffcanvasPlacementClass()) - .AddClass(Size.ToOffcanvasSizeClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Offcanvas, true), + (Placement.ToOffcanvasPlacementClass(), true), + (Size.ToOffcanvasSizeClass(), true)); /// /// Gets or sets the body CSS class. diff --git a/blazorbootstrap/Components/Pagination/Pagination.razor.cs b/blazorbootstrap/Components/Pagination/Pagination.razor.cs index 83eeb1716..23a5b733c 100644 --- a/blazorbootstrap/Components/Pagination/Pagination.razor.cs +++ b/blazorbootstrap/Components/Pagination/Pagination.razor.cs @@ -67,11 +67,10 @@ private async Task SetPageNumberTo(int newPageNumber) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Pagination) - .AddClass(Size.ToPaginationSizeClass(), Size != PaginationSize.None) - .AddClass(Alignment.ToPaginationAlignmentClass(), Alignment != Alignment.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Pagination, true), + (Size.ToPaginationSizeClass(), Size != PaginationSize.None), + (Alignment.ToPaginationAlignmentClass(), Alignment != Alignment.None)); /// /// Gets or sets the active page number. diff --git a/blazorbootstrap/Components/Pagination/PaginationItem.razor.cs b/blazorbootstrap/Components/Pagination/PaginationItem.razor.cs index 84a8b7de7..4407f0b6c 100644 --- a/blazorbootstrap/Components/Pagination/PaginationItem.razor.cs +++ b/blazorbootstrap/Components/Pagination/PaginationItem.razor.cs @@ -17,11 +17,10 @@ protected override void OnParametersSet() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.PaginationItem) - .AddClass(BootstrapClass.PaginationItemActive, Active) - .AddClass(BootstrapClass.PaginationItemDisabled, Disabled) - .Build(); + BuildClassNames(Class, + (BootstrapClass.PaginationItem, true), + (BootstrapClass.PaginationItemActive, Active), + (BootstrapClass.PaginationItemDisabled, Disabled)); /// /// Gets or sets the pagination item active state. diff --git a/blazorbootstrap/Components/Pagination/PaginationLink.razor.cs b/blazorbootstrap/Components/Pagination/PaginationLink.razor.cs index d5ad0731a..145d1799c 100644 --- a/blazorbootstrap/Components/Pagination/PaginationLink.razor.cs +++ b/blazorbootstrap/Components/Pagination/PaginationLink.razor.cs @@ -17,9 +17,7 @@ protected override void OnParametersSet() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.PaginationLink) - .Build(); + BuildClassNames(Class, (BootstrapClass.PaginationLink, true)); /// /// Gets or sets the link aria-label attribute. diff --git a/blazorbootstrap/Components/Placeholders/Placeholder.razor.cs b/blazorbootstrap/Components/Placeholders/Placeholder.razor.cs index 8ed2c3ef0..7166e560f 100644 --- a/blazorbootstrap/Components/Placeholders/Placeholder.razor.cs +++ b/blazorbootstrap/Components/Placeholders/Placeholder.razor.cs @@ -5,12 +5,11 @@ public partial class Placeholder : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Placeholder) - .AddClass(Width.ToPlaceholderWidthClass()) - .AddClass(Color.ToPlaceholderColorClass(), Color != PlaceholderColor.None) - .AddClass(Size.ToPlaceholderSizeClass(), Size != PlaceholderSize.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Placeholder, true), + (Width.ToPlaceholderWidthClass(), true), + (Color.ToPlaceholderColorClass(), Color != PlaceholderColor.None), + (Size.ToPlaceholderSizeClass(), Size != PlaceholderSize.None)); /// /// Gets or sets the placeholder color. diff --git a/blazorbootstrap/Components/Placeholders/PlaceholderContainer.razor.cs b/blazorbootstrap/Components/Placeholders/PlaceholderContainer.razor.cs index 553b8fcc1..55e28a2d4 100644 --- a/blazorbootstrap/Components/Placeholders/PlaceholderContainer.razor.cs +++ b/blazorbootstrap/Components/Placeholders/PlaceholderContainer.razor.cs @@ -5,9 +5,7 @@ public partial class PlaceholderContainer : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(Animation.ToPlaceholderAnimationClass()) - .Build(); + BuildClassNames(Class, (Animation.ToPlaceholderAnimationClass(), true)); /// /// Gets or sets the placeholder animation. diff --git a/blazorbootstrap/Components/Preload/Preload.razor.cs b/blazorbootstrap/Components/Preload/Preload.razor.cs index ecce3540e..6bf2add4e 100644 --- a/blazorbootstrap/Components/Preload/Preload.razor.cs +++ b/blazorbootstrap/Components/Preload/Preload.razor.cs @@ -55,18 +55,16 @@ private void OnShow(SpinnerColor spinnerColor, string? loadingText) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Modal) - .AddClass(BootstrapClass.PageLoadingModal) - .AddClass(BootstrapClass.ModalFade) - .AddClass(BootstrapClass.Show, showBackdrop) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Modal, true), + (BootstrapClass.PageLoadingModal, true), + (BootstrapClass.ModalFade, true), + (BootstrapClass.Show, showBackdrop)); protected override string? StyleNames => - new CssStyleBuilder(Style) - .AddStyle("display:block", showBackdrop) - .AddStyle("display:none", !showBackdrop) - .Build(); + BuildStyleNames(Style, + ("display:block", showBackdrop), + ("display:none", !showBackdrop)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Progress/Progress.razor.cs b/blazorbootstrap/Components/Progress/Progress.razor.cs index 125b27904..650abe762 100644 --- a/blazorbootstrap/Components/Progress/Progress.razor.cs +++ b/blazorbootstrap/Components/Progress/Progress.razor.cs @@ -22,14 +22,10 @@ protected override void OnInitialized() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Progress) - .Build(); + BuildClassNames(Class, (BootstrapClass.Progress, true)); protected override string? StyleNames => - new CssStyleBuilder(Style) - .AddStyle($"height:{height.ToString(CultureInfo.InvariantCulture)}px", height >= 0) - .Build(); + BuildStyleNames(Style, ($"height:{height.ToString(CultureInfo.InvariantCulture)}px", height >= 0)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Progress/ProgressBar.razor.cs b/blazorbootstrap/Components/Progress/ProgressBar.razor.cs index b76ab3cdb..d563583ab 100644 --- a/blazorbootstrap/Components/Progress/ProgressBar.razor.cs +++ b/blazorbootstrap/Components/Progress/ProgressBar.razor.cs @@ -78,18 +78,16 @@ public void SetWidth(double width) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.ProgressBar) - .AddClass(BootstrapClass.ProgressBarStriped, type is ProgressType.Striped or ProgressType.StripedAndAnimated) - .AddClass(BootstrapClass.ProgressBarAnimated, type == ProgressType.StripedAndAnimated) - .AddClass(color.ToProgressColorClass(), color != ProgressColor.None) - .Build(); + BuildClassNames(Class, + (BootstrapClass.ProgressBar, true), + (BootstrapClass.ProgressBarStriped, type is ProgressType.Striped or ProgressType.StripedAndAnimated), + (BootstrapClass.ProgressBarAnimated, type == ProgressType.StripedAndAnimated), + (color.ToProgressColorClass(), color != ProgressColor.None)); protected override string? StyleNames => - new CssStyleBuilder(Style) + BuildStyleNames(Style, // FIX: Toast progressbar not showing: https://github.com/vikramlearning/blazorbootstrap/issues/155 - .AddStyle($"width:{width.ToString(CultureInfo.InvariantCulture)}%", width is >= 0 and <= 100) - .Build(); + ($"width:{width.ToString(CultureInfo.InvariantCulture)}%", width is >= 0 and <= 100)); /// /// Gets or sets the progress color. diff --git a/blazorbootstrap/Components/Ribbon/Ribbon.razor.cs b/blazorbootstrap/Components/Ribbon/Ribbon.razor.cs index f4869a079..5d5f51af2 100644 --- a/blazorbootstrap/Components/Ribbon/Ribbon.razor.cs +++ b/blazorbootstrap/Components/Ribbon/Ribbon.razor.cs @@ -272,13 +272,12 @@ private async Task ShowTabAsync(RibbonTab tab) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Nav) - .AddClass(BootstrapClass.NavTabs, NavStyle == NavStyle.Tabs) - .AddClass(BootstrapClass.NavPills, NavStyle is (NavStyle.Pills or NavStyle.VerticalPills)) - .AddClass(BootstrapClass.NavUnderline, NavStyle is (NavStyle.Underline or NavStyle.VerticalUnderline)) - .AddClass(BootstrapClass.FlexColumn, IsVertical) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Nav, true), + (BootstrapClass.NavTabs, NavStyle == NavStyle.Tabs), + (BootstrapClass.NavPills, NavStyle is (NavStyle.Pills or NavStyle.VerticalPills)), + (BootstrapClass.NavUnderline, NavStyle is (NavStyle.Underline or NavStyle.VerticalUnderline)), + (BootstrapClass.FlexColumn, IsVertical)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Ribbon/RibbonGroup.razor.cs b/blazorbootstrap/Components/Ribbon/RibbonGroup.razor.cs index 488440e0b..db3af8db9 100644 --- a/blazorbootstrap/Components/Ribbon/RibbonGroup.razor.cs +++ b/blazorbootstrap/Components/Ribbon/RibbonGroup.razor.cs @@ -5,12 +5,11 @@ public partial class RibbonGroup : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("bb-ribbon-group") - .AddClass(BootstrapClass.Flex) - .AddClass(BootstrapClass.FlexRow) - .AddClass(BootstrapClass.Border) - .Build(); + BuildClassNames(Class, + ("bb-ribbon-group", true), + (BootstrapClass.Flex, true), + (BootstrapClass.FlexRow, true), + (BootstrapClass.Border, true)); /// /// Gets or sets the content to be rendered inside this component. diff --git a/blazorbootstrap/Components/Ribbon/RibbonItem.razor.cs b/blazorbootstrap/Components/Ribbon/RibbonItem.razor.cs index 2d604d8c4..3dbc0d744 100644 --- a/blazorbootstrap/Components/Ribbon/RibbonItem.razor.cs +++ b/blazorbootstrap/Components/Ribbon/RibbonItem.razor.cs @@ -18,16 +18,15 @@ private async Task OnRibbonItemClickAsync() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("bb-ribbon-item") - .AddClass(BootstrapClass.Flex) - .AddClass(BootstrapClass.FlexColumn) - .AddClass(BootstrapClass.AlignItemsCenter) - .AddClass("ms-1", IsFirstItem) - .AddClass("me-1", IsLastItem) - .AddClass("mx-1", !IsFirstItem && !IsLastItem) - .AddClass("p-1") - .Build(); + BuildClassNames(Class, + ("bb-ribbon-item", true), + (BootstrapClass.Flex, true), + (BootstrapClass.FlexColumn, true), + (BootstrapClass.AlignItemsCenter, true), + ("ms-1", IsFirstItem), + ("me-1", IsLastItem), + ("mx-1", !IsFirstItem && !IsLastItem), + ("p-1", true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Ribbon/RibbonItemGroup.razor.cs b/blazorbootstrap/Components/Ribbon/RibbonItemGroup.razor.cs index 39e15fe43..c19659f4d 100644 --- a/blazorbootstrap/Components/Ribbon/RibbonItemGroup.razor.cs +++ b/blazorbootstrap/Components/Ribbon/RibbonItemGroup.razor.cs @@ -5,14 +5,13 @@ public partial class RibbonItemGroup : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("bb-ribbon-item-group") - .AddClass(BootstrapClass.Flex) - .AddClass(BootstrapClass.FlexColumn) - .AddClass(BootstrapClass.AlignItemsCenter) - .AddClass("my-1") - .AddClass(BootstrapClass.BorderEnd) - .Build(); + BuildClassNames(Class, + ("bb-ribbon-item-group", true), + (BootstrapClass.Flex, true), + (BootstrapClass.FlexColumn, true), + (BootstrapClass.AlignItemsCenter, true), + ("my-1", true), + (BootstrapClass.BorderEnd, true)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Ribbon/RibbonTab.razor.cs b/blazorbootstrap/Components/Ribbon/RibbonTab.razor.cs index 6845dba73..006e857bc 100644 --- a/blazorbootstrap/Components/Ribbon/RibbonTab.razor.cs +++ b/blazorbootstrap/Components/Ribbon/RibbonTab.razor.cs @@ -24,7 +24,7 @@ protected override async ValueTask DisposeAsyncCore(bool disposing) protected override void OnInitialized() { - Id = IdGenerator.GetNextId(); // This is required + Id = IdUtility.GetNextId(); // This is required Parent.AddTab(this); } diff --git a/blazorbootstrap/Components/Sidebar/Sidebar.razor.cs b/blazorbootstrap/Components/Sidebar/Sidebar.razor.cs index ff383d7b8..f5685fc05 100644 --- a/blazorbootstrap/Components/Sidebar/Sidebar.razor.cs +++ b/blazorbootstrap/Components/Sidebar/Sidebar.razor.cs @@ -114,11 +114,10 @@ private string GetNavMenuCssClass() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("bb-sidebar") - .AddClass("collapsed", collapseSidebar) - .AddClass("expanded", !collapseSidebar) - .Build(); + BuildClassNames(Class, + ("bb-sidebar", true), + ("collapsed", collapseSidebar), + ("expanded", !collapseSidebar)); /// /// Gets or sets the badge text. diff --git a/blazorbootstrap/Components/Sidebar/SidebarItem.razor.cs b/blazorbootstrap/Components/Sidebar/SidebarItem.razor.cs index 540048b0f..20125c775 100644 --- a/blazorbootstrap/Components/Sidebar/SidebarItem.razor.cs +++ b/blazorbootstrap/Components/Sidebar/SidebarItem.razor.cs @@ -36,11 +36,10 @@ private void AutoHideNavMenu() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("nav-item") - .AddClass("nav-item-group", HasChilds) - .AddClass("active", navitemGroupExpanded) - .Build(); + BuildClassNames(Class, + ("nav-item", true), + ("nav-item-group", HasChilds), + ("active", navitemGroupExpanded)); /// /// Gets or sets the child items. diff --git a/blazorbootstrap/Components/Sidebar/SidebarItemGroup.razor.cs b/blazorbootstrap/Components/Sidebar/SidebarItemGroup.razor.cs index 345572776..30b6c4cff 100644 --- a/blazorbootstrap/Components/Sidebar/SidebarItemGroup.razor.cs +++ b/blazorbootstrap/Components/Sidebar/SidebarItemGroup.razor.cs @@ -5,9 +5,7 @@ public partial class SidebarItemGroup : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FlexColumn) - .Build(); + BuildClassNames(Class, (BootstrapClass.FlexColumn, true)); [CascadingParameter] public bool CollapseSidebar { get; set; } diff --git a/blazorbootstrap/Components/Sidebar2/Sidebar2.razor.cs b/blazorbootstrap/Components/Sidebar2/Sidebar2.razor.cs index ad805c4f0..66c11af33 100644 --- a/blazorbootstrap/Components/Sidebar2/Sidebar2.razor.cs +++ b/blazorbootstrap/Components/Sidebar2/Sidebar2.razor.cs @@ -115,11 +115,10 @@ private string GetNavMenuCssClass() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("bb-sidebar2") - .AddClass("collapsed", collapseSidebar) - .AddClass("expanded", !collapseSidebar) - .Build(); + BuildClassNames(Class, + ("bb-sidebar2", true), + ("collapsed", collapseSidebar), + ("expanded", !collapseSidebar)); /// /// Gets or sets the badge text. diff --git a/blazorbootstrap/Components/Sidebar2/Sidebar2Item.razor.cs b/blazorbootstrap/Components/Sidebar2/Sidebar2Item.razor.cs index 87cd650f7..77139dd39 100644 --- a/blazorbootstrap/Components/Sidebar2/Sidebar2Item.razor.cs +++ b/blazorbootstrap/Components/Sidebar2/Sidebar2Item.razor.cs @@ -43,12 +43,11 @@ private string GetNavLinkStyle() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("nav-item") - .AddClass($"nav-item-level-{Level}") - .AddClass("nav-item-group", HasChilds) - .AddClass("active", NavItemGroupExpanded) - .Build(); + BuildClassNames(Class, + ("nav-item", true), + ($"nav-item-level-{Level}", true), + ("nav-item-group", HasChilds), + ("active", NavItemGroupExpanded)); /// /// Gets or sets the child items. diff --git a/blazorbootstrap/Components/Sidebar2/Sidebar2ItemGroup.razor.cs b/blazorbootstrap/Components/Sidebar2/Sidebar2ItemGroup.razor.cs index 2ac889809..2740cac7a 100644 --- a/blazorbootstrap/Components/Sidebar2/Sidebar2ItemGroup.razor.cs +++ b/blazorbootstrap/Components/Sidebar2/Sidebar2ItemGroup.razor.cs @@ -5,9 +5,7 @@ public partial class Sidebar2ItemGroup : BlazorBootstrapComponentBase #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.FlexColumn) - .Build(); + BuildClassNames(Class, (BootstrapClass.FlexColumn, true)); [CascadingParameter] public bool CollapseSidebar { get; set; } diff --git a/blazorbootstrap/Components/SortableList/SortableList.razor.cs b/blazorbootstrap/Components/SortableList/SortableList.razor.cs index 50ac81226..63f454fce 100644 --- a/blazorbootstrap/Components/SortableList/SortableList.razor.cs +++ b/blazorbootstrap/Components/SortableList/SortableList.razor.cs @@ -76,9 +76,7 @@ public async Task OnUpdateJS(int oldIndex, int newIndex) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass("list-group") - .Build(); + BuildClassNames(Class, ("list-group", true)); /// /// Gets or sets a value indicating whether sorting is allowed for the list. diff --git a/blazorbootstrap/Components/Spinner/Spinner.razor.cs b/blazorbootstrap/Components/Spinner/Spinner.razor.cs index 6cfa9dd0e..24075ab56 100644 --- a/blazorbootstrap/Components/Spinner/Spinner.razor.cs +++ b/blazorbootstrap/Components/Spinner/Spinner.razor.cs @@ -57,11 +57,10 @@ protected override void OnInitialized() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(Type.ToSpinnerTypeClass()) - .AddClass(Color.ToSpinnerColorClass()) - .AddClass($"{Type.ToSpinnerTypeClass()}-{Size.ToSpinnerSizeClass()}", Type is (SpinnerType.Border or SpinnerType.Grow)) - .Build(); + BuildClassNames(Class, + (Type.ToSpinnerTypeClass(), true), + (Color.ToSpinnerColorClass(), true), + ($"{Type.ToSpinnerTypeClass()}-{Size.ToSpinnerSizeClass()}", Type is (SpinnerType.Border or SpinnerType.Grow))); /// /// Gets or sets the color of the spinner. diff --git a/blazorbootstrap/Components/Tabs/Tab.razor.cs b/blazorbootstrap/Components/Tabs/Tab.razor.cs index 8fcacd185..c97dbda28 100644 --- a/blazorbootstrap/Components/Tabs/Tab.razor.cs +++ b/blazorbootstrap/Components/Tabs/Tab.razor.cs @@ -24,7 +24,7 @@ protected override async ValueTask DisposeAsyncCore(bool disposing) protected override void OnInitialized() { - Id = IdGenerator.GetNextId(); // This is required + Id = IdUtility.GetNextId(); // This is required Parent.AddTab(this); } diff --git a/blazorbootstrap/Components/Tabs/Tabs.razor.cs b/blazorbootstrap/Components/Tabs/Tabs.razor.cs index bdaa49ecf..f64d9137d 100644 --- a/blazorbootstrap/Components/Tabs/Tabs.razor.cs +++ b/blazorbootstrap/Components/Tabs/Tabs.razor.cs @@ -276,13 +276,12 @@ private async Task ShowTabAsync(Tab tab) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Nav) - .AddClass(BootstrapClass.NavTabs, NavStyle == NavStyle.Tabs) - .AddClass(BootstrapClass.NavPills, NavStyle is (NavStyle.Pills or NavStyle.VerticalPills)) - .AddClass(BootstrapClass.NavUnderline, NavStyle is (NavStyle.Underline or NavStyle.VerticalUnderline)) - .AddClass(BootstrapClass.FlexColumn, IsVertical) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Nav, true), + (BootstrapClass.NavTabs, NavStyle == NavStyle.Tabs), + (BootstrapClass.NavPills, NavStyle is (NavStyle.Pills or NavStyle.VerticalPills)), + (BootstrapClass.NavUnderline, NavStyle is (NavStyle.Underline or NavStyle.VerticalUnderline)), + (BootstrapClass.FlexColumn, IsVertical)); /// /// Gets or sets the content to be rendered within the component. diff --git a/blazorbootstrap/Components/Toasts/SimpleToast.razor.cs b/blazorbootstrap/Components/Toasts/SimpleToast.razor.cs index 2358861a4..18367df74 100644 --- a/blazorbootstrap/Components/Toasts/SimpleToast.razor.cs +++ b/blazorbootstrap/Components/Toasts/SimpleToast.razor.cs @@ -64,11 +64,10 @@ protected override async Task OnInitializedAsync() #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Toast) - .AddClass(ToastMessage!.Type.ToToastTextColorClass(), ToastMessage is not null) - .AddClass(ToastMessage!.Type.ToToastBackgroundColorClass(), ToastMessage is not null) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Toast, true), + (ToastMessage!.Type.ToToastTextColorClass(), ToastMessage is not null), + (ToastMessage!.Type.ToToastBackgroundColorClass(), ToastMessage is not null)); /// /// Gets or sets the auto hide state. diff --git a/blazorbootstrap/Components/Toasts/Toast.razor.cs b/blazorbootstrap/Components/Toasts/Toast.razor.cs index d2f1cc933..d16ec42c6 100644 --- a/blazorbootstrap/Components/Toasts/Toast.razor.cs +++ b/blazorbootstrap/Components/Toasts/Toast.razor.cs @@ -149,10 +149,9 @@ private IconName GetToastIconName() => #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.Toast) - .AddClass(BackgroundColor.White.ToBackgroundClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.Toast, true), + (BackgroundColor.White.ToBackgroundClass(), true)); /// /// Gets or sets the auto hide state. diff --git a/blazorbootstrap/Components/Toasts/Toasts.razor.cs b/blazorbootstrap/Components/Toasts/Toasts.razor.cs index deec375b0..ae41e1328 100644 --- a/blazorbootstrap/Components/Toasts/Toasts.razor.cs +++ b/blazorbootstrap/Components/Toasts/Toasts.razor.cs @@ -82,11 +82,10 @@ private async Task OnToastShownAsync(ToastEventArgs args) #region Properties, Indexers protected override string? ClassNames => - new CssClassBuilder(Class) - .AddClass(BootstrapClass.ToastContainer) - .AddClass(BootstrapClass.PositionFixed) - .AddClass(Placement.ToToastsPlacementClass()) - .Build(); + BuildClassNames(Class, + (BootstrapClass.ToastContainer, true), + (BootstrapClass.PositionFixed, true), + (Placement.ToToastsPlacementClass(), true)); /// /// Gets or sets the auto hide state. diff --git a/blazorbootstrap/Config.cs b/blazorbootstrap/Config.cs index 75900126e..19fb67f36 100644 --- a/blazorbootstrap/Config.cs +++ b/blazorbootstrap/Config.cs @@ -13,8 +13,6 @@ public static class Config /// IServiceCollection public static IServiceCollection AddBlazorBootstrap(this IServiceCollection serviceCollection) { - serviceCollection.AddScoped(); - serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); diff --git a/blazorbootstrap/Utilities/CssClassBuilder.cs b/blazorbootstrap/Utilities/CssClassBuilder.cs deleted file mode 100644 index ebec0123b..000000000 --- a/blazorbootstrap/Utilities/CssClassBuilder.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// License: MIT -// See https://github.com/microsoft/fluentui-blazor/blob/dev/src/Core/Utilities/CssBuilder.cs - -namespace BlazorBootstrap; - -public readonly struct CssClassBuilder -{ - private readonly HashSet classList; - private readonly string? @class; - - public CssClassBuilder(string? cssClass) - { - classList = new HashSet(); - @class = cssClass; - } - - public CssClassBuilder AddClass(string value) - { - if (!string.IsNullOrWhiteSpace(value)) - classList.Add(value); - - return this; - } - - public CssClassBuilder AddClass(string value, bool when) - { - if (when && !string.IsNullOrWhiteSpace(value)) - classList.Add(value); - - return this; - } - - public string? Build() - { - var classNames = string.IsNullOrWhiteSpace(@class) ? classList : classList.Union(new[] { @class }); - - if (!classNames.Any()) - return null; - - return string.Join(" ", classNames); - } - - public override string? ToString() => Build(); -} diff --git a/blazorbootstrap/Utilities/CssStyleBuilder.cs b/blazorbootstrap/Utilities/CssStyleBuilder.cs deleted file mode 100644 index e4196c1dd..000000000 --- a/blazorbootstrap/Utilities/CssStyleBuilder.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// License: MIT -// See https://github.com/microsoft/fluentui-blazor/blob/dev/src/Core/Utilities/StyleBuilder.cs - -namespace BlazorBootstrap; - -public readonly struct CssStyleBuilder -{ - private readonly HashSet styleList; - private readonly string? style; - - public CssStyleBuilder(string? cssStyle) - { - styleList = new HashSet(); - style = cssStyle; - } - - public CssStyleBuilder AddStyle(string value) - { - if (!string.IsNullOrWhiteSpace(value)) - styleList.Add(value); - - return this; - } - - public CssStyleBuilder AddStyle(string value, bool when) - { - if (when && !string.IsNullOrWhiteSpace(value)) - styleList.Add(value); - - return this; - } - - public string? Build() - { - var styleNames = string.IsNullOrWhiteSpace(style) ? styleList : styleList.Union(new[] { style }); - - if (!styleNames.Any()) - return null; - - return string.Join(";", styleNames); - } - - public override string? ToString() => Build(); -} diff --git a/blazorbootstrap/Utilities/BootstrapIconProvider.cs b/blazorbootstrap/Utils/BootstrapIconUtility.cs similarity index 99% rename from blazorbootstrap/Utilities/BootstrapIconProvider.cs rename to blazorbootstrap/Utils/BootstrapIconUtility.cs index 1685316ec..67a217c1e 100644 --- a/blazorbootstrap/Utilities/BootstrapIconProvider.cs +++ b/blazorbootstrap/Utils/BootstrapIconUtility.cs @@ -1,6 +1,6 @@ namespace BlazorBootstrap; -public static class BootstrapIconProvider +public static class BootstrapIconUtility { #region Methods diff --git a/blazorbootstrap/Utilities/ColorBuilder.cs b/blazorbootstrap/Utils/ColorUtility.cs similarity index 96% rename from blazorbootstrap/Utilities/ColorBuilder.cs rename to blazorbootstrap/Utils/ColorUtility.cs index b64ff5d09..54f69141a 100644 --- a/blazorbootstrap/Utilities/ColorBuilder.cs +++ b/blazorbootstrap/Utils/ColorUtility.cs @@ -1,6 +1,6 @@ namespace BlazorBootstrap; -public static class ColorBuilder +public static class ColorUtility { #region Properties, Indexers diff --git a/blazorbootstrap/Utilities/FilterOperatorHelper.cs b/blazorbootstrap/Utils/FilterOperatorUtility.cs similarity index 99% rename from blazorbootstrap/Utilities/FilterOperatorHelper.cs rename to blazorbootstrap/Utils/FilterOperatorUtility.cs index 4e50b38a1..0fe5c2023 100644 --- a/blazorbootstrap/Utilities/FilterOperatorHelper.cs +++ b/blazorbootstrap/Utils/FilterOperatorUtility.cs @@ -1,6 +1,6 @@ namespace BlazorBootstrap; -public static class FilterOperatorHelper +public static class FilterOperatorUtility { #region Methods diff --git a/blazorbootstrap/Utilities/IdGenerator.cs b/blazorbootstrap/Utils/IdUtility.cs similarity index 80% rename from blazorbootstrap/Utilities/IdGenerator.cs rename to blazorbootstrap/Utils/IdUtility.cs index a47ab628a..3d9ab0b99 100644 --- a/blazorbootstrap/Utilities/IdGenerator.cs +++ b/blazorbootstrap/Utils/IdUtility.cs @@ -1,26 +1,11 @@ namespace BlazorBootstrap; -/// -/// An interface that generates unique IDs. -/// -public interface IIdGenerator -{ - #region Methods - - /// - /// Gets the next unique ID. - /// - string GetNextId(); - - #endregion -} - /// /// Generates efficient base32-encoded IDs. /// /// /// -public sealed class IdGenerator : IIdGenerator +public static class IdUtility { #region Fields and Constants @@ -41,13 +26,13 @@ public sealed class IdGenerator : IIdGenerator /// Generates a base32-encoded ID. /// /// The base32-encoded ID. - public string GetNextId() => GenerateId(Interlocked.Increment(ref lastId)); + public static string GetNextId() => GenerateId(Interlocked.Increment(ref lastId)); private static string GenerateId(long id) { return string.Create(13, id, (buffer, value) => { - char[] encode32Chars = IdGenerator.encode32Chars; + char[] encode32Chars = IdUtility.encode32Chars; buffer[12] = encode32Chars[value & 31]; buffer[11] = encode32Chars[(value >> 5) & 31]; From e22e5ebe82d29c23f0dc03700410d954d02b357c Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Sat, 8 Jun 2024 18:29:01 +0530 Subject: [PATCH 2/4] ChartOptions enhancements --- .../LineCharts/LineChartDocumentation.razor | 3 + ...LineChart_Demo_05_Tick_Configuration.razor | 120 ++++++++++++++ .../Charts/ChartOptions/ChartOptions.cs | 148 +++++++++++++++--- ...-06-08-blazorbootstrap-3.0.0-preview.1.md} | 7 +- 4 files changed, 251 insertions(+), 27 deletions(-) create mode 100644 BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_05_Tick_Configuration.razor rename docs/blog/{2024-05-24-blazorbootstrap-3.0.0-preview.1.md => 2024-06-08-blazorbootstrap-3.0.0-preview.1.md} (89%) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChartDocumentation.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChartDocumentation.razor index cedfad00c..d4dfc40f4 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChartDocumentation.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChartDocumentation.razor @@ -42,6 +42,9 @@ + + + @code { private readonly string pageUrl = "/charts/line-chart"; private readonly string title = "Blazor Line Chart"; diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_05_Tick_Configuration.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_05_Tick_Configuration.razor new file mode 100644 index 000000000..b2d4d56a2 --- /dev/null +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Charts/LineCharts/LineChart_Demo_05_Tick_Configuration.razor @@ -0,0 +1,120 @@ + + +
+ + + +
+ +@code { + private LineChart lineChart = default!; + private LineChartOptions lineChartOptions = default!; + private ChartData chartData = default!; + + private int datasetsCount; + private int labelsCount; + + private Random random = new(); + + protected override void OnInitialized() + { + chartData = new ChartData { Labels = GetDefaultDataLabels(6), Datasets = GetDefaultDataSets(3) }; + lineChartOptions = new() { Responsive = true, Interaction = new Interaction { Mode = InteractionMode.Index } }; + + // set ticks color + lineChartOptions.Scales.X!.Ticks = new ChartAxesTicks { Color = "red" }; + lineChartOptions.Scales.Y!.Ticks = new ChartAxesTicks { Color = ColorUtility.CategoricalTwelveColors[4] }; + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await lineChart.InitializeAsync(chartData, lineChartOptions); + } + await base.OnAfterRenderAsync(firstRender); + } + + private async Task ChangeTicksAlignmentToStart() + { + lineChartOptions.Scales.X!.Ticks!.TicksAlignment = TicksAlignment.Start; + await lineChart.UpdateAsync(chartData, lineChartOptions); + } + + private async Task ChangeTicksAlignmentToCenter() + { + lineChartOptions.Scales.X!.Ticks!.TicksAlignment = TicksAlignment.Center; + await lineChart.UpdateAsync(chartData, lineChartOptions); + } + + private async Task ChangeTicksAlignmentToEnd() + { + lineChartOptions.Scales.X!.Ticks!.TicksAlignment = TicksAlignment.End; + await lineChart.UpdateAsync(chartData, lineChartOptions); + } + + #region Data Preparation + + private List GetDefaultDataSets(int numberOfDatasets) + { + var datasets = new List(); + + for (var index = 0; index < numberOfDatasets; index++) + { + datasets.Add(GetRandomLineChartDataset()); + } + + return datasets; + } + + private LineChartDataset GetRandomLineChartDataset() + { + var c = ColorUtility.CategoricalTwelveColors[datasetsCount].ToColor(); + + datasetsCount += 1; + + return new LineChartDataset + { + Label = $"Team {datasetsCount}", + Data = GetRandomData(), + BackgroundColor = new List { c.ToRgbString() }, + BorderColor = new List { c.ToRgbString() }, + BorderWidth = new List { 2 }, + HoverBorderWidth = new List { 4 }, + PointBackgroundColor = new List { c.ToRgbString() }, + PointRadius = new List { 0 }, // hide points + PointHoverRadius = new List { 4 } + }; + } + + private List GetRandomData() + { + var data = new List(); + for (var index = 0; index < labelsCount; index++) + { + data.Add(random.Next(200)); + } + + return data; + } + + private List GetDefaultDataLabels(int numberOfLabels) + { + var labels = new List(); + for (var index = 0; index < numberOfLabels; index++) + { + labels.Add(GetNextDataLabel()); + } + + return labels; + } + + private string GetNextDataLabel() + { + labelsCount += 1; + return $"Day {labelsCount}"; + } + + #endregion Data Preparation + +} \ No newline at end of file diff --git a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs index 19a05f535..75504c305 100644 --- a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs +++ b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs @@ -71,15 +71,15 @@ public Interaction() private void SetMode(InteractionMode interactionMode) => ChartInteractionMode = interactionMode switch - { - InteractionMode.Dataset => "dataset", - InteractionMode.Index => "index", - InteractionMode.Nearest => "nearest", - InteractionMode.Point => "point", - InteractionMode.X => "x", - InteractionMode.Y => "y", - _ => "" - }; + { + InteractionMode.Dataset => "dataset", + InteractionMode.Index => "index", + InteractionMode.Nearest => "nearest", + InteractionMode.Point => "point", + InteractionMode.X => "x", + InteractionMode.Y => "y", + _ => "" + }; #endregion @@ -130,7 +130,6 @@ public class Scales [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ChartAxes? X { get; set; } = new(); [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ChartAxes? Y { get; set; } = new(); - #endregion } @@ -138,7 +137,7 @@ public class Scales public class ChartAxes { #region Properties, Indexers - + // Stacked public bool BeginAtZero { get; set; } = true; @@ -149,7 +148,7 @@ public class ChartAxes public ChartAxesBorder? Border { get; set; } /// - /// Grid settings + /// Gets or sets the grid configuration. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ChartAxesGrid? Grid { get; set; } @@ -187,11 +186,14 @@ public class ChartAxes public double? SuggestedMin { get; set; } /// - /// Tick settings + /// Gets or sets the tick configuration. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ChartAxesTicks? Ticks { get; set; } + /// + /// Gets or sets the title configuration. + /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ChartAxesTitle? Title { get; set; } @@ -204,8 +206,10 @@ public class ChartAxes ///
public class ChartAxesBorder { + #region Properties, Indexers + /// - /// The color of the border line. + /// The color of the border line. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Color { get; set; } @@ -240,22 +244,26 @@ public class ChartAxesBorder ///
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Z { get; set; } + + #endregion } /// -/// Defines options for the grid lines that run perpendicular to the axis. +/// Defines options for the grid lines that run perpendicular to the axis. /// /// public class ChartAxesGrid { + #region Properties, Indexers + /// /// If , gridlines are circular (on radar and polar area charts only). /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? Circular { get; set; } - + /// - /// Color of the grid axis lines. Here one can write a CSS method or even a JavaScript method for a dynamic color. + /// Color of the grid axis lines. Here one can write a CSS method or even a JavaScript method for a dynamic color. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Color { get; set; } @@ -266,7 +274,8 @@ public class ChartAxesGrid public bool Display { get; set; } = true; /// - /// If , draw lines on the chart area inside the axis lines. This is useful when there are multiple axes and you need to control which grid lines are drawn. + /// If , draw lines on the chart area inside the axis lines. This is useful when there are multiple + /// axes and you need to control which grid lines are drawn. /// public bool DrawOnChartArea { get; set; } = true; @@ -281,19 +290,20 @@ public class ChartAxesGrid public int LineWidth { get; set; } = 1; /// - /// If , grid lines will be shifted to be between labels. This is set to true for a bar chart by default. + /// If , grid lines will be shifted to be between labels. This is set to true for a bar chart by + /// default. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? Offset { get; set; } = false; /// - /// Length and spacing of the tick mark line. + /// Length and spacing of the tick mark line. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public List? TickBorderDash { get; set; } /// - /// Offset for the line dash of the tick mark. + /// Offset for the line dash of the tick mark. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? TickBorderDashOffset { get; set; } @@ -310,7 +320,6 @@ public class ChartAxesGrid [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? TickLength { get; set; } - /// /// Width of the tick mark in pixels. /// @@ -322,6 +331,22 @@ public class ChartAxesGrid ///
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Z { get; set; } + + #endregion +} + +public enum TicksAlignment +{ + Center, // default + Start, + End +} + +public enum TitleAlignment +{ + Center, // default + Start, + End } /// @@ -330,6 +355,31 @@ public class ChartAxesGrid /// public class ChartAxesTicks { + #region Fields and Constants + + private TicksAlignment ticksAlignment; + + #endregion + + #region Methods + + private void SetTicksAlignment(TicksAlignment interactionMode) => + Alignment = interactionMode switch + { + TicksAlignment.Center => "center", + TicksAlignment.Start => "start", + TicksAlignment.End => "end", + _ => null + }; + + #endregion + + #region Properties, Indexers + + [JsonPropertyName("align")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Alignment { get; private set; } + /// /// Color of label backdrops /// @@ -341,7 +391,7 @@ public class ChartAxesTicks ///
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? BackdropPadding { get; set; } - + /// /// Color of ticks /// @@ -382,6 +432,19 @@ public class ChartAxesTicks ///
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? TextStrokeWidth { get; set; } + + [JsonIgnore] + public TicksAlignment TicksAlignment + { + get => ticksAlignment; + set + { + ticksAlignment = value; + SetTicksAlignment(value); + } + } + + #endregion } /// @@ -389,10 +452,15 @@ public class ChartAxesTicks /// public class ChartAxesTicksMajor { + #region Properties, Indexers + /// - /// If , major ticks are generated. A major tick will affect autoskipping and major will be defined on ticks in the scriptable options context. + /// If , major ticks are generated. A major tick will affect auto skipping and major will be defined + /// on ticks in the scriptable options context. /// public bool Enabled { get; set; } = false; + + #endregion } /// @@ -401,6 +469,25 @@ public class ChartAxesTicksMajor /// public class ChartAxesTitle { + #region Fields and Constants + + private TitleAlignment titleAlignment; + + #endregion + + #region Methods + + private void SetTitleAlignment(TitleAlignment interactionMode) => + Alignment = interactionMode switch + { + TitleAlignment.Center => "center", // default + TitleAlignment.Start => "start", + TitleAlignment.End => "end", + _ => null + }; + + #endregion + #region Properties, Indexers /// @@ -408,7 +495,7 @@ public class ChartAxesTitle /// Options are: 'start', 'center', and 'end' /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? Align { get; set; } = "center"; + public string? Alignment { get; private set; } /// /// Color of text. @@ -429,6 +516,17 @@ public class ChartAxesTitle [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Text { get; set; } + [JsonIgnore] + public TitleAlignment TitleAlignment + { + get => titleAlignment; + set + { + titleAlignment = value; + SetTitleAlignment(value); + } + } + #endregion } diff --git a/docs/blog/2024-05-24-blazorbootstrap-3.0.0-preview.1.md b/docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md similarity index 89% rename from docs/blog/2024-05-24-blazorbootstrap-3.0.0-preview.1.md rename to docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md index d909e4959..dcedeb8d4 100644 --- a/docs/blog/2024-05-24-blazorbootstrap-3.0.0-preview.1.md +++ b/docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md @@ -1,5 +1,5 @@ --- -title: Blazor Bootstrap v3.0.0 +title: Blazor Bootstrap v3.0.0-preview.1 authors: name: Vikram Reddy title: Creator @@ -8,7 +8,7 @@ authors: tags: [v3.0.0, blazor, bootstrap, blazorbootstrap, accordion, button, callout, dropdown, grid, modal, ribbon, tab, sidebar, sidebar2] --- -We are excited to release version 3.0.0, which includes a Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!! +We are excited to release version v3.0.0-preview.1, which includes a Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!! ![image](https://i.imgur.com/XG4Wv17.png "Blazor Bootstrap: Grid Component - Column class") @@ -16,6 +16,9 @@ We are excited to release version 3.0.0, which includes a Grid, Modal, Sidebar, ## What's changed +- `Chart` components + - Tick Configuration support added + - `Grid` component - New parameter **FilterButtonColor** added to change the filter button color. - New parameter **FilterButtonCSSClass** added to apply custom CSS classes. From 8e3315c8673eb35db1006293d3dcde2b67312f83 Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Sat, 8 Jun 2024 18:31:48 +0530 Subject: [PATCH 3/4] JsonPropertyName update. --- blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs index 75504c305..9ec803587 100644 --- a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs +++ b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs @@ -494,6 +494,7 @@ private void SetTitleAlignment(TitleAlignment interactionMode) => /// Alignment of the title. /// Options are: 'start', 'center', and 'end' /// + [JsonPropertyName("align")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Alignment { get; private set; } From 252d1c688d81e162049669f7a0d4d11f6eff0a1d Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Sat, 8 Jun 2024 18:46:14 +0530 Subject: [PATCH 4/4] Demos, Docs update --- .../Client/wwwroot/appsettings.json | 2 +- .../Components/Pages/Index.razor | 26 +++++++++---------- .../SortableListDocumentation.razor | 2 +- BlazorBootstrap.Demo.Server/appsettings.json | 2 +- .../wwwroot/appsettings.json | 2 +- .../Charts/ChartOptions/ChartOptions.cs | 2 -- ...4-06-08-blazorbootstrap-3.0.0-preview.1.md | 5 ++-- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/BlazorBootstrap.Demo.Hosted/Client/wwwroot/appsettings.json b/BlazorBootstrap.Demo.Hosted/Client/wwwroot/appsettings.json index 3a0c857e3..9533f1486 100644 --- a/BlazorBootstrap.Demo.Hosted/Client/wwwroot/appsettings.json +++ b/BlazorBootstrap.Demo.Hosted/Client/wwwroot/appsettings.json @@ -1,7 +1,7 @@ { "version": "3.0.0-preview.1", "release": { - "short_description": "Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!!" + "short_description": "Charts, Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!!" }, "urls": { "docs": "//docs.blazorbootstrap.com/docs/getting-started/blazor-webassembly", diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Index.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Index.razor index 8a31ead04..8479eebec 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Index.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Index.razor @@ -77,7 +77,7 @@
@@ -87,7 +87,7 @@
@@ -117,7 +117,7 @@
@@ -137,7 +137,7 @@
@@ -162,7 +162,7 @@
@@ -172,17 +172,17 @@
@@ -197,7 +197,7 @@
@@ -270,22 +270,22 @@ diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/SortableList/SortableListDocumentation.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/SortableList/SortableListDocumentation.razor index 6281fe554..130e98546 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/SortableList/SortableListDocumentation.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/SortableList/SortableListDocumentation.razor @@ -4,7 +4,7 @@ -

Blazor Sortable List Preview

+

Blazor Sortable List

The Blazor Bootstrap Sortable List component, built on top of SortableJS, enables drag-and-drop reordering of lists.
diff --git a/BlazorBootstrap.Demo.Server/appsettings.json b/BlazorBootstrap.Demo.Server/appsettings.json index 2f807a814..1815699cf 100644 --- a/BlazorBootstrap.Demo.Server/appsettings.json +++ b/BlazorBootstrap.Demo.Server/appsettings.json @@ -8,7 +8,7 @@ "AllowedHosts": "*", "version": "3.0.0-preview.1", "release": { - "short_description": "Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!!" + "short_description": "Charts, Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!!" }, "urls": { "docs": "//docs.blazorbootstrap.com/getting-started/blazor-webassembly-net-8", diff --git a/BlazorBootstrap.Demo.WebAssembly/wwwroot/appsettings.json b/BlazorBootstrap.Demo.WebAssembly/wwwroot/appsettings.json index a10ce545a..a69fcb17c 100644 --- a/BlazorBootstrap.Demo.WebAssembly/wwwroot/appsettings.json +++ b/BlazorBootstrap.Demo.WebAssembly/wwwroot/appsettings.json @@ -1,7 +1,7 @@ { "version": "3.0.0-preview.1", "release": { - "short_description": "Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!!" + "short_description": "Charts, Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!!" }, "urls": { "docs": "//docs.blazorbootstrap.com/getting-started/blazor-webassembly-net-8", diff --git a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs index 9ec803587..77f2528dc 100644 --- a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs +++ b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs @@ -58,9 +58,7 @@ public class Interaction #region Constructors -#pragma warning disable CS8618 public Interaction() -#pragma warning restore CS8618 { Mode = InteractionMode.Nearest; } diff --git a/docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md b/docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md index dcedeb8d4..f263eee24 100644 --- a/docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md +++ b/docs/blog/2024-06-08-blazorbootstrap-3.0.0-preview.1.md @@ -8,7 +8,7 @@ authors: tags: [v3.0.0, blazor, bootstrap, blazorbootstrap, accordion, button, callout, dropdown, grid, modal, ribbon, tab, sidebar, sidebar2] --- -We are excited to release version v3.0.0-preview.1, which includes a Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!! +We are excited to release version v3.0.0-preview.1, which includes a Charts, Grid, Modal, Sidebar, Sidebar2 updates, and other improvements!!! ![image](https://i.imgur.com/XG4Wv17.png "Blazor Bootstrap: Grid Component - Column class") @@ -17,7 +17,8 @@ We are excited to release version v3.0.0-preview.1, which includes a Grid, Modal ## What's changed - `Chart` components - - Tick Configuration support added + - Tick configuration support added + - Grid configuration support added - `Grid` component - New parameter **FilterButtonColor** added to change the filter button color.