Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.25k stars 526 forks source link

Custom Enum object #3073

Closed stsrki closed 2 years ago

stsrki commented 2 years ago

Create a new object that will replace our current enum values like Color, Background, Target, etc. The idea is to be able to have a default set of values, with the ability to accept other types like string. Possibly with an implicit string operator.

Should be possible to do:

<Button Color="Color.Primary" />
<Button Color="btn-purple" />

<Link Target="frame-target" />

Inspiration https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/enumeration-classes-over-enum-types

David-Moreira commented 2 years ago

I'm starting work on this. We are changing the parameters to be of type string, right? That's the idea?

The inspiration link seems like it will work fine. But I was thinking that for us it might be worth it doing with some kind of interface based implementation instead that we can then inject different implementations based on the provider which will result in a different string (class output)

stsrki commented 2 years ago

I have kinda forgotten why exactly I wanted to use strings :)

The basic idea, I think, for the new Complex Enum is to be able to extend our current coloring system. For example, if we want to have Color="Color.Primary.WithGradient" or Color="Color.Primary.Accent2". Kinda like we have it on utility classes.

So yeah, something like interface-based implementation might be needed(internally), although I don't think we would want to implement them for every provider. Can you prototype it with pseudo-code here what you had in mind so I can have a clearer picture?

Since I think this will not be much of a breaking change we can consider it for v1.1.

stsrki commented 2 years ago

Oh yeah. Why I wanted string for some. Currently, on Link Target enum we only have some of the standard target types. But the problem is that target can sometimes refer to an iframe with an ID of the iframe, eg Target="frame-target". With the complex enum supporting the implicit string we could potentially support this scenario.

See #1448

David-Moreira commented 2 years ago

I have kinda forgotten why exactly I wanted to use strings :)

I guess it also helps users just implement their own abstractions if they want to or provide the value or values they want directly... since it just expects a string.

Edit: Might be more confusing to get to the helpers tough. An enum does have the intelisense. A string does not... the user needs to know there exists helpers, which are not as easily discovered.

stsrki commented 2 years ago

We will need to document it. And it also can be one more community article.

stsrki commented 2 years ago

@David-Moreira can you do a quick review?