Ok so I needed a color picker that I could stick in an editable grid or just use as a form field, but I did not want to render the complete box with the little color squares in the form, and well, a grid is pretty tight on space.
I went ahead and designed a color picker combo box that puts the hex value in the input field and underlines it in the selected color. One of the notable features is the monitorMouseLeave method that is found in Ext.Element, this performs an action after the users mouse leaves an element after a preset amount of time. In the code below it is used to hide the drop down color fields after the user leaves the picker for half a second. This way we don’t force them to make a selection, but do not penalize them for coloring outside of the lines with their mouse.
Ext.define('Ext.ux.ColorPickerCombo', {
extend: 'Ext.form.field.Trigger',
alias: 'widget.colorcbo',
triggerTip: 'Please select a color.',
onTriggerClick: function() {
var me = this;
picker = Ext.create('Ext.picker.Color', {
pickerField: this,
ownerCt: this,
renderTo: document.body,
floating: true,
hidden: true,
focusOnShow: true,
style: {
backgroundColor: "#fff"
} ,
listeners: {
scope:this,
select: function(field, value, opts){
me.setValue('#' + value);
me.inputEl.setStyle({backgroundColor:value});
picker.hide();
},
show: function(field,opts){
field.getEl().monitorMouseLeave(500, field.hide, field);
}
}
});
picker.alignTo(me.inputEl, 'tl-bl?');
picker.show(me.inputEl);
}
});
