Gathering detailed insights and metrics for react-photo-album
Gathering detailed insights and metrics for react-photo-album
Gathering detailed insights and metrics for react-photo-album
Gathering detailed insights and metrics for react-photo-album
@capacitor/camera
The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album.
react-photo-view
An exquisite React photo preview component
react-html5-camera-photo
React.js HTML5 Camera Photo
react-photo-gallery
Responsive Justified React Image Gallery Component
npm install react-photo-album
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
573 Stars
588 Commits
34 Forks
6 Watching
1 Branches
4 Contributors
Updated on 24 Nov 2024
Minified
Minified + Gzipped
TypeScript (93.29%)
JavaScript (3.71%)
SCSS (2.51%)
HTML (0.34%)
CSS (0.14%)
Cumulative downloads
Total Downloads
Last day
27.6%
6,698
Compared to previous day
Last week
11%
31,842
Compared to previous week
Last month
6.1%
123,458
Compared to previous month
Last year
119.9%
1,213,992
Compared to previous year
2
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.
https://react-photo-album.com/documentation
https://react-photo-album.com/examples
https://github.com/igordanchenko/react-photo-album/releases
1npm install react-photo-album
1import { RowsPhotoAlbum } from "react-photo-album"; 2import "react-photo-album/rows.css"; 3 4const photos = [ 5 { src: "/image1.jpg", width: 800, height: 600 }, 6 { src: "/image2.jpg", width: 1600, height: 900 }, 7]; 8 9export default function Gallery() { 10 return <RowsPhotoAlbum photos={photos} />; 11}
Rows layout fills the container space by arranging photos into rows that are
similar in height, 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 optimal layout, it
uses Dijkstra's algorithm to find the shortest path 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 a squared deviation from the targetRowHeight
. This
algorithm produces rows that are similar in height and photos that are not
stretched or abnormally shrunk (as what happens in a naive implementation). It
solves the issue of panoramas shrinking rows or having stragglers or stretched
images in the last row.
Columns layout fills the 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, with the only difference
being that 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 fill the container space flush to its bottom edge, but the columns end up being as close in height to each other as possible.
React Photo Album can automatically produce 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 the end-user viewport size. To
utilize images with automatic resolution switching, provide images of different
resolutions in the photo srcSet
attribute. To further improve app
responsiveness and bandwidth utilization, you can specify the sizes
prop that
describes the width of the photo album in various viewports.
1import { RowsPhotoAlbum } from "react-photo-album"; 2import "react-photo-album/rows.css"; 3 4const photos = [ 5 { 6 src: "/image1_800x600.jpg", 7 width: 800, 8 height: 600, 9 srcSet: [ 10 { src: "/image1_400x300.jpg", width: 400, height: 300 }, 11 { src: "/image1_200x150.jpg", width: 200, height: 150 }, 12 ], 13 }, 14 { 15 src: "/image2_1600x900.jpg", 16 width: 1600, 17 height: 900, 18 srcSet: [ 19 { src: "/image2_800x450.jpg", width: 800, height: 450 }, 20 { src: "/image2_400x225.jpg", width: 400, height: 225 }, 21 ], 22 }, 23]; 24 25export default function Gallery() { 26 return ( 27 <RowsPhotoAlbum 28 photos={photos} 29 sizes={{ 30 size: "1168px", 31 sizes: [ 32 { 33 viewport: "(max-width: 1200px)", 34 size: "calc(100vw - 32px)", 35 }, 36 ], 37 }} 38 /> 39 ); 40}
React Photo Album extensively uses CSS flexbox and CSS calc
functions to
calculate images' dimensions on the client. Thanks to this approach, server-side
rendered markup looks pixel-perfect on the client even before hydration. To
enable server-side rendering, specify the defaultContainerWidth
prop.
Otherwise, React Photo Album produces an empty markup on the server and renders
on the client only after hydration. Please note that unless your photo album is
of constant width that always matches the defaultContainerWidth
value, you
will most likely see a layout shift immediately after hydration. Alternatively,
you can provide a fallback skeleton in the skeleton
prop that will be rendered
in SSR and swapped with the actual photo album markup after hydration. Please
also refer to the
Server-Side Rendering
documentation for a comprehensive list of available solutions.
Thanks to Sandra G (aka neptunian) for authoring the original react-photo-gallery library that served as inspiration and foundation for react-photo-album.
MIT © 2021 Igor Danchenko
No vulnerabilities found.
No security vulnerabilities found.