1 | import { isObject } from "d3-let";
|
2 |
|
3 | const componentsFromType = {
|
4 | text: "input",
|
5 | email: "input",
|
6 | password: "input",
|
7 | checkbox: "input",
|
8 | number: "input",
|
9 | date: "input",
|
10 | url: "input",
|
11 | "datetime-local": "input"
|
12 | };
|
13 |
|
14 | export const formComponent = child => {
|
15 | var type = child.type || "text";
|
16 | return componentsFromType[type] || type;
|
17 | };
|
18 |
|
19 | export const addAttributes = (el, attributes) => {
|
20 | var expr, attr;
|
21 |
|
22 | if (!isObject(attributes)) return;
|
23 |
|
24 | for (attr in attributes) {
|
25 | expr = attributes[attr];
|
26 | if (isObject(expr)) expr = JSON.stringify(expr);
|
27 | el.attr(attr, expr || "");
|
28 | }
|
29 | };
|
30 |
|
31 | export function formChild(child) {
|
32 | var component = formComponent(child);
|
33 | return document.createElement(`d3-form-${component}`);
|
34 | }
|