Skip to content

Conversation

@bingzer
Copy link
Contributor

@bingzer bingzer commented Oct 17, 2023

Hello @DamianEdwards ,

I recently came across a situation where I needed to add a class based on a specific condition in my project. While searching, I noticed a similar feature request in Issue #31.

I've introduced the [asp-class-if-key] TagHelper with this syntax:

[asp-class-if-key]:

<div class="mt-0 p0" asp-class-if-bg-primary="(DateTime.UtcNow.Second % 2) == 0">
  This paragraph will have <code>bg-primary</code> class during <strong>even</strong> seconds.
</div>

which results in:

**** even second ****
<div class="mt-0 p-0 bg-primary">
  This paragraph will have <code>bg-primary</code> class during <strong>even</strong> seconds.
</div>

**** odd second ****
<div class="mt-0 p-0">
  This paragraph will have <code>bg-primary</code> class during <strong>even</strong> seconds.
</div>

Additionally, this PR supports various naming conventions, including camelCase, kebab-case, and underscore_case, as validated by the accompanying unit tests. I've also included unit tests and provided an example in the sample project. I believe that this feature could be valuable to other developers. Your review of this addition is greatly appreciated. Thank you for your consideration.

@bingzer bingzer marked this pull request as ready for review October 21, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant