jenkinsci / badge-plugin

Jenkins Badge plugin
https://plugins.jenkins.io/badge/
MIT License
32 stars 43 forks source link

Provide built-in css classes for text badges #201

Closed cronik closed 4 weeks ago

cronik commented 1 month ago

Restores stylized text only badges lost in 2.0 refactor. Text only badges (no icon or link) will render with rounded corners and default background color that matches the text color but with some opacity.

Before: Screenshot 2024-10-11 at 6 11 16 PM

After: Screenshot 2024-10-11 at 6 10 16 PM Screenshot 2024-10-11 at 5 53 07 PM

Submitter checklist

strangelookingnerd commented 1 month ago

The functionality itself was not really „lost“ but removed intentionally. I wanted to simplify the implementation of this plugin and more importantly give users full control over the badge styling. Any „implicit styling“ was therefore removed and I’m not really convinced that restoring it is a good idea.

Maybe a provocative question, but what if I actually want a text only badge without border / background?

Possibly related https://github.com/jenkinsci/badge-plugin/issues/177

cronik commented 1 month ago

I was able to reproduce something with a similar effect with a bunch of css

addBadge(text: "1.0.0", style: 'color: var(--green); border-radius: 5px; background: var(--light-green); padding: 0 0.4rem !important;')

Users need to dig deep into css to make a simple text tag look somewhat presentable. The end user pays the cost of the plugin simplification given the same could have been accomplished before with:

addShortText(text: '1.0.0', color: 'success')

It appears this cost transfer was intentional so as a compromise would you be ok with bundling some default css classes that can be explicitly added rather than included by default?

addBadge(text: "1.0.0", style: 'color: var(--success-color);', cssClass: 'badge-textTag')

If that sounds reasonable I can rework this PR and update documentation.

strangelookingnerd commented 1 month ago

Having a set of pre-defined CSS classes sounds like a great idea. We could add those to the documentation similar to the various examples for symbols.

cronik commented 4 weeks ago

Refactored to include 2 text badge css classes:

Examples on how they can be combined and tweaked with the style parameter

addBadge(text: "1.0.0", style: 'color: var(--success-color);', cssClass: 'badge-text--background')
addBadge(text: "2.0.0", style: 'color: var(--warning-color);', cssClass: 'badge-text--bordered')
addBadge(text: "3.0.0", style: 'color: var(--warning-color); border-radius: 6px;', cssClass: 'badge-text--bordered')
addBadge(text: "4.0.0", style: 'color: var(--warning-color);', cssClass: 'badge-text--background badge-text--bordered')
addBadge(text: "5.0.0", cssClass: 'badge-text--background badge-text--bordered')
Screenshot 2024-10-14 at 6 47 45 PM
mPokornyETM commented 4 weeks ago

Refactored to include 2 text badge css classes:

  • badge-text--background - Adds colored background with rounded corners.
  • badge-text--bordered - Adds border that is the same color as the text.

Examples on how they can be combined and tweaked with the style parameter

addBadge(text: "1.0.0", style: 'color: var(--success-color);', cssClass: 'badge-text--background')
addBadge(text: "2.0.0", style: 'color: var(--warning-color);', cssClass: 'badge-text--bordered')
addBadge(text: "3.0.0", style: 'color: var(--warning-color); border-radius: 6px;', cssClass: 'badge-text--bordered')
addBadge(text: "4.0.0", style: 'color: var(--warning-color);', cssClass: 'badge-text--background badge-text--bordered')
addBadge(text: "5.0.0", cssClass: 'badge-text--background badge-text--bordered')
Screenshot 2024-10-14 at 6 47 45 PM

it will be fine, when you bring this examplesalso in the 'official' (readme) documentation

strangelookingnerd commented 4 weeks ago

I’ll wait for #200 to be resolved before releasing this change. Thanks for the contribution @cronik

jimklimov commented 2 weeks ago

FWIW, in my use-cases I went with a CSS file that can be served from $JENKINS_HOME/userContent and requested via theme plugins (also, several CSS files can be served by one including them), and applying one of several classes depending on the message and its severity, e.g.

...this did partially start out from an attempt to recreate the Badge v1.9.x experience with the newer plugin releases, which this PR I think largely restores as a choosable option :)