@molecule/app-image-gallery-react 1.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,25 @@
1
+ import { type JSX } from 'react';
2
+ /** Props for {@link ImageGallery}. */
3
+ export interface ImageGalleryProps {
4
+ /** Image URLs in display order. */
5
+ images: string[];
6
+ /** Controlled selected index — caller owns state. */
7
+ selectedIndex?: number;
8
+ /** Called when a thumbnail is clicked. */
9
+ onSelect?: (index: number) => void;
10
+ /** Max thumbnails shown. Extra are summarised as "+N". */
11
+ maxThumbnails?: number;
12
+ /** Alt-text for screen readers. Applied per-image; falls back to `'Image N'`. */
13
+ alts?: string[];
14
+ /** Extra classes on the outer wrapper. */
15
+ className?: string;
16
+ }
17
+ /**
18
+ * Main image + thumbnail grid gallery. Controlled-optional: when
19
+ * `selectedIndex` is omitted the component tracks its own selection.
20
+ *
21
+ * Used for product images, property listings, portfolio galleries.
22
+ * @param props - Component props (see {@link ImageGalleryProps}).
23
+ */
24
+ export declare function ImageGallery({ images, selectedIndex, onSelect, maxThumbnails, alts, className, }: ImageGalleryProps): JSX.Element | null;
25
+ //# sourceMappingURL=ImageGallery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageGallery.d.ts","sourceRoot":"","sources":["../src/ImageGallery.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,OAAO,CAAA;AA8B1C,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,aAAa,EACb,QAAQ,EACR,aAAiB,EACjB,IAAI,EACJ,SAAS,GACV,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAkDxC"}
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { getClassMap } from '@molecule/app-ui';
4
+ /**
5
+ * Column counts the ClassMap `cm.grid()` resolver can actually render. The
6
+ * `@molecule/app-ui-tailwind` grid CVA only defines these keys — any other
7
+ * value produces no `grid-cols-*` class and the thumbnails collapse into a
8
+ * single column. Keep in sync with that bond's `grid` variants.
9
+ */
10
+ const SUPPORTED_GRID_COLS = [1, 2, 3, 4, 5, 6, 12];
11
+ /**
12
+ * Snaps an arbitrary desired column count to the largest ClassMap-supported
13
+ * value that does not exceed it (minimum 1). This lets any `maxThumbnails`
14
+ * render a real grid — thumbnails beyond the chosen column count simply wrap
15
+ * onto additional rows instead of breaking the layout.
16
+ *
17
+ * @param desired - The requested number of columns (e.g. `maxThumbnails`).
18
+ * @returns A column count guaranteed to resolve to a `grid-cols-*` class.
19
+ */
20
+ function toGridCols(desired) {
21
+ const clamped = Math.max(1, Math.floor(desired || 0));
22
+ let best = SUPPORTED_GRID_COLS[0];
23
+ for (const cols of SUPPORTED_GRID_COLS) {
24
+ if (cols <= clamped)
25
+ best = cols;
26
+ }
27
+ return best;
28
+ }
29
+ /**
30
+ * Main image + thumbnail grid gallery. Controlled-optional: when
31
+ * `selectedIndex` is omitted the component tracks its own selection.
32
+ *
33
+ * Used for product images, property listings, portfolio galleries.
34
+ * @param props - Component props (see {@link ImageGalleryProps}).
35
+ */
36
+ export function ImageGallery({ images, selectedIndex, onSelect, maxThumbnails = 4, alts, className, }) {
37
+ const cm = getClassMap();
38
+ const [internalIndex, setInternalIndex] = useState(0);
39
+ const idx = selectedIndex ?? internalIndex;
40
+ const setIdx = (i) => {
41
+ if (selectedIndex === undefined)
42
+ setInternalIndex(i);
43
+ onSelect?.(i);
44
+ };
45
+ if (images.length === 0)
46
+ return null;
47
+ const visible = images.slice(0, maxThumbnails);
48
+ const overflow = Math.max(0, images.length - visible.length);
49
+ return (_jsxs("div", { className: cm.cn(cm.stack(2), className), children: [_jsx("div", { style: { aspectRatio: '4 / 3' }, children: _jsx("img", { src: images[idx], alt: alts?.[idx] ?? `Image ${idx + 1}`, style: { width: '100%', height: '100%', objectFit: 'cover' } }) }), images.length > 1 && (_jsxs("div", { className: cm.grid({ cols: toGridCols(maxThumbnails), gap: 'sm' }), children: [visible.map((src, i) => (_jsx("button", { type: "button", onClick: () => setIdx(i), "aria-current": i === idx ? 'true' : undefined, "aria-label": alts?.[i] ?? `Image ${i + 1}`, style: { aspectRatio: '1 / 1' }, children: _jsx("img", { src: src, alt: "", style: { width: '100%', height: '100%', objectFit: 'cover' } }) }, i))), overflow > 0 && (_jsxs("div", { className: cm.cn(cm.flex({ align: 'center', justify: 'center' }), cm.textSize('sm'), cm.fontWeight('semibold')), style: { aspectRatio: '1 / 1' }, children: ["+", overflow] }))] }))] }));
50
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * React image gallery.
3
+ *
4
+ * Exports `<ImageGallery>` — main image + thumbnail grid with controlled-optional
5
+ * selection and "+N" overflow summarisation.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { ImageGallery } from '@molecule/app-image-gallery-react'
10
+ *
11
+ * const images = [
12
+ * 'https://example.com/photo-1.jpg',
13
+ * 'https://example.com/photo-2.jpg',
14
+ * 'https://example.com/photo-3.jpg',
15
+ * ]
16
+ *
17
+ * // Uncontrolled — manages its own selected index
18
+ * <ImageGallery images={images} maxThumbnails={4} />
19
+ *
20
+ * // Controlled — caller drives selected index
21
+ * <ImageGallery images={images} selectedIndex={activeIdx} onSelect={setActiveIdx} />
22
+ * ```
23
+ *
24
+ * @remarks
25
+ * - Renders `null` when `images` is empty — no empty-state UI.
26
+ * - `maxThumbnails` doubles as the thumbnail grid's column count. Any value is
27
+ * safe: it is snapped to the nearest column count the ClassMap grid actually
28
+ * supports (1-6 or 12), so a real `grid-cols-*` class is always emitted and
29
+ * extra thumbnails wrap onto additional rows instead of collapsing.
30
+ * - Default alt text is the English "Image N" — pass `alts` with translated
31
+ * strings in localized apps.
32
+ * - `getClassMap()` requires a bonded ClassMap (e.g.
33
+ * `@molecule/app-ui-tailwind`).
34
+ *
35
+ * @module
36
+ */
37
+ export * from './ImageGallery.js';
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,mBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * React image gallery.
3
+ *
4
+ * Exports `<ImageGallery>` — main image + thumbnail grid with controlled-optional
5
+ * selection and "+N" overflow summarisation.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { ImageGallery } from '@molecule/app-image-gallery-react'
10
+ *
11
+ * const images = [
12
+ * 'https://example.com/photo-1.jpg',
13
+ * 'https://example.com/photo-2.jpg',
14
+ * 'https://example.com/photo-3.jpg',
15
+ * ]
16
+ *
17
+ * // Uncontrolled — manages its own selected index
18
+ * <ImageGallery images={images} maxThumbnails={4} />
19
+ *
20
+ * // Controlled — caller drives selected index
21
+ * <ImageGallery images={images} selectedIndex={activeIdx} onSelect={setActiveIdx} />
22
+ * ```
23
+ *
24
+ * @remarks
25
+ * - Renders `null` when `images` is empty — no empty-state UI.
26
+ * - `maxThumbnails` doubles as the thumbnail grid's column count. Any value is
27
+ * safe: it is snapped to the nearest column count the ClassMap grid actually
28
+ * supports (1-6 or 12), so a real `grid-cols-*` class is always emitted and
29
+ * extra thumbnails wrap onto additional rows instead of collapsing.
30
+ * - Default alt text is the English "Image N" — pass `alts` with translated
31
+ * strings in localized apps.
32
+ * - `getClassMap()` requires a bonded ClassMap (e.g.
33
+ * `@molecule/app-ui-tailwind`).
34
+ *
35
+ * @module
36
+ */
37
+ export * from './ImageGallery.js';
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@molecule/app-image-gallery-react",
3
+ "version": "1.0.0",
4
+ "description": "Main image + thumbnail grid gallery with selection + optional upload",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "image-gallery",
25
+ "react"
26
+ ],
27
+ "license": "Apache-2.0",
28
+ "peerDependencies": {
29
+ "@molecule/app-react": "^1.0.0",
30
+ "@molecule/app-ui": "^1.0.0",
31
+ "@molecule/app-ui-react": "^1.0.0",
32
+ "react": "^18.0.0 || ^19.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@molecule/app-react": "1.0.0",
36
+ "@molecule/app-ui": "1.0.0",
37
+ "@molecule/app-ui-react": "1.0.0",
38
+ "@types/node": "26.1.2",
39
+ "@types/react": "19.2.17",
40
+ "@types/react-dom": "19.2.3",
41
+ "react": "19.2.8",
42
+ "react-dom": "19.2.8",
43
+ "typescript": "6.0.3",
44
+ "vitest": "4.1.10"
45
+ }
46
+ }