Skip to content
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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

@flohw
Copy link

@flohw flohw commented Sep 17, 2021

Hi

I create updated this PR to fix issue #35001 I 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-image which has an inverted color than the default one. (white instead of black basically)

Before updating the PR:
image

After PR update:
image

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

@flohw flohw requested a review from as a code owner Sep 17, 2021
@flohw flohw marked this pull request as draft Sep 17, 2021
@flohw flohw changed the title [Draft] Allow to customise form-switch colors Allow to customise form-switch colors Sep 17, 2021
@flohw flohw force-pushed the feature/custom-switch-with-theme-colors branch from 4c4e81e to 4c5ff2f Sep 22, 2021
@flohw
Copy link
Author

@flohw flohw commented Sep 24, 2021

@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

@flohw flohw force-pushed the feature/custom-switch-with-theme-colors branch 6 times, most recently from b63b325 to 142249c Oct 6, 2021
@flohw flohw marked this pull request as ready for review Oct 6, 2021
@flohw
Copy link
Author

@flohw flohw commented Oct 6, 2021

Hello here (maybe @GeoSot ?)

I updated my PR with the complete implementation. Hopefully this can be merged soon.

Thank you

@GeoSot
Copy link
Member

@GeoSot GeoSot commented Oct 6, 2021

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
I guess, they will prioritize it and evaluate it eventually 😃

@flohw
Copy link
Author

@flohw flohw commented Oct 20, 2021

Hello there,
One month after opening this pr for review and then completing it with the hope to have more interest I still have no clue on what this PR will become.

Hopefully this time I will have some feedback.

Thanks.

@flohw
Copy link
Author

@flohw flohw commented Nov 19, 2021

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.
Copy link
Member

@ffoodd ffoodd Nov 20, 2021

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. :)

Copy link
Author

@flohw flohw Nov 22, 2021

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"?

@ffoodd
Copy link
Member

@ffoodd ffoodd commented Nov 20, 2021

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?

@flohw
Copy link
Author

@flohw flohw commented Nov 22, 2021

@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 .swtich-<theme-color> only. I think we can make a function to colorize it properly but not sure how to implement it properly.

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.

@ffoodd
Copy link
Member

@ffoodd ffoodd commented Nov 22, 2021

You might use the existing str-replace() function instead, to replace the color used in the main SVG variable with the theme color.

Just be aware that escape-svg() replaces # with %23.

@flohw
Copy link
Author

@flohw flohw commented Nov 22, 2021

I updated locally to have the knob matching the color when the check box in not checked.

image

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.

@flohw
Copy link
Author

@flohw flohw commented Nov 22, 2021

Here is another update for the off colored case when the checkbox is not checked.
I alse added the colored borders.
image

WDYT?

@flohw
Copy link
Author

@flohw flohw commented Nov 24, 2021

Hi @ffoodd,

I updated the knob color and active/focus outline too.
After some other check, I didn't apply what I did on .switch-off-* yesterday because it breaks the possibility to have .switch-<color>.switch-off-<another color>. So .switch-off-* are colored when the checkbox is not checked and default main color when checked.

Is it good for you? Maybe you have a solution to improve mine which I don't know?

@flohw flohw force-pushed the feature/custom-switch-with-theme-colors branch 3 times, most recently from dc6eee3 to 703dde3 Nov 24, 2021
@flohw
Copy link
Author

@flohw flohw commented Dec 6, 2021

Hi @ffoodd,

Any update on this?

Thanks

@ffoodd
Copy link
Member

@ffoodd ffoodd commented Dec 7, 2021

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.

@flohw flohw force-pushed the feature/custom-switch-with-theme-colors branch from 703dde3 to c0ce10c Dec 23, 2021
@flohw
Copy link
Author

@flohw flohw commented Dec 23, 2021

Thanks @ffoodd
I subscribed to the issue to know when I can rework this PR.

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 (.switch-on-*) or not checked (.switch-off-*).

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?
image

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! 🎅

Copy link
Member

@ffoodd ffoodd left a comment

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>
Copy link
Member

@ffoodd ffoodd Feb 8, 2022

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?

Copy link
Author

@flohw flohw Feb 8, 2022

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.

Copy link
Author

@flohw flohw Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is another attempt but I am not super convinced: by reading/seeing this I don't really know which use cases could be covered. But this might not what the documentation is meant for, isn't it?
image

}

&.switch-off-#{$state} {
&:not([class*="switch-on-"]) .form-check-input:checked {
Copy link
Member

@ffoodd ffoodd Feb 8, 2022

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?

Copy link
Author

@flohw flohw Feb 8, 2022

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.

Copy link
Author

@flohw flohw Feb 8, 2022

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)
image

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

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

scss/forms/_form-check.scss Outdated Show resolved Hide resolved
scss/forms/_form-check.scss Outdated Show resolved Hide resolved
@flohw
Copy link
Author

@flohw flohw commented Feb 8, 2022

@ffoodd
I just pushed the refactor and marked as resolved the related comments while keeping open where I think the discussion should continue 🙂

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 😅) and I am also not sure frontend developers like this kind of selector a lot 😅.

Let me know if you have an idea about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants