vikramlearning / blazorbootstrap

An Enterprise-class Blazor Bootstrap Component library built on the Blazor and Bootstrap CSS frameworks.
https://docs.blazorbootstrap.com/
Apache License 2.0
565 stars 15 forks source link

DEBATE: get rid of all the ''individual color enums'' #767

Open Lucasharskamp opened 1 week ago

Lucasharskamp commented 1 week ago

There might be something I'm missing here @gvreddy04 , so I want your input on this: but why does this library have so many ''Color'' enums? BackgroundColor, ToastType, all the ones in the Enums -> Color folder, etc.

Most of them contain the following colors: None, Default, Primary, Secondary, Success, Danger, Warning, Info, Light and Dark. Some also contain Transparent.

Problem 1: it isn't up to the library to determine how the components are used.

ToastType for example doesn't contain an option for Transparent or None. Why not? Maybe the programmer in this case wants to have the contents of the Toast be a div.container with gutters where only specific sections get a background. it isn't up to Blazor.Bootstrap to decide what is and isn't allowed.

Same goes for Callout: Callout only gets Default, Danger, Warning, Info and Success. But I don't care, really! I want a Light or Dark or Transparent callout if those are the needs of the UI.

Problem 2: unclear naming

Primary, Secondary, Success, etc are clear. The problem lies with these 3: None, Default and Transparent.

What does None mean in this context? Does it mean we have no background (transparent) or that we revert to the default background? Or are we using the CSS inherit functionality?

Proposed solution:

Proposed solution: just have 1 enum for Colors for everything in the library, even for text. If the user wants text to be transparent, than we must trust them to have a good reason for it. The library exists to help create business solutions, but not infringe on what those business solutions are. It also removes some needless transformation methods that turn an enum of, say, AlertColor to TextColor or anything like that.

public enum BsColor
{
    Default = 0,
    Primary,
    Secondary,
    Success,
    Danger,
    Warning,
    Info,
    Light,
    Dark,
   Body, // grab from --bs-body, useful for backgrounds but others as well. 
    White, // refers to --bs-white
    Black, // refers to --bs-black
    Transparent,
    Muted,
    Link
}

It's called BsColor as a reference as how Bootstrap has its variables beginning with --bs-, for the sake of readability in code and differentiate it from System.Drawing.Color.

A gradient can be handled by simply providing an extra bool parameter signifying the gradient, that if true will add the .bg-gradient class to the component. The only problem may be for Muted/Link colors, but then again, one can also just ignore it, create a custom css for it for the user to fill in or use NotImplementedExceptions