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)

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