0.0.7 • Published 3 years ago

@space-kit/react-flow v0.0.7

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

React Flow

Installation

npm install --save @space-kit/react-flow

Documentation

APIs

  • <FlowProvider /> - Provider to handle all blocks drag and drop
  • <Canvas /> - Canvas where the blocks are drawn
  • <DraggableBlock /> - Make your blocks draggable
  • useFlow - Hook to get data about the blocks, removeBlock etc.

FlowProvider

Example

import { FlowProvider } from '@space-kit/react-flow';

<FlowProvider
  blocks={blocks}
  padding={{ x: 20, y: 80 }}
  arrowColor="#ffffff"
  onBlockSelected={(blockId: string) => {
    console.log('Block selected', blockId);
  }}
  onBlockChange={(blocks: BlockItem[]) => {
    console.log(blocks);
  }}
>

Props Table

PropTypeDescription
childrenReact.ReactElement OR React.ReactElement[]Any react children
blocksBlockItem[]Initial blocks
paddingFlowPositionGap between each blocks
arrowColorstringColor of the arrows
onBlockSelected(blockId: string) => voidCalls when a block is selected
onBlockChange(blocks: BlockItem[]) => voidCalls when blocks are changed

Canvas

Example

import { Canvas } from '@space-kit/react-flow';

<Canvas
  style={{
    width: '100%',
    border: '1px solid #000',
    background: '#2f2b2b',
    height: 700,
    overflow: 'scroll',
  }}
/>;

Props Table

PropTypeDescription
styleReact.CSSPropertiesStyles that should be applied to canvas

DraggableBlock

Example

import { DraggableBlock } from '@space-kit/react-flow';

<DraggableBlock
  id="block1"
  draggable
  blockTemplate={({ isActive }) => (
    <DragTemplate data="Block 1" isActive={isActive} />
  )}
  width={100}
  height={60}
>
  Blocks
</DraggableBlock>;

Props Table

PropTypeDescription
idstringUnique id for each draggable block. This will be used for rendering template and width
childrenReact.ReactChildThe block that needs to be dragged
draggablebooleanIs the block draggable
clonebooleanDoes the drag clone the component
onClick() => voidCalls when a draggable is clicked
blockTemplate(component: ComponentProps) => React.ReactChildReact component that needs to be rendered in the canvas
widthnumberWidth of the block
heightnumberHeight of the block

useFlow

Example

import { useFlow } from '@space-kit/react-flow';

const { blocks, removeBlock } = useFlow();
ParametersDescription
blocksGet the blocks that are rendered
removeBlockCan be used to remove a block
0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago