Giter VIP home page Giter VIP logo

react-selections's Introduction

React Selections

Build Status Coverage Status

This is a library that provides a set of tools for drawing regions with cursor.

Example

Installation

npm install --save @madappgang/react-selections

Usage

You need to specify an area for the selections to be rendered inside of. Selections can't be drawn outside the container. The package provides a container component, which you should use to render as a parent node to your selections (and other components as well).

import { Selection, SelectionContainer } from '@madappgang/react-selections';

You then simply wrap your area that you want to render selections above in the container:

const selectionArea = {
  id: 1,
  dimensions: {
    height: 150,
    width: 300
  },
  coordinates: {
    x: 100,
    y: 100
  },
};

...
<SelectionContainer>
  <Selection
    area={selectionArea}
    className="my-selection"
  />
  ...
  <AnyOtherComponent />
  ...
</SelectionContainer>
...

As you see you can render anything inside the container, it will recognize selections inside and pass them special props.

Interactive selections

If you need a selection to be draggable/resizable you need to specify it explicitly with an interactive boolean property.

<Selection interactive area={area} />

Then you have to provide a handler that is going to handle area updates.

...

constructor() {
  ...

  this.state = {
    selectionArea: { ... },
  };
}

...

handleSelectionAreaUpdate(selectionArea) {
  this.setState({ selectionArea });
}

render() {
  return (
    <SelectionContainer>
      ...
      <Selection
        interactive
        area={this.selectionArea}
        onAreaUpdate={this.handleSelectionAreaUpdate}
      />
    </SelectionContainer>
  );
}

...

...

react-selections's People

Contributors

arthurknoep avatar dprovodnikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-selections's Issues

Demo code

Hello! This is a great little package I have been using in a personal project for some time, thanks for making it public way back! Love having my little objects available at all times.

I am however having a bit of an issue adding random colors for individual objects like you have shown in your README. Could you please show off the code used for the demo? :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.