Skip to content

Add contrast() function to check contrast ratio for two colors #7944

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

Open
wants to merge 2 commits into
base: dev-2.0
Choose a base branch
from

Conversation

FerrinThreatt
Copy link

Resolves #6971

Changes:

Added a new contrast function that checks the color contrast ratio for two colors
This function allows users to see if their colors align with WCAG21 accessibility standards. There are supplementary double AA and triple AAA constants for provided as well.

PR Checklist

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks for making this change! For my own understanding / for possible future documentation, do you know how this handles colors with alpha?

@@ -25,7 +26,7 @@ import {

OKLab,
OKLCH as OKLCHSpace,

contrast,
Copy link
Contributor

Choose a reason for hiding this comment

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

cool, TIL colorjs has this built in!

* // Test for contrast
* let result = color1.contrast(color2)
*
* console.log(result)
Copy link
Contributor

Choose a reason for hiding this comment

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

On the p5.js reference, this will require users to open the console to see the result. Do you think we could show the result on the screen with something like text()?

* Checks if two colors contrast ratio is WCAG 2.1 compliant and returns the ratio
*
* @param {Color} other
* @returns {{ ratio: Number, passes: boolean }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if passes is using AA or AAA or something else?

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

Successfully merging this pull request may close these issues.

2 participants