feat: allow passing JSX children to island + nested islands (#1285)
This commit is contained in:
@@ -3,14 +3,18 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
import * as $1 from "./routes/passthrough.tsx";
|
||||
import * as $$0 from "./islands/Counter.tsx";
|
||||
import * as $$1 from "./islands/Passthrough.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $0,
|
||||
"./routes/passthrough.tsx": $1,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$0,
|
||||
"./islands/Passthrough.tsx": $$1,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useState } from "preact/hooks";
|
||||
import { ComponentChildren } from "preact";
|
||||
|
||||
interface PassthroughProps {
|
||||
children: ComponentChildren;
|
||||
n: number;
|
||||
}
|
||||
|
||||
export default function Passthrough({ children, n }: PassthroughProps) {
|
||||
const [v, set] = useState(0);
|
||||
return (
|
||||
<div
|
||||
class="pass-through"
|
||||
style="background: #85efac; padding: 1rem; border: 4px solid blue; border-radius: .5rem; margin: 1rem;"
|
||||
>
|
||||
<h2>This is an Island #{n}</h2>
|
||||
<button
|
||||
onClick={() => set((v2) => v2 + 1)}
|
||||
>
|
||||
update {v}
|
||||
</button>
|
||||
<div style="padding: 1rem 0">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { ComponentChildren } from "preact";
|
||||
import Passthrough from "../islands/Passthrough.tsx";
|
||||
|
||||
export interface FooProps {
|
||||
children?: ComponentChildren;
|
||||
n: number;
|
||||
}
|
||||
|
||||
function Foo(props: FooProps) {
|
||||
return (
|
||||
<div style="background: #e6afaf; border: 4px solid red; border-radius: .5rem; padding: 1rem; margin: 1rem;">
|
||||
<h2 class="foobar">This is static server content: #{props.n}</h2>
|
||||
<h3 class="foobar">This is static server content: #{props.n}</h3>
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function PassthroughPage() {
|
||||
return (
|
||||
<div style="padding: 2rem">
|
||||
<h2>Single</h2>
|
||||
<Passthrough n={1}>
|
||||
<Foo n={1} />
|
||||
</Passthrough>
|
||||
|
||||
<h2>Nested</h2>
|
||||
<Passthrough n={2}>
|
||||
<Foo n={2}>
|
||||
<Passthrough n={3}>
|
||||
<Foo n={3}>
|
||||
<Passthrough n={4}>
|
||||
<Foo n={4} />
|
||||
</Passthrough>
|
||||
</Foo>
|
||||
</Passthrough>
|
||||
<Passthrough n={5}>
|
||||
<Foo n={5}>
|
||||
<Passthrough n={6}>
|
||||
<Foo n={6} />
|
||||
</Passthrough>
|
||||
</Foo>
|
||||
</Passthrough>
|
||||
</Foo>
|
||||
</Passthrough>
|
||||
|
||||
<h2>Island in Island</h2>
|
||||
<Passthrough n={4}>
|
||||
<Passthrough n={5}>
|
||||
<Foo n={4} />
|
||||
</Passthrough>
|
||||
</Passthrough>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user