Skip to content

Commit 0c72ff4

Browse files
committed
chore: props table ui
1 parent 707dcc3 commit 0c72ff4

5 files changed

Lines changed: 142 additions & 15 deletions

File tree

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@solidjs/router": "^0.15.3",
1717
"@solidjs/start": "^1.1.0",
1818
"monaco-editor": "^0.52.2",
19+
"shiki": "^3.4.2",
1920
"solid-docgen": "workspace:*",
2021
"solid-js": "^1.9.5",
2122
"typescript": "^5.8.3",

docs/src/component/PropsTable.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
html[data-theme="dark"] .shiki,
2+
html[data-theme="dark"] .shiki span {
3+
color: var(--1) !important;
4+
background-color: var(--1-bg) !important;
5+
/* Optional, if you also want font styles */
6+
font-style: var(--1-font-style) !important;
7+
font-weight: var(--1-font-weight) !important;
8+
text-decoration: var(--1-text-decoration) !important;
9+
}
10+
11+
.shiki, .shiki span {
12+
--0-bg: var(--sb-code-background-color) !important;
13+
--1-bg: var(--sb-code-background-color) !important;
14+
}
15+
16+
.props-table-type {
17+
display: inline-block;
18+
font-size: .9em;
19+
padding: 0.1em 0.3em;
20+
border-radius: var(--sb-border-radius);
21+
background-color: var(--sb-code-background-color);
22+
}

docs/src/component/PropsTable.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { mdxComponents } from "@kobalte/solidbase/client";
2+
import { createHighlighter } from "shiki";
23
import type { Documentation } from "solid-docgen";
34
import { stringifyType } from "solid-docgen/stringify";
4-
import { Dynamic, For, Show } from "solid-js/web";
5+
import { Dynamic, For, NoHydration } from "solid-js/web";
6+
import "./PropsTable.css";
57

68
interface PropsTableProps {
79
docgen: Documentation;
810
}
911

12+
const highlighter = await createHighlighter({
13+
themes: ["github-dark", "github-light"],
14+
langs: ["typescript"],
15+
});
16+
1017
export function PropsTable(props: PropsTableProps) {
1118
return (
1219
<>
@@ -16,8 +23,6 @@ export function PropsTable(props: PropsTableProps) {
1623
<thead>
1724
<tr>
1825
<th>Prop</th>
19-
<th>Type</th>
20-
<th>Default</th>
2126
<th>Description</th>
2227
</tr>
2328
</thead>
@@ -32,18 +37,23 @@ export function PropsTable(props: PropsTableProps) {
3237
</Dynamic>
3338
</td>
3439
<td>
35-
<Dynamic component={mdxComponents.code}>
36-
{stringifyType(propValue.type)}
37-
</Dynamic>
38-
</td>
39-
<td>
40-
<Show when={propValue.defaultValue}>
41-
<Dynamic component={mdxComponents.code}>
42-
{stringifyType(propValue.defaultValue!, " ", ",")}
43-
</Dynamic>
44-
</Show>
40+
<NoHydration>
41+
<span class="props-table-type" innerHTML={highlighter.codeToHtml(
42+
stringifyType(propValue.type) + (propValue.defaultValue ? ` = ${stringifyType(propValue.defaultValue!, " ", ",")}` : "" ),
43+
{
44+
lang: "typescript",
45+
themes: {
46+
0: "github-light",
47+
1: "github-dark",
48+
},
49+
defaultColor: "0",
50+
cssVariablePrefix: "--",
51+
}
52+
)}/>
53+
<br />
54+
</NoHydration>
55+
{propValue.description}
4556
</td>
46-
<td>{propValue.description}</td>
4757
</tr>
4858
)}
4959
</For>

pnpm-lock.yaml

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/stringify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function stringifyType(
5353
obj += "}";
5454

5555
if (obj.replaceAll(/\$SOLID_DOCGEN_NEWLINE\$\s*/g, " ").length < maxObjLen)
56-
obj = obj.replaceAll(/\$SOLID_DOCGEN_NEWLINE\$\s+/g, " ");
56+
obj = obj.replaceAll(/\$SOLID_DOCGEN_NEWLINE\$\s*/g, " ");
5757
else obj = obj.replaceAll("$SOLID_DOCGEN_NEWLINE$", "\n");
5858

5959
return obj;

0 commit comments

Comments
 (0)