Skip to content

Commit 6927e1e

Browse files
committed
Not terrible pure CSS implementation
1 parent 9ba98e4 commit 6927e1e

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed
Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,64 @@
1+
import clsx from "clsx";
2+
3+
import type { TypeInfo } from "../../../renderers/base/base.ts";
14
import type { PropertyProps } from "../common/types.ts";
5+
import styles from "./styles.module.css";
6+
7+
function TypeSegment({ typeInfo }: { typeInfo: TypeInfo }) {
8+
switch (typeInfo.label) {
9+
case "array":
10+
case "map":
11+
case "set": {
12+
return (
13+
<span className={styles.typeSegment}>
14+
<span>{typeInfo.label}&lt;</span>
15+
<span>
16+
{typeInfo.children.map((childTypeInfo, i) => (
17+
<span
18+
key={i}
19+
className={clsx(styles.typeSegment, styles.unionSegment)}
20+
>
21+
<TypeSegment typeInfo={childTypeInfo} />
22+
</span>
23+
))}
24+
</span>
25+
<span>&gt;</span>
26+
</span>
27+
);
28+
}
29+
case "union":
30+
case "enum": {
31+
return (
32+
<span className={styles.typeSegment}>
33+
{typeInfo.children.map((childTypeInfo, i) => (
34+
<span
35+
key={i}
36+
className={clsx(styles.typeSegment, styles.unionSegment)}
37+
>
38+
<TypeSegment typeInfo={childTypeInfo} />
39+
</span>
40+
))}
41+
</span>
42+
);
43+
}
44+
default: {
45+
return (
46+
<span
47+
className={styles.typeSegment}
48+
dangerouslySetInnerHTML={{ __html: typeInfo.linkedLabel }}
49+
/>
50+
);
51+
}
52+
}
53+
}
254

355
export function DocusaurusProperty({ children, typeInfo }: PropertyProps) {
456
return (
5-
<div>
6-
{children}
7-
{typeInfo.label}
57+
<div className={styles.container}>
58+
<div>{children}</div>
59+
<div>
60+
<TypeSegment typeInfo={typeInfo} />
61+
</div>
862
</div>
963
);
1064
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.container {
2+
display: flex;
3+
align-items: center;
4+
row-gap: 0.5rem;
5+
flex-wrap: wrap;
6+
}
7+
8+
.container h1,
9+
.container h2,
10+
.container h3,
11+
.container h4,
12+
.container h5,
13+
.container h6 {
14+
margin: 0;
15+
}
16+
17+
.typeSegment {
18+
display: flex;
19+
align-items: center;
20+
flex-wrap: wrap;
21+
}
22+
23+
.unionSegment:not(:first-child)::before {
24+
content: "\00a0|\00a0";
25+
}

packages/docs-md/src/renderers/base/mdx.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { dirname, relative } from "node:path";
22

33
import type { TryItNowProps } from "../../components/TryItNow/common/types.ts";
4+
import { HEADINGS } from "../../pages/content/constants.ts";
45
import type {
56
RendererAppendSidebarLinkArgs,
67
RendererAppendTryItNowArgs,
78
RendererCreateAppendCodeArgs,
89
RendererCreateExpandableSectionArgs,
910
RendererCreatePillArgs,
11+
RendererCreatePropertyArgs,
1012
RendererCreateSectionContentArgs,
1113
RendererCreateSectionTitleArgs,
1214
RendererCreateTabbedSectionTabArgs,
@@ -190,6 +192,17 @@ export abstract class MdxRenderer extends MarkdownRenderer {
190192
return "</SectionTab>";
191193
}
192194

195+
public override createProperty(
196+
...[typeInfo, id, cb]: RendererCreatePropertyArgs
197+
) {
198+
this.insertComponentImport("Property");
199+
return `<Property typeInfo={${JSON.stringify(typeInfo)}}>
200+
201+
${this.createHeading(HEADINGS.PROPERTY_HEADING_LEVEL, cb(), { escape: "mdx", id })}
202+
203+
</Property>`;
204+
}
205+
193206
public override appendSidebarLink(
194207
...[{ title, embedName }]: RendererAppendSidebarLinkArgs
195208
) {

0 commit comments

Comments
 (0)