Skip to content

Commit 368d5e3

Browse files
authored
docs: Add toggle to show experimental examples (#822)
1 parent 54c3137 commit 368d5e3

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

apps/typegpu-docs/src/components/ExampleLayout.tsx

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cs from 'classnames';
22
import { useAtom, useAtomValue } from 'jotai';
3+
import { useState } from 'react';
34
import DiscordIconSvg from '../assets/discord-icon.svg';
45
import GithubIconSvg from '../assets/github-icon.svg';
56
import HamburgerSvg from '../assets/hamburger.svg';
@@ -11,8 +12,7 @@ import {
1112
import ExampleList from './ExampleList';
1213
import ExamplePage from './ExamplePage';
1314
import { Button } from './design/Button';
14-
15-
const isDev = import.meta.env.DEV;
15+
import { Toggle } from './design/Toggle';
1616

1717
export function ExampleLayout() {
1818
const menuShown = useAtomValue(menuShownAtom);
@@ -47,9 +47,14 @@ export function ExampleLayout() {
4747
);
4848
}
4949

50+
const experimentalShowingLSKey = 'experimental-showing';
51+
5052
function SideMenu() {
5153
const menuShown = useAtomValue(menuShownAtom);
5254
const menuShownMobile = useAtomValue(menuShownMobileAtom);
55+
const [experimentalShowing, setExperimentalShowing] = useState(
56+
localStorage.getItem(experimentalShowingLSKey) === 'true',
57+
);
5358

5459
return (
5560
<aside
@@ -93,11 +98,28 @@ function SideMenu() {
9398

9499
<ExampleList
95100
excludeTags={[
96-
isDev ? [] : ['experimental'],
101+
experimentalShowing ? [] : ['experimental'],
97102
typeof MediaStreamTrackProcessor === 'undefined' ? ['camera'] : [],
98103
].flat()}
99104
/>
100105

106+
<hr className="my-0 box-border w-full border-t border-tameplum-100" />
107+
108+
<label className="flex items-center justify-between gap-3 text-sm cursor-pointer">
109+
<span>Experimental examples</span>
110+
<Toggle
111+
checked={experimentalShowing}
112+
onChange={(e) => {
113+
const checked = e.target.checked;
114+
localStorage.setItem(
115+
experimentalShowingLSKey,
116+
checked ? 'true' : 'false',
117+
);
118+
setExperimentalShowing(checked);
119+
}}
120+
/>
121+
</label>
122+
101123
<div className="flex justify-between text-tameplum-800 text-xs">
102124
<div>&copy; {new Date().getFullYear()} Software Mansion S.A.</div>
103125
<div className="flex gap-3 items-center">

apps/typegpu-docs/src/components/ExampleLink.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import useEvent from '../utils/useEvent';
1111
type Props = {
1212
exampleKey: string | undefined;
1313
children?: string;
14+
isExperimental: boolean;
1415
};
1516

1617
export function ExampleLink(props: Props) {
17-
const { exampleKey, children } = props;
18+
const { exampleKey, children, isExperimental } = props;
1819

1920
const [currentExample, setCurrentExample] = useAtom(currentExampleAtom);
2021
const setMenuShownMobile = useSetAtom(menuShownMobileAtom);
@@ -40,7 +41,9 @@ export function ExampleLink(props: Props) {
4041
'flex justify-between items-center cursor-pointer no-underline',
4142
active
4243
? 'bg-clip-text bg-gradient-to-r from-gradient-purple-dark to-gradient-blue-dark text-transparent'
43-
: 'text-black',
44+
: isExperimental
45+
? 'text-gray-400'
46+
: 'text-black',
4447
)}
4548
>
4649
{children}

apps/typegpu-docs/src/components/ExampleList.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ function ExampleList({ excludeTags = [] }: { excludeTags?: string[] }) {
1919
}
2020

2121
return (
22-
<ExampleLink key={example.key} exampleKey={example.key}>
22+
<ExampleLink
23+
key={example.key}
24+
exampleKey={example.key}
25+
isExperimental={
26+
example.metadata.tags?.includes('experimental') ?? false
27+
}
28+
>
2329
{example.metadata.title}
2430
</ExampleLink>
2531
);

0 commit comments

Comments
 (0)