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)

71 lines (70 loc) 2.63 kB
import { jsx as o } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js"; import b from "classnames"; import { useState as D, useEffect as m, useMemo as h } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js"; import { useResponsiveContainer as I, containerQueries as N } from "../../../../hooks/useResponsiveContainer.js"; import _ from "../Button.js"; import { ButtonVariant as l } from "../types.js"; import S from "./useDownload.js"; /* empty css */ import F from "../../../../core/Context/preact/useCoreContext.js"; import Y from "../../Spinner/Spinner.js"; import { Icon as k } from "../../Icon/Icon.js"; import { Fragment as A } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js"; import { downloadBlob as E } from "../../../../utils/file/download.js"; function M({ className: y, disabled: C, endpointName: R, requestParams: g, setError: d, errorDisplay: c, onDownloadRequested: v, iconButton: n = !1, errorMessage: f, ...p }) { const { i18n: r } = F(), [i, u] = D(!1), x = I(N.down.xs), { data: s, error: e, isFetching: t } = S(R, g, i); m(() => { i && u(!1); }, [i]), m(() => { s && E(s); }, [s]), m(() => { d && e && d(e); }, [e, d]); const w = () => { u(!0), v?.(); }, a = h(() => t ? /* @__PURE__ */ o(Y, { size: "small" }) : /* @__PURE__ */ o(k, { name: "download" }), [t]), T = h(() => n ? a : t ? `${r.get("common.actions.download.labels.inProgress")}..` : r.get("common.actions.download.labels.default"), [a, r, t, n]); return /* @__PURE__ */ o(A, { children: [ /* @__PURE__ */ o( "div", { className: b("adyen-pe-download", { "adyen-pe-download-icon-button-container": n }), children: [ x ? /* @__PURE__ */ o(_, { iconButton: !0, variant: l.TERTIARY, onClick: w, ...p, children: a }) : /* @__PURE__ */ o( _, { className: b( "adyen-pe-download__button", { "adyen-pe-download__button--loading": t, "adyen-pe-download__button--icon": n }, y ), disabled: C || t, variant: n ? l.TERTIARY : l.SECONDARY, onClick: w, ...!n && { iconLeft: a }, ...p, children: T } ), e && c && /* @__PURE__ */ o("div", { className: "adyen-pe-download__error", children: c }) ] } ), e && f && f(e) ] }); } export { M as default };