@react-md/utils
Version:
General utils for react-md.
44 lines • 1.51 kB
JavaScript
import { getContrastRatio } from "./getContrastRatio";
/**
* The contrast ratio that can be used for large text where large text is
* considered 18pt or 14pt bold.
*/
export var LARGE_TEXT_CONTRAST_RATIO = 3;
/**
* The contrast ratio that can be used for normal text.
*/
export var NORMAL_TEXT_CONTRAST_RATIO = 4.5;
/**
* The AAA contrast ratio for passing WGAC 2.0 color contrast ratios.
*/
export var AAA_CONTRAST_RATIO = 7;
/**
* Checks if there is an acceptable contrast ratio between the background and
* foreground colors based on the provided compliance level.
*
* @param background - The background color to check against
* @param foreground - The foreground color to check against
* @param compliance - The compliance level to use or a custom number as a
* ratio.
* @returns true if there is enough contrast between the foreground and
* background colors for the provided compliance level.
*/
export function isContrastCompliant(background, foreground, compliance) {
if (compliance === void 0) { compliance = "normal"; }
var ratio;
switch (compliance) {
case "large":
ratio = LARGE_TEXT_CONTRAST_RATIO;
break;
case "normal":
ratio = NORMAL_TEXT_CONTRAST_RATIO;
break;
case "AAA":
ratio = AAA_CONTRAST_RATIO;
break;
default:
ratio = compliance;
}
return getContrastRatio(background, foreground) >= ratio;
}
//# sourceMappingURL=isContrastCompliant.js.map