Git Product home page Git Product logo

gpickr's Introduction

This is a demo of how pickr could be implemented / integrated in other scenarios.

Usage

const gpickr = new GPickr({
    el: '.gradient-pickr',
    
    // Pre-defined stops. These are the default since at least two should be defined
    stops: [
        ['rgb(255,132,109)', 0],
        ['rgb(255,136,230)', 1]
    ]
})

GPickr Instance / static props

  • gpickr.Pickr - Pickr.
  • gpickr.addStop(color:String, loc:Number) - Add a color-stop.
  • gpickr.removeStop(v:String|Number|Stop) - Remove a color stop by color, location or stop-instance.
  • gpickr.getGradient() - Returns the current gradient as css string.
  • gpickr.getStops() - Array of stop objects with each a location between 0 and 1 as well as an rgba color value. The toString function is overridden and returns the array ready-to-use as comma seperated list, useful if a custom direcation / angle want to be used.
  • gpickr.getLinearAngle() - Returns the current selected angle. -1 if currently in radial-mode
  • gpickr.setLinearAngle(angle:Number) - Applies a new angle to the current linear gradient.
  • gpickr.getRadialPosition() - Returns the current chosen direction. null if currently in linear-mode
  • gpickr.setRadialPosition(position:String) - Sets a new position for the current radial-gradient.
  • gpickr.on(event:String, cb:Function) - Appends an event listener to the given corresponding event-name (see section Events), returns the gpickr instance so it can be chained.
  • gpickr.off(event:String, cb:Function) - Removes an event listener from the given corresponding event-name (see section Events), returns the gpickr instance so it can be chained.

Events

Event Description
init Initialization done - gpickr can be used
change User changed the gradient

Example:

gpickr.on('init', instance => {
    console.log('init', instance);
}).on('change', instance => {
    console.log('change', instance.getGradient());
});

gpickr's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gpickr's Issues

Parsing existing gradient-strings

I am trying to set a gradient color via javascript function using below gradient css

radial-gradient(circle at bottom right, rgba(66, 68, 90, 1) 0%,rgba(66, 68, 90, 1) 0%,rgba(255, 168, 125, 1) 0%,rgba(255, 69, 69, 1) 100%)

And JS is

gpickr.setGradient('radial-gradient(circle at bottom right, rgba(66, 68, 90, 1) 0%,rgba(66, 68, 90, 1) 0%,rgba(255, 168, 125, 1) 0%,rgba(255, 69, 69, 1) 100%)')

when the above code used the output should look like below

Correct Output

Instead the output looks like

Wrong Output

You can run the above JS in your demo via browser console and try

Error in setLinearAngle

There's an error in gpickr.js - setLinearAngle, lines 403/404:

angle = typeof angle === 'number' ? angle : (normalize.angleToDegrees(angle) || (this._angles.find(v => v.name === angle) || {}).angle);

when angle = '0deg', normalize.angleToDegrees(angle) returns (correctly) 0, but in this case in the expression this is considered as logical "false", so lines 403/404 return a value of 'undefined' !

I solved it in the following way:

if (typeof angle !== 'number') { if ((angle = normalize.angleToDegrees(angle)) === null) { angle = (this._angles.find(v => v.name === angle) || {}).angle; } }

Publish In NPM

Hi There

today I have successfully implemented/integrated this project into WPOnion but I am not able to install it via NPM. so my wponion's release is on hold. until this gets released in NPM.

I hope you can get this released soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.