How to use the tinycolor2.mostReadable function in tinycolor2

To help you get started, we’ve selected a few tinycolor2 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 plotly / plotly.js / src / traces / parcats / parcats.js View on Github external
// Hover label text
    var hoverinfoParts = [];
    if(catViewModel.parcatsViewModel.hoverinfoItems.indexOf('count') !== -1) {
        hoverinfoParts.push(['Count:', labels.countLabel].join(' '));
    }
    if(catViewModel.parcatsViewModel.hoverinfoItems.indexOf('probability') !== -1) {
        hoverinfoParts.push('P(color ∩ ' + catLabel + '): ' + labels.probabilityLabel);
        hoverinfoParts.push('P(' + catLabel + ' | color): ' + pCatGivenColor.toFixed(3));
        hoverinfoParts.push('P(color | ' + catLabel + '): ' + pColorGivenCat.toFixed(3));
    }

    var hovertext = hoverinfoParts.join('<br>');

    // Compute text color
    var textColor = tinycolor.mostReadable(bandViewModel.color, ['black', 'white']);

    return {
        trace: trace,
        x: hoverCenterX - rootBBox.left,
        y: hoverCenterY - rootBBox.top,
        // name: 'NAME',
        text: hovertext,
        color: bandViewModel.color,
        borderColor: 'black',
        fontFamily: 'Monaco, "Courier New", monospace',
        fontColor: textColor,
        fontSize: 10,
        idealAlign: hoverLabelIdealAlign,
        hovertemplate: trace.hovertemplate,
        hovertemplateLabels: labels,
        eventData: [{
github apollographql / space-kit / src / Button / Button.tsx View on Github external
// Text color will always be the same for secondary buttons
  if (color === colors.white) {
    return colors.grey.darker;
  }

  switch (feel) {
    case "raised":
      // Set the base (meaning no pseudo-selectors) text color for raised
      // buttons. Otherwise return `undefined` to not change the color.
      //
      // We have some special logic for the raised color; set the text color to
      // be what is most readable between white and the default text color and
      // the _hover_ color's background. This is overrideable by the user, but
      // it shouldn't need to be.
      return !mode
        ? tinycolor
            .mostReadable(
              getHoverBackgroundColor({ color, feel, theme }),
              [colors.white, colors.grey.darker],
              {
                level: "AA",
                size: "small",
              }
            )
            .toString()
        : undefined;
    case "flat":
      if (color === defaultColor) {
        return theme === "dark" ? colors.grey.light : colors.grey.darker;
      }

      // We have a custom color and we're in dark mode, lighten the base and
github StoDevX / AAO-React-Native / source / views / streaming / radio / station-ksto.js View on Github external
// @flow

import * as React from 'react'
import {sto} from '../../../lib/colors'
import {TabBarIcon} from '@frogpond/navigation-tabs'
import {type TopLevelViewPropsType} from '../../types'
import * as logos from '../../../../images/streaming'
import {RadioControllerView} from './index'
import tinycolor from 'tinycolor2'
import {ThemeProvider} from '@frogpond/app-theme'
import {type PlayerTheme} from './types'

let tintColor = '#37a287'
const colors: PlayerTheme = {
	tintColor,
	buttonTextColor: tinycolor
		.mostReadable(tintColor, [sto.white, sto.black])
		.toRgbString(),
	textColor: tintColor,
	imageBorderColor: 'transparent',
	imageBackgroundColor: tinycolor(tintColor)
		.complement()
		.setAlpha(0.2)
		.toRgbString(),
}

export class KstoStationView extends React.Component {
	static navigationOptions = {
		tabBarLabel: 'KSTO',
		tabBarIcon: TabBarIcon('radio'),
	}
github azazdeaz / transhand / demo / src / iframe / prepare.js View on Github external
export default function scatterThings() {
  var colors = ['#7FDBFF', '#0074D9', '#001F3F', '#39CCCC', '#3D9970',
    '#FF4136', '#85144B', '#FF851B', '#B10DC9', '#FFDC00', '#F012BE',
    '#aaa', '#fff', '#ddd']

  var takeOne = arr =&gt; pullAt(arr, random(arr.length - 1))

  var rootNode = document.querySelector('#stuffs')
  document.body.style.backgroundColor = takeOne(colors)
  document.querySelector('#source &gt; a').style.color = tinycolor.mostReadable(
    document.body.style.backgroundColor,
    colors
  ).toHexString()
  // for (let j = 0; j &lt; 7; ++j) {
  //   createElement(63, 63, 'div', rootNode)
  // }

  createElement(
    242 + 132 * Math.random(),
    242 + 132 * Math.random(),
    'iframe',
    rootNode,
    function (e) {
      var iframe = e.target
      iframe.style.border = 'none'
      iframe.contentDocument.write('this is an iframe (WIP)')
github AdaptiveConsulting / ReactiveTraderCloud / src / client / src / rt-storybook / Palette / ColorGroup / ColorTile / ColorTile.tsx View on Github external
const getBestTextColor = (
  background: string,
  colorOptions: {
    [color: string]: string
  }
) => {
  return Color.mostReadable(background, Object.values(colorOptions)).toHexString()
}
github WordPress / gutenberg / packages / block-editor / src / components / colors / utils.js View on Github external
export function getMostReadableColor( colors, colorValue ) {
	return tinycolor.mostReadable(
		colorValue,
		map( colors, 'color' )
	).toHexString();
}
github material-foundation / material-remixer-js / src / lib / ColorUtils.ts View on Github external
static mostReadable(baseColor: any, colorList: any[]): string {
    colorList.map((color) => {
      return TinyColor(color);
    });
    return TinyColor.mostReadable(TinyColor(baseColor), colorList).toRgbString();
  }
}
github WordPress / gutenberg / packages / blocks / src / api / utils.js View on Github external
export function normalizeIconObject( icon ) {
	if ( isValidIcon( icon ) ) {
		return { src: icon };
	}

	if ( has( icon, [ 'background' ] ) ) {
		const tinyBgColor = tinycolor( icon.background );

		return {
			...icon,
			foreground: icon.foreground ? icon.foreground : mostReadable(
				tinyBgColor,
				ICON_COLORS,
				{ includeFallbackColors: true, level: 'AA', size: 'large' }
			).toHexString(),
			shadowColor: tinyBgColor.setAlpha( 0.3 ).toRgbString(),
		};
	}

	return icon;
}
github StoDevX / AAO-React-Native / modules / colors / util.js View on Github external
export function firstReadable(
	background: string,
	possibilities: Array,
) {
	possibilities = possibilities.map(c =&gt; tinycolor(c))
	let readable = possibilities.find(c =&gt; tinycolor.isReadable(c, background))
	if (readable) {
		return readable
	}
	return tinycolor.mostReadable(background, [black, white])
}