Git Product home page Git Product logo

react-absolute-grid's Introduction

React Absolute Grid

Unmaintained:

This library is unmaintained and has not been tested to work with React 16+. We're looking for maintainers. If you're interested, file an issue.

Description:

An absolute layout grid with animations, filtering, zooming, and drag and drop support. Use your own component as the grid item. See the Demo.

Usage:

Install with npm install react-absolute-grid

import React from 'react';
import createAbsoluteGrid from './lib/AbsoluteGrid.jsx';

// This is the component that will display your data
import YourDisplayComponent from 'your-display-component';

 var sampleItems = [
  {key: 1, name: 'Test', sort: 0, filtered: 0},
  {key: 2, name: 'Test 1', sort: 1, filtered: 0},
];

// Pass your display component to create a new grid
const AbsoluteGrid = createAbsoluteGrid(YourDisplayComponent, {someProp: 'my component needs this'});
React.render(<AbsoluteGrid items={sampleItems} />, document.getElementById('Container'));

CreateAbsoluteGrid

createAbsoluteGrid(DisplayComponent, displayProps = {}, forceImpure = false)
  • DisplayComponent: is a react component to display in your grid
  • displayProps: optional : are properties you want passed down to the DisplayComponent such as event handlers.
  • forceImpure: optional : not recommended Will make this function as an impure component, meaning it always renders.

Options (Properties)

Property Default Description
items [] The array of items in the grid
keyProp 'key' The property to be used as a key
filterProp 'filtered' The property to be used for filtering, if the filtered value is true, the item won't be displayed. It's important to not remove items from the array because that will cause React to remove the DOM, for performance we would rather hide it then remove it.
sortProp 'sort' The property to sort on
itemWidth 128 The width of an item
itemHeight 128 The height of an item
verticalMargin -1 How much space between rows, -1 means the same as columns margin which is dynamically calculated based on width
responsive false If the container has a dynamic width, set this to true to update when the browser resizes
dragEnabled false Enables drag and drop listeners, onMove will be called with the keys involved in a drag and drop
animation 'transform 300ms ease' The CSS animation to use on elements. Pass a blank string or false for no animation.
zoom 1 Zooms the contents of the grid, 1 = 100%
onMove fn(from, to) This function is called when an item is dragged over another item. It is your responsibility to update the sort of all items when this happens.
onDragStart fn(e) This function is called when an item starts dragging, this is NOT required.
onDragMove fn(e) This function is called when as an item is being moved, this is NOT required.
onDragEnd fn(e) This function is called when an item has finished its drag, this is NOT required.

Your Component

Your component will receive item, index and itemsLength as props, as well as anything you pass into the createAbsoluteGrid function. Here's the simplest possible example:

import React from 'react';

export default function SampleDisplay(props) {
    // Supposing your item shape is something like {name: 'foo'}
    const { item, index, itemsLength } = props;
    return <div>Item {index} of {itemsLength}: {item.name}</div>;
}

What Makes AbsoluteGrid Unique?

The idea behind AbsoluteGrid is high performance. This is achieved by using Translate3d to position each item in the layout. Items are never removed from the DOM, instead they are hidden. For best performance you should avoid re-arranging or removing items which you pass into AbsoluteGrid, instead you can use the filtered and sort properties to hide or sort an item. Those properties are customizable using the keyProp and filterProp properties. In addition, all data passed must be immutable so that we don't waste any renders.

Your Display Component props

Each Component is passed the following props, as well as anything passed into the second parameter of createAbsoluteGrid

Property Description
item The data associated with the GridItem
index The index of the item data in the items array
itemsLength The total length of the items array
...displayProps props passed into createAbsoluteGrid

ToDo:

  • Tests
  • Improve Drag & Drop browser support and reliability

Browser Compatibility

This component should work in all browsers that support CSS3 3D Transforms. If you need IE9 support you can modify it to use transform rather than transform3d. Pull requests welcome!

Drag and Drop only works on IE11+ due to lack of pointer events, although there is a workaround coming soon.

Migrating from 2.x

Instead of passing displayObject to the AbsoluteGrid component, pass the component directly into the composer function, createAbsoluteGrid which returns an AbsoluteGrid component. That's it!

react-absolute-grid's People

Contributors

bjoerge avatar conorhastings avatar diwu1989 avatar jrowny avatar okonet avatar sl4vr avatar wyze 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  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  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  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  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

react-absolute-grid's Issues

Webpack 4 : Not possible to compile :(

Here is the error message that i have :

./node_modules/react-absolute-grid/lib/AbsoluteGrid.jsx Module parse failed: Unexpected token (17:24) You may need an appropriate loader to handle this file type. | | return class extends Comp { | static defaultProps = { | items: [], | keyProp: 'key',
This error occurred during the build time and cannot be dismissed.

It is impossible for me actually to use the component :(.
I have webpack 4 and jsx is activated in config file.

I just tried to implement the exemple of the doc in a fonctionnal project.

Request: use .js instead of .jsx

Using .js as a file extension will make this easier to consume as a library for those of us that don't have jsx in a webpack loader :)

Question: How to fix the max height of the grid

Hi,
I'm looking for a way to fix the height of the grid. For now, I tried to put a height on its container but the grid style render out of the box. I tried to put a fixed size everywhere but nothing worked to make the grid in a fixed sized box with a scollbar.
Can someone indicate me a way to do it ?

Thanks,

How to filter grid items using radio buttons in a React component?

I'm having trouble wiring up react-absolute-grid using radio buttons within a React component. I tried adapting the demo implementation to a React component, but I may be making some errors along the way.

Initially, both grid items are rendered, but they are not filtered (i.e. shown/hidden) as I click the radio buttons (even though this.state.filteredItems updates with each radio button click).

Here's what I have so far:

import React from 'react'
import createAbsoluteGrid from 'react-absolute-grid'

const items = [
  { key: 1, name: 'Test 1', filtered: false },
  { key: 2, name: 'Test 2', filtered: false }
]

const GridItem = ({ item }) => <p>{item.name}</p>
const AbsoluteGrid = createAbsoluteGrid(GridItem)

class Grid extends React.Component {
  constructor(props) {
    super(props)
    this.state = { filteredItems: items.slice() }
  }

  filterItems = event => {
    let name = event.target.value
    this.setState.filteredItems = this.state.filteredItems.map(item => {
      let isMatched = item.name == name
      item.filtered = !isMatched
      return item
    })
  }

  render() {
    return (
      <div>
        <input onClick={this.filterItems} type="radio" value="Test 1" name="name"/> Test 1
        <input onClick={this.filterItems} type="radio" value="Test 2" name="name"/> Test 2
	<AbsoluteGrid items={this.state.filteredItems} responsive={true} />
      </div>
    )
  }
}

Can you let me know what I'm doing wrong?

onDragEnd param undefined.

The onDragEnd = e =>{ e is undefined}

I am not able to receive e it is undefined. while the same works well with onDragStart and onDragMove.

Could you please check.

Can't delete a displayObject item without a warning

Hi everyone,

First, thanks for the great work.

I can't figure out how to remove an item in the items array. I've tried using splice for an element and then re-rendering, but I get the warning:

Warning: setState(...): Can only update a mounted or mounting component

I store the items array in a state (this.state.imageBlocks). Every displayObject has an onClick handler bound to the below mentioned callback destroyImage that removes the item and updates the state array.

 destroyImage(item) {
    var newBlocks = this.state.imageBlocks, index;
    index = newBlocks.findIndex(i => i.key === item.key);
    newBlocks.splice(index, 1);
    this.setState({imageBlocks: newBlocks});
  },

I assume the warning relates to not unbinding onClick handler in the componentDidUnmount of the displayObject. I wasn't able to find a way to unbind that.

Any pointers would be appreciated.

dragEnabled=true does not work with material-ui TextField in grid item component

I am using material-ui along with AbsoluteGrid. When I have the TextField component in my grid item component, I cannot click on the TextField to select it and start editing text. Only with dragEnabled=false does this work. I believe this is because the AbsoluteGrid is eating the touch events in the onDrag function.

IE 10 drag and drop support

Beautiful work! I'm hoping to use this for a project, but IE 10 support is a hard requirement. The Readme says that IE 10 support is coming soon - how soon? I'd be happy to help.

createAbsoluteGrid is not a function

[email protected]
[email protected]

migrated from 2.0.1 to 3.0.1

    var createAbsoluteGrid = require('react-absolute-grid');
    
    var Createvisit= createReactClass({
      
    getInitialState: function(){
        return {
          result:[],
        };
      },

      componentWillMount: function() {
        const AbsoluteGrid = createAbsoluteGrid(SampleDisplay);
      },

  render: function() {
    return (
      <AbsoluteGrid items={this.state.result}/>
    )
  }
});
module.exports =  Createvisit;

var SampleDisplay = createReactClass({
  render: function() {
    const { item, index, itemsLength } = this.props;
    ..........
    ..........
    return (
      <div style={itemStyle} className="gridItem" id={id} onClick={this.click}>
        <span className="name" id={id}>
        {itemname}</span>
      </div>
    );
  }
});`

React 0.16 Support

With React 0.16, it throws an error because PropTypes is no longer included with the main React package. It has a separate package now.

Responsive in Container (Revisited)

Hello,
So I saw this post: #19

I don't see any built-in way to tell it the current grid width so that it can be fit inside the container this way. Perhaps it would be good to have a gridWidth prop that listens for changes from the parent and re-calculates as-necessary?

react-absolute-grid on mobile

Hello,

I'm struggling for a while in a problem with animations + cordova.
Any kind of implementation of animation that I try I do not get 20fps on the mobile enviroment.

Did you already tested on mobile?

Another question is:

Can I implement a list of itens instead of a grid?

Rendering expandable elements

Hi,

I work on a use case where I need to sort a few elements that could be expanded. The problem I encountered was that when an element was expanded the expanded content was overflowing behind the next element in the same column.

Initial state

image

Expanded state (with darker blue is the expanded content)

image

A better behavior would be the following, where the expanded content moves the item down to y-axis

image

HelpWanted: Unexpected token:You may need an appropriate loader

hi,

i'm probably doing something stupid, but while trying to implement it in my project i get:

ERROR in ./node_modules/react-absolute-grid/lib/AbsoluteGrid.jsx
Module parse failed: d:...........\node_modules\react-absolute-grid\lib\AbsoluteGrid.jsx Unexpected token (16:24)
You may need an appropriate loader to handle this file type.
|
| return class extends Comp {
| static defaultProps = {
| items: [],
| keyProp: 'key',

In my webconfig there is something added for jsx:

  {
            test: /\.(js|jsx)$/,
            include: [].concat(
              this.includedPackages,
              [this.srcPathAbsolute]
            ),
            loaders: [
              // Note: Moved this to .babelrc
              { loader: 'babel-loader' }
            ]
          },

My package.json

{
  "name": "material",
  "private": true,
  "version": "2.0.0",
  "main": "",
  "scripts": {
    "clean": "rimraf dist/*",
    "build": "npm run clean && webpack --progress --bail --env dist -p",
    "lint": "eslint ./src",
    "lint-fix": "eslint ./src --fix",
    "lint-sass": "sass-lint -c .sass-lint.yml 'src/styles/**/*.scss' -v -q",
    "posttest": "npm run lint",
    "serve:dev": "webpack-dev-server --open --env dev",
    "serve:dist": "webpack-dev-server --open --env dist -p --progress",
    "start": "npm run serve:dev"
  },
  "dependencies": {
    "classnames": "~2.2.5",
    "core-js": "^2.5.1",
    "echarts": "^3.7.1",
    "element-resize-event": "^2.0.9",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "font-awesome": "~4.7.0",
    "history": "^4.6.1",
    "jquery": "^3.2.1",
    "jquery-slimscroll": "~1.3.8",
    "material-ui": "^0.19.1",
    "popper.js": "^1.11.0",
    "prop-types": "^15.5.10",
    "rc-queue-anim": "^1.0.4",
    "re-bulma": "^0.4.4",
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-hot-loader": "^3.0.0-beta.6",
    "react-loadable": "^4.0.5",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-router-redux": "^5.0.0-alpha.6",
    "react-sortable-hoc": "^0.6.8",
    "react-tap-event-plugin": "^2.0.1",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-promise": "^0.5.3",
    "redux-thunk": "^2.2.0",
    "styled-components": "^2.1.2",
    "underscore": "^1.8.3",
    "url-join": "^2.0.2"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.3",
    "babel-core": "^6.24.1",
    "babel-eslint": "^7.2.3",
    "babel-loader": "^7.1.2",
    "babel-plugin-istanbul": "^4.1.4",
    "babel-plugin-styled-components": "^1.2.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-airbnb": "^2.0.0",
    "babel-preset-es2015-native-modules": "^6.6.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "bootstrap": "~4.0.0-beta",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.7",
    "eslint": "^4.6.0",
    "eslint-config-airbnb": "^15.0.1",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-import": "^2.3.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.0.1",
    "file-loader": "^0.11.2",
    "glob": "^7.1.2",
    "node-sass": "^4.5.3",
    "null-loader": "^0.1.1",
    "phantomjs-prebuilt": "^2.1.15",
    "postcss-loader": "^2.0.5",
    "rimraf": "^2.6.1",
    "sass-lint": "^1.11.1",
    "sass-loader": "^6.0.5",
    "style-loader": "^0.18.2",
    "url-loader": "^0.5.8",
    "webpack": "^3.1.0",
    "webpack-dev-server": "^2.4.5"
  },
  "engines": {
    "node": ">=6.9.0",
    "npm": ">= 3"
  }
}

Anyone got an idea about this?
thanks in advance,
steven

TypeError: Cannot read property 'object' of undefined when calling createAbsoluteGrid()

TypeError: Cannot read property 'object' of undefined when calling createAbsoluteGrid() for the follwoing

"dependencies": {
"jquery-ui-bundle": "^1.12.1",
"lodash": "^4.17.4",
"react": "^16.2.0",
"react-absolute-grid": "^3.0.0",
"react-dnd": "^2.5.4",
"react-dnd-html5-backend": "^2.5.4",
"react-dom": "^16.2.0",
"react-grid-layout": "^0.16.2",
"react-gridstack": "^0.1.4",
"react-scripts": "1.1.0"
}

The way PropTypes is being imported inside of AbsoluteGrid.jsx no longer works. I fixing that after changing it to:

import PropTypes from 'prop-types';

But then there are further errors after that has been fixed.

dragEnabled does not update on AbsoluteGrid

I don't want my grid to be draggable at certain times, so I have some state that I update to tell the grid whether it is draggable or not. However, ever though the grid rerenders when the updating the state from isDragEnabled = true -> isDragEnabled = false, the grid still remains draggable. Is this a bug?

render() {
    const { classes } = this.props;

    if (this.state.items !== null) {
      return <div className={classes.root}>
        <h2>{this.state.title}</h2>
        <Votes />
        {/* dragEnabled and TextField do not play well, so don't allow dragging when creating a post */}
        <AbsoluteGrid 
          items={this.state.items} 
          dragEnabled={this.state.isDragEnabled}
          itemWidth={220}
          itemHeight={250}/>
      </div>
    } else {
      return <CircularProgress size={50} />
    }
  }

Provide a dist for npm users instead of JSX

I think the issue I have with #13 is basically related to that you provides the source code of your module. This requires parsing and building step in the consumer project. Exporting a library with a compiled source might be a better solution IMO. I'll submit a PR.

Having React in dependencies causes errors

I'm having issues with the latest version because of this lines:

https://github.com/jrowny/react-absolute-grid/blob/master/package.json#L16-L17

My Karma test runner throws Error: Cannot find module "./ReactElement"

After removing node_modules/react-absolute-grid/node_modules/react and node_modules/react-absolute-grid/node_modules/react-dom everything it fine.

I think this is the common issue with multiple React instances. Having React in peerDependencies should enough AFAIK.

React.createElement: type is invalid

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of n.

Delegate drag and drop to react-dnd?

I'm a fan of small components with an open API allowing composing them easily. react-dnd is a perfect example of what I'm talking about.

I'm wondering if drag'n'drop functionality could be removed from absolute-grid whatsoever. What do you think? I could do a PR to remove but not sure if you would accept it and be willing to release a new major version without it.

Export BaseDisplayObject

As far I can understand there is no way to create own GridItem without extending from BaseDisplayObject. Shouldn't it be exported in this case then?

How to fit AbsoluteGrid in container?

Specifying itemWidth and itemHeight that is bigger than the containing div will create overflow. Unfortunately, I do not always know the container size. Is there a way to make sure that this component does not overflow its containing div?

First issue

this.props.dragmanager.endDrag();

Fix that ^

<AbsoluteGrid> does not render inside react-bootstrap <Tab>

For some reason, <AbsoluteGrid /> does not render inside of a react-bootstrap <Tab> element.

e.g. This works

<AbsoluteGrid items={items} />

But this doesn't:

import { Tabs, Tab } from 'react-bootstrap';
<Tab eventKey={0} title="Calculators">
   <AbsoluteGrid items={items} />
</Tab>

And by render, I don't mean a styling issue, the DOM for <AbsoluteGrid> does not even get created. Anything else inside the <Tab> renders correctly.

How to run in windows

This may save you a few minutes. I may have missed a step but this is what I remember typing in to get this to run.

in package.json edit the "dev" line and remove single quotes around webpack/dev.config.js
npm install
npm install -g win-node-env
npm install -g webpack-dev-server
npm run (This lists all of the options)
npm run dev
open this URL http://localhost:8080/webpack-dev-server/

Usage with render()?

Hi,

I'm trying to integrate this component into my project, but I can't get it to render. I've read through the Usage and README, but it doesn't seem to include any examples of how to render the grid inside a component's render() function. I'm using react 15.x

Here's my render function:

render: function() {
        const {unit} = this.props;
        const AbsoluteGrid = createAbsoluteGrid(DraggableItem);

        return (
            <div className="tab-pane fade">
                <div className="col-md-12 col-xs-12 text-right edit-organization-field">
                    <button type="button">Add new... </button>
                </div>

                <div className="col-md-12">
                    <AbsoluteGrid items={unit.items}
                                  keyProp="id"
                                  sortProp="displayOrder"
                                  responsive={true}
                                  dragEnabled={true}/>
                </div>
            </div>
        )
    }

And here's my DisplayComponent:

class DraggableItem extends React.PureComponent {

    render() {
        const {item} = this.props;

        return (
            <div>
                <img src={Utils.getIcon(item.icon, false)} />
                <p  className="icon-heading">{item.name}</p>
            </div>
        );
    }
}

Running the project and that page just gives me an empty div where the AbsoluteGrid should be.
However, when making an edit and triggering a re-build, it re-renders the page, and the grid shows (although it's not functional). Is there something I'm doing wrong?

Babel 6.x support?

Hello there,

I'm facing the following issue when using babelify transform within our browserify gulp task:

ReferenceError: [BABEL] /path/to/node_modules/react-absolute-grid/lib/AbsoluteGrid.jsx: Using removed Babel 5 option: /path/to/node_modules/react-absolute-grid/.babelrc.stage - Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets

We are using the following package versions:

babelify: v7.3.0
babel-core: v6.0.14
browserify: v13.0.1

No matter how I configure my gulp task or the project, the same error error persists.

Are you planning on supporting the 6.x.x version of babel? Or should I just use the /dist/index.js instead of letting the grid build along with my project?

Thanks in advance!

Items are rendered on top of each other. How do I fix it?

Items are stacked on top of each and not aligned in a grid. How do I fix them?

I'm using Semantic UI for React. And I have put it in what's called a Segment which is inside a Container. I don't think they should cause any problem as removing them doesn't help.

Other than that I'm using JSX and next.js, which probably makes get rendered on the server, which again I think shouldn't be a problem. I guess.

Thanks a lot!

image

Cannot find babelify

I am trying to use this in one of my projects. However I get this error:
Cannot find module 'babelify' from '<my_project_directory>/node_modules/react-absolute-grid'

When I run browserify from Grunt.

How handle click on single item ?

Hello, how can I handle click on a single item ?
I've tried to pass to displayObject this (<Card onClick={this.handleClick.bind(this)} />) but the click is not fired.

issue

i am just at the beginning, wanna view the grid only

//////////////////////////////////////////////////////////////////////////////////////////////////

var AbsoluteGrid = require('react-absolute-grid');
var _ = require('lodash');

import SampleDisplay from './SampleDisplay';
import * as data from './mytest/sampleData.js';

var sampleItems = data.screens;
var displayObject = ();
var zoom = 0.7;
var render;

export default class extends React.Component {
render() {
return (


<AbsoluteGrid items={sampleItems}
displayObject={()} />

);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'use strict';

export default class SampleDisplay extends React.Component {
constructor(props) {
super(props);
}

render() {
    return <div><span>{this.props.item}</span></div>;
    }

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

when u render the first one, it doesnt render

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.