1 // ::- Represents a submenu wrapping a group of elements that start
2 // hidden and expand to the right when hovered over or tapped.
3 import {prefix, renderItems} from "./menu-utils";
4 import crel from "crelt";
7 // :: ([MenuElement], ?Object)
8 // The following options are recognized:
10 // **`action`**`: function(FormData)`
11 // : The submission action to run when the form is submitted.
12 // **`canceler`**`: function`
13 // : The cancel action to run when the form is cancelled.
14 constructor(content, options) {
15 this.options = options || {};
16 this.content = Array.isArray(content) ? content : [content];
19 // :: (EditorView) → {dom: dom.Node, update: (EditorState) → bool}
20 // Renders the submenu.
22 const items = renderItems(this.content, view)
24 const formButtonCancel = crel("button", {class: prefix + "-dialog-button", type: "button"}, "Cancel");
25 const formButtonSave = crel("button", {class: prefix + "-dialog-button", type: "submit"}, "Save");
26 const footer = crel("div", {class: prefix + "-dialog-footer"}, formButtonCancel, formButtonSave);
27 const form = crel("form", {class: prefix + "-dialog-form", action: '#'}, items.dom, footer);
29 form.addEventListener('submit', event => {
30 event.preventDefault();
31 if (this.options.action) {
32 this.options.action(new FormData(form));
36 formButtonCancel.addEventListener('click', event => {
37 if (this.options.canceler) {
38 this.options.canceler();
42 function update(state) {
43 return items.update(state);
46 return {dom: form, update}
51 export default DialogForm;