renderEditPanel = (frame, handleChange) => {
const template = (inputs) => {
return htl.html`
<div style="display: flex; flex-direction: column;">
${inputs}
</div>`;
};
const selects = EDITABLES.map(({ id, title, options }) => {
const select = Inputs.select(options, {
label: title,
value: frame.getAttribute(id)
});
const input = d3.select(select).on("input", ({ target: { value } }) => {
const option = options[value];
frame.setAttribute(id, option);
handleChange();
});
input.style("width", "15em");
input.select("label").style("width", "4em");
input.select("select").style("width", "10em");
return select;
});
const openButton = renderButton(
"◘"
);
const closeButton = renderRemoveButton(null, null, "align-self: end;");
const panel = htl.html`
<div style="
display: flex;
padding: 2em;
justify-content: end;
position: absolute;
padding: 0.5em;
border-radius: 4px;
background: #fff;
background: pink;
bottom: 0px;
">
${closeButton}
${Inputs.form(selects, { template })}
</div>`;
const panelD3 = d3.select(panel);
const openButtonD3 = d3.select(openButton);
let showPanel = false;
const toggleShow = () => {
showPanel = !showPanel;
openButtonD3.style("visibility", showPanel ? "hidden" : "visible");
panelD3.style("display", showPanel ? "initial" : "none");
};
d3.select(closeButton).on("click", toggleShow);
d3.select(openButton).on("click", toggleShow);
toggleShow();
return htl.html`
<div style="position: relative; z-index: 2;">
${panel}
${openButton}
</div>`;
}