-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Iframe & configurator updates (widget-ui-9) (#3255)
* feat: widget init mods * feat: widget menu links * feat: select menu * feat: select menu * feat: select menu * Update apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/index.tsx Co-authored-by: Alexandr Kazachenko <[email protected]> * feat: fix semicolons * feat: menu styling * feat: general styling * feat: connect wallet internal * feat: connect wallet internal * feat: connect wallet internal * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * feat: widget configurator app * refactor: extract AccountElement and AccountModalState * feat: update theme * feat: update modalheader * feat: update modalheader * feat: update modalheader * feat: refactor code * feat: iframe resizer * feat: powered by footer * feat: iframe WIP * feat: revert tsconfig * feat: fix import * feat: fix gap loading spinner * feat: cleanup + optimize iframeresizer * feat: add ENUM * feat: optimize iframeResizer script * feat: fix height iframe * feat: configurator background * feat: fix fav tokens styles * feat: fix img alt --------- Co-authored-by: Michel <[email protected]> Co-authored-by: Alexandr Kazachenko <[email protected]>
- Loading branch information
1 parent
36c7e13
commit e3a4a14
Showing
21 changed files
with
181 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/widget-configurator/src/app/configurator/attachIframeResizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// TODO: Move this to libs/common-utils/src/iframeResizer.ts as a helper function | ||
// Adding the file here to avoid TS errors around environment variables | ||
|
||
import { useEffect } from 'react' | ||
|
||
interface IframeResizerProps { | ||
iframeId: string | ||
originCheck?: string | ||
} | ||
|
||
// A utility function to adjust iframe height based on postMessage from iframe content. | ||
export function AttachIframeResizer({ iframeId, originCheck }: IframeResizerProps) { | ||
useEffect(() => { | ||
const iframeElement = document.getElementById(iframeId) | ||
|
||
if (!iframeElement) { | ||
console.error(`No iframe found with ID: ${iframeId}`) | ||
return | ||
} | ||
|
||
const handleMessage = (event: MessageEvent) => { | ||
// If an originCheck is provided, validate against it | ||
if (originCheck && event.origin !== originCheck) return | ||
|
||
const data = event.data | ||
|
||
// Validate the data format and type before processing it | ||
if ( | ||
typeof data === 'object' && | ||
data.type === 'iframeHeight' && | ||
Object.prototype.hasOwnProperty.call(data, 'height') | ||
) { | ||
console.log('got iframeHeight ====>', data.height) | ||
iframeElement.style.height = 'auto' // Reset the iframe's height | ||
iframeElement.style.height = `${data.height}px` // Adjust the height based on the content | ||
} | ||
} | ||
|
||
window.addEventListener('message', handleMessage) | ||
|
||
// Cleanup: Remove the event listener when the component is unmounted | ||
return () => { | ||
window.removeEventListener('message', handleMessage) | ||
} | ||
}, [iframeId, originCheck]) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.