Skip to content

Commit 62fcec8

Browse files
authored
chore(docs): make the docs playground version-aware (#2924)
* Make the docs playground version-aware * Fix navbar files for biome
1 parent bde059f commit 62fcec8

6 files changed

Lines changed: 91 additions & 5 deletions

File tree

website/docusaurus.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Config } from "@docusaurus/types";
44
import { themes as prismThemes } from "prism-react-renderer";
55

66
const nodeRequire = createRequire(import.meta.url);
7+
const nextDocsVersion = nodeRequire("../package.json").version;
78
const stableDocsVersion = nodeRequire(
89
"react-day-picker-v9/package.json",
910
).version;
@@ -48,7 +49,7 @@ const config: Config = {
4849
lastVersion: "current",
4950
versions: {
5051
next: {
51-
label: "next",
52+
label: nextDocsVersion,
5253
badge: true,
5354
banner: "unreleased",
5455
noIndex: true,
@@ -203,8 +204,7 @@ const config: Config = {
203204
label: "Documentation",
204205
},
205206
{
206-
href: "/playground",
207-
label: "Playground",
207+
type: "custom-versionedPlayground",
208208
position: "left",
209209
},
210210
{

website/src/components/Playground/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ const localeImportsByCalendar = {
5454
hebrew: { enUS: enUSHebrew, he: heHebrew },
5555
};
5656

57-
export function Playground() {
58-
const { props, setProps } = useQueryStringSync();
57+
type PlaygroundProps = {
58+
basePath?: string;
59+
};
60+
61+
export function Playground({ basePath = "/playground" }: PlaygroundProps) {
62+
const { props, setProps } = useQueryStringSync(basePath);
5963
const [selected, setSelected] = React.useState<
6064
Date | Date[] | DateRange | undefined
6165
>();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Head from "@docusaurus/Head";
2+
import Layout from "@theme/Layout";
3+
4+
import { Playground } from "../../components/Playground";
5+
6+
export default function NextPlaygroundPage() {
7+
return (
8+
<Layout>
9+
<Head>
10+
<title>DayPicker Playground (next)</title>
11+
<meta
12+
name="description"
13+
content="Customize the upcoming DayPicker release and see the code changes in real time."
14+
/>
15+
</Head>
16+
<main>
17+
<Playground basePath="/next/playground" />
18+
</main>
19+
</Layout>
20+
);
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ComponentTypes from "@theme-original/NavbarItem/ComponentTypes";
2+
import type { ComponentType } from "react";
3+
4+
import VersionedPlaygroundNavbarItem from "./VersionedPlaygroundNavbarItem";
5+
6+
type NavbarItemComponentMap = Record<
7+
string,
8+
ComponentType<Record<string, unknown>>
9+
>;
10+
11+
export default {
12+
...(ComponentTypes as NavbarItemComponentMap),
13+
"custom-versionedPlayground": VersionedPlaygroundNavbarItem,
14+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Link from "@docusaurus/Link";
2+
import { useDocsVersionCandidates } from "@docusaurus/plugin-content-docs/client";
3+
import { useLocation } from "@docusaurus/router";
4+
5+
type Props = {
6+
docsPluginId?: string;
7+
label?: string;
8+
className?: string;
9+
mobile?: boolean;
10+
position?: "left" | "right";
11+
[key: string]: unknown;
12+
};
13+
14+
export default function VersionedPlaygroundNavbarItem({
15+
docsPluginId,
16+
label = "Playground",
17+
className,
18+
mobile = false,
19+
position,
20+
...props
21+
}: Props) {
22+
const version = useDocsVersionCandidates(docsPluginId)[0];
23+
const { pathname } = useLocation();
24+
const to = version.name === "next" ? "/next/playground" : "/playground";
25+
const isActive = /^\/(?:next\/)?playground\/?$/.test(pathname);
26+
const activeClassName = mobile
27+
? "menu__link--active"
28+
: "navbar__link--active";
29+
const link = (
30+
<Link
31+
{...props}
32+
className={[
33+
mobile ? "menu__link" : "navbar__item navbar__link",
34+
className,
35+
isActive ? activeClassName : "",
36+
]
37+
.filter(Boolean)
38+
.join(" ")}
39+
to={to}
40+
>
41+
{label}
42+
</Link>
43+
);
44+
45+
return mobile ? <li className="menu__list-item">{link}</li> : link;
46+
}

website/versioned_docs/version-next/start.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function MyDatePicker() {
5050
## Learn More
5151

5252
- 📘 [DayPicker Anatomy](./docs/anatomy.mdx) - Understand the parts that make up a DayPicker component.
53+
- 🎮 [DayPicker Playground](/next/playground) - Experiment with the upcoming version and see the code update in real time.
5354
- 📚 [API Reference](/next/api) - Browse the prerelease v10 props, components, labels, and utilities.
5455

5556
### Customization

0 commit comments

Comments
 (0)