2021-06-21 03:23:39 +03:00
import { h , Component } from '/js/web_modules/preact.js' ;
2021-03-16 01:32:52 +03:00
import htm from '/js/web_modules/htm.js' ;
2021-06-21 03:23:39 +03:00
import MicroModal from '/js/web_modules/micromodal/dist/micromodal.min.js' ;
2021-04-01 08:28:55 +03:00
2021-03-16 01:32:52 +03:00
const html = htm . bind ( h ) ;
2021-06-21 03:23:39 +03:00
export default class ExternalActionModal extends Component {
constructor ( props ) {
super ( props ) ;
this . state = {
iframeLoaded : false ,
} ;
2021-04-01 08:28:55 +03:00
2021-06-21 03:23:39 +03:00
this . setIframeLoaded = this . setIframeLoaded . bind ( this ) ;
}
componentDidMount ( ) {
// initalize and display Micromodal on mount
try {
MicroModal . init ( {
awaitCloseAnimation : false ,
awaitOpenAnimation : true , // if using css animations to open the modal. This allows it to wait for the animation to finish before focusing on an element inside the modal.
} ) ;
MicroModal . show ( 'external-actions-modal' , {
onClose : this . props . onClose ,
} ) ;
} catch ( e ) {
console . log ( "micromodal error: " , e ) ;
}
2021-04-01 08:28:55 +03:00
}
2021-06-21 03:23:39 +03:00
setIframeLoaded ( ) {
this . setState ( {
iframeLoaded : true ,
} ) ;
}
2021-03-16 01:32:52 +03:00
2021-06-21 03:23:39 +03:00
render ( ) {
const { action } = this . props ;
const { url , title , description } = action ;
const { iframeLoaded } = this . state ;
const iframeStyle = iframeLoaded ? null : {
backgroundImage : 'url(/img/loading.gif)' ,
} ;
return html `
< div class = "modal micromodal-slide" id = "external-actions-modal" aria - hidden = "true" >
< div class = "modal__overlay" tabindex = "-1" data - micromodal - close >
< div id = "modal-container" class = "modal__container rounded-md" role = "dialog" aria - modal = "true" aria - labelledby = "modal-1-title" >
< header id = "modal-header" class = "modal__header flex flex-row justify-between items-center bg-gray-300 p-3 rounded-t-md" >
< h2 class = "modal__title text-indigo-600 font-semibold" >
$ { title || description }
< / h 2 >
< button class = "modal__close" aria - label = "Close modal" data - micromodal - close > < / b u t t o n >
< / h e a d e r >
< div id = "modal-content-content" class = "modal-content-content" >
< div id = "modal-content" class = "modal__content text-gray-600 rounded-b-md overflow-y-auto overflow-x-hidden" >
< iframe
id = "external-modal-iframe"
style = $ { iframeStyle }
class = "bg-gray-100 bg-center bg-no-repeat"
width = "100%"
allowpaymentrequest = "true"
allowfullscreen = "false"
sandbox = "allow-same-origin allow-scripts allow-popups allow-forms"
src = $ { url }
onload = $ { this . setIframeLoaded }
/ >
< / d i v >
2021-03-16 01:32:52 +03:00
< / d i v >
< / d i v >
< / d i v >
< / d i v >
2021-06-21 03:23:39 +03:00
` ;
}
2021-03-16 01:32:52 +03:00
}
2021-06-21 03:23:39 +03:00
export function ExternalActionButton ( { action , onClick } ) {
2021-03-16 01:32:52 +03:00
const { title , icon , color = undefined } = action ;
const logo =
icon &&
html `
< span class = "external-action-icon" > < img src = $ { icon } alt = "" / > < / s p a n >
` ;
const bgcolor = color && { backgroundColor : ` ${ color } ` } ;
2021-06-21 03:23:39 +03:00
const handleClick = ( ) => onClick ( action ) ;
2021-03-16 01:32:52 +03:00
return html `
< button
class = "external-action-button rounded-sm flex flex-row justify-center items-center overflow-hidden bg-gray-800"
onClick = $ { handleClick }
style = $ { bgcolor }
>
$ { logo }
< span class = "external-action-label" > $ { title } < / s p a n >
< / b u t t o n >
` ;
}