How to use the tinycolor2.fromRatio 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 raquelxmoss / cycle-color-picker / src / helpers.js View on Github external
export function getColorFromRGBA (state, channel, value) {
  const color = tinycolor.fromRatio(state.color).toRgb();
  color[channel] = value;

  return color;
}
github raquelxmoss / cycle-color-picker / src / view.js View on Github external
function renderSwatch (state) {
  const color = tinycolor.fromRatio(state.color);

  const swatchBackground = color.clone().setAlpha(state.color.a);
  const swatchStyle = {'background-color': tinycolor(swatchBackground).toRgbString()};

  return (
    div('.swatch', [
      div('.swatch-underlay', [
        div('.swatch-color', {style: swatchStyle})
      ])
    ])
  );
}
github JonDum / ractive-colorpicker / src / ractive-colorpicker.js View on Github external
var format = this.get('format');

                var r = this.get('r');
                var g = this.get('g');
                var b = this.get('b');

                var h = this.get('h');
                var s = this.get('s');
                var v = this.get('l');
                var a = this.get('a');

                var color;

                if(format == 'Hsl')
                    color = tinycolor.fromRatio({h:h, s:s, v:v, a:a});
                else
                    color = tinycolor.fromRatio({r:r, g:g, b:b, a:a});

                if(a < 1 && format == 'Hex')
                    format += '8';

                return color['to'+format+'String']()
            },
github raquelxmoss / cycle-color-picker / src / view.js View on Github external
function renderColorInputs (state) {
  const format = state.colorInputFormat.value;
  const color = tinycolor.fromRatio(state.color);

  return div('.color-display', [
    colorInputViews[format](color)
  ]);
}
github raquelxmoss / cycle-color-picker / src / view.js View on Github external
function renderAlphaInput (state) {
  const alphaIndicatorStyle = {
    left: `${state.alphaContainer.width * state.color.a}px`
  };

  const color = tinycolor.fromRatio(state.color);

  const gradientStart = color.clone().setAlpha(0);
  const gradientStyle = {background: `linear-gradient(to right, ${tinycolor(gradientStart).toRgbString()}  0%, ${color.toHexString()} 100%)`};

  return (
    div('.alpha-container', [
      div('.alpha', [
        div('.checkerboard'),
        div('.gradient-overlay', {style: gradientStyle}),
        div('.alpha-indicator', {style: alphaIndicatorStyle})
      ])
    ])
  );
}
github dy / settings-panel / components / color.js View on Github external
})

  icon.onmouseover = function () {
    picker.$el.style.display = ''
  }

  var initial = opts.initial
  switch (opts.format) {
    case 'rgb':
      initial = tinycolor(initial).toHexString()
      break
    case 'hex':
      initial = tinycolor(initial).toHexString()
      break
    case 'array':
      initial = tinycolor.fromRatio({r: initial[0], g: initial[1], b: initial[2]}).toHexString()
      break
    default:
      break
  }

  var picker = new ColorPicker({
    el: icon,
    color: initial,
    background: theme.background1,
    width: 125,
    height: 100
  })

  css(picker.$el, {
    marginTop: '2em',
    display: 'none',
github opencolor-tools / sketch-opencolor / src / utils / sketch-dom.js View on Github external
export function hexColor (color) {
  if (color) {
    return tinycolor.fromRatio({r: color.red(), g: color.green(), b: color.blue()}).toHexString().toUpperCase()
  } else {
    return null
  }
}
github JonDum / ractive-colorpicker / src / ractive-colorpicker.js View on Github external
self.observe('h s l', function() {

            var h = this.get('h');
            var s = this.get('s');
            var v = this.get('l');

            var color = tinycolor.fromRatio({h:h, s:s, v:v});

            var rgb = color.toRgb();

            self.set({
                r: rgb.r,
                g: rgb.g,
                b: rgb.b,
            });

        }, {init: false});