Skip to content

Commit f82f392

Browse files
ortatom-shermanphryneasrickhanloniiSebastian Silbermann
authored
Adds a TypeScript overview page (#6120)
* Start of the typescript page * Intro * Intro * Use State * Use Reducer * Start of context * Use Ref * Events * Wrap up 1st draft * Better titles * Apply suggestions from code review Co-authored-by: Tom Sherman <[email protected]> Co-authored-by: Lenz Weber-Tronic <[email protected]> * Note types/react and types/react-dom, and tone down the usecontext null check * Feedback * Given a 2nd run through of the doc * Apply suggestions from code review Co-authored-by: Ricky <[email protected]> * Document where `State` is coming from * Link what inferred types are * Remove "knock-on" We already say "cause" which makes "knock-on" a bit redundant * Move useRef TS usage to useRef reference page dropped useEffect since there's nothing specific about this hook. * Add installation section * Link to framework specific guides * Edits * Edit footer * Rm useRef docs --------- Co-authored-by: Tom Sherman <[email protected]> Co-authored-by: Lenz Weber-Tronic <[email protected]> Co-authored-by: Ricky <[email protected]> Co-authored-by: Sebastian Silbermann <[email protected]>
1 parent cd13b52 commit f82f392

File tree

4 files changed

+499
-0
lines changed

4 files changed

+499
-0
lines changed

src/components/MDX/Sandpack/NavigationBar.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {ResetButton} from './ResetButton';
2121
import {DownloadButton} from './DownloadButton';
2222
import {IconChevron} from '../../Icon/IconChevron';
2323
import {Listbox} from '@headlessui/react';
24+
import {OpenInTypeScriptPlaygroundButton} from './OpenInTypeScriptPlayground';
2425

2526
export function useEvent(fn: any): any {
2627
const ref = useRef(null);
@@ -184,6 +185,11 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
184185
<DownloadButton providedFiles={providedFiles} />
185186
<ResetButton onReset={handleReset} />
186187
<OpenInCodeSandboxButton />
188+
{activeFile.endsWith('.tsx') && (
189+
<OpenInTypeScriptPlaygroundButton
190+
content={sandpack.files[activeFile]?.code || ''}
191+
/>
192+
)}
187193
</div>
188194
</div>
189195
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*/
4+
5+
import {IconNewPage} from '../../Icon/IconNewPage';
6+
7+
export const OpenInTypeScriptPlaygroundButton = (props: {content: string}) => {
8+
const contentWithReactImport = `import * as React from 'react';\n\n${props.content}`;
9+
return (
10+
<a
11+
className="text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1 ml-2 md:ml-1"
12+
href={`https://www.typescriptlang.org/play#src=${encodeURIComponent(
13+
contentWithReactImport
14+
)}`}
15+
title="Open in TypeScript Playground"
16+
target="_blank"
17+
rel="noreferrer">
18+
<IconNewPage
19+
className="inline ml-1 mr-1 relative top-[1px]"
20+
width="1em"
21+
height="1em"
22+
/>
23+
<span className="hidden md:block">TypeScript Playground</span>
24+
</a>
25+
);
26+
};

0 commit comments

Comments
 (0)