Skip to content

Commit d452644

Browse files
authored
[Docs Site] Add components for type highlighting (#17056)
1 parent 37ff8b7 commit d452644

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

src/components/MetaInfo.astro

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
import { z } from "astro:schema";
3+
4+
type Props = z.infer<typeof props>;
5+
6+
const props = z
7+
.object({
8+
text: z.string(),
9+
})
10+
.strict();
11+
12+
const { text } = props.parse(Astro.props);
13+
---
14+
15+
<span class="text-xs align-middle">{text}</span>

src/components/Type.astro

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { Badge } from "@astrojs/starlight/components";
4+
5+
type Props = z.infer<typeof props>;
6+
7+
const props = z
8+
.object({
9+
text: z.string(),
10+
})
11+
.strict();
12+
13+
const { text } = props.parse(Astro.props);
14+
---
15+
16+
<Badge
17+
text={text}
18+
size="small"
19+
style={{
20+
color: "var(--sl-text-white)",
21+
backgroundColor: "var(--sl-color-gray-6)",
22+
borderColor: "var(--sl-color-gray-3)",
23+
fontSize: "0.7rem",
24+
fontWeight: "bold",
25+
}}
26+
/>

src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export { default as LinkTitleCard } from "./LinkTitleCard.astro";
2626
export { default as ListExamples } from "./ListExamples.astro";
2727
export { default as ListTutorials } from "./ListTutorials.astro";
2828
export { default as Markdown } from "./Markdown.astro";
29+
export { default as MetaInfo } from "./MetaInfo.astro";
2930
export { default as NetworkMap } from "./NetworkMap.astro";
3031
export { default as PagesBuildEnvironment } from "./PagesBuildEnvironment.astro";
3132
export { default as PagesBuildEnvironmentLanguages } from "./PagesBuildEnvironmentLanguages.astro";
@@ -48,6 +49,7 @@ export { default as Stream } from "./Stream.astro";
4849
export { default as ThreeCardGrid } from "./ThreeCardGrid.astro";
4950
export { default as TroubleshootingList } from "./TroubleshootingList.astro";
5051
export { default as TunnelCalculator } from "./TunnelCalculator.astro";
52+
export { default as Type } from "./Type.astro";
5153
export { default as WorkersAIModels } from "./WorkersAIModels.astro";
5254
export { default as WorkersArchitectureDiagram } from "./WorkersArchitectureDiagram.astro";
5355
export { default as WorkersIsolateDiagram } from "./WorkersIsolateDiagram.astro";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Type highlighting
3+
description: Components for styling type information for CLI/function parameters.
4+
---
5+
6+
## Type
7+
8+
```mdx live
9+
import { Type } from "~/components";
10+
11+
<Type text="Promise<T | string | ArrayBuffer>" />
12+
```
13+
14+
## MetaInfo
15+
16+
```mdx live
17+
import { MetaInfo } from "~/components";
18+
19+
<MetaInfo text="(default: false) optional" />
20+
```
21+
22+
## Combined example
23+
24+
```mdx live
25+
import { Type, MetaInfo } from "~/components";
26+
27+
- `name` <Type text="string" />
28+
- The name of your service.
29+
- `local` <Type text="boolean" /> <MetaInfo text="(default: true) optional" />
30+
- If the service should run locally or not.
31+
```

0 commit comments

Comments
 (0)