@n-ivan/react-justified-gallery 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +157 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # react-justified-gallery
2
+
3
+ A React component for creating beautiful justified image galleries with automatic layout calculations and responsive behavior.
4
+
5
+ ## Features
6
+
7
+ - **Perfect Justification** - Images fill the full container width while preserving aspect ratios
8
+ - **Fully Responsive** - Automatically recalculates layout on container resize using ResizeObserver
9
+ - **Flexible Rendering** - Custom render prop for complete control over image display
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @n-ivan/react-justified-gallery
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```tsx
20
+ import { JustifiedGallery } from 'react-justified-gallery';
21
+
22
+ const images = [
23
+ [
24
+ { src: 'image1.jpg', width: 1920, height: 1080 },
25
+ { src: 'image2.jpg', width: 800, height: 600 }
26
+ ],
27
+ [
28
+ { src: 'image3.jpg', width: 1200, height: 1200 }
29
+ ]
30
+ ];
31
+
32
+ function App() {
33
+ return <JustifiedGallery images={images} gap={8} />;
34
+ }
35
+ ```
36
+
37
+ ## Data Structure
38
+
39
+ The gallery accepts a **2D array** where each inner array represents a row of images:
40
+
41
+ ```typescript
42
+ type ImageData = {
43
+ src: string;
44
+ width: number; // Original width in pixels
45
+ height: number; // Original height in pixels
46
+ alt?: string; // Optional alt text
47
+ [key: string]: unknown; // Any additional properties
48
+ };
49
+
50
+ type GalleryData = ImageData[][];
51
+ ```
52
+
53
+ ## API Reference
54
+
55
+ ### Props
56
+
57
+ | Prop | Type | Default | Description |
58
+ |------|------|---------|-------------|
59
+ | `images` | `ImageData[][]` | **required** | 2D array of image data |
60
+ | `gap` | `number` | `8` | Gap between images in pixels |
61
+ | `renderImage` | `function` | - | Custom render function for images |
62
+ | `resizeDebounce` | `number` | `150` | Debounce delay for resize (ms) |
63
+ | `lazyLoad` | `boolean` | `true` | Enable native lazy loading |
64
+ | `onImageLoad` | `function` | - | Callback when image loads |
65
+ | `onImageError` | `function` | - | Callback when image fails |
66
+ | `containerStyle` | `CSSProperties` | - | Styles for gallery container |
67
+ | `rowStyle` | `CSSProperties` | - | Styles for each row |
68
+
69
+ ### RenderImage Props
70
+
71
+ When using the `renderImage` prop, you receive the following properties:
72
+
73
+ ```typescript
74
+ interface RenderImageProps {
75
+ image: ImageData; // Original image data
76
+ computedWidth: number; // Calculated width
77
+ computedHeight: number; // Calculated height
78
+ originalWidth: number; // Original image width
79
+ originalHeight: number; // Original image height
80
+ rowIndex: number; // Row index (0-based)
81
+ imageIndex: number; // Image index in row (0-based)
82
+ isFirstInRow: boolean; // First image in row
83
+ isLastInRow: boolean; // Last image in row
84
+ }
85
+ ```
86
+
87
+ ## How It Works
88
+
89
+ The component calculates the optimal height for each row based on:
90
+
91
+ 1. **Total aspect ratio** of all images in the row
92
+ 2. **Available width** (container width minus gaps)
93
+ 3. **Individual aspect ratios** of each image
94
+
95
+ This ensures:
96
+ - All images in a row have the same height
97
+ - Each image maintains its original aspect ratio
98
+ - The row fills the complete container width
99
+
100
+ ## Development
101
+
102
+ ### Install Dependencies
103
+
104
+ ```bash
105
+ npm install
106
+ ```
107
+
108
+ ### Run Demo
109
+
110
+ ```bash
111
+ npm run demo
112
+ ```
113
+
114
+ ### Run Tests
115
+
116
+ ```bash
117
+ npm test
118
+ ```
119
+
120
+ ### Build Library
121
+
122
+ ```bash
123
+ npm run build
124
+ ```
125
+
126
+ ### Type Check
127
+
128
+ ```bash
129
+ npm run lint
130
+ ```
131
+
132
+ ## TypeScript
133
+
134
+ Full TypeScript support with exported types:
135
+
136
+ ```tsx
137
+ import type {
138
+ JustifiedGalleryProps,
139
+ ImageData,
140
+ RenderImageProps
141
+ } from 'react-justified-gallery';
142
+ ```
143
+
144
+ ## Browser Support
145
+
146
+ Modern browsers with support for:
147
+ - ResizeObserver
148
+ - ES2020+ features
149
+ - React 18+
150
+
151
+ ## License
152
+
153
+ MIT
154
+
155
+ ## Contributing
156
+
157
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n-ivan/react-justified-gallery",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A React component for creating justified image galleries",
5
5
  "keywords": [
6
6
  "react",
@@ -51,8 +51,8 @@
51
51
  "vitest": "^1.0.4"
52
52
  },
53
53
  "peerDependencies": {
54
- "react": "^18.0.0",
55
- "react-dom": "^18.0.0"
54
+ "react": "^18.0.0 || ^19.0.0",
55
+ "react-dom": "^18.0.0 || ^19.0.0"
56
56
  },
57
57
  "module": "./dist/justified-gallery.js"
58
58
  }