Giter Club home page Giter Club logo

pickr's Introduction

Logo

Flat, Simple, Hackable Color-Picker.

License MIT Webpack No dependencies Build Status npm package Current version


Demo

Fully Featured demo


Features

  • Simple usage
  • No jQuery
  • No dependencies
  • Multiple color representations
  • Color comparison
  • Opacity control
  • Supports touch devices
  • Nodejs support

Install

Via npm

$ npm install pickr-widget --save

Link styles and add scripts

<link rel="stylesheet" href="node_modules/pickr/dist/pickr.min.css"/>
<script src="node_modules/pickr/dist/pickr.min.js"></script>

Usage

const pickr = Pickr.create({
    el: '.color-picker'
});

Optional options

const pickr = new Pickr({

    // Selector or element which will be replaced with the actual color-picker
    el: '.color-picker',
    
    // Default color
    default: 'fff',

    // Defines the position of the color-picker. Available options are
    // top, left and middle relativ to the picker button.
    position: 'middle',

    // Show or hide specific components.
    // By default only the palette (and the save button) is visible.
    components: {

        preview: true, // Left side color comparison
        opacity: true, // Opacity slider
        hue: true,     // Hue slider

        // Bottom output bar, theoretically you could use 'true' as propery.
        // But this would also hide the save-button.
        output: {
            hex: true,  // hex option  (hexadecimal representation of the rgb value)
            rgba: true, // rgba option (red green blue and alpha)
            hsla: true, // hsla option (hue saturation lightness and alpha)
            hsva: true, // hsva option (hue saturation value and alpha)
            cmyk: true, // cmyk option (cyan mangenta yellow key )
            input: true // input / output element
        },
    },


    // User has changed the color
    onChange(hsva, instance) {
        hsva;     // HSVa color object
        instance; // Current Pickr instance
    },

    // User has clicked the save button
    onSave(hsva, instance) {
        // same as onChange
    }
});

The HSVaColor object

As default color representation is hsva (hue, saturation, value and alpha) used, but you can also convert it to other formats as listed below.

  • hsva.toHSVA() - Converts the object to a hsva string / array.
  • hsva.toHSLA() - Converts the object to a hsla string / array.
  • hsva.toRGBA() - Converts the object to a rgba string / array.
  • hsva.toHEX() - Converts the object to a hexa-decimal string / array.
  • hsva.toCMYK() - Converts the object to a cymk string / array.
  • hsva.clone() - Clones the color object.

The toString() is overriden so you can get a color representaion string.

hsva.toRGBA(); // Returns [r, g, b, a]
hsva.toRGBA().toString();     // Returns rgba(r, g, b, a)

Methods

  • pickr.setHSVA(h:Number,s:Number,v:Number,a:Float) - Set an color.
  • pickr.setColor(string:String) - Parses a string which represents a color
  • pickr.show() - Shows the color-picker.
  • pickr.hide() - Hides the color-picker.
  • pickr.cancel() - Cancels the current color picking.
  • pickr.getRoot():HTMLElement - Returns the root DOM-Element of the color-picker.
  • pickr.getColor():HSVaColor - Returns the current HSVaColor object.

Static methods

Pickr

  • Pickr.create(options:Object):Pickr - Creates a new instance.

Pickr.utils

  • on(el:HTMLElement, event:String, fn:Function[, options :Object]) - Attach an event handler function.
  • off(el:HTMLElement, event:String, fn:Function[, options :Object]) - Remove an event handler.
  • createElementFromString(html:String):HTMLElement - Creates an new HTML Element out of this string.
  • eventPath(evt:Event):[HTMLElement] - A polyfill for the event-path event propery.

pickr's People

Contributors

simonwep avatar

Watchers

 avatar  avatar  avatar

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.