1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource npm:hono/jsx **/
import { Example, ExampleSnippet } from "https://esm.town/v/pomdtr/val_town_by_example_parse";
import { TocGroup, TocItem } from "https://esm.town/v/pomdtr/val_town_by_example_toc";
export function IndexItem(props: { item: TocItem }) {
return (
<li>
<a
href={props.item.href}
class={props.item.href ? "underline" : undefined}
title={props.item.description}
>
{props.item.title}
</a>
</li>
);
}
export function IndexGroup(props: { group: TocGroup }) {
return (
<li class="md:w-1/4">
<h2 class="text-lg flex gap-1 mb-1 items-center">
<div class="font-bold">{props.group.title}</div>
</h2>
<ul>
{props.group.items.map((item) => <IndexItem item={item} />)}
</ul>
</li>
);
}
export function Example({ example }: { example: Example }) {
return (
<div>
<div class="flex justify-between items-center">
<h1 class="mt-2 text-3xl font-bold">{example.title}</h1>
<div class="flex justify-between items-center gap-x-2">
{example.preview
? (
<a
href={example.preview}
class="px-4 py-2 rounded bg-gray-100 hover:bg-gray-300 text-slate-900"
>
Open preview
</a>
)
: null}
<a
href={example.href}
class="px-4 py-2 rounded bg-gray-100 hover:bg-gray-300 text-slate-900"
>
Edit example
</a>
</div>
</div>
{example.description && (
<div class="mt-1">
<p class="text-gray-500">{example.description}</p>
</div>
)}
{example.vals.map((val) => (
<div class="mt-10">
{val.snippets.map((snippet, i) => (
<Snippet
firstOfFile={i === 0}
lastOfFile={i === val.snippets.length - 1}
val={val}
snippet={snippet}
/>
))}
</div>
))}
{example.resources.length > 0
? (
<div class="grid grid-cols-1 sm:grid-cols-10 gap-x-8">
<div class="col-span-3 mt-8"></div>
<div class="col-span-7 mt-8 border-t">
<p class="text-gray-500 pt-2">Additional resources:</p>
<ul class="list-disc list-inside mt-1">
{example.resources.map(({ link, title }) => (
<li class="text-gray-700 hover:text-gray-900" key={link + title}>
<a class="hover:underline focus:underline" href={link}>
{title}
</a>
</li>
))}
</ul>
</div>
</div>
)
: null}
</div>
);
}
export function Snippet(props: {
firstOfFile: boolean;
lastOfFile: boolean;