UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

52 lines (51 loc) 2.11 kB
import { jsx as o } from "../../../../external/preact/jsx-runtime/dist/jsxRuntime.module.js"; import _ from "classnames"; import { useState as g, useEffect as m } from "../../../../external/preact/hooks/dist/hooks.module.js"; import k from "../../../../core/Context/useCoreContext.js"; import { useResponsiveContainer as x, containerQueries as B } from "../../../../hooks/useResponsiveContainer.js"; import h from "../../SVGIcons/Download.js"; import v from "../Button.js"; import { ButtonVariant as b } from "../types.js"; import y from "./useDownload.js"; /* empty css */ import C from "../../Spinner/Spinner.js"; function N({ blob: r, filename: c }) { const t = document.createElement("a"), a = URL.createObjectURL(r); t.href = a, t.download = c || "download"; const n = () => { setTimeout(() => { URL.revokeObjectURL(a); }, 150); }; t.addEventListener("click", n, { once: !0 }), t.click(); } function D({ className: r, disabled: c, endpointName: t, params: a, setError: n, errorDisplay: f, onDownloadRequested: d }) { const { i18n: u } = k(), [s, p] = g(!1), L = x(B.down.xs), { data: l, error: i, isFetching: e } = y(t, a, s); m(() => { s && p(!1); }, [s]), m(() => { l && N(l); }, [l]), m(() => { n && i && n(i); }, [i, n]); const w = () => { p(!0), d == null || d(); }; return /* @__PURE__ */ o("div", { className: "adyen-pe-download", children: [ L ? /* @__PURE__ */ o(v, { iconButton: !0, variant: b.TERTIARY, onClick: w, children: e ? /* @__PURE__ */ o(C, { size: "small" }) : /* @__PURE__ */ o(h, {}) }) : /* @__PURE__ */ o( v, { className: _("adyen-pe-download__button", { "adyen-pe-download__button--loading": e }, r), disabled: c || e, variant: b.SECONDARY, onClick: w, iconLeft: e ? /* @__PURE__ */ o(C, { size: "small" }) : /* @__PURE__ */ o(h, {}), children: e ? `${u.get("downloading")}..` : u.get("download") } ), i && f && /* @__PURE__ */ o("div", { className: "adyen-pe-download__error", children: f }) ] }); } export { D as default };