Sandbox 组件通过 iframe 提供一个隔离环境,用于安全渲染任意 HTML 内容。它支持自定义 HTML、脚本、样式等属性,适用于 WordPress 开发中的沙盒场景。
import { SandBox } from '@wordpress/components';
const MySandBox = () => (
<SandBox html="<p>Content</p>" title="SandBox" type="embed" />
);This component provides an isolated environment for arbitrary HTML via iframes.
import { SandBox } from '@wordpress/components';
const MySandBox = () => (
<SandBox html="<p>Content</p>" title="SandBox" type="embed" />
);
html: stringThe HTML to render in the body of the iframe document.
onFocus: React.DOMAttributes< HTMLIFrameElement >[ 'onFocus' ]The onFocus callback for the iframe.
scripts: string[]An array of script URLs to inject as <script> tags into the bottom of the <body> of the iframe document.
styles: string[]An array of CSS strings to inject into the <head> of the iframe document.
title: stringThe <title> of the iframe document.
type: stringThe CSS class name to apply to the <html> and <body> elements of the iframe.
tabIndex: HTMLElement[ 'tabIndex' ]The tabindex the iframe should receive.