index.tsx
63 lines
| 1 | import {createRoot, render} from '@wordpress/element'; |
| 2 | import RevealForm from './Components/RevealForm'; |
| 3 | import ModalForm from './Components/ModalForm'; |
| 4 | import IframeResizer from 'iframe-resizer-react'; |
| 5 | |
| 6 | import './styles/index.scss'; |
| 7 | |
| 8 | /** |
| 9 | * @since 3.0.0 |
| 10 | */ |
| 11 | function DonationFormBlockApp({formFormat, dataSrc, embedId, openFormButton}) { |
| 12 | if (formFormat === 'reveal') { |
| 13 | return <RevealForm openFormButton={openFormButton} dataSrc={dataSrc} embedId={embedId} />; |
| 14 | } |
| 15 | |
| 16 | if (formFormat === 'modal') { |
| 17 | return <ModalForm openFormButton={openFormButton} dataSrc={dataSrc} embedId={embedId} />; |
| 18 | } |
| 19 | |
| 20 | return ( |
| 21 | <IframeResizer |
| 22 | id={embedId} |
| 23 | src={dataSrc} |
| 24 | checkOrigin={false} |
| 25 | style={{ |
| 26 | width: '1px', |
| 27 | minWidth: '100%', |
| 28 | border: '0', |
| 29 | }} |
| 30 | /> |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | const roots = document.querySelectorAll('.root-data-givewp-embed'); |
| 35 | |
| 36 | roots.forEach((root) => { |
| 37 | const dataSrc = root.getAttribute('data-src'); |
| 38 | const embedId = root.getAttribute('data-givewp-embed-id'); |
| 39 | const formFormat = root.getAttribute('data-form-format'); |
| 40 | const openFormButton = root.getAttribute('data-open-form-button'); |
| 41 | |
| 42 | if (createRoot) { |
| 43 | createRoot(root).render( |
| 44 | <DonationFormBlockApp |
| 45 | openFormButton={openFormButton} |
| 46 | formFormat={formFormat} |
| 47 | dataSrc={dataSrc} |
| 48 | embedId={embedId} |
| 49 | /> |
| 50 | ); |
| 51 | } else { |
| 52 | render( |
| 53 | <DonationFormBlockApp |
| 54 | openFormButton={openFormButton} |
| 55 | formFormat={formFormat} |
| 56 | dataSrc={dataSrc} |
| 57 | embedId={embedId} |
| 58 | />, |
| 59 | root |
| 60 | ); |
| 61 | } |
| 62 | }); |
| 63 |