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";
6 class DialogRadioOptions {
8 * Given inputOptions should be keyed by label, with values being values.
9 * Values of empty string will be treated as null.
10 * @param {Object} inputOptions
11 * @param {{label: string, id: string, attrs?: Object, value: function(PmEditorState): string|null}} options
13 constructor(inputOptions, options) {
14 this.inputOptions = inputOptions;
15 this.options = options || {};
18 // :: (EditorView) → {dom: dom.Node, update: (EditorState) → bool}
19 // Renders the submenu.
23 const optionInputLabels = Object.keys(this.inputOptions).map(label => {
24 const inputAttrs = Object.assign({
26 name: this.options.id,
27 value: this.inputOptions[label],
28 class: prefix + '-dialog-radio-option',
29 }, this.options.attrs || {});
30 const input = crel("input", inputAttrs);
32 return crel("label", input, label);
35 const optionInputWrap = crel("div", {class: prefix + '-dialog-radio-option-wrap'}, optionInputLabels);
37 const label = crel("label", {}, this.options.label);
38 const rowRap = crel("div", {class: prefix + '-dialog-form-row'}, label, optionInputWrap);
40 const update = (state) => {
41 const value = this.options.value(state);
42 for (const input of inputs) {
43 input.checked = (input.value === value || (value === null && input.value === ""));
48 return {dom: rowRap, update}
53 export default DialogRadioOptions;