2021-06-10 05:29:52 +00:00
|
|
|
import React, { useEffect } from "react";
|
2021-06-09 09:39:17 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
|
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
|
|
|
|
import { hexToRgba } from "components/ads/common";
|
|
|
|
|
|
|
|
|
|
function Iframe(props: IframeComponentProps) {
|
|
|
|
|
return <iframe {...props} src={props.source} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const IframeWithBorder = styled(Iframe)<IframeComponentProps>`
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
border-color: ${(props) =>
|
|
|
|
|
hexToRgba(
|
|
|
|
|
props.borderColor || "#f2f2f2",
|
|
|
|
|
(props.borderOpacity && !isNaN(props.borderOpacity)
|
|
|
|
|
? props.borderOpacity
|
|
|
|
|
: 100) / 100,
|
|
|
|
|
)};
|
|
|
|
|
border-width: ${(props) =>
|
|
|
|
|
props.borderWidth ? Number(props.borderWidth) : 0}px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export interface IframeComponentProps extends ComponentProps {
|
|
|
|
|
source: string;
|
|
|
|
|
title?: string;
|
2021-06-10 05:29:52 +00:00
|
|
|
onURLChanged: (url: string) => void;
|
|
|
|
|
onMessageReceived: (message: MessageEvent) => void;
|
2021-06-09 09:39:17 +00:00
|
|
|
borderColor?: string;
|
|
|
|
|
borderOpacity?: number;
|
|
|
|
|
borderWidth?: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function IframeComponent(props: IframeComponentProps) {
|
2021-06-10 05:29:52 +00:00
|
|
|
const { onMessageReceived, onURLChanged, source } = props;
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
onURLChanged(source);
|
|
|
|
|
}, [source]);
|
2021-06-09 09:39:17 +00:00
|
|
|
return <IframeWithBorder {...props} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default IframeComponent;
|