An open API service indexing awesome lists of open source software.

https://github.com/smithg09/react-blockly-playground

React Wrapper for Google's Blockly Library
https://github.com/smithg09/react-blockly-playground

Last synced: 2 months ago
JSON representation

React Wrapper for Google's Blockly Library

Awesome Lists containing this project

README

        

# react-blockly-playground

[![Built on Blockly](https://tinyurl.com/built-on-blockly)](https://github.com/google/blockly)

A React Wrapper for using Blockly, the visual programming editor from Google I wrote react-blockly-playground for an internal platform at Tekie to cater student's curriculum activity.

Features:

* Provides a hook as well as a function component for ease of use + flexibility
* Supports the JSON toolbox format
* Automatically propagates prop updates to Blockly
* Provides callbacks for workspace injection, disposal, changes, and XML import errors
* Automatically generates workspace XML, debounced for performance

## Installation

To add react-blockly to a React app that uses npm, run:

```bash
npm install --save react-blockly-playground
```

## How to use

You can use react-blockly as either a component or a hook.

### As component

Write `import { BlocklyWorkspace } from 'react-blockly-playground';` in your code and use BlocklyWorkspace as a component.

Example:

```jsx
import { BlocklyWorkspace } from 'react-blockly';

function MyBlocklyEditor() {
const [xml, setXml] = useState();

return (
{}}
onInject={(e) => {}}
customTheme={Blockly.Theme.Playground}
blocklyKey='One'
/>
)
}
```

### Using the hook

Write `import { useBlocklyWorkspace } from 'react-blockly-playground';` in your code and use this hook to inject a Blockly workspace into your rendered components.

Example:

```jsx
import { useBlocklyWorkspace } from 'react-blockly-playground';

function MyBlocklyHookEmbed() {
const blocklyRef = useRef(null);
const { workspace, xml } = useBlocklyWorkspace({
ref: blocklyRef,
toolboxConfiguration: MY_TOOLBOX, // this must be a JSON toolbox definition
initialXml: xml,
});

return (

// Blockly will be injected here
)
}
```