UNPKG

@commercelayer/react-components

Version:
2 lines 1.38 kB
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=PaymentSourceBrandIcon;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand,issuer_type:issuerType}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand,issuer_type:customerIssuerType}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand??issuerType??customerIssuerType,ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${cardBrand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand:cardBrand,defaultSrc,url,width,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("img",{ref,src:url,onError:handleError,width,...p})}exports.default=PaymentSourceBrandIcon;