daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

Added button state Active #45

Closed josephwoodward closed 8 years ago

josephwoodward commented 9 years ago

This one should solve issue #19

Though it seems a little too simple to implement, I figure I must be missing something?

daveaglick commented 9 years ago

Sweet! This came in right on my way out the door, so I'll take a look tonight - though I might not get to it until Monday (I try to decompress over the weekend :) ).

josephwoodward commented 9 years ago

No worries. I've started using it in a project so it's nice giving back. I'll see if there are some other tasks I can pick up.

Let me know if I've missed something in this one though and I'll make the necessary changes.

daveaglick commented 9 years ago

Finally had a chance to look at this - sorry for the delay! I think this one is going to be a little different because the active state is in addition to the button state. Take a look at the same code from the Bootstrap docs:

<button type="button" class="btn btn-primary btn-lg active">Primary button</button>
<button type="button" class="btn btn-default btn-lg active">Button</button>

Notice that these buttons have both btn-primary/btn-default and active CSS classes. If we add the active CSS class to the ButtonState enum, then it would be used instead of one of the existing button states.

I think the correct approach would be similar to how the disabled state is set by adding or removing an additional CSS class when calling an extension method specific to that flag. There's already support for this type of thing in the library, so the code is really easy - here's the one for disabling a LinkButton:

public static ComponentBuilder<TConfig, LinkButton> SetDisabled<TConfig>(this ComponentBuilder<TConfig, LinkButton> builder, bool disabled = true)
    where TConfig : BootstrapConfig
{
    builder.Component.ToggleCss(Css.Disabled, disabled);
    return builder;
}

Off the top of my head, I'm guessing the new extension would look something like:

public static ComponentBuilder<TConfig, LinkButton> SetActive<TConfig>(this ComponentBuilder<TConfig, LinkButton> builder, bool active = true)
    where TConfig : BootstrapConfig
{
    builder.Component.ToggleCss(Css.Active, active);
    return builder;
}

We'll also need a second extension for Button since the active state can apply to both buttons and link buttons.

Hopefully that all made sense. Feel free to hit me up if you need any help or if this turns out to be more than you were hoping to tackle. I don't mind going in and making the change, but I love supporting contributors even more :)

josephwoodward commented 9 years ago

Thanks for the help, I thought it felt a little too easy :) I'll sort it, it's a great library so it's good being able to contribute back!

josephwoodward commented 9 years ago

Finally found time to get back to this. I've removed the ButtonState enum and added the SetActive to both Button and LinkButton extensions.

daveaglick commented 8 years ago

Thanks! I'll try and get a new NuGet release out in the next day or two.