2025-01-28 18:51:12 +01:00
|
|
|
import { PPIcon } from './Icons';
|
2024-11-05 13:49:38 +04:00
|
|
|
|
2025-01-14 12:04:20 +01:00
|
|
|
const ImageBadge = ( { images } ) => {
|
|
|
|
if ( ! images || ! images.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BadgeContent>
|
|
|
|
<span className="ppcp-r-badge-box__title-image-badge">
|
2025-01-28 18:51:12 +01:00
|
|
|
{ images.map( ( badge, index ) => (
|
|
|
|
<PPIcon
|
|
|
|
key={ `badge-${ index }` }
|
|
|
|
imageName={ badge }
|
|
|
|
className="ppcp-r-badge-box__image"
|
|
|
|
/>
|
|
|
|
) ) }
|
2025-01-14 12:04:20 +01:00
|
|
|
</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';
|
2025-01-14 12:04:20 +01:00
|
|
|
const titleClassName = imageBadge.length
|
2024-11-26 15:01:21 +04:00
|
|
|
? `${ titleBaseClassName } ppcp-r-badge-box__title--has-image-badge`
|
|
|
|
: titleBaseClassName;
|
2025-01-14 12:04:20 +01:00
|
|
|
|
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 }>
|
2025-01-14 12:04:20 +01:00
|
|
|
<span className={ titleTextClassName }>{ title }</span>
|
2024-11-05 13:49:38 +04:00
|
|
|
|
2025-01-14 12:04:20 +01:00
|
|
|
<ImageBadge images={ imageBadge } />
|
|
|
|
<BadgeContent>{ textBadge }</BadgeContent>
|
2024-11-26 15:01:21 +04:00
|
|
|
</span>
|
|
|
|
<div className="ppcp-r-badge-box__description">
|
2025-01-14 12:04:20 +01:00
|
|
|
{ description && (
|
2024-11-26 15:01:21 +04:00
|
|
|
<p
|
|
|
|
className="ppcp-r-badge-box__description"
|
|
|
|
dangerouslySetInnerHTML={ {
|
2025-01-14 12:04:20 +01:00
|
|
|
__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;
|