Skip to content

Instantly share code, notes, and snippets.

@amio
Last active August 20, 2016 14:37
Show Gist options
  • Save amio/8983fe352fb6664e7f13716af7a12744 to your computer and use it in GitHub Desktop.
Save amio/8983fe352fb6664e7f13716af7a12744 to your computer and use it in GitHub Desktop.
Reproduce invisible `foreignObject` in preact. https://github.com/developit/preact/issues/278
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
/** @jsx h */
import { h, render, Component, svg, g } from 'preact'
render(
<svg width="100%" height="500">
<rect x="10" y="10" width="100" height="150" fill="blue"/>
<foreignObject x="10" y="10" width="100" height="150">
<div xmlns="http://www.w3.org/1999/xhtml">
Here is a <strong>paragraph</strong> that requires <em>word wrap</em></div>
</foreignObject>
<circle cx="200" cy="200" r="100" fill="red" />
<foreignObject x="120" y="120" width="180" height="180">
<div xmlns="http://www.w3.org/1999/xhtml">
<ul>
<li><strong>First</strong> item</li>
<li><em>Second</em> item</li>
<li>Thrid item</li>
</ul>
</div>
</foreignObject>
</svg>,
document.body
)
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"preact": "5.4.1"
}
}
"use strict";
var _preact = require("preact");
(0, _preact.render)((0, _preact.h)(
"svg",
{ width: "100%", height: "500" },
(0, _preact.h)("rect", { x: "10", y: "10", width: "100", height: "150", fill: "blue" }),
(0, _preact.h)(
"foreignObject",
{ x: "10", y: "10", width: "100", height: "150" },
(0, _preact.h)(
"div",
{ xmlns: "http://www.w3.org/1999/xhtml" },
"Here is a ",
(0, _preact.h)(
"strong",
null,
"paragraph"
),
" that requires ",
(0, _preact.h)(
"em",
null,
"word wrap"
)
)
),
(0, _preact.h)("circle", { cx: "200", cy: "200", r: "100", fill: "red" }),
(0, _preact.h)(
"foreignObject",
{ x: "120", y: "120", width: "180", height: "180" },
(0, _preact.h)(
"div",
{ xmlns: "http://www.w3.org/1999/xhtml" },
(0, _preact.h)(
"ul",
null,
(0, _preact.h)(
"li",
null,
(0, _preact.h)(
"strong",
null,
"First"
),
" item"
),
(0, _preact.h)(
"li",
null,
(0, _preact.h)(
"em",
null,
"Second"
),
" item"
),
(0, _preact.h)(
"li",
null,
"Thrid item"
)
)
)
)
), document.body); /** @jsx h */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment