geostyler
Version:
Framework for styling geodata
77 lines (76 loc) • 2.2 kB
JavaScript
import { jsx as n } from "react/jsx-runtime";
import { useState as g, useRef as O, useLayoutEffect as x, useMemo as j } from "react";
import { Select as y, Form as G, Input as L } from "antd";
import { useGeoStylerLocale as R, useGeoStylerData as $ } from "../../../context/GeoStylerContext/GeoStylerContext.js";
import { getFormItemConfig as k } from "../../../Util/FormItemUtil.js";
const w = y.Option, H = ({
value: l,
hideAttributeType: u = !1,
attributeNameFilter: i = () => !0,
attributeNameMappingFunction: a = (o) => o,
validateStatus: f = "success",
onAttributeChange: p,
size: m
}) => {
const o = R("AttributeCombo"), c = $(), [d, E] = g(), [h, b] = g(), r = O(null);
x(() => {
r && r.current && r.current.input && (r.current.input.selectionStart = d, r.current.input.selectionEnd = h);
}, [d, h, l]);
const I = j(() => {
if (c) {
const t = c.schema.properties, s = [];
for (const e in t)
Object.prototype.hasOwnProperty.call(t, e) && s.push(e);
return s.filter(i).map((e) => {
const S = a(e);
return /* @__PURE__ */ n(
w,
{
value: e,
children: u ? S : `${S} (${t[e].type})`
},
e
);
});
}
return [];
}, [c, i, a, u]), C = f !== "success" ? o.help : null, D = k();
return /* @__PURE__ */ n("div", { className: "gs-attribute-combo", children: /* @__PURE__ */ n(
G.Item,
{
...D,
label: o.label,
colon: !1,
validateStatus: f,
help: C,
children: c ? /* @__PURE__ */ n(
y,
{
value: l,
onChange: p,
placeholder: o.placeholder,
size: m,
children: I
}
) : /* @__PURE__ */ n(
L,
{
ref: r,
draggable: !0,
onDragStart: (t) => t.preventDefault(),
value: l,
placeholder: o.placeholder,
size: m,
onChange: (t) => {
p && p(t.target.value);
const s = t.target.selectionStart, e = t.target.selectionEnd;
E(s), b(e);
}
}
)
}
) });
};
export {
H as AttributeCombo
};