UNPKG

geoiq-frontend-ui-kit

Version:

This project is a UI kit for GeoIQ's frontend. It's built with React, TypeScript, and Vite.

91 lines (90 loc) 3.25 kB
import t from "react"; import { Typography as u } from "./index.es17.js"; import { Button as p } from "./index.es7.js"; import { FormField as x } from "./index.es150.js"; import { Plus as E } from "lucide-react"; import { useFormValues as v } from "./index.es146.js"; const R = ({ field: n }) => { const { values: i, setValue: h, setFormValues: y } = v(), m = (() => { const r = [], s = `${n.id}||`, o = /* @__PURE__ */ new Set(); Object.keys(i).forEach((e) => { if (e.startsWith(s)) { const a = e.match(new RegExp(`^${n.id}\\|\\|(\\d+)\\|\\|`)); a && a[1] && o.add(parseInt(a[1])); } }); const l = Array.from(o).sort((e, a) => e - a); for (const e of l) { const a = {}; for (const c of n.options) { const d = `${n.id}||${e}||${c.id}`; d in i && (a[c.id] = i[d]); } r.push(a); } return r; })(), f = () => { const r = m.length; n.options.forEach((s) => { h(`${n.id}||${r}||${s.id}`, void 0); }); }, $ = (r) => { const s = { ...i }, o = `${n.id}||`; Object.keys(i).filter( (e) => e.startsWith(o) ).forEach((e) => { const a = e.match(new RegExp(`^${n.id}\\|\\|(\\d+)\\|\\|`)); if (a && a[1]) { const c = parseInt(a[1]); if (c === r) delete s[e]; else if (c > r) { const d = e.substring( e.indexOf("||", o.length) ), g = `${n.id}||${c - 1}${d}`; s[g] = i[e], delete s[e]; } } }), y(s); }; return /* @__PURE__ */ t.createElement("div", { className: "flex flex-col gap-4" }, m.length === 0 && /* @__PURE__ */ t.createElement("div", { className: "flex items-center justify-between" }, /* @__PURE__ */ t.createElement(u, { variant: "body1", className: "text-light-4" }, "No entry added yet."), /* @__PURE__ */ t.createElement( p, { size: "sm", prefixIcon: /* @__PURE__ */ t.createElement(E, { size: 20 }), variant: "secondary", onClick: f, className: "capitalize w-fit", title: "Add " } )), m.map((r, s) => /* @__PURE__ */ t.createElement("div", { key: `${n.id}-entry-${s}` }, /* @__PURE__ */ t.createElement("div", { className: "flex items-center justify-between mb-3" }, /* @__PURE__ */ t.createElement(u, { variant: "body2", className: "text-light-4" }, "Entry ", s + 1), /* @__PURE__ */ t.createElement( p, { size: "sm", variant: "link-secondary", onClick: () => $(s), className: "w-fit text-danger-1" }, "Remove" )), /* @__PURE__ */ t.createElement("div", { className: "flex flex-col gap-3" }, n.options.map((o) => { const l = `${n.id}||${s}||${o.id}`, e = { ...o, id: l }; return /* @__PURE__ */ t.createElement(x, { key: l, field: e }); })))), m.length ? /* @__PURE__ */ t.createElement("div", { className: "flex justify-end" }, /* @__PURE__ */ t.createElement( p, { size: "sm", prefixIcon: /* @__PURE__ */ t.createElement(E, { size: 20 }), variant: "secondary", onClick: f, className: "mt-2 capitalize w-fit", title: `Add more ${n.name}` } )) : null); }; export { R as RepeatableGroup }; //# sourceMappingURL=index.es155.js.map