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
Allow to customise form-switch colors #35004
base: main
Are you sure you want to change the base?
Conversation
4c4e81e
to
4c5ff2f
|
@GeoSot I just seen the tags you added. Is that something you may consider merging at some point ? I only made the PR as a POC but I can go further if this is a feature that would be merged. Also if it's a feature that could be merged, am I on the right path with this little change or am I wrong and should take another path for this changes? Thanks |
b63b325
to
142249c
|
Hello here (maybe @GeoSot ?) I updated my PR with the complete implementation. Hopefully this can be merged soon. Thank you |
|
Hey @flohw . Sorry for my late answer, I missed that message. Your MR is css scoped, and I am more to the Js section of the team. I tagged it to help our guys give the proper attention |
|
Hello there, Hopefully this time I will have some feedback. Thanks. |
|
Hello, Two months have past. Anyone would give me some feedback? |
| `disabled` attribute. They also can be theme-colored when they are checked | ||
| and another when they are not checked. |
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 sentence sounds weird to me, some native english speaking friend might reword this. :)
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.
Maybe "The checked and not checked colors are customizable separately"?
|
We're kinda busy out of Bootstrap, sorry for the delay. Could you please check focus and active states for colored switched? They still use the standard light blue, which is a bit awkward IMHO. Using the according theme color and lightning it would be more accurate, wouldn't it? |
|
@ffoodd Thank you for your feed back. I can understand you are busy, no problem. I only hoped to have some feedback. Hopefully we can work on this now :-) I updated the PR with focus and active state. The only last thing I can see it the knob remains blue with Maybe // Where to put this function ?
@function form-switch-bg-off-swtich($color) {
background-image: escape-svg(url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'><circle r='3' fill='#{$color}'/></svg>"));
}
// In_form-check.scss
.switch-off-#{state} {
// ...
@form-switch-bg-off-switch($value)
}Let me know if it could be ok for you. Thanks again for your review. |
|
You might use the existing Just be aware that |
|
I updated locally to have the knob matching the color when the check box in not checked. Is this what you had in mind? (note that the offset are due to firefox screenshot and everything is perfectly aligned on my screen I also tried to rephrase the documentation above. Is it clearer than my previous attempt? ^^ Thanks again for your time. |
|
Hi @ffoodd, I updated the knob color and active/focus outline too. Is it good for you? Maybe you have a solution to improve mine which I don't know? |
dc6eee3
to
703dde3
|
Hi @ffoodd, Any update on this? Thanks |
|
Sorry for the delay. Regarding the docs, I think it should be made clearer: maybe use a grid or something to show each variant and its states beside each other, as we do for buttons examples? On the Sass / CSS side, I think we'll need to align with our current progress using CSS custom properties. Your suggestion is a perfect candidate for such approach. I think your suggestion is valuable, but it may have to wait that we moved our forms to CSS custom properties. |
703dde3
to
c0ce10c
|
Thanks @ffoodd I made some updates to be more logic with the colors and when they are applied to better distinguish the status depending if we want to highlight the checked ( I am not sure on my selector line 127 which is a bit complex at first glance but is only here to revert some inheritance. Maybe there is a technique I don't know. I more a Symfony developer with some css knowledge and open to learn. I updated the documentation, this is how it's displayed now. Is it ok? But the html needed for this is a bit long/messy. Again, maybe there is a way I don't know to reduce the code? Thanks again for any advice you can give me. Have a merry Christmas a bit in advance too! |
Still things to improve but this is a really neat idea, thanks a lot for your work!
| <div class="row"> | ||
| <div class="col fw-bold">Checked status</div> | ||
| <div class="col fw-bold">Not checked status</div> | ||
| </div> |
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.
In fact I'd go for a much simpler presentation, like buttons examples: a single row of example, prededed with a heading (eg. "Themed switch" then switch-on and switch-off).
Would this look accurate to you?
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.
Yes I tried but due to longer labels I find this solution more elegant to display. And the special case where swich-on and switch-off can be applied at the same time is a bit harder to display.
I will try again your solution.
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.
scss/forms/_form-check.scss
Outdated
| } | ||
|
|
||
| &.switch-off-#{$state} { | ||
| &:not([class*="switch-on-"]) .form-check-input:checked { |
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.
Is &:not([class*="switch-on-"]) needed? What's its purpose?
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.
In case we want to customize both status, the switch-on- classes overrides the rules.
Maybe your solution will prevent this case.
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 was wrong about this. (this PR and what I've done is a bit old
This is to invert how the interface would look like when there is no switch-on class for a better emphasis of the switch-off case.
When the switch-off class is applied, the chosen color is visible when the checkbox is not checked. But if the user enables (checks) it, the color is the default primary one and the status becomes unclear. By adding this rule, it inverts how the switch looks like to emphases the unchecked status.
When the user enables the checkbox (so the status is "checked", or "on", the value would be submitted in a form)

When the user disable the checkbox (so the status is "unchecked", or "off", the value would not be submitted in a form)

When this rule is not added, the "checked" status looks like this, which is confusing:

|
@ffoodd The drawback of this refactor is that it requires more classes on the element. From a developer experience it's not very convenient. (the compiled css is also very important) Maybe the solution would be to go for something like this: [class*="switch-on"] {
...
@each ... {
&-#{$color} { ... }
}
}But I am not sure it exists (just tried but sass doesn't like it Let me know if you have an idea about this. |




Hi
I
createupdated this PR to fix issue #35001I would like to submit this PR for any comments before taking it further. Hopefully it's the good thing to do. Feel free to add any feedback.For example at the moment, contrast with other colors than white, not checked switch misses some contrast.Fixed with another variable
$form-switch-bg-off-imagewhich has an inverted color than the default one. (white instead of black basically)Before updating the PR:

After PR update:

I also not make any changes for disabled input too.I didn't make any changes for disabled input but results looks good to me.
I only create this PR to know if I am in the good direction and if it has any chance to be merged.I updated the documentation too. Let me know if some example needs to be removed and if the line 105 should not be wrapped. It has been done automatically by my IDE and leave as is as I didn't feel comfortable to horizontally scroll to read when editing.
Thanks
PS: my commit is not signed properly, I will sign it properly if I am allowed to go further.closes #35001
The text was updated successfully, but these errors were encountered: