@railzai/railz-visualizations
Version:
Railz.ai Visualizations
40 lines • 1.47 kB
JavaScript
/*!
* Accounting Data as a Service™ is the solution that makes sense of your business customers' financial data.
* Built with Stencil
* Copyright (c) FIS.
*/
import * as contrast from 'get-contrast';
import { isEmpty } from 'lodash-es';
import { errorLog, warnLog } from '../services/logger';
import Translations from '../config/translations/en.json';
/**
* Check if colors passed are accessibility friendly
* @param backgroundColor: background color
* @param foregroundColor: foreground color
* @param message: extra message if needed to describe the warning if any
*/
export const checkAccessibility = (backgroundColor, foregroundColor, message) => {
let accessible = true;
if (!isEmpty(backgroundColor) && !isEmpty(foregroundColor)) {
try {
const score = contrast.score(backgroundColor, foregroundColor);
if (!['AA', 'AAA'].includes(score)) {
accessible = false;
warnLog(message, { backgroundColor, foregroundColor }, Translations.RV_ACCESSIBILITY_FAILED_AA_AAA);
}
else if (!['AAA'].includes(score)) {
accessible = false;
warnLog(message, { backgroundColor, foregroundColor }, Translations.RV_ACCESSIBILITY_FAILED_AAA);
}
}
catch (e) {
accessible = false;
errorLog(message, { backgroundColor, foregroundColor }, Translations.RV_ACCESSIBILITY_CHECK_FAILED);
}
}
else {
accessible = false;
}
return accessible;
};
//# sourceMappingURL=accessibility.js.map