-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
18,948 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["env", "react", "stage-2"], | ||
"plugins": ["add-module-exports"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"extends": ["naver"], | ||
"rules": { | ||
"comma-dangle": ["error", { | ||
"arrays": "always-multiline", | ||
"objects": "always-multiline", | ||
"imports": "always-multiline", | ||
"exports": "always-multiline", | ||
"functions": "never" | ||
}], | ||
"react/jsx-uses-react": "error", | ||
"react/jsx-uses-vars": "error", | ||
"class-methods-use-this": ["error", { | ||
"exceptMethods": [ | ||
"render", | ||
"getInitialState", | ||
"getDefaultProps", | ||
"getChildContext", | ||
"componentWillMount", | ||
"componentDidMount", | ||
"componentWillReceiveProps", | ||
"shouldComponentUpdate", | ||
"componentWillUpdate", | ||
"componentDidUpdate", | ||
"componentWillUnmount" | ||
] | ||
}] | ||
}, | ||
"parser": "babel-eslint", | ||
"plugins": ["react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/ | ||
examples/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# react-infinitegrid [![npm version](https://badge.fury.io/js/%40egjs%2Freact-infinitegrid.svg)](https://badge.fury.io/js/%40egjs%2Freact-infinitegrid) | ||
|
||
A react component that can easily use [egjs-infinitegrid](https://github.com/naver/egjs-infinitegrid) | ||
|
||
* Demo | ||
* [API Documentation](https://github.com/naver/egjs-infinitegrid/wiki/react-infinitegrid-API-documentation) | ||
|
||
## Install | ||
```bash | ||
$ npm install @egjs/react-infinitegrid --save | ||
``` | ||
|
||
## How to use | ||
```js | ||
// GridLayout, JustifiedLayout, FrameLayout, SquareLayout, PackingLayout | ||
import {GridLayout} from "@egjs/react-infinitegrid"; | ||
``` | ||
|
||
```jsx | ||
<GridLayout | ||
tag = "div" | ||
threshold = {100} | ||
isOverflowScroll = {false} | ||
isEqualSize = {false} | ||
useRecycle = {true} | ||
horizontal = {false} | ||
percentage = {false} | ||
onAppend = {e => append} | ||
onPrepend = {e => append} | ||
onLayoutComplete = {e => layoutComplete} | ||
onImageError = {e => imageError} | ||
onChange = {e => imageError}> | ||
<Item/> | ||
<Item/> | ||
<Item/> | ||
<Item/> | ||
<Item/> | ||
<Item/> | ||
<Item/> | ||
</GridLayout> | ||
``` | ||
|
||
### More examples | ||
```jsx | ||
this.loading = (<LoadingBar append>Loading... append</LoadingBar>); | ||
this.state = { | ||
loading: false, | ||
list: loadItems(0, 0), | ||
}; | ||
this.onAppend = this.onAppend.bind(this); | ||
this.onLayoutComplete = this.onLayoutComplete.bind(this); | ||
loadItems(groupKey, start) { | ||
const items = []; | ||
|
||
for (let i = 0; i < 20; ++i) { | ||
items.push(<Item groupKey={groupKey} key={start + i} />); | ||
} | ||
return items; | ||
} | ||
onAppend({groupKey}) { | ||
const list = this.state.list; | ||
const start = list.length; | ||
const items = this.loadItems(groupKey + 1, start); | ||
|
||
this.setState({loading: this.loading, list: list.concat(items)}); | ||
} | ||
onLayoutComplete() { | ||
this.setState({loading: false}); | ||
} | ||
render() { | ||
return (<GridLayout onAppend={this.onAppend} | ||
onLayoutComplete={this.onLayoutComplete} | ||
loading={this.state.loading}> | ||
{this.state.list} | ||
</GridLayout>); | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> | ||
<div class="demobox"> | ||
<div id="__react-content"></div> | ||
</div> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
left: 0; | ||
} | ||
.item { | ||
width: 250px; | ||
opacity: 0; | ||
} | ||
.item .thumbnail { | ||
max-height: 300px; | ||
overflow: hidden; | ||
border-radius: 8px; | ||
} | ||
.item .thumbnail img { | ||
width: 100%; | ||
} | ||
.item .info { | ||
margin-top: 10px; | ||
font-weight: bold; | ||
color: #777; | ||
} | ||
.item.animate { | ||
transition: opacity ease 1s; | ||
transition-delay: 0.2s; | ||
opacity: 1; | ||
} | ||
.loading { | ||
width: 100%; | ||
height: 50px; | ||
line-height: 50px; | ||
text-align: center; | ||
font-weight: bold; | ||
} | ||
</style> | ||
|
||
<script src="../build/commons.js"></script> | ||
<script src="../build/GridLayout.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, {Component} from "react"; | ||
import ReactDOM from "react-dom"; | ||
import {GridLayout} from "../../src/index.js"; | ||
|
||
class Item { | ||
render() { | ||
const no = this.props.num; | ||
const text = `egjs ${no}`; | ||
|
||
return (<div class="item"> | ||
<div class="thumbnail"> | ||
<img src={`https://naver.github.io/egjs-infinitegrid/assets/image/${no}.jpg`}/> | ||
</div> | ||
<div class="info"> | ||
{text} | ||
</div> | ||
</div>); | ||
} | ||
} | ||
|
||
class App extends Component { | ||
constructor(prop) { | ||
super(prop); | ||
this.loading = (<div class="loading" append>Loading...</div>); | ||
this.state = { | ||
loading: null, | ||
list: [], | ||
}; | ||
this.onAppend = this.onAppend.bind(this); | ||
this.onLayoutComplete = this.onLayoutComplete.bind(this); | ||
} | ||
loadItems(groupKey, start = this.state.list.length) { | ||
const items = []; | ||
|
||
for (let i = 0; i < 20; ++i) { | ||
items.push(<Item groupKey={groupKey} num={start + i} key={start + i} />); | ||
} | ||
return items; | ||
} | ||
onAppend({groupKey}) { | ||
if (this.state.loading) { | ||
return; | ||
} | ||
const list = this.state.list; | ||
const start = list.length; | ||
const items = this.loadItems(groupKey + 1, start); | ||
|
||
this.setState({loading: this.loading, list: list.concat(items)}); | ||
} | ||
onLayoutComplete(e) { | ||
this.setState({loading: false}); | ||
} | ||
render() { | ||
const {list} = this.state; | ||
|
||
return ( | ||
<GridLayout margin={10} | ||
align={"center"} | ||
onAppend={this.onAppend} | ||
onLayoutComplete={this.onLayoutComplete} | ||
> | ||
{list} | ||
</GridLayout> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render(<App />, document.getElementById("__react-content")); | ||
|
Oops, something went wrong.