After transitioning to Bootstrap 5, I observed a unique feature where an algorithm determines the text color for buttons when they are hovered or active.
For instance:
- For a primary color of black, hovering over the button changes the background to black while the text becomes white.
- If the primary color is white, the background turns white upon hover with black text.
- When the primary color is something like green, Bootstrap relies on the
min-contrast-ratio
variable to make the decision.
As I am developing a theme builder, I would like to replicate this behavior using JavaScript. However, I am unsure of how to execute it. The Bootstrap documentation mentions the use of a WCAG 2.1 algorithm for this purpose, but I have been unable to locate any resources on implementing this algorithm in JavaScript.
I attempted to review the Bootstrap source code, but my limited understanding of SCSS left me perplexed. If anyone could provide guidance on how to achieve this effect, I would greatly appreciate it.