|
| 1 | +import { useState } from 'react' |
| 2 | +import Tippy from '@tippyjs/react' |
| 3 | +import { IframeElementProps } from './types' |
| 4 | +import { stopPropagation, VisibleModal } from '../../../Common' |
| 5 | +import { ReactComponent as ICFullScreen } from '../../../Assets/Icon/ic-fullscreen-2.svg' |
| 6 | +import { ReactComponent as ICClose } from '../../../Assets/Icon/ic-close.svg' |
| 7 | +import './IframeElement.scss' |
| 8 | +import { GenericSectionErrorState } from '../GenericSectionErrorState' |
| 9 | + |
| 10 | +const IframeElement = ({ URL, width, height, title, maxHeight, maxWidth }: IframeElementProps) => { |
| 11 | + const [showFullScreen, setShowFullScreen] = useState<boolean>(false) |
| 12 | + const [hasError, setHasError] = useState<boolean>(false) |
| 13 | + |
| 14 | + const handleEnterFullScreen = () => { |
| 15 | + setShowFullScreen(true) |
| 16 | + } |
| 17 | + |
| 18 | + const handleExitFullScreen = () => { |
| 19 | + setShowFullScreen(false) |
| 20 | + } |
| 21 | + |
| 22 | + const handleError = () => { |
| 23 | + setHasError(true) |
| 24 | + } |
| 25 | + |
| 26 | + if (hasError) { |
| 27 | + return <GenericSectionErrorState description="Please try again later" /> |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <> |
| 32 | + <div className="flexbox-col dc__gap-4"> |
| 33 | + <div className="flexbox dc__content-space dc__gap-4"> |
| 34 | + <h3 className="m-0 fs-12 cn-7 fw-6 dc__truncate">{title}</h3> |
| 35 | + |
| 36 | + <Tippy content="Enter Full Screen" className="default-tt" arrow={false}> |
| 37 | + <button |
| 38 | + type="button" |
| 39 | + className="p-0 flex dc__no-border dc__no-background dc__outline-none-imp dc__tab-focus icon-dim-18 dc__tab-focus" |
| 40 | + onClick={handleEnterFullScreen} |
| 41 | + aria-label="Enter Full Screen" |
| 42 | + > |
| 43 | + <ICFullScreen className="dc__no-shrink icon-dim-18" /> |
| 44 | + </button> |
| 45 | + </Tippy> |
| 46 | + </div> |
| 47 | + |
| 48 | + {/* eslint-disable-next-line jsx-a11y/iframe-has-title */} |
| 49 | + <iframe |
| 50 | + src={URL} |
| 51 | + width={Math.min(maxWidth, width)} |
| 52 | + height={Math.min(maxHeight, height)} |
| 53 | + className="dc__no-border" |
| 54 | + onError={handleError} |
| 55 | + sandbox="allow-same-origin allow-scripts" |
| 56 | + referrerPolicy="no-referrer" |
| 57 | + /> |
| 58 | + </div> |
| 59 | + |
| 60 | + {showFullScreen && ( |
| 61 | + <VisibleModal className="" close={handleExitFullScreen}> |
| 62 | + <div |
| 63 | + className="dc__overflow-scroll br-8 dc__position-rel bcn-0 custom-panel--iframe-element flexbox-col dc__content-space" |
| 64 | + onClick={stopPropagation} |
| 65 | + > |
| 66 | + <div className="flexbox dc__align-items-center dc__content-space dc__border-bottom py-20 px-16"> |
| 67 | + <h3 className="m-0 cn-9 fs-16 fw-6 lh-24 dc__truncate">{title}</h3> |
| 68 | + <button |
| 69 | + type="button" |
| 70 | + className="p-0 flex dc__no-border dc__no-background dc__outline-none-imp dc__tab-focus icon-dim-18 dc__tab-focus" |
| 71 | + onClick={handleExitFullScreen} |
| 72 | + aria-label="Close" |
| 73 | + > |
| 74 | + <ICClose className="dc__no-shrink icon-dim-18 fcn-6" /> |
| 75 | + </button> |
| 76 | + </div> |
| 77 | + <div className="flex px-16 py-8 h-100"> |
| 78 | + {/* eslint-disable-next-line jsx-a11y/iframe-has-title */} |
| 79 | + <iframe |
| 80 | + src={URL} |
| 81 | + width="100%" |
| 82 | + height="100%" |
| 83 | + className="dc__no-border" |
| 84 | + sandbox="allow-same-origin allow-scripts" |
| 85 | + referrerPolicy="no-referrer" |
| 86 | + /> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </VisibleModal> |
| 90 | + )} |
| 91 | + </> |
| 92 | + ) |
| 93 | +} |
| 94 | + |
| 95 | +export default IframeElement |
0 commit comments