Skip to content

Commit a51e5b5

Browse files
committed
Color Input and Icon Input:
- Adds two new input types, one for icons and another for colors, both are dynamically updated for show the actual value. See #74630
1 parent 4342b9a commit a51e5b5

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

src/elements/Input/ColorInput.coffee

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
###
2+
* coffeescript-ui - Coffeescript User Interface System (CUI)
3+
* Copyright (c) 2013 - 2025 Programmfabrik GmbH
4+
* MIT Licence
5+
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
6+
###
7+
8+
class CUI.ColorInput extends CUI.Input
9+
10+
initOpts: ->
11+
super()
12+
13+
readOpts: ->
14+
@opts.leftControlElement = new CUI.Button
15+
onClick: (ev, btn) =>
16+
@__input.focus()
17+
super()
18+
19+
onDataChanged: (ev, info) ->
20+
super(ev, info)
21+
@__toggleColor()
22+
23+
initValue: ->
24+
super()
25+
if not @__data[@_name] or @__data[@_name].length == 0
26+
@_leftControlElement.hide(true)
27+
else
28+
@_leftControlElement.DOM.style.backgroundColor = @__data[@_name]
29+
@_leftControlElement.show(true)
30+
31+
__toggleColor: ->
32+
if @__input.value.length > 0 and @__checkInputInternal()
33+
# Set the background color of the @_leftControlElement to the value of the input
34+
@_leftControlElement.DOM.style.backgroundColor = @__input.value
35+
@_leftControlElement.show(true)
36+
else
37+
@_leftControlElement.hide(true)

src/elements/Input/IconInput.coffee

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
###
2+
* coffeescript-ui - Coffeescript User Interface System (CUI)
3+
* Copyright (c) 2013 - 2025 Programmfabrik GmbH
4+
* MIT Licence
5+
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
6+
###
7+
8+
class CUI.IconInput extends CUI.Input
9+
10+
initOpts: ->
11+
super()
12+
13+
readOpts: ->
14+
@opts.leftControlElement = new CUI.Button
15+
icon: "fa-star"
16+
onClick: (ev, btn) =>
17+
@__input.focus()
18+
super()
19+
20+
onDataChanged: (ev, info) ->
21+
super(ev, info)
22+
@__toggleIcon()
23+
24+
initValue: ->
25+
super()
26+
if not @__data[@_name] or @__data[@_name].length == 0
27+
@_leftControlElement.hide(true)
28+
else
29+
@_leftControlElement.setIcon(@__data[@_name])
30+
31+
__toggleIcon: ->
32+
if @__input.value.length > 0
33+
@_leftControlElement.setIcon(@__input.value)
34+
@_leftControlElement.show(true)
35+
else
36+
@_leftControlElement.setIcon("")
37+
@_leftControlElement.hide(true)

src/elements/Input/Input.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class CUI.Input extends CUI.DataFieldInput
153153
check: ["code"]
154154
controlElement:
155155
check: (v) -> v instanceof CUI.DOMElement
156+
leftControlElement:
157+
check: (v) -> v instanceof CUI.DOMElement
156158

157159
readOpts: ->
158160

@@ -951,6 +953,10 @@ class CUI.Input extends CUI.DataFieldInput
951953
CUI.dom.addClass(@_controlElement, 'cui-input-control-element')
952954
@append(@_controlElement, @getTemplateKeyForRender())
953955

956+
if @_leftControlElement
957+
CUI.dom.addClass(@_leftControlElement, 'cui-input-control-element')
958+
@prepend(@_leftControlElement, @getTemplateKeyForRender())
959+
954960
# @append(@getChangedMarker(), @getTemplateKeyForRender())
955961

956962
for k in ["empty", "invalid", "valid"]

src/index.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ require('./elements/Input/InputBlock.coffee')
100100
require('./elements/Input/NumberInputBlock.coffee')
101101
require('./elements/Input/NumberInput.coffee')
102102
require('./elements/Input/EmailInput.coffee')
103+
require('./elements/Input/IconInput.coffee')
104+
require('./elements/Input/ColorInput.coffee')
103105
require('./elements/Input/CodeInput.coffee')
104106
require('./elements/DateTime/DateTime.coffee')
105107
require('./elements/DateTime/Timezone.coffee')

0 commit comments

Comments
 (0)