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, randHtmlId} from "./menu-utils";
4 import crel from "crelt";
8 // The following options are recognized:
10 // **`label`**`: string`
11 // : The label to show for the input.
13 // : The id to use for this input
14 // **`attrs`**`: Object`
15 // : The attributes to add to the input element.
16 // **`value`**`: function(state) -> string`
17 // : The getter for the input value.
18 constructor(options) {
19 this.options = options || {};
22 // :: (EditorView) → {dom: dom.Node, update: (EditorState) → bool}
23 // Renders the submenu.
25 const id = randHtmlId();
26 const inputAttrs = Object.assign({type: "text", name: this.options.id, id: this.options.id}, this.options.attrs || {})
27 const input = crel("input", inputAttrs);
28 const label = crel("label", {for: id}, this.options.label);
30 const rowRap = crel("div", {class: prefix + '-dialog-form-row'}, label, input);
32 const update = (state) => {
33 input.value = this.options.value(state);
37 return {dom: rowRap, update}
42 export default DialogInput;