UNPKG

geoiq-frontend-ui-kit

Version:

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

83 lines (82 loc) 3.44 kB
import { Typography as p } from "./index.es17.js"; import e, { useState as N, useRef as h } from "react"; import "./index.es32.js"; import { useToast as v } from "./index.es73.js"; import { Spinner as x } from "./index.es56.js"; import { Upload as w, X as k, Pen as I } from "lucide-react"; import { useFormValues as R } from "./index.es146.js"; const j = ({ id: u, onChange: a, value: l, accept: g = "image/*", error: c }) => { const { onAssetUpload: s, onToggleImageEditor: o } = R(), { toast: n } = v(), [t, m] = N(!1), r = h(null), f = (i) => { const d = i.target.files?.[0]; !d || t || s && (m(!0), s(d).then((E) => { a(E), n({ title: "Alert!", description: "File uploaded successfully.", icon: "success" }); }).catch(() => { a(void 0), n({ title: "Alert!", description: "Error uploading file", icon: "warning" }); }).finally(() => { m(!1), r.current && (r.current.value = ""); })); }, b = (i) => { a(i); }, y = () => { t || r.current?.click(); }; return /* @__PURE__ */ e.createElement("div", { className: "relative" }, t && /* @__PURE__ */ e.createElement("div", { className: "absolute inset-0 z-10 flex items-center justify-center bg-white bg-opacity-70" }, /* @__PURE__ */ e.createElement(x, { 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: y }, /* @__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(w, { className: "w-6 h-6 text-gray-500" })), /* @__PURE__ */ e.createElement(p, { variant: "body1", className: "text-gray-600" }, t ? "Uploading..." : l ? "Replace Image" : "Attach Image"))), /* @__PURE__ */ e.createElement( "input", { ref: r, id: `${u}-gallery`, type: "file", accept: g, disabled: t, onChange: f, className: "hidden" } ), c && /* @__PURE__ */ e.createElement(p, { variant: "body1", className: "mt-1 text-danger-1" }, c)), l && /* @__PURE__ */ e.createElement("div", { className: "grid grid-cols-2 gap-4 mt-4 sm:grid-cols-3 md:grid-cols-4" }, /* @__PURE__ */ e.createElement("div", { className: "relative flex rounded" }, /* @__PURE__ */ e.createElement( "img", { src: l.public_url, alt: "Preview", className: "object-cover w-full h-24 rounded" } ), /* @__PURE__ */ e.createElement( "button", { onClick: () => { t || a(void 0); }, className: "absolute p-1 text-white bg-white rounded-full right-2 top-2 opacity-70 hover:opacity-100" }, /* @__PURE__ */ e.createElement(k, { size: 16, className: "stroke-danger" }) ), o && /* @__PURE__ */ e.createElement( "button", { onClick: () => { o({ imageUrl: l.public_url, index: -1, onReplaceImage: b }); }, className: "absolute p-1 text-white bg-white rounded-full left-2 top-2 opacity-70 hover:opacity-100" }, /* @__PURE__ */ e.createElement(I, { size: 16, className: "stroke-danger" }) )))); }; export { j as SingleImagePicker }; //# sourceMappingURL=index.es151.js.map