Skip to content

Commit 3492b82

Browse files
authored
Adding autoresize and hideclosebutton for Overlay component (#14)
1 parent bcf4cef commit 3492b82

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/overlay/template.jsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** @jsx node */
33
/* eslint max-lines: off, react/jsx-max-depth: off */
44

5-
import { isIos, animate, noop, destroyElement, uniqueID, supportsPopups, type EventEmitterType } from 'belter/src';
5+
import { isIos, animate, noop, destroyElement, uniqueID, supportsPopups, type EventEmitterType, toCSS } from 'belter/src';
66
import { EVENT, CONTEXT } from 'zoid/src';
77
import { node, type ElementNode } from 'jsx-pragmatic/src';
88
import { LOGO_COLOR, PPLogo, PayPalLogo } from '@paypal/sdk-logos/src';
@@ -20,10 +20,12 @@ export type OverlayProps = {|
2020
content? : void | {|
2121
windowMessage? : string,
2222
continueMessage? : string
23-
|}
23+
|},
24+
autoResize? : boolean,
25+
hideCloseButton? : boolean
2426
|};
2527

26-
export function Overlay({ context, close, focus, event, frame, prerenderFrame, content = {} } : OverlayProps) : ElementNode {
28+
export function Overlay({ context, close, focus, event, frame, prerenderFrame, content = {}, autoResize, hideCloseButton } : OverlayProps) : ElementNode {
2729

2830
const uid = `paypal-overlay-${ uniqueID() }`;
2931

@@ -58,6 +60,25 @@ export function Overlay({ context, close, focus, event, frame, prerenderFrame, c
5860
};
5961
};
6062

63+
const setupAutoResize = (el) => {
64+
event.on(EVENT.RESIZE, ({ width: newWidth, height: newHeight }) => {
65+
if (typeof newWidth === 'number') {
66+
el.style.width = toCSS(newWidth);
67+
}
68+
69+
if (typeof newHeight === 'number') {
70+
el.style.height = toCSS(newHeight);
71+
}
72+
});
73+
};
74+
75+
const outletOnRender = (el) => {
76+
setupAnimations('component')(el);
77+
if (autoResize) {
78+
setupAutoResize(el);
79+
}
80+
};
81+
6182
let outlet;
6283

6384
if (frame && prerenderFrame) {
@@ -80,7 +101,7 @@ export function Overlay({ context, close, focus, event, frame, prerenderFrame, c
80101
});
81102

82103
outlet = (
83-
<div class={ CLASS.OUTLET } onRender={ setupAnimations('component') }>
104+
<div class={ CLASS.OUTLET } onRender={ outletOnRender }>
84105
<node el={ frame } />
85106
<node el={ prerenderFrame } />
86107
</div>
@@ -95,7 +116,7 @@ export function Overlay({ context, close, focus, event, frame, prerenderFrame, c
95116
<html>
96117
<body>
97118
<div id={ uid } onClick={ focusCheckout } class={ `paypal-overlay-context-${ context } paypal-checkout-overlay` }>
98-
<a href='#' class="paypal-checkout-close" onClick={ closeCheckout } aria-label="close" role="button" />
119+
{ !hideCloseButton && <a href='#' class="paypal-checkout-close" onClick={ closeCheckout } aria-label="close" role="button" /> }
99120
<div class="paypal-checkout-modal">
100121
<div class="paypal-checkout-logo">
101122
<PPLogo logoColor={ LOGO_COLOR.WHITE } />

0 commit comments

Comments
 (0)