GithubHelp home page GithubHelp logo

naver / egjs-grid Goto Github PK

View Code? Open in Web Editor NEW
262.0 10.0 15.0 15.5 MB

A component that can arrange items according to the type of grids

Home Page: https://naver.github.io/egjs-grid/

License: Other

JavaScript 4.47% TypeScript 73.42% HTML 13.44% CSS 0.56% Svelte 2.19% Vue 3.53% MDX 2.38%
grid image video masonry justified packing frame layout egjs react

egjs-grid's Introduction

Grid

npm version    Github actions  Coveralls github    React  Angular  Vue  Svelte

A component that can arrange items according to the type of grids.

DemoAPI

Grids

MasonryGrid JustifiedGrid FrameGrid PackingGrid
  • MasonryGrid: The MasonryGrid is a grid that stacks items with the same width as a stack of bricks. Adjust the width of all images to the same size, find the lowest height column, and insert a new item.
  • JustifiedGrid: 'justified' is a printing term with the meaning that 'it fits in one row wide'. The JustifiedGrid is a grid that the item is filled up on the basis of a line given a size.
  • FrameGrid: 'Frame' is a printing term with the meaning that 'it fits in one row wide'. The FrameGrid is a grid that the item is filled up on the basis of a line given a size.
  • PackingGrid: The PackingGrid is a grid that shows the important items bigger without sacrificing the weight of the items. Rows and columns are separated so that items are dynamically placed within the horizontal and vertical space rather than arranged in an orderly fashion.

Documents

Download and Installation

Download dist files from repo directly or install it via npm.

$ npm install @egjs/grid
<script src="//naver.github.io/egjs-grid/release/latest/dist/grid.min.js"></script>

How to use

import { MasonryGrid, JustifiedGrid, FrameGrid, PackingGrid } from "@egjs/grid";


// Grid.MasonryGrid
const grid = new MasonryGrid(container, {
  gap: 5,
});

grid.renderItems();

Use Faster & Lazy Rendering

  • When the loading="lazy" or data-grid-lazy="true"(external lazy loading) attribute is used, Rendering of the items occurs immediately. When items are loaded, they are rendered sequentially.
<img src="..." />
<img src="..." />
<img src="..." loading="lazy" />
<img data-grid-lazy="true" />
  • If you use data-grid-width and data-grid-height attributes, the size of self, child image, and video elements is automatically adjusted until loading is complete.
<div data-grid-width="100" data-grid-height="100">
   <img src="..." />
   <img src="..." />
   <img src="..." />
</div>
  • If you use data-grid-skip="true" attribute, you can omit it even if there are images in itself and child image, and video elements.
<div data-grid-skip="true">
   <img src="..." />
   <img src="..." />
   <img src="..." />
</div>

Detect resize of Container & Children

Grid calculates the size of container and children by window resizing event. However, even if the size of the window does not change, the size of the event container and children can change. Most of the first rendering issues are also like this.

In this case, I recommend ResizeObserver for you.

Provides useResizeObserver option to detect size change of container and observeChildren option to detect size change of children.

import { MasonryGrid, JustifiedGrid, FrameGrid, PackingGrid } from "@egjs/grid";


// Grid.MasonryGrid
const grid = new MasonryGrid(container, {
  gap: 5,
  useResizeObserver: true,
  observeChildren: true,
});

grid.renderItems();

Pre-guess size for performance or invisible items.

What if all items were the same size?

If you use the isEqualSize option, all items are considered to be the same size. Each resize only calculates the size of one item. Add data-grid-not-equal-size="true" attribute if there is an exceptional item whose size needs to be calculated while using isEqualSize.

<div class="item item1"></div>
<div class="item item1"></div>
<div class="item item1"></div>
<!--item2 is a different size than item1.-->
<div class="item item2" data-grid-not-equal-size="true"></div>

What if a size group exists?

isEqualSize assumes all items are equal. But if there are more than two size-groups, use data-grid-size-group.

<!--item1 has the same size.-->
<div class="item item1" data-grid-size-group="1"></div>
<div class="item item1" data-grid-size-group="1"></div>
<!--item2 has the same size.-->
<div class="item item2" data-grid-size-group="2"></div>
<div class="item item2" data-grid-size-group="2"></div>

What if all items don't change size?

If all items do not have a constant size, use the isConstantSize option. Resizing doesn't calculate the item's size. If you want to recalculate, use .updateItems(items, { useOrgResize: true }) method or .renderItems({ useOrgResize: true }) method.

Packages

Package Version Description
@egjs/react-grid version React port of @egjs/grid
@egjs/ngx-grid version Angular port of @egjs/grid
@egjs/vue-grid version Vue.js port of @egjs/grid
@egjs/svelte-grid version Svelte port of @egjs/grid

Supported Browsers

The following are the supported browsers.

Internet Explorer Chrome Firefox Safari iOS Android
9+ Latest Latest Latest 7+ 4+(polyfill 2.2+)

How to start developing egjs-grid?

For anyone interested to develop egjs-grid, follow the instructions below.

Development Environment

1. Clone the repository

Clone the egjs-grid repository and install the dependency modules.

# Clone the repository.
$ git clone https://github.com/naver/egjs-grid.git

2. Install dependencies

# Install the dependency modules.
$ npm install

3. npm start

Run storybook for development.

Open http://localhost:6006 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

3. npm build

Use npm script to build Grid

$ npm run build

Two folders will be created after complete build is completed.

  • dist folder: Includes the grid.js and grid.min.js files.
  • doc folder: Includes API documentation. The home page for the documentation is doc/index.html.

Linting

To keep the same code style, we adopted ESLint to maintain our code quality. The rules are modified version based on Airbnb JavaScript Style Guide. Setup your editor for check or run below command for linting.

$ npm run lint

Test

Once you created a branch and done with development, you must perform a test running with npm test command before your push the code to a remote repository.

$ npm run test

Running npm test command will start Mocha tests via Karma-runner.

Bug Report

If you find a bug, please report to us opening a new Issues on GitHub.

License

egjs-grid is released under the MIT license.

Copyright (c) 2021-present 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.

egjs-grid's People

Contributors

arturovt avatar chakflying avatar daybrush avatar grasshopper42 avatar malangfox avatar quyctd 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

egjs-grid's Issues

bug: the gap not work

Description

this is a bug?
desc: the gap now work when loading,only work when loaded completely
image
image

Steps to check or reproduce

use @egjs/react-grid package will show this problem

vue-grid is not working in vue2

Description

Some of the APIs are Vue3.

function render(_ctx, _cache, $props, $setup, $data, $options) {
  return vue.openBlock(), vue.createBlock("div", _hoisted_1, [vue.renderSlot(_ctx.$slots, "default")], 512
  /* NEED_PATCH */
  );
}

Steps to check or reproduce

DOESNT RE-RENDER - If children sizes change

Description

Justified grid doesn't re-render items if their sizes change.

Steps to check or reproduce

I fetch multiple images but the initial grid stays, how do I re-render the grid to dynamically resize every item if they change?

My code:

...
const [images, setImages] = useState<any[]>([])

...

<JustifiedGrid
  gap={5}
  defaultDirection={"end"}
  align={'justify'}
  columnRange={[1,4]}
  rowRange={0}
  sizeRange={[100,500]}
  isCroppedSize={false}
  displayedRow={-1}
  useResizeObserver={true}
  observeChildren={true}
  autoResize={true}
>
  {images.map((x: any, index: number) => (
    <div key={index} className='w-full overflow-hidden'>
      <Image src={x?.url} alt='' className='' />
    </div>
  ))}
</JustifiedGrid>

Here's the result:

aaaa.mov

svelte package does not work

Description

I am trying to implement a masonry layout using the svelte package but it doesn't align anything, it doesn't even modify the children

Steps to check or reproduce

<MasonryGrid column={4} columnSize={200} align={'end'}>
      {#each category.posters as card}
        <Card {card} />
      {/each}
    </MasonryGrid>

Sveltekit: <MasonryGrid> is not a valid SSR component

Description

Does not work with Sveltekit (via Vite).

Steps to check or reproduce

Install it on a fresh Sveltekit starter.

I tried adding as a devDep and an dep to no avail. I also tried adding the package to the vite's optimizeDeps in the sveltekit config, to no avail.

image

MasonryGrid is undefined

Description

Hey y'all. The issue I'm experiencing is that on first render MasonryGrid comes through undefined causing my app to crash. I've fixed the issue by adding a {Boolean(MasonryGrid) && ...(<MasonryGrid>.... where I'm using the library but that seems odd. I'm putting this here to see if anyone else is experiencing the issue or if this is a known problem.

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Steps to check or reproduce

I'm just importing MasonryGrid into my react component and using it with "gap" and "column" props.

I want to limit the number of rows displayed on the screen.

Description

<div class="container" style="overflow: hidden;">
<!-- row 1 -->
    <div class="item"></div>
    <div class="item"></div>
<!-- row 2 -->
    <div class="item"></div>
<!-- row 3 -->
    <div class="item"></div>
</div>

I want to display only row 2 on the screen.

Steps to check or reproduce

No event occurs in react.

Description

No event occurs in react.

<MasonryGrid onRenderComplete={e => {
    console.log(e);
}} />

Steps to check or reproduce

The transition behavior in InfiniteGrid is strange.

Description

  1. InfiniteGrid's element is placed at left: -9999, top: -9999 with transition
  2. Set InfiniteGrid's element to Grid's poses.
  3. It is expressed as if the item is flying through the transition.

Steps to check or reproduce

TypeError: Cannot read property 'destroy' of undefined

Description

Running a toy example of egjs-grid for svelte, and I'm getting the error in the title.

Steps to check or reproduce

    import { JustifiedGrid } from "@egjs/svelte-grid";
  
    const gap = 5;
    const defaultDirection = "end";
    const rowRange = 0;
    const columnRange = [1,8];
    const sizeRange = [200,1000];
    const isCroppedSize = false;
    const displayedRow = -1;
  </script>
  
  <JustifiedGrid
    class="container"
    {defaultDirection}
    {gap}
    {rowRange}
    {columnRange}
    {sizeRange}
    {isCroppedSize}
    {displayedRow}
  >
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
    <div class="item">5</div>
    <div class="item">6</div>
    <div class="item">7</div>
    <div class="item">8</div>
    <div class="item">9</div>
    <div class="item">10</div>
  </JustifiedGrid>```

add `weightPriority` for simple weight preset

The priority that determines the weight of the item.

  • weightPriority: "custom"
    • sizeWeight: 1,
    • ratioWeight: 1,
  • weightPriority: "size"
    • sizeWeight: 100
    • ratioWeight: 1
  • weightPriority: "ratio"
    • sizeWeight: 1
    • ratioWeight: 100

build failed with SvelteKit latest version

Description

It seems to be similar with naver/egjs-infinitegrid#505 (comment)

this is error log

/* empty css                                                    */import { MasonryGrid as MasonryGrid$1 } from "@egjs/grid";
                                                                           ^^^^^^^^^^^
SyntaxError: Named export 'MasonryGrid' not found. The requested module '@egjs/grid' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@egjs/grid';
const { MasonryGrid: MasonryGrid$1 } = pkg;

Steps to check or reproduce

update to svelte-kit latest version
and npm run build

Can isEqualSize be used when there are two or more size groups?

Description

<!--item1 has the same size.-->
<div class="item item1" data-grid-size-group="1"></div>
<div class="item item1" data-grid-size-group="1"></div>
<!--item2 has the same size.-->
<div class="item item2" data-grid-size-group="2"></div>
<div class="item item2" data-grid-size-group="2"></div>

Steps to check or reproduce

Vanilla Svelte renders images as list instead of a grid

Description

Images are rendered but as a list instead of a grid. Also, console gives some errors:

[HMR][Svelte] Unrecoverable HMR error in <App>: next update will trigger a full reload proxy.js:15:11
    logError http://localhost:5173/node_modules/svelte-hmr/runtime/proxy.js?v=1b726137:15
    Proxy<App> http://localhost:5173/node_modules/svelte-hmr/runtime/proxy.js?v=1b726137:380
    <anonymous> http://localhost:5173/src/main.js:4
Uncaught TypeError: options.props is undefined
    JustifiedGrid JustifiedGrid.js:11
    instance Grid.svelte:51
    run index.mjs:20
    mount_component index.mjs:1953
    flush index.mjs:1191
    init index.mjs:2048
    App App.svelte:426
    createProxiedComponent svelte-hooks.js:341
    ProxyComponent proxy.js:242
    Proxy<App> proxy.js:349
    <anonymous> main.js:4
Uncaught (in promise) TypeError: grid is undefined

Steps to check or reproduce

Using a clean svelte + vite project (no sveltekit)

1.- Create new svelte project with vite

npm create vite@latest

select vanilla svelte and javascript

2.- Replace App.svelte contents file with storybook example

Versions

Node: v18.12.1
Svelte: 3.54.0
egjs-grid: 1.11.2

TypeError TS2322: is missing the following properties from type - Vue 3 - TypeScript

Description

TypeError when run 'type check' command

error TS2322: Type '{ gap: number; defaultDirection: string; columnRange: number[]; rowRange: number; sizeRange: number[]; isCroppedSize: boolean; displayedRow: number; autoResize: true; class: string; }' is not assignable to type 'ComponentProps<VueGridInterface<typeof JustifiedGrid>>'.
  Type '{ gap: number; defaultDirection: string; columnRange: number[]; rowRange: number; sizeRange: number[]; isCroppedSize: boolean; displayedRow: number; autoResize: true; class: string; }' is missing the following properties from type 'VueGridInterface<typeof JustifiedGrid>': $el, $_grid, $props, syncElements, and 6 more.

76     <JustifiedGrid


Steps to check or reproduce

"@egjs/vue-grid": "^1.11.2",
"vue": "^3.2.45"
"typescript": "^4.9.4",
"vite": "^4.0.4",
"vue-tsc": "^1.0.24"

FrameGrid: relationship of frame property to resulting layout is not obvious

Description

Trying to work this out through playing with it.

https://naver.github.io/egjs-grid/storybook/?path=/story/examples-framegrid--frame-grid-template
image

  • default says 1,1,2,2,3,3,2,2,4,4,4,5 but when i put that in, there's a storybook form validation error (the input field is red) and nothing is rendered
  • when i change it to [[1,1,2,2,3,3],[2,2,4,4,4,5]] then it renders

Looking at the resulting output
image

edit it just dawned on my that you're using frame to define named grid slots:

https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template


Steps to check or reproduce

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.