UNPKG

geostyler

Version:
87 lines (86 loc) 2.69 kB
import { jsxs as d, jsx as t } from "react/jsx-runtime"; import { useState as h, useEffect as E } from "react"; import { Select as x, Card as m, Avatar as O } from "antd"; /* empty css */ import { useGeoStylerComposition as q, useGeoStylerLocale as w } from "../../../context/GeoStylerContext/GeoStylerContext.js"; const z = x.Option, D = (N) => { var p, u; const C = q("IconEditor"), v = { ...N, ...C }, { iconLibraries: n = [], selectedIconSrc: a, onIconSelect: g } = v, L = w("IconSelector"), [s, f] = h(), [o, y] = h(); E(() => { let e = {}; a && (e = G(a, n)), !((e == null ? void 0 : e.libIndex) === s || (e == null ? void 0 : e.iconIndex) === (o == null ? void 0 : o.iconIndex)) && (f(e.libIndex), y(e)); }, [a, n, s, o]); const G = (e, c) => { let r, I, S = !1; for (let l = 0; l < c.length; l++) { const b = c[l]; if (S) break; for (let i = 0; i < b.icons.length; i++) if (b.icons[i].src === e) { r = l, I = i, S = !0; break; } } return { libIndex: r, iconIndex: I }; }, j = (e) => { f(e); }, k = (e, c) => { let r = "gs-icon-selector-grid"; return o && o.libIndex === s && o.iconIndex === c && (r += " gs-icon-selector-grid-selected"), /* @__PURE__ */ d( m.Grid, { className: r, onClick: () => { g && g(e.src); }, children: [ /* @__PURE__ */ t( O, { className: "gs-icon-selector-grid-avatar", size: "default", src: e.src, alt: e.caption, shape: "square" } ), /* @__PURE__ */ t( m.Meta, { className: "gs-icon-selector-grid-description", description: e.caption } ) ] }, c.toString() ); }; return /* @__PURE__ */ d("div", { className: "gs-icon-selector", children: [ /* @__PURE__ */ d("div", { className: "gs-lib-row", children: [ /* @__PURE__ */ t("span", { className: "gs-label", children: `${L.librarySelectLabel}:` }), /* @__PURE__ */ t( x, { className: "gs-select", allowClear: !1, defaultValue: s, onChange: j, children: n.map((e, c) => /* @__PURE__ */ t(z, { value: c, children: e.name }, c.toString())) } ) ] }), /* @__PURE__ */ t(m, { className: "gs-icon-selector-card", children: (u = (p = n[s]) == null ? void 0 : p.icons) == null ? void 0 : u.map((e, c) => k(e, c)) }) ] }); }; export { D as IconSelector };