claviska / jquery-minicolors

jQuery MiniColors Plugin
MIT License
956 stars 312 forks source link

Allow for objects in swatches array (optional) #250

Closed exside closed 6 years ago

exside commented 6 years ago

This give the possibility to add a title/description/color name to predefined colors, often clients ask for that if they have to follow some kind of corporate style guide...

rather simple change, it is now possible to specify the swatches option like that:

$colorinput.minicolors({
    // ... other options
    swatches: [ // predefined colors
        {name: 'deep-space (very dark blue)', color: '#0D2345'},
        {name: 'some-blue (corporate color)', color: '#0082CA'},
        {name: 'green-apple (very sour)', color: '#05DCAC'}
    ]
});

backwards compatibility is of course there as it now can deal with objects if passed, otherwise it will just work like before.

If an object like above is passed the description/text/name whatever we want to call it will be added as a simple title attribute to the predefined color swatches in the picker and will be shown on mouseover (stay a little longer over it, nothing changed there in the default browser behaviour).

exside commented 6 years ago

Thanks for merging!