4.11.1 • Published 4 days ago

@egjs/react-infinitegrid v4.11.1

Weekly downloads
524
License
MIT
Repository
github
Last release
4 days ago

react-infinitegrid npm version

A react component that can easily use egjs-infinitegrid

Install

$ npm install @egjs/react-infinitegrid  --save

How to use

// GridLayout, JustifiedLayout, FrameLayout, SquareLayout, PackingLayout
import {GridLayout} from "@egjs/react-infinitegrid";

<GridLayout
	tag = "div"
	options={{
		threshold: 100,
		isOverflowScroll: false,
		isEqualSize: false,
		isContantSize: false,
		useFit: false,
		useRecycle: false,
		horizontal: false,
	}}
	layoutOptions={{
		align: "justify",
	}}
	onAppend = {e => append}
	onPrepend = {e => append}
	onLayoutComplete = {e => layoutComplete}
	onImageError = {e => imageError}
	onChange = {e => chnage}>
	<Item groupKey={0} key={0}/>
	<Item groupKey={0} key={1}/>
	<Item groupKey={1} key={2}/>
	<Item groupKey={1} key={3}/>
	<Item groupKey={2} key={4}/>
	<Item groupKey={2} key={5}/>
	<Item groupKey={2} key={6}/>
</GridLayout>

Props

nametypedefaultdescription
tagstring"div"The tag name of the wrapper element
containerTagstring"div"The tag name of the container element
groupByFunctionget groupKey or data-groupkeyGet a unique key to distinguish between groups.
useFirstRenderbooleanfalseThe useFirstRender option determines whether the markup will be shown on the first rendering or after loading is complete.
loadingReact.ReactElementSpecifies the Loading Bar to use for append or prepend items.
statusIInfiniteGridStatusnullState object of the react-infinitegrid module
layoutTypeClassGridLayoutSpecifies the Layout class to use.
optionsIInfiniteGridOptions{}The option object of the eg.InfiniteGrid module
layoutOptionsIInfiniteGridOptions{}Options to apply to the Layout.
...othersDOM AttributesYou can set the attribute of the wrapper element.
export interface InfiniteGridProps<T extends ILayout = any> {
	tag?: string;
	containerTag?: string;
	useFirstRender?: boolean;
	status?: IInfiniteGridStatus | null;
	options?: Partial<IInfiniteGridOptions>;
	layoutOptions?: Partial<T["options"]>;
	loading?: React.ReactElement | null;
	layoutType?: new (...args: any[]) => ILayout;
	groupBy?: (item: any, index: number) => any;
	onAppend?: (param: OnAppend) => any;
	onPrepend?: (param: OnPrepend) => any;
	onLayoutComplete?: (param: OnLayoutComplete) => any;
	onImageError?: (param: OnImageError) => any;
	onChange?: (param: OnChange) => any;
	[others: string]: any;
}

Options

More examples

this.state = {
	list: loadItems(0, 0),
};
loadItems = (groupKey, start) => {
	const items = [];

	for (let i = 0; i < 20; ++i) {
		items.push(<Item groupKey={groupKey} key={start + i} />);
	}
	return items;
}
onAppend = ({groupKey, startLoading}) => {
	const list = this.state.list;
	const start = list.length;
	const items = this.loadItems(groupKey + 1, start);

	startLoading();
	this.setState({list: list.concat(items)});
}
onLayoutComplete = ({isLayout, endLoading}) => {
	!isLayout && endLoading();
}
render() {
	return (<GridLayout onAppend={this.onAppend}
	onLayoutComplete={this.onLayoutComplete}
	loading={<div className="loading">Loading... append</div>}>
		{this.state.list}
	</GridLayout>);
}

migration 1.x=> 3.x

InfiniteGris's props are bundled into options, layoutOptions.

// 1.x
<GridLayout
	isOverflowScroll = {false}
	isEqualSize = {false}
	isConstantSize = {false}
	useFit = {true}
	useRecycle = {true}
	useFirstRender = {true}
	horizontal = {false}
	align = "justify"
/>
// 3.x
<GridLayout
	useFirstRender={true}
	options={{
		isOverflowScroll: false,
		isEqualSize: false,
		isContantSize: false,
		useFit: false,
		useRecycle: false,
		horizontal: true,
	}}
	layoutOptions={{
		align: "justify",
	}}
/>

InfiniteGrid's event types are changed.

// 1.x
interface InfiniteGridProps {
	tag?: string,
	type?: (...args: any[]) => any,
	options?: object,
	margin?: number,
	threshold?: number,
	isOverflowScroll?: boolean,
	isEqualSize?: boolean,
	useRecycle?: boolean,
	isConstantSize?: boolean,
	horizontal?: boolean,
	loading?: React.ReactNode,
	transitionDuration?: number,
	onAppend?: (param: OnAppendParameter) => void,
	onPrepend?: (param: OnPrependParameter) => void,
	onLayoutComplete?: (param: OnLayoutCompleteParameter) => void,
	onImageError?: (param: any) => void,
	onChange?: (param: OnChangeParameter) => void,
	status?: object,
	useFit?: boolean,
	[others: string]: any,
}

// 3.x
export interface InfiniteGridProps<T extends ILayout = any> {
	tag?: string;
	containerTag?: string;
	useFirstRender?: boolean;
	status?: IInfiniteGridStatus | null;
	options?: Partial<IInfiniteGridOptions>;
	layoutOptions?: Partial<T["options"]>;
	loading?: React.ReactElement | null;
	layoutType?: new (...args: any[]) => ILayout;
	groupBy?: (item: any, index: number) => any;
	onAppend?: (param: OnAppend) => any;
	onPrepend?: (param: OnPrepend) => any;
	onLayoutComplete?: (param: OnLayoutComplete) => any;
	onImageError?: (param: OnImageError) => any;
	onChange?: (param: OnChange) => any;
	[others: string]: any;
}

itemIndex changed totalIndex in onImageError event.

// 1.x
<InfiniteGrid onImageError={e => {
	this.items.splice(e.itemIndex, 1);

	this.setState({ items: [...this.items] });
}} />
// 3.x
<InfiniteGrid onImageError={e => {
	this.items.splice(e.totalIndex, 1);
	
	this.setState({ items: [...this.items] });
}}>

Development

# Run webpack-dev-server server and see examples for development
$ npm run start

Bug Report

If you find a bug, please report it to us using the Issues page on GitHub.

License

react-infinitegrid is released under the MIT license.

Copyright (c) 2017 NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4.12.0-beta.7

4 days ago

4.12.0-beta.6

21 days ago

4.12.0-beta.5

1 month ago

4.12.0-beta.3

2 months ago

4.11.1

2 months ago

4.12.0-beta.1

3 months ago

4.12.0-beta.0

4 months ago

4.10.1-beta.0

8 months ago

4.10.1

8 months ago

4.11.0-beta.0

5 months ago

4.11.0

4 months ago

4.9.0

1 year ago

4.10.0

10 months ago

4.9.0-beta.4

1 year ago

4.9.0-beta.2

1 year ago

4.9.0-beta.3

1 year ago

4.10.0-beta.4

11 months ago

4.10.0-beta.2

11 months ago

4.10.0-beta.3

11 months ago

4.10.0-beta.0

11 months ago

4.10.0-beta.1

11 months ago

4.8.0-beta.0

1 year ago

4.8.0-beta.1

1 year ago

4.8.0-beta.2

1 year ago

4.8.1

1 year ago

4.8.0

1 year ago

4.9.0-beta.1

1 year ago

4.7.1

2 years ago

4.5.0-beta.0

2 years ago

4.7.0

2 years ago

4.6.0

2 years ago

4.5.1-beta.0

2 years ago

4.5.0

2 years ago

4.4.0

2 years ago

4.4.1-beta.0

2 years ago

4.3.1

2 years ago

4.3.0

2 years ago

4.2.1

2 years ago

4.2.0-beta.0

2 years ago

4.2.1-beta.0

2 years ago

4.2.0

2 years ago

4.2.0-beta.1

2 years ago

4.1.1

2 years ago

4.1.0

2 years ago

4.0.0

3 years ago

4.0.0-beta.3

3 years ago

4.0.0-beta.2

3 years ago

4.0.0-beta.1

3 years ago

4.0.0-beta.0

3 years ago

3.3.0

3 years ago

3.3.0-beta.0

3 years ago

3.2.5

3 years ago

3.2.5-beta.0

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.2.3-beta.1

3 years ago

3.2.3-beta.0

3 years ago

3.2.2

3 years ago

3.2.2-rc

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.1-rc

3 years ago

3.1.0

3 years ago

3.0.6

3 years ago

3.0.6-rc

3 years ago

1.6.5-rc

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.4-rc

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

1.6.3

4 years ago

1.6.3-rc

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-beta3

4 years ago

3.0.0-beta2

4 years ago

3.0.0-beta

4 years ago

1.6.2

5 years ago

1.6.2-rc

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.1-rc

5 years ago

1.5.0

5 years ago

1.5.0-rc2

5 years ago

1.5.0-rc

5 years ago

1.4.0

5 years ago

1.4.0-rc3

5 years ago

1.4.0-rc2

5 years ago

1.4.0-rc

5 years ago

1.3.0

5 years ago

1.3.0-rc

5 years ago

1.2.6

5 years ago

1.2.6-rc2

5 years ago

1.2.6-rc

5 years ago

1.2.5

5 years ago

1.2.5-rc2

5 years ago

1.2.5-rc

5 years ago

1.2.4

5 years ago

1.2.4-rc2

5 years ago

1.2.4-rc

5 years ago

1.2.3

5 years ago

1.2.3-rc

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.1-beta

6 years ago

1.2.1-alpha

6 years ago

1.2.0

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.8.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0-beta

6 years ago

0.4.0-alpha

6 years ago

0.3.4

6 years ago

0.3.4-alpha

6 years ago

0.3.3-beta

6 years ago

0.3.3-alpha

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.7-alpha

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago