You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/src/pages/advanced-usage/components.mdx
+54-48Lines changed: 54 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ import SandpackDecorators from "../../components/Decorators";
5
5
6
6
# Components
7
7
8
-
<br/>
8
+
<br/>
9
9
<imgsrc="/docs/components.jpg" />
10
10
11
11
Several `Sandpack` prefixed components are available in the `sandpack-react` package. They can be used to build custom presets, as long as they render within the providers we talked about during the previous section.
| `initMode` | This provides a way to control how some components are going to be initialized on the page. The CodeEditor and the Preview components are quite expensive and might overload the memory usage, so this gives a certain control of when to initialize them. | `"immediate" \|"lazy" \|"user-visible"` | `"lazy"` |
233
-
| `extensions` | CodeMirror extensions for the editor state, which can provide extra features and functionalities to the editor component. | `Extension[]` | `undefined` |
|`id`| By default, Sandpack generates a random value to use as an id. Usethis to override this value if you need predictable values. |`string`|`undefined`|
236
-
|`readOnly`| This disables editing of the editor content by the user. |`boolean`|`false`|
237
-
|`showReadOnly`| Controls the visibility of Read-only label, which will only appears when `readOnly` is `true`|`boolean`|`true`|
238
-
|`additionalLanguages`| Provides a way to add custom language modes by supplying a language type, applicable file extensions, and a LanguageSupport instance for that syntax mode |`CustomLanguage[]`|`undefined`|
233
+
| `extensions` | CodeMirror extensions for the editor state, which can provide extra features and functionalities to the editor component. | `Extension[]` | `undefined` |
|`id`| By default, Sandpack generates a random value to use as an id. Usethis to override this value if you need predictable values. |`string`|`undefined`|
236
+
|`readOnly`| This disables editing of the editor content by the user. |`boolean`|`false`|
237
+
|`showReadOnly`| Controls the visibility of Read-only label, which will only appears when `readOnly` is `true`|`boolean`|`true`|
238
+
|`additionalLanguages`| Provides a way to add custom language modes by supplying a language type, applicable file extensions, and a LanguageSupport instance for that syntax mode |`CustomLanguage[]`|`undefined`|
239
239
240
240
</details>
241
241
@@ -372,7 +372,7 @@ This is especially useful to get the cursor's current position, add custom decor
372
372
373
373
## File Explorer
374
374
375
-
The `SandpackFileExplorer` provides a minimal but very powerful experience to navigate through files. You can open and close folders, and open new files.
375
+
The `SandpackFileExplorer` provides a minimal but very powerful experience to navigate through files. You can open and close folders, and open new files.
376
376
377
377
<CodeBlock stack>
378
378
{`import {
@@ -393,7 +393,6 @@ export default () => (
393
393
`}
394
394
</CodeBlock>
395
395
396
-
397
396
<details>
398
397
<summary>Options</summary>
399
398
@@ -405,6 +404,13 @@ export default () => (
405
404
406
405
</details>
407
406
407
+
If you're looking for extra feature we recommend using [AaronPowell96/sandpack-file-explorer](https://github.com/AaronPowell96/sandpack-file-explorer) package which support things such as:
408
+
409
+
- Add and remove files or directories,
410
+
- Drag and drop to move files or directories,
411
+
- Allow users to customise the entire folder structure right within your website!
412
+
- Works out of the box with all of Sandpack's templates.
413
+
408
414
## Tests
409
415
410
416
The `SandpackTests` component renders a thin wrapper around [`Jest`](https://jestjs.io/) to run tests directly in the browser. This means you can run tests but additional configuration may not possible given the browser environment.
@@ -456,8 +462,8 @@ export default () => (
456
462
<details>
457
463
<summary>Options</summary>
458
464
459
-
| Prop | Description | Type | Default |
460
-
| `verbose` | Display individual test results with the test suite hierarchy. | `boolean` | `false`|
465
+
| Prop | Description | Type | Default |
466
+
| `verbose` | Display individual test results with the test suite hierarchy. | `boolean` | `false`|
461
467
| `watchMode` | Watch files for changes and rerun all tests. Note if changing a test file then the current file will run on it's own | `boolean` | `true` |
462
468
| `onComplete` | A callback that is invoked with the completed specs. | Function | `undefined` |
463
469
@@ -481,15 +487,15 @@ Add the matchers either as a dependency or as a file and then import the matcher
481
487
SandpackTests
482
488
} from"@codesandbox/sandpack-react";
483
489
484
-
constextendedTest= \`import * as matchers from 'jest-extended';
490
+
constextendedTest= \`import \* as matchers from 'jest-extended';
485
491
import { add } from './add';
486
492
487
493
expect.extend(matchers);
488
494
489
495
describe('jest-extended matchers are supported', () => {
490
-
test('adding two positive integers yields a positive integer', () => {
491
-
expect(add(1, 2)).toBePositive();
492
-
});
496
+
test('adding two positive integers yields a positive integer', () => {
497
+
expect(add(1, 2)).toBePositive();
498
+
});
493
499
});
494
500
\`;
495
501
@@ -552,8 +558,6 @@ There are three ways to print the logs:
552
558
- `<SandpackConsole />`: standalone component to render the logs;
553
559
- `useSandpackConsole`: React hook to consume the console logs from a Sandpack client;
554
560
555
-
556
-
557
561
<CodeBlock stack>
558
562
{`import { Sandpack } from "@codesandbox/sandpack-react";
| `resetOnPreviewRestart` | Reset the console list on every preview restart | `boolean` | `false` |
586
+
| `ref` | Make possible to imperatively interact with the console component | `SandpackConsoleRef` | `SandpackConsoleRef` |
587
+
| `standalone` | It runs its sandpack-client, meaning it doesn't depend on a `SandpackPreview` component. |`boolean`|`false`|
588
+
|`actionsChildren`||JSX.Element|`null`|
585
589
586
590
</details>
587
591
@@ -622,14 +626,14 @@ export default () => (
622
626
<details>
623
627
<summary>Options</summary>
624
628
625
-
| Prop | Description | Type | Default |
626
-
| :- | :- | :- | :- |
627
-
| `showTabs` | | `boolean` | `false` |
628
-
| `showLineNumbers` | | `boolean` | `false` |
629
-
| `decorators` | Provides a way to draw or style a piece of the content. | `Decorators` | `undefined` |
630
-
| `code` | | `string` | `undefined` |
631
-
| `wrapContent` | | `boolean` | `false` |
632
-
| `initMode` | This provides a way to control how some components are going to be initialized on the page. The CodeEditor and the Preview components are quite expensive and might overload the memory usage, so this gives a certain control of when to initialize them. | `"immediate" \| "lazy" \| "user-visible"` | `"lazy"` |
| `decorators` | Provides a way to draw or style a piece of the content. | `Decorators` | `undefined` |
634
+
| `code` | | `string` | `undefined` |
635
+
| `wrapContent` || `boolean` | `false` |
636
+
| `initMode` | This provides a way to control how some components are going to be initialized on the page. The CodeEditor and the Preview components are quite expensive and might overload the memory usage, so this gives a certain control of when to initialize them. | `"immediate" \| "lazy" \| "user-visible"` | `"lazy"` |
633
637
634
638
</details>
635
639
@@ -670,7 +674,6 @@ export default () => (
670
674
`}
671
675
</CodeBlock>
672
676
673
-
674
677
The `UnstyledOpenInCodeSandboxButton` is a basic component that does not carry any styles. If you want a ready-to-use component, use the `OpenInCodeSandboxButton` instead, which has the same functionality but includes the CodeSandbox logo.
675
678
676
679
## Other components
@@ -706,6 +709,9 @@ Some of the components have configuration props that toggle subparts on/off or t
706
709
of them comunicate with sandpack through the shared context.
707
710
708
711
<Callout icon="🎉">
709
-
**Congrats!**<br/>
710
-
You can now easily create a custom Sandpack component by reusing some of the building components of the library. The next step is to build your own sandpack components with the help of our custom hooks.
711
-
</Callout>
712
+
**Congrats!**
713
+
<br />
714
+
You can now easily create a custom Sandpack component by reusing some of the
715
+
building components of the library. The next step is to build your own
716
+
sandpack components with the help of our custom hooks.
0 commit comments