Skip to content

Commit 08949cb

Browse files
committed
docs: update version banner + jsx imports
1 parent 826fcd1 commit 08949cb

File tree

5 files changed

+153
-12
lines changed

5 files changed

+153
-12
lines changed

apps/website/docs/guide/04-jsx-components/01-using-jsx.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,26 @@ builders:
4040
## Example usage
4141

4242
```tsx
43-
import { Button, ActionRow } from 'commandkit';
43+
import {
44+
Container,
45+
TextDisplay,
46+
ActionRow,
47+
Button,
48+
} from 'commandkit';
49+
import { ButtonStyle } from 'discord.js';
4450

4551
const message = (
4652
<Container>
4753
<TextDisplay>Welcome to our server!</TextDisplay>
4854
<ActionRow>
49-
<Button style="primary">Click me!</Button>
55+
<Button style={ButtonStyle.Primary}>Click me!</Button>
5056
</ActionRow>
5157
</Container>
5258
);
59+
60+
interaction.reply({
61+
components: [message],
62+
});
5363
```
5464

5565
## JSX fragments
@@ -64,4 +74,8 @@ const elements = (
6474
<TextDisplay>Second message</TextDisplay>
6575
</>
6676
);
77+
78+
interaction.reply({
79+
components: elements,
80+
});
6781
```

apps/website/docusaurus.config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ const config: Config = {
3434
'classic',
3535
{
3636
docs: {
37-
lastVersion: '0.1.10',
37+
lastVersion: 'current',
3838
versions: {
3939
current: {
40-
label: 'v1',
40+
label: '1.x',
4141
// path: 'v1',
42-
badge: false,
42+
badge: true,
43+
banner: 'none',
4344
},
4445
'0.1.10': {
45-
label: 'v0.1.10',
46+
label: '0.1.10',
4647
path: 'v0',
48+
badge: true,
49+
banner: 'none',
4750
},
4851
},
4952
sidebarPath: './sidebars.ts',
@@ -140,8 +143,8 @@ const config: Config = {
140143
type: 'docsVersionDropdown',
141144
position: 'right',
142145
versions: {
143-
current: { label: 'v1' },
144-
'0.1.10': { label: 'v0' },
146+
current: { label: '1.x' },
147+
'0.1.10': { label: '0.1.10' },
145148
},
146149
},
147150
{

apps/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@docusaurus/core": "3.8.1",
1919
"@docusaurus/plugin-sitemap": "^3.7.0",
2020
"@docusaurus/preset-classic": "3.8.1",
21+
"@docusaurus/theme-common": "^3.8.1",
2122
"@docusaurus/theme-mermaid": "^3.8.1",
2223
"@docusaurus/theme-search-algolia": "^3.7.0",
2324
"@mdx-js/react": "^3.0.0",
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// borrowed from https://github.com/trpc/trpc/blob/ec5185f702a683e84590492189844c4a39f9529c/www/src/theme/DocVersionBanner/index.tsx
2+
import React from 'react';
3+
4+
import Link from '@docusaurus/Link';
5+
import { useLocation } from '@docusaurus/router';
6+
import { ThemeClassNames } from '@docusaurus/theme-common';
7+
import useGlobalData from '@docusaurus/useGlobalData';
8+
import DocVersionBanner from '@theme-original/DocVersionBanner';
9+
import clsx from 'clsx';
10+
11+
type VersionLabel = '1.x' | '0.1.10';
12+
13+
interface Version {
14+
name: string;
15+
label: VersionLabel;
16+
isLast: boolean;
17+
path: string;
18+
mainDocId: string;
19+
docs: Doc[];
20+
draftIds: any[];
21+
sidebars: Sidebars;
22+
}
23+
24+
interface Doc {
25+
id: string;
26+
path: string;
27+
sidebar?: string;
28+
}
29+
30+
interface Sidebars {
31+
docs: Docs;
32+
}
33+
34+
interface Docs {
35+
link: Link;
36+
}
37+
38+
interface Link {
39+
path: string;
40+
label: string;
41+
}
42+
43+
function useTypedVersion() {
44+
const location = useLocation();
45+
46+
const globalData = useGlobalData();
47+
48+
const versions: Version[] = (
49+
globalData['docusaurus-plugin-content-docs'] as any
50+
).default.versions;
51+
52+
const byLabel = {} as Record<VersionLabel, Version>;
53+
for (const version of versions) {
54+
byLabel[version.label] = version;
55+
}
56+
57+
const currentVersion: Version =
58+
versions
59+
.filter((it) => it.path !== '/docs')
60+
.find((it) => location.pathname.startsWith(it.path)) ??
61+
versions.find((it) => it.isLast) ??
62+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63+
versions[0]!;
64+
65+
return {
66+
currentVersion,
67+
byLabel,
68+
};
69+
}
70+
71+
export default function DocVersionBannerWrapper(
72+
props: React.ComponentProps<typeof DocVersionBanner>,
73+
) {
74+
const location = useLocation();
75+
const versions = useTypedVersion();
76+
77+
switch (versions.currentVersion.label) {
78+
case '1.x': {
79+
if (
80+
location.pathname.startsWith('/docs/guide/advanced/migrating-from-v0')
81+
) {
82+
// skip banner on migration page
83+
return null;
84+
}
85+
86+
return (
87+
<div
88+
className={clsx(
89+
ThemeClassNames.docs.docVersionBanner,
90+
'alert alert--info margin-bottom--md space-y-2',
91+
)}
92+
role="alert"
93+
>
94+
<p>
95+
You are looking at documentation for CommandKit version{' '}
96+
<strong>1.x</strong> (release candidate).
97+
</p>
98+
<ul className="list-inside list-disc">
99+
<li>
100+
To go to the v0 documentation,{' '}
101+
<Link href="/docs/v0/guide/installation">click here</Link>.
102+
</li>
103+
<li>
104+
To see how to migrate from v0 to v1,{' '}
105+
<Link href="/docs/guide/advanced/migrating-from-v0">
106+
click here
107+
</Link>
108+
.
109+
</li>
110+
</ul>
111+
</div>
112+
);
113+
}
114+
115+
case '0.1.10':
116+
default: {
117+
return <DocVersionBanner {...props} />;
118+
}
119+
}
120+
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)