Closed cronik closed 4 weeks 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
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.
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.
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')
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
parameteraddBadge(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')
it will be fine, when you bring this examplesalso in the 'official' (readme) documentation
I’ll wait for #200 to be resolved before releasing this change. Thanks for the contribution @cronik
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 :)
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:
After:
Submitter checklist