simonwep / pickr

🎨 Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!
https://simonwep.github.io/pickr
MIT License
4.31k stars 284 forks source link

Please add a "copy" button in this picker #129

Open AryanJaiswal opened 5 years ago

AryanJaiswal commented 5 years ago

Requesting a feature to copy the code in the input box

AryanJaiswal commented 5 years ago

And also how to change the box size that should be clicked to open the picker

simonwep commented 5 years ago

You can style .pcr-button or use useAsButton to create your own :)

saeed74 commented 3 years ago

I changed save btn to copy with listeners:

    pickr.on('save', (color, instance) => {

        var data = $('.pcr-result').val();
        copyToClipboard(data);

    });

copyToClipboard function:

function copyToClipboard(text) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val(text).select();
    document.execCommand("copy");
    $temp.remove();
}

you can also change text of SAVE to COPY if you want:

const pickr = Pickr.create({
    el: '.mepickr',
    theme: 'nano',
    swatches: [
        '#F44336',
        '#F9C70E',
        '#2AB3D1',
        '#0C32F5',
        '#D11AFF',
        '#1FD4C3',
        '#15C083'
    ],
    components: {
        preview: true,
        opacity: true,
        hue: true,
        interaction: {
            hex: true,
            rgba: false,
            hsla: false,
            hsva: false,
            cmyk: false,
            input: true,
            clear: false,
            save: true
        }
    },
    i18n: {
       'btn:save': 'Copy'
    }
});