-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML labels for radio/checkbox options #412
Conversation
2240ec3
to
445cc8e
Compare
Jest Coverage
|
This PR also includes various changes to the workflows and test harness to make them compatible with the current |
…adios If a checkbox or radio option specifies "htmlLabel" then this will be rendered _as HTML_ instead of the regular "label" being rendered as text. Use cases for this could be - showing the labels in differnt colours `<span style='color:red'>Negative</span>` - adding emphasis to particular parts of the label `<b>Reasonably</b> confident` - adding margin to the bottom of an option to separate groups of related choices `<div style='margin-bottom: 1.5em'>Last option in this group</div>`
In newer docker versions, compose is a plugin to the docker command rather than a command in its own right.
Use inline-flex for the checkbox/radio `<label>` so that even if the label includes something like a div with bottom margin, the helptext popup still appears beside the label rather than underneath it
Added special classes to the CSS that users can add to a span or something inside an option's htmlLabel to affect the margin above or below the option as a whole (as opposed to just above or below the label).
29ef3ca
to
6d7ce11
Compare
{{ option.text }} | ||
<span v-if="option.html" v-html="option.html"></span> | ||
<span v-else>{{ option.text }}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core of the changes - if there's an HTML label then bind that with v-html
, otherwise use the text label as before.
|
||
// Import Bootstrap an BootstrapVue CSS files (order is important) | ||
import 'bootstrap/dist/css/bootstrap.css' | ||
import 'bootstrap-vue/dist/bootstrap-vue.css' | ||
|
||
|
||
//Importing scss assets needs an @/ in front of it | ||
|
||
import "@/assets/sass/app.scss" | ||
|
||
// Import Bootstrap an BootstrapVue CSS files (after app.scss, which includes bootstrap) | ||
import 'bootstrap-vue/dist/bootstrap-vue.css' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed app.scss
to import the bootstrap sass directly, so we don't need to import the pre-compiled CSS as well.
// is equivalent to putting 'mb-4' on the option div itself. | ||
@each $size, $length in $spacers { | ||
@each $dir, $edge in (above:top, below:bottom) { | ||
:is(.custom-checkbox, .custom-radio):has(.tw-space-#{$dir}-#{$size}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes use of the :has
selector (supported since late 2022 in Chrome and relatives but only since the end of 2023 in Firefox) - I've introduced classes that you can put on an element inside the htmlLabel
to influence the margins of the containing div
for that option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes looks good to me!
Summary
Add the ability to specify an
htmlLabel
instead of a plain textlabel
for radio and checkbox options. The motivating use case was a feature request from a user within the GATE team who wanted to be able to add colours to their checkbox labels, e.g. green for positive sentiment, red for negative, but HTML labels would open up other possibilities, e.g. addingmargin-bottom
to certain options to separate a long list of radio choices into logical groups (#404).Implementation
I've added handling for
htmlLabel
to thegenerateBVOptions
function, whereby ifhtmlLabel
is set in an option in the project config (or afromDocument
field) then it adds anhtml
property to the generated option object.CheckboxInput
andRadioInput
look for thishtml
property, and if found they render it into aspan
withv-html
and ignore the usualtext
. If there is no HTML label then thetext
label is rendered in the normal way.I've also added some special CSS classes
tw-space-(above|below)-[1-5]
that you can apply to an element inside thehtmlLabel
that do the equivalent of adding the Bootstrap margin classesmt-[1-5]
ormb-[1-5]
to the containing div that holds that label and its associated checkbox. These can be used to visually separate groups of logically-related options.Examples
Coloured option labels
Separating options into groups