| 1 |
import type { BlockSaveProps } from '@wordpress/blocks'; |
| 2 |
import { useBlockProps } from '@wordpress/block-editor'; |
| 3 |
|
| 4 |
import type { VippsBadgeBlockAttributes, VippsBadgeBlockConfig } from './types'; |
| 5 |
|
| 6 |
declare var injectedVippsBadgeBlockConfig: VippsBadgeBlockConfig; |
| 7 |
const blockConfig = injectedVippsBadgeBlockConfig; |
| 8 |
|
| 9 |
export default function save({ |
| 10 |
attributes, |
| 11 |
}: BlockSaveProps<VippsBadgeBlockAttributes>) { |
| 12 |
// Let the user choose the variant. If the current one isn't in the list, add it (though we don't know the label then. IOK 2020-12-18 |
| 13 |
const variantOptions = blockConfig.variants; |
| 14 |
const current = attributes.variant; |
| 15 |
let found = false; |
| 16 |
for (let i = 0; i < variantOptions.length; i++) { |
| 17 |
if (current == variantOptions[i].value) { |
| 18 |
found = true; |
| 19 |
break; |
| 20 |
} |
| 21 |
} |
| 22 |
if (!found) variantOptions.push({ label: current, value: current }); |
| 23 |
const attrs = { |
| 24 |
variant: current, |
| 25 |
// Looks like button and badge web components now use 'da' instead of 'dk' for danish. LP 2026-08-11 |
| 26 |
language: 'dk' === attributes.language ? 'da' : attributes.language, |
| 27 |
brand: blockConfig.brand, |
| 28 |
}; |
| 29 |
|
| 30 |
let extraclass = |
| 31 |
attributes.className && attributes.className !== 'undefined' |
| 32 |
? attributes.className |
| 33 |
: ''; |
| 34 |
|
| 35 |
return ( |
| 36 |
<> |
| 37 |
<div |
| 38 |
{...useBlockProps.save({ |
| 39 |
className: 'vipps-badge-wrapper ' + extraclass, |
| 40 |
})} |
| 41 |
> |
| 42 |
{/* <vipps-badge> is a web component that is enqueued with slug vipps-onsite-messageing. LP 18.11.2024 */} |
| 43 |
{/* @ts-ignore */} |
| 44 |
<vipps-mobilepay-badge {...attrs} /> |
| 45 |
</div> |
| 46 |
</> |
| 47 |
); |
| 48 |
} |
| 49 |
|