Gathering detailed insights and metrics for @scissorhands/react-photo-album
Gathering detailed insights and metrics for @scissorhands/react-photo-album
Responsive photo gallery component for React
npm install @scissorhands/react-photo-album
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.08%)
JavaScript (0.76%)
Shell (0.16%)
Total Downloads
8,344
Last Day
1
Last Week
10
Last Month
52
Last Year
344
379 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.0.16
Package Id
@scissorhands/react-photo-album@0.0.16
Unpacked Size
87.99 kB
Size
18.93 kB
File Count
7
NPM Version
6.14.15
Node Version
14.18.1
Cumulative downloads
Total Downloads
Last day
-80%
1
Compared to previous day
Last week
-64.3%
10
Compared to previous week
Last month
420%
52
Compared to previous month
Last year
-94%
344
Compared to previous year
1
32
React Photo Album is a responsive photo gallery component for React. React Photo Album supports rows, columns, and masonry layouts. Inspired by react-photo-gallery, re-engineered from the ground up.
All examples are available on CodeSandbox.
https://react-photo-album.com/documentation
1npm install react-photo-album
or
1yarn add react-photo-album
1import PhotoAlbum from "react-photo-album"; 2 3const photos = [ 4 { 5 src: "/images/image1.jpg", 6 width: 800, 7 height: 600 8 }, 9 { 10 src: "/images/image2.jpg", 11 width: 1600, 12 height: 900 13 } 14]; 15 16<PhotoAlbum layout="rows" photos={photos} />
Rows layout fills the rectangular container space by arranging photos into rows that are similar in size, with the
height of each row being as close to the targetRowHeight
as possible. This layout uses an algorithm adapted from the
Knuth and Plass line breaking algorithm. To calculate the single best layout, it uses Dijkstra's algorithm to find the
shortest past in a graph where each photo to break on represents a node, and each row represents an edge. The cost of
each edge is calculated as the squared deviation from the targetRowHeight
. This algorithm produces rows that are
similar in height and photos that are not being stretched or shrunken abnormally (as is what happens in a naive
implementation). It solves the issue of panoramas shrinking rows or having stragglers or stretched images in the last
row, instead creating a justified grid. The graph is being built as the shortest path is being calculated to improve
algorithm's performance, so the entire adjacency list is not calculated ahead of time.
Columns layout fills the rectangular container space by arranging photos into a predefined number of columns, determined
by the columns
parameter. This layout uses an algorithm very similar to the one described above, but instead of
Dijkstra's algorithm, it uses a dynamic programming algorithm to find the shortest path of length N in a directed
weighted graph.
Masonry layout arranges photos into columns of equal width by placing each photo into the shortest column. This layout does not completely fill the rectangular container space, but the columns end up being as close in height to each other as possible.
React Photo Album automatically generates sizes
and srcset
image attributes. In the case of SSR, React Photo Album
includes sizes
and srcset
image attributes in the server-rendered markup, allowing browsers to pick images of the
most appropriate resolution depending on their viewport size.
React Photo Album extensively uses CSS flexbox and CSS calc
function to calculate the dimensions of images on the
client. Unlike its predecessor, React Photo Album avoids setting the exact dimensions of images in pixels. Thanks to
this approach, server-side rendered markup looks pixel-perfect on the client even before hydration (or even when
JavaScript is completely disabled in the browser). React Photo Album calculates spacing
, padding
, columns
, and
other responsive parameters on the server-side using the defaultContainerWidth
value, which is set to 800px by
default. Keep in mind that responsive parameters may contribute to cumulative layout shifts during the initial page
load. If CLS becomes an issue in your case, you may want to consider using hard-coded values for columns
, spacing
, padding
, etc., instead of the default responsive values.
MIT © 2021 Igor Danchenko
No vulnerabilities found.
No security vulnerabilities found.