Skip to content

Commit 0b99a61

Browse files
authored
Iframe srcdoc and sandbox (#191)
1 parent fe5005e commit 0b99a61

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/npm-fastui/src/components/Iframe.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { FC } from 'react'
33
import type { Iframe } from '../models'
44

55
export const IframeComp: FC<Iframe> = (props) => {
6-
const { src, width, height, title } = props
7-
return <iframe src={src} width={width} height={height} title={title} />
6+
const { src, width, height, title, sandbox, srcdoc } = props
7+
return <iframe src={src} width={width} height={height} title={title} sandbox={sandbox} srcDoc={srcdoc} />
88
}

src/npm-fastui/src/models.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ export interface Iframe {
231231
width?: string | number
232232
height?: string | number
233233
className?: ClassName
234+
srcdoc?: string
235+
sandbox?: string
234236
type: 'Iframe'
235237
}
236238
export interface Video {

src/python-fastui/fastui/components/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ class Iframe(_p.BaseModel, extra='forbid'):
254254
width: _t.Union[str, int, None] = None
255255
height: _t.Union[str, int, None] = None
256256
class_name: _class_name.ClassNameField = None
257+
srcdoc: _t.Union[str, None] = None
258+
sandbox: _t.Union[str, None] = None
257259
type: _t.Literal['Iframe'] = 'Iframe'
258260

259261

src/python-fastui/tests/test_components.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
that's just testing pydantic!
66
"""
77
from fastui import FastUI, components
8+
from pydantic_core import Url
89

910

1011
def test_div_text():
@@ -50,3 +51,13 @@ def test_root_model_single():
5051
'type': 'Text',
5152
}
5253
]
54+
55+
56+
def test_iframe():
57+
iframe = components.Iframe(src='https://www.example.com', srcdoc='<p>hello world</p>', sandbox='allow-scripts')
58+
assert iframe.model_dump(by_alias=True, exclude_none=True) == {
59+
'src': Url('https://www.example.com'),
60+
'type': 'Iframe',
61+
'srcdoc': '<p>hello world</p>',
62+
'sandbox': 'allow-scripts',
63+
}

0 commit comments

Comments
 (0)