@@ -0,0 +1,26 @@
|
||||
import { type Signal, useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
export interface CounterProps {
|
||||
id?: string;
|
||||
count: Signal<number>;
|
||||
}
|
||||
|
||||
export function Counter(props: CounterProps) {
|
||||
const active = useSignal(false);
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div id={props.id} class={active.value ? "ready" : ""}>
|
||||
<button class="decrement" onClick={() => props.count.value -= 1}>
|
||||
-1
|
||||
</button>
|
||||
<p class="output">{props.count}</p>
|
||||
<button class="increment" onClick={() => props.count.value += 1}>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
import type { ComponentChildren } from "preact";
|
||||
|
||||
export function CounterWithSlots(
|
||||
props: { children?: ComponentChildren; jsx?: ComponentChildren },
|
||||
) {
|
||||
const sig = useSignal(0);
|
||||
const active = useSignal(false);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div class={active.value ? "ready" : ""}>
|
||||
<div class="counter-with-children">
|
||||
<p class="output">{sig}</p>
|
||||
<button onClick={() => sig.value = sig.peek() + 1}>update</button>
|
||||
</div>
|
||||
<div class="children">
|
||||
{props.children}
|
||||
</div>
|
||||
<div class="jsx">
|
||||
{props.jsx}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export function EscapeIsland(props: { str: string }) {
|
||||
const active = useSignal(false);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div class={active.value ? "ready" : ""}>
|
||||
it works
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { VNode } from "preact";
|
||||
|
||||
import { FragmentIsland } from "./FragmentIsland.tsx";
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
function Foo(props: { children: () => VNode }) {
|
||||
return props.children();
|
||||
}
|
||||
|
||||
export function FnIsland() {
|
||||
const active = useSignal(false);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div class={active.value ? "ready" : ""}>
|
||||
<Foo>
|
||||
{() => <FragmentIsland />}
|
||||
</Foo>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export function FragmentIsland() {
|
||||
return (
|
||||
<>
|
||||
<p>it{" "}</p>
|
||||
<p>works</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { Counter } from "./Counter.tsx";
|
||||
|
||||
export function IslandInIsland() {
|
||||
const sig = useSignal(0);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button class="trigger" onClick={() => sig.value = sig.peek() + 1}>
|
||||
trigger
|
||||
</button>
|
||||
<Counter count={sig} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import data from "./data.json" with { type: "json" };
|
||||
|
||||
export function JsonIsland() {
|
||||
return <pre>{JSON.stringify(data)}</pre>;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
import type { ComponentChildren } from "preact";
|
||||
|
||||
export interface JsxIslandProps {
|
||||
children?: ComponentChildren;
|
||||
}
|
||||
|
||||
export function JsxChildrenIsland(props: JsxIslandProps) {
|
||||
const active = useSignal(false);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div class={active.value ? "ready" : ""}>
|
||||
<div class="children">{props.children}</div>
|
||||
{active.value ? <div class="after">{props.children}</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
import type { ComponentChildren } from "preact";
|
||||
|
||||
export interface JsxConditionalProps {
|
||||
jsx?: ComponentChildren;
|
||||
children?: ComponentChildren;
|
||||
}
|
||||
|
||||
export function JsxConditional(props: JsxConditionalProps) {
|
||||
const active = useSignal(false);
|
||||
const sig = useSignal(0);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div class={active.value ? "ready" : ""}>
|
||||
<p class="cond-output">{sig}</p>
|
||||
<button class="cond-update" onClick={() => sig.value = sig.peek() + 1}>
|
||||
update
|
||||
</button>
|
||||
<div class="jsx">{active.value ? props.jsx : null}</div>
|
||||
<div class="children">{active.value ? props.children : null}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { type ComponentChildren, isValidElement } from "preact";
|
||||
|
||||
export interface JsxIslandProps {
|
||||
jsx?: ComponentChildren;
|
||||
children?: ComponentChildren;
|
||||
}
|
||||
|
||||
export function JsxIsland(props: JsxIslandProps) {
|
||||
const active = useSignal(false);
|
||||
const sig = useSignal(0);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
return (
|
||||
<div class={active.value ? "ready" : ""}>
|
||||
<p class="output">{sig}</p>
|
||||
<button class="update" onClick={() => sig.value = sig.peek() + 1}>
|
||||
update
|
||||
</button>
|
||||
<div class="jsx">{props.jsx}</div>
|
||||
<div class="children">{props.children}</div>
|
||||
<pre>{JSON.stringify({jsx: isValidElement(props.jsx), children: isValidElement(props.children)})}</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { ComponentChildren } from "preact";
|
||||
import { Counter } from "./Counter.tsx";
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export interface MultipleProps {
|
||||
id?: string;
|
||||
children?: ComponentChildren;
|
||||
}
|
||||
|
||||
export function Multiple1(props: MultipleProps) {
|
||||
const sig = useSignal(0);
|
||||
return <Counter id={props.id} count={sig} />;
|
||||
}
|
||||
export function Multiple2(props: MultipleProps) {
|
||||
const sig = useSignal(0);
|
||||
return <Counter id={props.id} count={sig} />;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
export function NullIsland() {
|
||||
useEffect(() => {
|
||||
const div = document.createElement("div");
|
||||
div.className = "ready";
|
||||
document.body.appendChild(div);
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Partial } from "@fresh/core/runtime";
|
||||
|
||||
export function PartialInIsland() {
|
||||
return (
|
||||
<Partial name="invalid">
|
||||
<p class="invalid">invalid</p>
|
||||
</Partial>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { ComponentChildren } from "preact";
|
||||
|
||||
export function PassThrough(props: { children?: ComponentChildren }) {
|
||||
return (
|
||||
<div class="passthrough">
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
export interface SelfCounterProps {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export function SelfCounter(props: SelfCounterProps) {
|
||||
const count = useSignal(0);
|
||||
const active = useSignal(false);
|
||||
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div id={props.id} class={active.value ? "ready self-counter" : ""}>
|
||||
<button type="button" class="decrement" onClick={() => count.value -= 1}>
|
||||
-1
|
||||
</button>
|
||||
<p class="output">{count}</p>
|
||||
<button type="button" class="increment" onClick={() => count.value += 1}>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"foo": 123
|
||||
}
|
||||
Reference in New Issue
Block a user