geostyler
Version:
Framework for styling geodata
75 lines (74 loc) • 2.1 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 C, Input as G } from "antd";
import { useGeoStylerLocale as L, useGeoStylerData as R } from "../../../context/GeoStylerContext/GeoStylerContext.js";
const $ = y.Option, q = ({
value: l,
hideAttributeType: u = !1,
attributeNameFilter: a = () => !0,
attributeNameMappingFunction: i = (o) => o,
validateStatus: f = "success",
onAttributeChange: p,
size: d
}) => {
const o = L("AttributeCombo"), c = R(), [m, E] = g(), [h, b] = g(), r = O(null);
x(() => {
r && r.current && r.current.input && (r.current.input.selectionStart = m, r.current.input.selectionEnd = h);
}, [m, h, l]);
const D = 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(a).map((e) => {
const S = i(e);
return /* @__PURE__ */ n(
$,
{
value: e,
children: u ? S : `${S} (${t[e].type})`
},
e
);
});
}
return [];
}, [c, a, i, u]), I = f !== "success" ? o.help : null;
return /* @__PURE__ */ n("div", { className: "gs-attribute-combo", children: /* @__PURE__ */ n(
C.Item,
{
label: o.label,
colon: !1,
validateStatus: f,
help: I,
children: c ? /* @__PURE__ */ n(
y,
{
value: l,
onChange: p,
placeholder: o.placeholder,
size: d,
children: D
}
) : /* @__PURE__ */ n(
G,
{
ref: r,
draggable: !0,
onDragStart: (t) => t.preventDefault(),
value: l,
placeholder: o.placeholder,
size: d,
onChange: (t) => {
p && p(t.target.value);
const s = t.target.selectionStart, e = t.target.selectionEnd;
E(s), b(e);
}
}
)
}
) });
};
export {
q as AttributeCombo
};