I have created a custom colorpicker list button widget, which should emulate the oh-colorpicker with openIn set to “popup”, but with the possibility to fully customize the popup window.
Since I wanted to show the currently set color in a box I’ve had to fiddle around with the HSB values to convert them to CSS HSL or RGB values and I’ve come up with a working solution:
- component: Label
config:
style:
width: 32px
height: 32px
border-radius: 5px
background-color: >
= "hsl(" + items[props.colorItem].state.split(",")[0] + "," + ( ((2 - items[props.colorItem].state.split(",")[1] / 100) * items[props.colorItem].state.split(",")[2] / 2) < 50
? Math.round( items[props.colorItem].state.split(",")[1] / (200 - items[props.colorItem].state.split(",")[1]) * 100 )
: Math.round( items[props.colorItem].state.split(",")[1] * items[props.colorItem].state.split(",")[2] / (200 - ((2 - items[props.colorItem].state.split(",")[1] / 100) * items[props.colorItem].state.split(",")[2] / 2) * 2) )
)
+ "%," + Math.round((2 - items[props.colorItem].state.split(",")[1] / 100) * items[props.colorItem].state.split(",")[2] / 2) + "%)"
The background-color part (looks awful doesn’t it?) basically emulates the following JavaScript:
var l = (2 - hsv.s / 100) * hsv.v / 2;
var h = hsv.h
var s = l < 50 ? hsv.s / (200 - hsv.s) * 100 : hsv.s * hsv.v / (200 - l * 2)
return "hsl(" + h + "," + s + "%," + l + "%)"
Is there any known possibility to add a chunk of javascript to the page or to set an intermediate variable inside the expression?