How to use the @ctrl/tinycolor.readability function in @ctrl/tinycolor

To help you get started, we’ve selected a few @ctrl/tinycolor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleChromeLabs / ProjectVisBug / app / features / accessibility.js View on Github external
let background  = getComputedBackgroundColor(el)

  const [ aa_contrast, aaa_contrast ] = [
    isReadable(background, foreground, { level: "AA", size: textSize.toLowerCase() }),
    isReadable(background, foreground, { level: "AAA", size: textSize.toLowerCase() })
  ]

  return foreground === background
    ? `🤷‍♂️ foreground matches background`
    : `
        <span>Color contrast</span>
        <span value="">
          <span style="background-color:${background};
            color:${foreground};">${Math.floor(readability(background, foreground)  * 100) / 100}</span>
        </span>
        <span>› AA ${textSize}</span>
        <span style="${aa_contrast ? 'color:green;' : 'color:red'}" value="">${aa_contrast ? '✓' : '×'}</span>
        <span>› AAA ${textSize}</span>
        <span style="${aaa_contrast ? 'color:green;' : 'color:red'}" value="">${aaa_contrast ? '✓' : '×'}</span>
      `
}

@ctrl/tinycolor

Fast, small color manipulation and conversion for JavaScript

MIT
Latest version published 7 months ago

Package Health Score

76 / 100
Full package analysis