Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@opentf/react-sandbox

The CodeSandbox sandpack wrapper with tabs layout.

react, sandbox, sandpack

readme

 OPEN TECH FOUNDATION

React Sandbox

Demo gif

The CodeSandbox sandpack wrapper with additional features.

View Demo

Features

  • Multiple Layouts (Tabs, Code+Console, etc)
  • Choose between console types: Basic or Advanced(console-feed)

Installation

npm install @opentf/react-sandbox
yarn add @opentf/react-sandbox
pnpm add @opentf/react-sandbox
bun add @opentf/react-sandbox

Usage

import { SandBox } from '@opentf/react-sandbox';

export default function App() {
  const code = `export default function App() {
    return <h1>Hello world</h1>
  }`;

  return <SandBox code={code} />;
}

Props

Name Type Required Default Description
code string Yes '' Template specific default file content
Eg: nextjs -> pages/index.js
template string No 'react' The codesandbox template.
theme SandpackThemeProp No 'auto' The codesandbox theme.
layout string No 'Default' Currently, there are three presets available:
1. Default
2.Tabs
3. Code_Console
deps string[] No [] The npm dependencies.
eg: ['lodash', 'immer@10.0.0'].
files Record<string, string> No {} The files prop accepts an object, where each key is the relative path of that file in the sandbox folder structure.
cdns string[] No [] Any third party external dependencies, eg: ['https://cdn.tailwindcss.com']
tabIndex number No 0 The tab index to select in the Tabs layout
consoleType string No 'Basic' There are two types, Basic and Advanced.
It uses console-feed for 'Advanced'

License

Copyright (c) Thanga Ganapathy (MIT License).

changelog

@opentf/react-sandbox

0.15.0

Minor Changes

  • 400af78: Added missing theme prop.

0.14.0

Minor Changes

  • 084fc3e: Updated pkg deps.

0.13.0

Minor Changes

  • cde1a26: Added pkg publishing provenance.

0.12.0

Minor Changes

  • aff1aa7: Update code sandbox to upstream

0.11.0

Minor Changes

  • 55519b7: Added multiple layouts

0.10.0

Minor Changes

  • 281b642: Added client-server tabs to the advanced console.

0.9.0

Minor Changes

  • 757863c: Added consoleType prop for basic & advanced(console-feed) console.

0.8.1

Patch Changes

  • 4972e5e: Update readme with demo links

0.8.0

Minor Changes

  • 9857106: Added template specific default files config

0.7.0

Minor Changes

  • 8bc197c: Added tabIndex prop for sandbox

0.6.0

Minor Changes

  • eb83c75: Added style prop to the sandbox component

0.5.0

Minor Changes

  • 4adf299: Fixed console props & styles

0.4.0

Minor Changes

  • 2694751: Fixed pkg entries

0.3.1

Patch Changes

  • 7e332f5: Fix pkg repo url & readme screenshot path

0.3.0

Minor Changes

  • 86c98e1: Added tabs layout, upgraded sandpack, migrated to tsup, pnpm & added demo