@@ -14,9 +14,36 @@ class CUI.ColorInput extends CUI.Input
1414 @opts .leftControlElement = new CUI.Button
1515 tabindex : - 1
1616 onClick : (ev , btn ) =>
17- @__input .focus ()
17+ if @ isDisabled ()
18+ return
19+ @__colorPicker ? .click ()
1820 super ()
1921
22+ render : ->
23+ super ()
24+ @__colorPicker = CUI .dom .$element (" input" , " cui-color-picker-native" ,
25+ type : " color"
26+ tabindex : " -1"
27+ )
28+
29+ CUI .Events .listen
30+ node : @__colorPicker
31+ type : " input"
32+ call : =>
33+ @__input .value = @__colorPicker .value
34+ @ __toggleColor ()
35+
36+ CUI .Events .listen
37+ node : @__colorPicker
38+ type : " change"
39+ call : =>
40+ @__input .value = @__colorPicker .value
41+ @ __toggleColor ()
42+ new CUI.Event (type : " input" , node : @__input ).dispatch ()
43+
44+ CUI .dom .append (@DOM , @__colorPicker )
45+ @
46+
2047 onDataChanged : (ev , info ) ->
2148 super (ev, info)
2249 @ __toggleColor ()
@@ -28,12 +55,19 @@ class CUI.ColorInput extends CUI.Input
2855 else
2956 @_leftControlElement .DOM .style .setProperty (" --btn-background" , @__data [@_name ])
3057 @_leftControlElement .removeClass (' is-empty' )
58+ @ __syncColorPicker (@__data [@_name ])
59+
60+ __syncColorPicker : (value ) ->
61+ if not @__colorPicker
62+ return
63+ if value and / ^ #[0-9a-fA-F ] {6} $ / .test (value)
64+ @__colorPicker .value = value
3165
3266 __toggleColor : ->
3367 if @__input .value .length > 0 and @ __checkInputInternal ()
34- # Set the background color of the @_leftControlElement to the value of the input
3568 @_leftControlElement .DOM .style .setProperty (" --btn-background" , @__input .value )
3669 @_leftControlElement .removeClass (' is-empty' )
70+ @ __syncColorPicker (@__input .value )
3771 else
38- @_leftControlElement .DOM .style .removeProperty (" --btn-background" );
72+ @_leftControlElement .DOM .style .removeProperty (" --btn-background" )
3973 @_leftControlElement .addClass (' is-empty' )
0 commit comments