Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code improvements #745

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

private BarChartDataset GetRandomBarChartDataset()
{
var c = ColorBuilder.CategoricalTwelveColors[datasetsCount].ToColor();
var c = ColorUtility.CategoricalTwelveColors[datasetsCount].ToColor();

datasetsCount += 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
var dataset1 = new BarChartDataset()
{
Data = new List<double> { 55000, 15000, 18000, 21000 },
BackgroundColor = new List<string> { ColorBuilder.CategoricalTwelveColors[0] },
BorderColor = new List<string> { ColorBuilder.CategoricalTwelveColors[0] },
BackgroundColor = new List<string> { ColorUtility.CategoricalTwelveColors[0] },
BorderColor = new List<string> { ColorUtility.CategoricalTwelveColors[0] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;
var colors = ColorUtility.CategoricalTwelveColors;

var labels = new List<string> { "Chrome", "Firefox", "Safari", "Edge" };
var datasets = new List<IChartDataset>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;
var colors = ColorUtility.CategoricalTwelveColors;

var labels = new List<string> { "Chrome", "Firefox", "Safari", "Edge" };
var datasets = new List<IChartDataset>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;
var colors = ColorUtility.CategoricalTwelveColors;

var labels = new List<string> { "Chrome", "Firefox", "Safari", "Edge" };
var datasets = new List<IChartDataset>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

private LineChartDataset GetRandomLineChartDataset()
{
var c = ColorBuilder.CategoricalTwelveColors[datasetsCount].ToColor();
var c = ColorUtility.CategoricalTwelveColors[datasetsCount].ToColor();

datasetsCount += 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;
var colors = ColorUtility.CategoricalTwelveColors;

var labels = new List<string> { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
var datasets = new List<IChartDataset>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;
var colors = ColorUtility.CategoricalTwelveColors;

var labels = new List<string> { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
var datasets = new List<IChartDataset>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;
var colors = ColorUtility.CategoricalTwelveColors;

var labels = new List<string> { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
var datasets = new List<IChartDataset>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions blazorbootstrap/Components/Accordion/Accordion.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// If <see langword="true" />, accordion items stay open when another item is opened.
Expand Down
8 changes: 3 additions & 5 deletions blazorbootstrap/Components/Accordion/AccordionItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));

/// <summary>
/// Gets or sets the active state.
Expand Down
9 changes: 4 additions & 5 deletions blazorbootstrap/Components/Alert/Alert.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
15 changes: 7 additions & 8 deletions blazorbootstrap/Components/Badge/Badge.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
21 changes: 10 additions & 11 deletions blazorbootstrap/Components/Button/Button.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the button active state.
Expand Down
7 changes: 3 additions & 4 deletions blazorbootstrap/Components/Callout/Callout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 4 additions & 5 deletions blazorbootstrap/Components/Card/Card.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
4 changes: 1 addition & 3 deletions blazorbootstrap/Components/Card/CardBody.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
4 changes: 1 addition & 3 deletions blazorbootstrap/Components/Card/CardFooter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
4 changes: 1 addition & 3 deletions blazorbootstrap/Components/Card/CardGroup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
7 changes: 3 additions & 4 deletions blazorbootstrap/Components/Card/CardHeader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
7 changes: 3 additions & 4 deletions blazorbootstrap/Components/Card/CardLink.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
4 changes: 1 addition & 3 deletions blazorbootstrap/Components/Card/CardSubTitle.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
4 changes: 1 addition & 3 deletions blazorbootstrap/Components/Card/CardText.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
4 changes: 1 addition & 3 deletions blazorbootstrap/Components/Card/CardTitle.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Gets or sets the content to be rendered within the component.
Expand Down
Loading
Loading