@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.24 kB
JavaScript
"use client";
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=PaymentSourceBrandName;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),capitalize_1=tslib_1.__importDefault(require("lodash/capitalize")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandName(_a){var{children,label}=_a,props=tslib_1.__rest(_a,["children","label"]);const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,brandName=cardBrand&&(0,capitalize_1.default)(cardBrand.replace(/_|-/gm," ")),parentProps=Object.assign({brand:brandName,label},props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},props,{children:label||(0,capitalize_1.default)(brandName)}))}exports.default=PaymentSourceBrandName;