mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Initial Axo Blocks commit
This commit is contained in:
parent
796ded031e
commit
ebd87b70e9
27 changed files with 43827 additions and 1 deletions
|
@ -0,0 +1,62 @@
|
|||
import ReactDOM from 'react-dom/client';
|
||||
import { FastlaneWatermark } from '../components/FastlaneWatermark';
|
||||
|
||||
export const setupWatermark = ( fastlaneSdk, shouldIncludeAdditionalInfo ) => {
|
||||
const emailInput = document.getElementById( 'email' );
|
||||
let watermarkRoot = null;
|
||||
let watermarkContainer = null;
|
||||
|
||||
if ( emailInput ) {
|
||||
const emailLabel =
|
||||
emailInput.parentNode.querySelector( 'label[for="email"]' );
|
||||
watermarkContainer = document.createElement( 'div' );
|
||||
watermarkContainer.setAttribute(
|
||||
'class',
|
||||
'ppcp-axo-block-watermark-container'
|
||||
);
|
||||
|
||||
if ( emailLabel ) {
|
||||
emailLabel.parentNode.insertBefore(
|
||||
watermarkContainer,
|
||||
emailLabel.nextSibling
|
||||
);
|
||||
} else {
|
||||
emailInput.parentNode.appendChild( watermarkContainer );
|
||||
}
|
||||
|
||||
const watermarkElement = document.createElement( 'div' );
|
||||
watermarkContainer.appendChild( watermarkElement );
|
||||
|
||||
watermarkRoot = ReactDOM.createRoot( watermarkElement );
|
||||
watermarkRoot.render(
|
||||
<FastlaneWatermark
|
||||
fastlaneSdk={ fastlaneSdk }
|
||||
name="fastlane-watermark-email"
|
||||
includeAdditionalInfo={ shouldIncludeAdditionalInfo }
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return { watermarkRoot, watermarkContainer, emailInput };
|
||||
};
|
||||
|
||||
export const cleanupWatermark = ( {
|
||||
watermarkRoot,
|
||||
watermarkContainer,
|
||||
emailInput,
|
||||
onEmailSubmit,
|
||||
} ) => {
|
||||
if ( watermarkRoot && watermarkContainer ) {
|
||||
watermarkRoot.unmount();
|
||||
watermarkContainer.parentNode.removeChild( watermarkContainer );
|
||||
console.log( 'Fastlane watermark removed' );
|
||||
}
|
||||
if ( emailInput ) {
|
||||
emailInput.removeEventListener( 'keyup', async ( event ) => {
|
||||
const email = event.target.value;
|
||||
if ( email ) {
|
||||
await onEmailSubmit( email );
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue