Skip to content

Commit 5de83cd

Browse files
docs: Use StackBlitz for S2, and remove CodeSandbox (#9321)
* Add StackBlitz for S2 * Remove CodeSandbox for now * fix: stackblitz examples * Simplify --------- Co-authored-by: Robert Snow <[email protected]>
1 parent 5da33c5 commit 5de83cd

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

packages/dev/s2-docs/pages/react-aria/getting-started.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Install React Aria with your preferred package manager.
2828

2929
## Quick start
3030

31-
The documentation for each component includes vanilla CSS and [Tailwind](https://tailwindcss.com) examples. Copy and paste these into your project and make them your own. You can also download each example as a ZIP or open in CodeSandbox or StackBlitz.
31+
The documentation for each component includes vanilla CSS and [Tailwind](https://tailwindcss.com) examples. Copy and paste these into your project and make them your own. You can also download each example as a ZIP or open in StackBlitz.
3232

3333
<ExampleSwitcher>
3434
```tsx render docs={docs.exports.Select} links={docs.links} props={[]} type="vanilla" files={["starters/docs/src/Select.tsx", "starters/docs/src/Select.css"]} showCoachMark

packages/dev/s2-docs/src/CodePlatter.tsx

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import {ActionButton, ActionButtonGroup, Button, ButtonGroup, Content, createIcon, Dialog, DialogContainer, Heading, Link, Menu, MenuItem, MenuTrigger, Text, ToastQueue, Tooltip, TooltipTrigger} from '@react-spectrum/s2';
44
import {CopyButton} from './CopyButton';
5-
import {createCodeSandbox, getCodeSandboxFiles} from './CodeSandbox';
65
import {createStackBlitz} from './StackBlitz';
76
import Download from '@react-spectrum/s2/icons/Download';
87
import type {DownloadFiles} from './CodeBlock';
8+
import {getCodeSandboxFiles} from './CodeSandbox';
99
import {keyframes} from '../../../@react-spectrum/s2/style/style-macro' with {type: 'macro'};
1010
import {Library} from './library';
1111
import LinkIcon from '@react-spectrum/s2/icons/Link';
1212
import OpenIn from '@react-spectrum/s2/icons/OpenIn';
13-
import Polygon4 from '@react-spectrum/s2/icons/Polygon4';
13+
// import Polygon4 from '@react-spectrum/s2/icons/Polygon4';
1414
import Prompt from '@react-spectrum/s2/icons/Prompt';
1515
import React, {createContext, ProviderProps, ReactNode, RefObject, useContext, useRef, useState} from 'react';
1616
import {ShadcnCommand} from './ShadcnCommand';
@@ -72,7 +72,7 @@ export function ShareUrlProvider(props: ProviderProps<string | null>) {
7272
export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) {
7373
let codeRef = useRef<HTMLDivElement | null>(null);
7474
let [showShadcn, setShowShadcn] = useState(false);
75-
let [showCodeSandbox, setShowCodeSandbox] = useState(false);
75+
// let [showCodeSandbox, setShowCodeSandbox] = useState(false);
7676
let getText = () => codeRef.current!.querySelector('pre')!.textContent!;
7777
let {library} = useContext(CodePlatterContext);
7878
if (!type) {
@@ -158,16 +158,16 @@ export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) {
158158
<Text>Install with shadcn</Text>
159159
</MenuItem>
160160
}
161-
{files &&
161+
{/* {files &&
162162
<MenuItem
163163
onAction={() => {
164164
setShowCodeSandbox(true);
165165
}}>
166166
<Polygon4 />
167167
<Text slot="label">Open in CodeSandbox</Text>
168168
</MenuItem>
169-
}
170-
{files && type !== 's2' &&
169+
} */}
170+
{files &&
171171
<MenuItem
172172
onAction={() => {
173173
createStackBlitz(getExampleFiles(codeRef, files, urls, entry), deps, type, entry);
@@ -192,11 +192,11 @@ export function CodePlatter({children, type, showCoachMark}: CodePlatterProps) {
192192
<div ref={codeRef}>
193193
{children}
194194
</div>
195-
<DialogContainer onDismiss={() => setShowCodeSandbox(false)}>
195+
{/* <DialogContainer onDismiss={() => setShowCodeSandbox(false)}>
196196
{showCodeSandbox &&
197197
<CodeSandboxDialog getExampleFiles={getExampleFiles} codeRef={codeRef} files={files} urls={urls} entry={entry} deps={deps} type={type} />
198198
}
199-
</DialogContainer>
199+
</DialogContainer> */}
200200
<DialogContainer onDismiss={() => setShowShadcn(false)}>
201201
{showShadcn &&
202202
<ShadcnDialog registryUrl={registryUrl} />
@@ -250,9 +250,12 @@ function getExampleCode(codeRef: RefObject<HTMLDivElement | null>, urls: {[name:
250250
}
251251
}
252252

253-
return code
253+
if (!code.includes('export default function')) {
254254
// Export the last function
255-
.replace(/\nfunction ([^(]+)((.|\n)+\n\}\n?)$/, '\nexport default function Example$2')
255+
code = code.replace(/\nfunction ([^(]+)((.|\n)+\n\}\n?)$/, '\nexport default function Example$2');
256+
}
257+
258+
return code
256259
// Add function wrapper around raw JSX in examples.
257260
.replace(/\n<((?:.|\n)+)/, (_, code) => {
258261
let res = '\nexport default function Example() {\n return (\n <';
@@ -319,31 +322,31 @@ function ShadcnDialog({registryUrl}) {
319322
);
320323
}
321324

322-
function CodeSandboxDialog({getExampleFiles, codeRef, files, urls, entry, deps, type}) {
323-
return (
324-
<Dialog size="L">
325-
{({close}) => (<>
326-
<Heading slot="title">Create a CodeSandbox</Heading>
327-
<Content>
328-
<p>This will create an editable sandbox with this example in a new tab.</p>
329-
<p><strong>Troubleshooting:</strong> If the sandbox fails to open or isn't created, try logging in to CodeSandbox first. If you're already logged in, try signing out and back in.</p>
330-
</Content>
331-
332-
<ButtonGroup>
333-
<Button variant="secondary" slot="close">Cancel</Button>
334-
<Button
335-
variant="accent"
336-
onPress={() => {
337-
createCodeSandbox(getExampleFiles(codeRef, files, urls, entry), deps, type, entry);
338-
close();
339-
}}>
340-
Open in CodeSandbox
341-
</Button>
342-
</ButtonGroup>
343-
</>)}
344-
</Dialog>
345-
);
346-
}
325+
// function CodeSandboxDialog({getExampleFiles, codeRef, files, urls, entry, deps, type}) {
326+
// return (
327+
// <Dialog size="L">
328+
// {({close}) => (<>
329+
// <Heading slot="title">Create a CodeSandbox</Heading>
330+
// <Content>
331+
// <p>This will create an editable sandbox with this example in a new tab.</p>
332+
// <p><strong>Troubleshooting:</strong> If the sandbox fails to open or isn't created, try logging in to CodeSandbox first. If you're already logged in, try signing out and back in.</p>
333+
// </Content>
334+
335+
// <ButtonGroup>
336+
// <Button variant="secondary" slot="close">Cancel</Button>
337+
// <Button
338+
// variant="accent"
339+
// onPress={() => {
340+
// createCodeSandbox(getExampleFiles(codeRef, files, urls, entry), deps, type, entry);
341+
// close();
342+
// }}>
343+
// Open in CodeSandbox
344+
// </Button>
345+
// </ButtonGroup>
346+
// </>)}
347+
// </Dialog>
348+
// );
349+
// }
347350

348351
const pulseAnimation = keyframes(`
349352
0% {

packages/dev/s2-docs/src/StackBlitz.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function getFiles(
6565
dependencies: {
6666
react: '^19',
6767
'react-dom': '^19',
68+
...(type === 's2' ? {'@react-spectrum/s2': 'latest'} : {}),
6869
...deps
6970
},
7071
devDependencies: {
@@ -77,17 +78,21 @@ function getFiles(
7778
'@tailwindcss/vite': '^4',
7879
'tailwindcss-react-aria-components': '^2',
7980
'tailwindcss-animate': '^1'
81+
} : {}),
82+
...(type === 's2' ? {
83+
'unplugin-parcel-macros': '^0.1.2-alpha.1'
8084
} : {})
8185
}
8286
}, null, 2) + '\n',
8387
'vite.config.ts': `import {defineConfig} from 'vite';
84-
import react from '@vitejs/plugin-react';${type === 'tailwind' ? "\nimport tailwindcss from '@tailwindcss/vite';" : ''}
88+
import react from '@vitejs/plugin-react';${type === 'tailwind' ? "\nimport tailwindcss from '@tailwindcss/vite';" : ''}${type === 's2' ? "\nimport macros from 'unplugin-parcel-macros';" : ''}
8589
8690
export default defineConfig({
87-
plugins: [react()${type === 'tailwind' ? ', tailwindcss()' : ''}],
91+
plugins: [${type === 's2' ? 'macros.vite(), ' : ''}react()${type === 'tailwind' ? ', tailwindcss()' : ''}],
8892
});
8993
`,
90-
'index.html': `<html lang="en">
94+
'index.html': `<!DOCTYPE html>
95+
<html lang="en">
9196
<head>
9297
<meta charset="utf-8">
9398
<title>Test</title>
@@ -99,10 +104,10 @@ export default defineConfig({
99104
</body>
100105
</html>
101106
`,
102-
'src/index.tsx': `import {createRoot} from 'react-dom/client';
107+
'src/index.tsx': `import {createRoot} from 'react-dom/client';${type === 's2' ? "\nimport '@react-spectrum/s2/page.css';\nimport {Provider} from '@react-spectrum/s2';" : ''}
103108
import ${entryName} from './${entryName}';
104109
105-
createRoot(document.getElementById('root')!).render(<${entryName} />);
110+
createRoot(document.getElementById('root')!).render(${type === 's2' ? `\n <Provider>\n <${entryName} />\n </Provider>\n` : `<${entryName} />`});
106111
`,
107112
'tsconfig.json': JSON.stringify({
108113
compilerOptions: {

0 commit comments

Comments
 (0)