Skip to content

Commit 830aa92

Browse files
committed
Adds a new opt for being able to add extra buttons in modals header. See #70423
1 parent 25fcccb commit 830aa92

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/elements/Modal/Modal.coffee

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class CUI.Modal extends CUI.LayerPane
1717
constructor: (opts) ->
1818
super(opts)
1919

20+
if @_header_buttons
21+
for btnOpts in @_header_buttons
22+
@__addCustomHeaderButton(btnOpts)
23+
2024
toggleFillScreenButton = CUI.Pane.getToggleFillScreenButton(tooltip: @_fill_screen_button_tooltip)
2125
@__addHeaderButton("fill_screen_button", toggleFillScreenButton)
2226

@@ -80,6 +84,9 @@ class CUI.Modal extends CUI.LayerPane
8084
check: "PlainObject"
8185
onToggleFillScreen:
8286
check: Function
87+
# custom buttons to add to the header
88+
header_buttons:
89+
check: Array
8390

8491
@mergeOpt "placement",
8592
default: "c"
@@ -106,6 +113,18 @@ class CUI.Modal extends CUI.LayerPane
106113
@append(btn, "header_right")
107114
return btn
108115

116+
__addCustomHeaderButton: (_btn) ->
117+
if CUI.util.isPlainObject(_btn)
118+
btn = new CUI.defaults.class.Button(_btn)
119+
else
120+
btn = _btn
121+
122+
CUI.util.assert(btn instanceof CUI.Button, "Modal.__addCustomHeaderButton", "Button needs to be instance of Button", btn: btn)
123+
CUI.util.assert(@__pane instanceof CUI.SimplePane, "new #{@__cls}", "opts.header_buttons can only be used if opts.pane is instance of SimplePane.", pane: @__pane, opts: @opts)
124+
125+
@append(btn, "header_right")
126+
return btn
127+
109128
__runOnAllButtons: (func) ->
110129
for el in CUI.dom.matchSelector(@__layer.DOM, ".cui-button,.cui-data-field")
111130
btn = CUI.dom.data(el, "element")

0 commit comments

Comments
 (0)