Justified Gallery is a JavaScript library that allows you to create an high quality justified gallery of images.
This is a common problem for people who create websites: you have a series of images to display, but you are not sure how to arrange them in an elegant way. Important websites such as 500px, Flickr, or Google display images in an excellent way, justifying them similarly to brick wall. Justified Gallery will give you the power to do that too.
Justified Gallery is a professional and open source library that even 500px chose for displaying their images!
import { JustifiedGallery } from "justified-gallery";
import "justified-gallery/style.css";
const gallery = document.getElementById("gallery");
const jg = new JustifiedGallery(gallery);
jg.init();
// later, on unmount:
jg.destroy();JustifiedGallery is a plain class working against a real HTMLElement, so it
integrates the same way in any framework: get a ref to the container, call
init() once it's mounted, and call destroy() on cleanup. See
test/browser/html/react_gallery.tsx and
test/browser/html/vue_gallery.vue for
working React and Vue examples.
-
Prerequisites:
- Node.js
npm installto install all dependencies.
-
Develop:
npm run devstarts a Vite dev server againsttest/browser, serving the source directly (no build step needed while iterating). In this mode/text/browser/htmlpages can be explored. These are the same pages used by the e2e tests.
-
Build:
npm run buildcompiles the library for distribution: bundlessrc/justified-gallery.tswith Vite intodist/justified-gallery.jsanddist/assets/justified-gallery.css, and emits type declarations (dist/*.d.ts) withtsc.npm run previewserves the builtdistoutput locally.
-
Test:
npm testruns the full suite (unit tests, then browser/e2e tests).npm run test:unitruns the Vitest unit tests intest/unit.npm run test:e2eruns the Playwright browser tests intest/browser.
-
Try the built package as a real npm dependency:
scripts/test-local-package.shbuilds the library,npm links it, and links/serves it fromsandbox-consumer/(a throwaway, gitignored Vite project) — useful to confirm the published package resolves and works the way a downstream consumer would experience it.