UNPKG

geoiq-frontend-ui-kit

Version:

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

135 lines (134 loc) 5.06 kB
import * as e from "react"; import { useState as $, useRef as T } from "react"; import { Input as x } from "./index11.es.js"; import { Typography as g } from "./index19.es.js"; import "./index35.es.js"; import { useToast as R } from "./index86.es.js"; import { Spinner as U } from "./index63.es.js"; import { Upload as I, Pen as z, X as C } from "lucide-react"; import { useFormValues as M } from "./index138.es.js"; const W = ({ id: p, onChange: o, value: r = [], accept: E = "image/*", error: u, maxImages: l = 20, placeholder: f }) => { const { onAssetUpload: h, onToggleImageEditor: y } = M(), { toast: c } = R(), [i, b] = $(!1), m = T(null), N = async (a) => { const t = a.target.files; if (!(!t?.length || i)) { if (r.length + t.length > l) { c({ title: "Alert!", description: `Maximum ${l} images allowed.`, icon: "warning" }); return; } if (h) { b(!0); try { const s = Array.from(t).map((d) => h(d)), A = (await Promise.all(s)).map((d) => ({ ...d, tag: "" })); o([...r, ...A]), c({ title: "Alert!", description: `${t.length} ${t.length === 1 ? "image" : "images"} uploaded successfully.`, icon: "success" }); } catch { c({ title: "Alert!", description: "Error uploading images", icon: "warning" }); } finally { b(!1), m.current && (m.current.value = ""); } } } }, w = () => { !i && r.length < l ? m.current?.click() : r.length >= l && c({ title: "Alert!", description: `Maximum ${l} images allowed.`, icon: "warning" }); }, v = (a) => { if (!i) { const t = [...r]; t.splice(a, 1), o(t); } }, k = (a, t) => { const s = [...r], n = s[t]; s.splice(t, 1, { ...n, ...a }), o(s); }; return /* @__PURE__ */ e.createElement("div", { className: "relative" }, i && /* @__PURE__ */ e.createElement("div", { className: "absolute inset-0 z-10 flex items-center justify-center bg-white bg-opacity-70" }, /* @__PURE__ */ e.createElement(U, { className: "w-8 h-8 text-primary-1" })), /* @__PURE__ */ e.createElement("div", { className: "relative p-8 border-2 border-dashed rounded-lg border-primary-1 bg-primary-1" }, /* @__PURE__ */ e.createElement( "button", { className: "w-full", onClick: w, type: "button", disabled: i || r.length >= l }, /* @__PURE__ */ e.createElement("div", { className: "flex flex-col items-center gap-3 text-center" }, /* @__PURE__ */ e.createElement("div", { className: "bg-gray-100 rounded-full" }, /* @__PURE__ */ e.createElement(I, { className: "w-6 h-6 text-gray-500" })), /* @__PURE__ */ e.createElement(g, { variant: "body1", className: "text-gray-600" }, i ? "Uploading..." : r.length >= l ? `Maximum ${l} images reached` : "Add Images"), r.length > 0 && /* @__PURE__ */ e.createElement(g, { variant: "body1", className: "text-gray-500" }, r.length, " of ", l, " images")) ), /* @__PURE__ */ e.createElement( "input", { ref: m, id: `${p}-gallery`, type: "file", accept: E, disabled: i || r.length >= l, onChange: N, className: "hidden", multiple: !0 } ), u && /* @__PURE__ */ e.createElement(g, { variant: "body1", className: "mt-1 text-danger-1" }, u)), r.length > 0 && /* @__PURE__ */ e.createElement("div", { className: "grid grid-cols-2 gap-4 mt-4 sm:grid-cols-3 md:grid-cols-4" }, r.map((a, t) => /* @__PURE__ */ e.createElement("div", { key: a.private_url, className: "flex flex-col gap-2" }, /* @__PURE__ */ e.createElement("div", { key: t, className: "relative flex rounded" }, /* @__PURE__ */ e.createElement( "img", { src: a.public_url, alt: `Preview ${t + 1}`, className: "object-cover w-full h-24 rounded" } ), y && /* @__PURE__ */ e.createElement( "button", { type: "button", onClick: (s) => { s.currentTarget.blur(), y({ imageUrl: a.public_url, index: t, onReplaceImage: k }); }, className: "absolute p-1 text-white bg-white rounded-full left-2 top-2 opacity-70 hover:opacity-100" }, /* @__PURE__ */ e.createElement(z, { size: 16, className: "stroke-danger" }) ), /* @__PURE__ */ e.createElement( "button", { onClick: () => v(t), className: "absolute p-1 text-white bg-white rounded-full right-2 top-2 opacity-70 hover:opacity-100", type: "button", disabled: i }, /* @__PURE__ */ e.createElement(C, { size: 16, className: "stroke-danger" }) )), /* @__PURE__ */ e.createElement( x, { id: p + t, type: "text", placeholder: f || "", value: a.tag, required: !0, onChange: (s) => { const n = [...r]; n[t].tag = s.target.value, o(n); } } ))))); }; export { W as TaggableImageUploadFieldWithInput }; //# sourceMappingURL=index178.es.js.map