woocommerce-paypal-payments/modules/ppcp-settings/resources/js/Components/ReusableComponents/BadgeBox.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-11-05 13:49:38 +04:00
import data from '../../utils/data';
const ImageBadge = ( { images } ) => {
if ( ! images || ! images.length ) {
return null;
}
return (
<BadgeContent>
<span className="ppcp-r-badge-box__title-image-badge">
{ images.map( ( badge ) => data().getImage( badge ) ) }
</span>
</BadgeContent>
);
};
// If `children` is not empty, it's output and wrapped in spaces.
const BadgeContent = ( { children } ) => {
if ( ! children ) {
return null;
}
return <> { children } </>;
};
const BadgeBox = ( {
title,
textBadge,
imageBadge = [],
titleType = BADGE_BOX_TITLE_BIG,
description = '',
} ) => {
let titleSize = BADGE_BOX_TITLE_SMALL;
if ( BADGE_BOX_TITLE_BIG === titleType ) {
titleSize = BADGE_BOX_TITLE_BIG;
}
2024-11-05 17:54:47 +04:00
2024-11-26 15:01:21 +04:00
const titleTextClassName =
'ppcp-r-badge-box__title-text ' +
`ppcp-r-badge-box__title-text--${ titleSize }`;
2024-11-05 17:54:47 +04:00
2024-11-26 15:01:21 +04:00
const titleBaseClassName = 'ppcp-r-badge-box__title';
const titleClassName = imageBadge.length
2024-11-26 15:01:21 +04:00
? `${ titleBaseClassName } ppcp-r-badge-box__title--has-image-badge`
: titleBaseClassName;
2024-11-05 13:49:38 +04:00
return (
2024-11-26 15:01:21 +04:00
<div className="ppcp-r-badge-box">
<span className={ titleClassName }>
<span className={ titleTextClassName }>{ title }</span>
2024-11-05 13:49:38 +04:00
<ImageBadge images={ imageBadge } />
<BadgeContent>{ textBadge }</BadgeContent>
2024-11-26 15:01:21 +04:00
</span>
<div className="ppcp-r-badge-box__description">
{ description && (
2024-11-26 15:01:21 +04:00
<p
className="ppcp-r-badge-box__description"
dangerouslySetInnerHTML={ {
__html: description,
2024-11-26 15:01:21 +04:00
} }
></p>
) }
</div>
</div>
);
2024-11-05 13:49:38 +04:00
};
2024-11-05 17:54:47 +04:00
export const BADGE_BOX_TITLE_BIG = 'big';
export const BADGE_BOX_TITLE_SMALL = 'small';
2024-11-05 13:49:38 +04:00
export default BadgeBox;