0.1.1 • Published 3 years ago

building-editor-react v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

building-editor-react

npm version

React wrapper for building-editor

Installation

npm install building-editor-react

Usage

Sample code

At any parent component

import { Provider } from 'building-editor-react';

function MyEditorParent() {
  return (
    <Provider>
      Your children
    </Provider>
  );
}

At any child component

import { Editor, ViewCube, useEvents } from 'building-editor-react';
import MyMenu from './MyMenu'; // your menu component described below

function MyEditor() {
  useEvents(); // if you need

  return (
    <>
      <Editor contextMenu={<MyMenu />} />
      <ViewCube style={{ position: 'absolute', zIndex: 1, left: 50, bottom: 50 }} />
    </>
  );
}

API

Editor

Editor component to make your editor. It takes config and contextMenu props.

Provider

Editor context provider component which must be placed parent component of Editor.

ContextMenu, ContextMenuItem, useContextMenuClose

Create your custom context menu component as below.

import { ContextMenu, ContextMenuItem, useContextMenuClose } from 'building-editor-react';

function MyMenu() {
  const closeContextMenu = useContextMenuClose();

  return (
    <ContextMenu
      onClose={closeContextMenu}
    >
      <ContextMenuItem>Your Menu</ContextMenuItem>
      <ContextMenuItem>Your Menu2</ContextMenuItem>
    </ContextMenu>
  );
}

ViewCube

Built-in ViewCube component. It's not able to be customized for now.

useEditor, useEditorState

Editor instance of building-editor is accessible from this hooks. You can get whole editor instance with useEditor while curated properties are available with useEditorState.

const { editor, setEditor } = useEditor();
const { renderer, scene, sceneHelpers, viewportCamera, raycaster, selected, hovered, gridHelper, axesHelper, planeHelper, stencilPlane } = useEditorState();

useActions

Many actions are available from this hooks. Check here to use them.

useEvents

This is built-in handler of building-editor events. It's not necessary to use this, but you can easily create editor behavior with useEvent.

0.1.0

3 years ago

0.1.1

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago