@reuse-sh/lightbox 0.0.5 → 0.0.6

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 +84 -21
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -23,36 +23,99 @@ These are the rules the code keeps. An adaptation on any framework keeps them to
23
23
  npm install @reuse-sh/lightbox
24
24
  ```
25
25
 
26
- ## Browser
27
-
28
- ```js
29
- import { createLightbox } from "@reuse-sh/lightbox";
30
- import "@reuse-sh/lightbox/styles.css";
31
-
32
- const viewer = createLightbox({ thumbnails: true });
33
- viewer.open([{
34
- src: "/photo.jpg",
35
- alt: "A mountain lake",
36
- width: 1600,
37
- height: 1200,
38
- origin: document.querySelector("img"),
39
- }]);
26
+ <!-- examples:start -->
27
+
28
+ ## Usage
29
+
30
+ [Documentation](https://reuse.sh/lightbox/getting-started)
31
+
32
+ ### React
33
+
34
+ #### Package styles
35
+
36
+ Import the package stylesheet once in your main CSS. The components layer lets Tailwind utilities adapt its presentation.
37
+
38
+ ```css
39
+ @import "@reuse-sh/lightbox/styles.css" layer(components);
40
40
  ```
41
41
 
42
- ## React
42
+ #### Usage
43
+
44
+ Keep a real image link as the trigger, then open its full-size image through useLightbox. The origin image gives the opening and closing transition its actual crop.
43
45
 
44
46
  ```tsx
47
+ "use client";
48
+
45
49
  import { useLightbox } from "@reuse-sh/lightbox/react";
46
- import "@reuse-sh/lightbox/styles.css";
47
50
 
48
- function Gallery({ images }) {
49
- const viewer = useLightbox();
50
- return <button onClick={() => viewer.open(images)}>
51
- Open gallery
52
- </button>;
51
+ export function Gallery() {
52
+ const lightbox = useLightbox({});
53
+ return (
54
+ <a href="/images/print-large.jpg" onClick={(event) => {
55
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
56
+ event.preventDefault();
57
+ lightbox.open([{
58
+ src: event.currentTarget.href,
59
+ alt: "Marble print",
60
+ origin: event.currentTarget.querySelector("img"),
61
+ }]);
62
+ }}>
63
+ <img src="/images/print.jpg" alt="Marble print" width="640" height="480" />
64
+ </a>
65
+ );
53
66
  }
54
67
  ```
55
68
 
69
+ #### Integration
70
+
71
+ Links still open the image without JavaScript. The native dialog keeps focus inside, Escape closes it, and close restores the opening element. The React hook destroys its viewer on unmount.
72
+
73
+ ### HTML + JavaScript
74
+
75
+ #### Usage
76
+
77
+ Keep a real image link as the trigger, then enhance the gallery with bindLightboxGallery. The origin image gives the opening and closing transition its actual crop.
78
+
79
+ ```html
80
+ <div id="gallery">
81
+ <a href="/images/print-large.jpg">
82
+ <img data-lightbox-src="/images/print-large.jpg" src="/images/print.jpg" alt="Marble print" width="640" height="480" />
83
+ </a>
84
+ </div>
85
+ ```
86
+
87
+ #### Styles
88
+
89
+ Import the package stylesheet once. Keep application layout styles scoped to this integration.
90
+
91
+ ```css
92
+ @import "@reuse-sh/lightbox/styles.css";
93
+ ```
94
+
95
+ #### Initialize
96
+
97
+ Run this after the markup exists. Keep the returned controller for the lifetime of this content.
98
+
99
+ ```javascript
100
+ import { bindLightboxGallery } from "@reuse-sh/lightbox";
101
+
102
+ const gallery = bindLightboxGallery(document.querySelector("#gallery"), {});
103
+ ```
104
+
105
+ #### Integration
106
+
107
+ Links still open the image without JavaScript. The native dialog keeps focus inside, Escape closes it, and close restores the opening element.
108
+
109
+ #### Cleanup
110
+
111
+ Run this when the view is removed, before mounting another controller on the same element.
112
+
113
+ ```javascript
114
+ gallery.destroy();
115
+ ```
116
+
117
+ <!-- examples:end -->
118
+
56
119
  ## Documentation
57
120
 
58
121
  - Examples and API: https://reuse.sh/lightbox
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuse-sh/lightbox",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "An image lightbox on native scrolling, with thumbnail transitions, zoom, pan, and pinch.",
5
5
  "keywords": [
6
6
  "reuse",
@@ -51,7 +51,7 @@
51
51
  "@types/react": "19.3.0"
52
52
  },
53
53
  "dependencies": {
54
- "@reuse-sh/carousel": "0.1.0"
54
+ "@reuse-sh/carousel": "0.1.1"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"