Skip to content

Commit 3df2d12

Browse files
committed
add styling prop to forward iframe styles
1 parent 379930b commit 3df2d12

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export default App;
4242

4343
`<Retool>` also accepts optional `allow` and `sandbox` parameters to configure permissions of the iframe used to embed the Retool app. `allow-scripts` and `allow-same-origin` are required in order to run Retool, so if `sandbox` is specified, `allow-scripts` and `allow-same-origin` will always be appended to ensure the Retool app works.
4444

45+
`<Retool>` will accept an optional `styling` prop object that can be used to pass in styles to the iframe component.
46+
4547
### Example
4648

4749
Running `yarn start` will start an application with a basic Retool app embeded.

src/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Retool from "./components/Retool";
22
import { useState } from "react";
33

44
const App = () => {
5+
const iframeStyle = {
6+
border: "2px solid red",
7+
};
8+
59
const sample = {
610
example1: "",
711
example2: false,
@@ -36,6 +40,7 @@ const App = () => {
3640
height="700px"
3741
width="1000px"
3842
onData={setRetoolData}
43+
styling={iframeStyle}
3944
></Retool>
4045
<h1> {JSON.stringify(retoolData)} </h1>
4146
</div>

src/components/Retool.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { useEffect, useRef, useState } from "react";
22

3-
const MINIMUM_SANDBOX_PERMISSIONS = 'allow-scripts allow-same-origin'
4-
5-
const Retool = ({ data, url, height, width, onData, sandbox, allow }) => {
3+
const MINIMUM_SANDBOX_PERMISSIONS = "allow-scripts allow-same-origin";
4+
5+
const Retool = ({
6+
data,
7+
url,
8+
height,
9+
width,
10+
onData,
11+
sandbox,
12+
allow,
13+
styling,
14+
}) => {
615
const embeddedIframe = useRef(null);
716
const [elementWatchers, setElementWatchers] = useState({});
817

@@ -92,7 +101,12 @@ const Retool = ({ data, url, height, width, onData, sandbox, allow }) => {
92101
}
93102
};
94103

95-
const sandboxAttrib = typeof sandbox === 'string' ? `${MINIMUM_SANDBOX_PERMISSIONS} ${sandbox}` : sandbox === true ? MINIMUM_SANDBOX_PERMISSIONS : sandbox
104+
const sandboxAttrib =
105+
typeof sandbox === "string"
106+
? `${MINIMUM_SANDBOX_PERMISSIONS} ${sandbox}`
107+
: sandbox === true
108+
? MINIMUM_SANDBOX_PERMISSIONS
109+
: sandbox;
96110

97111
return (
98112
<iframe
@@ -104,6 +118,7 @@ const Retool = ({ data, url, height, width, onData, sandbox, allow }) => {
104118
src={url}
105119
ref={embeddedIframe}
106120
title="retool"
121+
style={styling}
107122
/>
108123
);
109124
};

0 commit comments

Comments
 (0)