Skip to content

Commit 16b31d9

Browse files
committed
TemplateList component
1 parent 01e7a42 commit 16b31d9

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

schemas/function.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ $defs:
121121
description: |
122122
The default value for this parameter, if none was given in the call to the function.
123123
This property automatically implicitly marks this parameter as optional.
124+
templateList:
125+
type: string
126+
description: It allows to display a list of possible values (radio station IDs, bone IDs, onPlayerChat message types, etc.).
127+
124128
ignore_parameters:
125129
type: array
126130
description: |
@@ -152,4 +156,7 @@ $defs:
152156
description: Type of the return value.
153157
name:
154158
type: string
155-
description: Name of the return value.
159+
description: Name of the return value.
160+
templateList:
161+
type: string
162+
description: It allows to display a list of possible values (radio station IDs, bone IDs, onPlayerChat message types, etc.).
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
const { name } = Astro.props;
3+
4+
const lists: Record<string, { id: number; label: string }[]> = {
5+
"message-types": [
6+
{ id: 0, label: "normal message" },
7+
{ id: 1, label: "action message (/me)" },
8+
{ id: 2, label: "team message" },
9+
{ id: 3, label: "private message" },
10+
{ id: 4, label: "internal message" },
11+
],
12+
};
13+
14+
const icons: Record<string, string> = {
15+
"message-types": "💬",
16+
};
17+
18+
const items = lists[name] || [];
19+
const icon = icons[name] || "";
20+
---
21+
22+
{
23+
items.length > 0 && (
24+
<ul class="template-list" style={`--icon: "${icon}"`}>
25+
{items.map((item) => (
26+
<li>
27+
<strong>{item.id}</strong>: {item.label}
28+
</li>
29+
))}
30+
</ul>
31+
)
32+
}
33+
34+
<style>
35+
.template-list {
36+
list-style: none;
37+
font-style: italic;
38+
border: 1px solid var(--sl-color-white);
39+
padding-left: 0;
40+
}
41+
42+
.template-list li::before {
43+
content: var(--icon, "○");
44+
margin-right: 0.5rem;
45+
margin-left: 0.5rem;
46+
}
47+
48+
:root[data-theme="light"] .template-list li::before {
49+
filter: sepia(1) hue-rotate(-50deg) saturate(5) brightness(1.1)
50+
drop-shadow(0 0 1px black);
51+
}
52+
53+
:root[data-theme="dark"] .template-list li::before {
54+
filter: sepia(1) hue-rotate(-50deg) saturate(5) brightness(0.8)
55+
drop-shadow(0 0 1px white);
56+
}
57+
</style>

web/src/pages/reference/[func].astro

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ChangelogList from '@src/components/ChangelogList.astro';
1818
import ItemDescription from '@src/components/ItemDescription.astro';
1919
import EnhancedMarkdown from '@src/components/EnhancedMarkdown.astro';
2020
import PreviewImages from '@src/components/PreviewImages.astro';
21+
import TemplateList from '@src/components/TemplateList.astro';
2122
2223
import { marked } from 'marked';
2324
@@ -241,6 +242,9 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
241242
<li>
242243
<strong>{param.name}</strong>:
243244
<EnhancedMarkdown content={param.description} inline={true}/>
245+
{param.templateList && (
246+
<TemplateList name={param.templateList}/>
247+
)}
244248
</li>
245249
))}
246250
</ul>
@@ -258,6 +262,9 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
258262
<li>
259263
<strong>{param.name}</strong> (default: <em>{param.default}</em>):
260264
<EnhancedMarkdown content={param.description} inline={true}/>
265+
{param.templateList && (
266+
<TemplateList name={param.templateList}/>
267+
)}
261268
</li>
262269
))}
263270
</ul>
@@ -269,7 +276,12 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
269276
<h4>Returns</h4>
270277
<ul>
271278
{syntax.returns.values.map((ret: any) => (
272-
<li set:html={"<strong>" + ret.type + "</strong>: " + renderInlineMarkdown(ret.name)} />
279+
<li>
280+
<strong>{ret.type}</strong>: {renderInlineMarkdown(ret.name)}
281+
{ret.templateList && (
282+
<TemplateList name={ret.templateList}/>
283+
)}
284+
</li>
273285
))}
274286
</ul>
275287

web/src/utils/functions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ type Parameter = {
8181
type: string;
8282
description: string;
8383
default?: string;
84+
templateList?: string;
8485
};
8586

8687
type ReturnValue = {
8788
type: string;
8889
name: string;
90+
templateList?: string;
8991
};
9092

9193
type ReturnBlock = {

0 commit comments

Comments
 (0)