Skip to content

Commit a208b37

Browse files
committed
Add states as sample data, add filtering and demo, update readme, add animation prop
1 parent 2bc2597 commit a208b37

11 files changed

+722
-110
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Jonathan
3+
Copyright (c) 2015 Jonathan Rowny
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

ReadMe.md renamed to README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ Options (Properties)
2323
=====
2424

2525
* **items** | default: [] | The array of items in the grid
26-
* **displayObject** | default: <GridItem/> | The React compnent used to display items
26+
* **displayObject** | default: &lt;GridItem/&gt; | The React compnent used to display items
2727
* **keyProp** | default: 'key' | The property to be used as a key
2828
* **filterProp** | default: '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.
2929
* **sortProp** | default: 'sort' | The property to sort on
3030
* **itemWidth** | default: 128 | The width of an item
3131
* **itemHeight** | default: 128 | The height of an item
3232
* **verticalMargin** | default: -1 | How much space between rows, -1 means the same as coumns spacing which is dynamically calculated
3333
* **responsive** | default: false | If the container has a dynamic width, set this to true to update when the browser resizes
34+
* **animation** | default: 'transform 300ms ease' | The CSS animation to use on elements. Pass a blank string or `false` for no animation.
3435
* **zoom** | default: 1 | Zooms the contents of the grid
3536

3637
Creating a DisplayObject component

demo.js

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
'use strict';
22

33
import React from 'react';
4-
import AbsoluteGrid from './lib/AbsoluteGrid.jsx';
4+
import AbsoluteGrid from './index.js';
55
import TestDisplay from './demo/TestDisplay.jsx';
6+
import * as data from './demo/sampleData.js';
67

7-
main();
8+
demo();
89

9-
function main() {
10+
function demo() {
1011

1112
/*
12-
The data structure is pretty strict, we require a unique identifier (in this case key) and a sort
13+
key and sort are required, but configureable with keyProp and sortProp.
1314
*/
14-
var sampleItems = [
15-
{key: 1, name: 'Test', sort: 0, filtered: 0},
16-
{key: 2, name: 'Test 1', sort: 2, filtered: 0},
17-
{key: 3, name: 'Test 2', sort: 2, filtered: 0},
18-
{key: 4, name: 'Test 3', sort: 3, filtered: 0},
19-
{key: 5, name: 'Test 4', sort: 4, filtered: 0},
20-
{key: 6, name: 'Test 5', sort: 5, filtered: 0},
21-
{key: 7, name: 'Test 6', sort: 5, filtered: 0},
22-
{key: 8, name: 'Test 7', sort: 6, filtered: 0},
23-
{key: 9, name: 'Test 8', sort: 7, filtered: 0},
24-
{key: 10, name: 'Test 9', sort: 8, filtered: 0},
25-
{key: 11, name: 'Test 10', sort: 9, filtered: 0},
26-
{key: 12, name: 'Test 11', sort: 10, filtered: 0}
27-
];
15+
var sampleItems = data.states;
16+
2817
var testDisplay = (<TestDisplay />);
29-
30-
React.render(<AbsoluteGrid items={sampleItems} />, document.getElementById('BasicDemo'));
31-
React.render(<AbsoluteGrid items={sampleItems} displayObject={testDisplay}/>, document.getElementById('DisplayObjectDemo'));
18+
//Most Basic Demo
19+
React.render(<AbsoluteGrid items={sampleItems} keyProp="abbreviation"/>, document.getElementById('BasicDemo'));
20+
21+
//Using Custom Display
22+
React.render(<AbsoluteGrid items={sampleItems} keyProp="abbreviation" displayObject={testDisplay}/>, document.getElementById('DisplayObjectDemo'));
23+
24+
//Using Custom Display and Filtering
25+
var onFilter = function(event){
26+
var search = new RegExp(event.target.value, 'i');
27+
sampleItems.forEach(function(item){
28+
item.filtered = !item.name.match(search);
29+
});
30+
React.render(<AbsoluteGrid items={sampleItems} displayObject={testDisplay} keyProp="abbreviation"/>, document.getElementById('FilterDemo'));
31+
};
32+
React.render(<input onChange={onFilter} type='text'/>, document.getElementById('Filter'));
33+
React.render(<AbsoluteGrid items={sampleItems} displayObject={testDisplay} keyProp="abbreviation"/>, document.getElementById('FilterDemo'));
34+
3235
}

demo/AbsoluteGrid.js

+355-52
Large diffs are not rendered by default.

demo/TestDisplay.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class TestDisplay extends React.Component {
2020
itemStyle.backgroundColor = this.getRandomColor();
2121
itemStyle.borderRadius = '10px';
2222

23-
return <div style={itemStyle} className="gridItem">Custom Display Object: {this.props.item.name}</div>;
23+
return <div style={itemStyle} className="gridItem">{this.props.item.name}</div>;
2424
}
2525
}
2626

demo/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
border-radius:4px;
1919
background-color:#fff;
2020
padding:20px;
21+
overflow:hidden;
2122
}
2223
</style>
2324
</head>
@@ -27,7 +28,8 @@ <h1>Basic Demo</h1>
2728
<h1>Using a Custom Renderer (DisplayObject)</h1>
2829
<div id="DisplayObjectDemo" class="demo"></div>
2930
<h1>Filtering with Animation</h1>
30-
<div>Coming soon...</div>
31+
<div id="Filter"></div>
32+
<div id="FilterDemo" class="demo"></div>
3133
<h1>Drag and Drop with Animation</h1>
3234
<div>Coming soon...</div>
3335
<h1>Selection with Drag and Drop</h1>

0 commit comments

Comments
 (0)