├── .eslintignore
├── .prettierrc.js
├── .gitignore
├── .npmignore
├── .huskyrc.js
├── src
├── utils.js
├── lightgalleryContext.js
├── index.js
├── withLightgallery.js
├── useLightgallery.js
├── LightgalleryItem.js
└── LightgalleryProvider.js
├── .babelrc.json
├── example
├── styles.css
├── index.html
└── index.js
├── .eslintrc.js
├── .github
└── workflows
│ └── npm-publish.yml
├── LICENSE
├── rollup.config.js
├── package.json
└── readme.md
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | tabWidth: 4,
3 | };
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn-error.log
3 | dist
4 | .example_dist
5 | .cache
6 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /src
3 | /example
4 | /.yarn-error.log
5 | /.cache
6 | /.example_dist
7 | /.github
--------------------------------------------------------------------------------
/.huskyrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | hooks: {
3 | "pre-commit": "yarn run eslint",
4 | },
5 | };
6 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Generator of class names for elements
3 | */
4 | export const addPrefix = (str) => `react_lightgallery_${str}`;
5 |
--------------------------------------------------------------------------------
/.babelrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["@babel/preset-env", "@babel/preset-react"],
3 | "plugins": ["@babel/plugin-proposal-class-properties"]
4 | }
5 |
--------------------------------------------------------------------------------
/src/lightgalleryContext.js:
--------------------------------------------------------------------------------
1 | import { createContext } from "react";
2 |
3 | export const lightgalleryContext = createContext();
4 | export default lightgalleryContext;
5 |
--------------------------------------------------------------------------------
/example/styles.css:
--------------------------------------------------------------------------------
1 | @import url("https://fonts.googleapis.com/css2?family=Open+Sans&display=swap");
2 |
3 | .navbar-logo {
4 | font-family: "Open Sans";
5 | font-size: 24px;
6 | color: #fff;
7 | background-color: #0a4f56;
8 | }
9 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import { LightgalleryItem } from "./LightgalleryItem";
2 | import { LightgalleryProvider } from "./LightgalleryProvider";
3 | import { useLightgallery } from "./useLightgallery";
4 | import { withLightgallery } from "./withLightgallery";
5 |
6 | export {
7 | LightgalleryItem,
8 | LightgalleryProvider,
9 | useLightgallery,
10 | withLightgallery,
11 | };
12 |
--------------------------------------------------------------------------------
/src/withLightgallery.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { useLightgallery } from "./useLightgallery";
3 | import hoistNonReactStatic from "hoist-non-react-statics";
4 |
5 | export const withLightgallery = (WrappedComponent) => {
6 | const WithLightgallery = (props) => {
7 | const { openGallery } = useLightgallery();
8 | return ;
9 | };
10 | hoistNonReactStatic(WithLightgallery, WrappedComponent);
11 | WithLightgallery.displayName = `withLightgallary(${WrappedComponent.displayName})`;
12 | return WithLightgallery;
13 | };
14 |
15 | export default withLightgallery;
16 |
--------------------------------------------------------------------------------
/src/useLightgallery.js:
--------------------------------------------------------------------------------
1 | import { useContext } from "react";
2 | import { lightgalleryContext } from "./lightgalleryContext";
3 |
4 | export const useLightgallery = () => {
5 | const { hasGroup, openGalleryByIndex: _openGalleryByIndex } = useContext(
6 | lightgalleryContext
7 | );
8 | const openGallery = (group_name, item_idx = 0) => {
9 | if (!group_name) {
10 | throw new Error(
11 | "You must to provide 'group_name' on call function 'openGallery'"
12 | );
13 | }
14 | if (!hasGroup(group_name)) {
15 | throw new Error(`Group '${group_name}' is not exists`);
16 | }
17 | _openGalleryByIndex(item_idx, group_name);
18 | };
19 | return { openGallery };
20 | };
21 |
22 | export default useLightgallery;
23 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: true,
4 | node: true,
5 | es6: true,
6 | },
7 | extends: [
8 | "eslint:recommended",
9 | "plugin:react/recommended",
10 | "prettier",
11 | "plugin:import/errors",
12 | "plugin:import/warnings",
13 | ],
14 | parser: "babel-eslint",
15 | parserOptions: {
16 | ecmaFeatures: {
17 | jsx: true,
18 | },
19 | ecmaVersion: 2018,
20 | sourceType: "module",
21 | },
22 | plugins: ["react", "prettier", "import"],
23 | rules: {
24 | indent: ["error", 4],
25 | "linebreak-style": ["error", "unix"],
26 | quotes: ["error", "double"],
27 | semi: ["error", "always"],
28 | "no-console": "off",
29 | "no-prototype-builtins": "off",
30 | },
31 | globals: {
32 | lightGallery: true,
33 | },
34 | };
35 |
--------------------------------------------------------------------------------
/.github/workflows/npm-publish.yml:
--------------------------------------------------------------------------------
1 | name: npm-publish
2 | on:
3 | push:
4 | branches:
5 | - master
6 | - workflow-configuration
7 | jobs:
8 | npm-publish:
9 | name: npm-publish
10 | runs-on: ubuntu-latest
11 | steps:
12 | - name: Checkout repository
13 | uses: actions/checkout@master
14 | - name: Set up Node.js
15 | uses: actions/setup-node@master
16 | with:
17 | node-version: 12.0.0
18 | - name: Install yarn
19 | run: npm install yarn -g
20 | - name: Install deps
21 | run: yarn install
22 | - name: Build bundle
23 | run: yarn build
24 | - name: Publish if version has been updated
25 | uses: pascalgn/npm-publish-action@06e0830ea83eea10ed4a62654eeaedafb8bf50fc
26 | env:
27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 | NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 VLZH
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included
14 | in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | const resolve = require("rollup-plugin-node-resolve");
2 | const babel = require("rollup-plugin-babel");
3 | const commonjs = require("rollup-plugin-commonjs");
4 | const { terser } = require("rollup-plugin-terser");
5 |
6 | const isProduction = process.env.NODE_ENV === "production";
7 |
8 | module.exports = {
9 | input: "src/index.js",
10 | output: {
11 | file: "./dist/index.js",
12 | format: "cjs",
13 | },
14 | plugins: [
15 | resolve({
16 | // pass custom options to the resolve plugin
17 | customResolveOptions: {
18 | moduleDirectory: "node_modules",
19 | },
20 | }),
21 | babel({
22 | exclude: "node_modules/**", // only transpile our source code
23 | }),
24 | commonjs({
25 | include: "node_modules/**",
26 | namedExports: {},
27 | }),
28 | // production plugins
29 | ...(isProduction ? [terser()] : []),
30 | ],
31 | external: [
32 | "browser-or-node",
33 | "lg-autoplay.js",
34 | "lg-fullscreen.js",
35 | "lg-hash.js",
36 | "lg-pager.js",
37 | "lg-share.js",
38 | "lg-thumbnail.js",
39 | "lg-video.js",
40 | "lg-zoom.js",
41 | "lightgallery.js",
42 | "prop-types",
43 | "react",
44 | "react-dom",
45 | "uniqid",
46 | ],
47 | inlineDynamicImports: true,
48 | };
49 |
--------------------------------------------------------------------------------
/src/LightgalleryItem.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import PT from "prop-types";
3 | import uniqid from "uniqid";
4 | //
5 | import lightgalleryContext from "./lightgalleryContext";
6 | import { addPrefix } from "./utils";
7 |
8 | export class LightgalleryItem extends Component {
9 | static propTypes = {
10 | children: PT.any,
11 | group: PT.string.isRequired,
12 | src: PT.string.isRequired,
13 | thumb: PT.string,
14 | subHtml: PT.oneOfType([PT.string, PT.object]),
15 | downloadUrl: PT.string,
16 | itemClassName: PT.string,
17 | };
18 | static contextType = lightgalleryContext;
19 |
20 | state = {
21 | id: uniqid(),
22 | };
23 |
24 | componentDidMount() {
25 | this.register();
26 | }
27 |
28 | componentWillUnmount() {
29 | this.unregister();
30 | }
31 |
32 | /**
33 | * Register this slide in provider
34 | */
35 | register = () => {
36 | const { src, thumb = src, subHtml = "", downloadUrl = "" } = this.props;
37 | this.context.registerPhoto(this.state.id, this.props.group, {
38 | src,
39 | thumb,
40 | subHtml,
41 | downloadUrl,
42 | });
43 | };
44 |
45 | /**
46 | * Unregister this slide in provider
47 | */
48 | unregister = () => {
49 | this.context.unregisterPhoto(this.state.id, this.props.group);
50 | };
51 |
52 | /**
53 | * Open this slide
54 | */
55 | open = () => {
56 | this.context.openGallery(this.state.id, this.props.group);
57 | };
58 |
59 | render() {
60 | const { itemClassName = addPrefix("item"), children } = this.props;
61 | return (
62 |
63 | {children}
64 |
65 | );
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
15 |
19 | react-lightgallery example
20 |
21 |
22 |
23 |
52 |
53 |
54 |
55 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-lightgallery",
3 | "version": "0.9.0",
4 | "description": "React wrapper for https://github.com/sachinchoolur/lightgallery.js",
5 | "keywords": [
6 | "react",
7 | "gallery",
8 | "image-gallery",
9 | "lightbox",
10 | "lightgallery.js",
11 | "lg-zoom.js",
12 | "lg-thumbnail.js",
13 | "lg-video.js",
14 | "lightgallery"
15 | ],
16 | "main": "dist/index.js",
17 | "scripts": {
18 | "build": "NODE_ENV=production yarn rollup -c ./rollup.config.js",
19 | "build:example": "NODE_ENV=production yarn rollup -c ./rollup.config.js",
20 | "start": "yarn rollup --watch -c ./rollup.config.js",
21 | "start:example": "parcel serve --out-dir ./.example_dist ./example/index.html",
22 | "lint": "yarn eslint ./"
23 | },
24 | "author": "VLZH",
25 | "repository": "https://github.com/VLZH/react-lightgallery.git",
26 | "license": "MIT",
27 | "dependencies": {
28 | "browser-or-node": "^1.3.0",
29 | "hoist-non-react-statics": "^3.3.2",
30 | "lg-autoplay.js": "^1.2.0",
31 | "lg-fullscreen.js": "^1.2.0",
32 | "lg-hash.js": "^1.0.0",
33 | "lg-pager.js": "^1.0.0",
34 | "lg-share.js": "^1.3.0",
35 | "lg-thumbnail.js": "^1.2.0",
36 | "lg-video.js": "^1.2.0",
37 | "lg-zoom.js": "^1.2.0",
38 | "lightgallery.js": "^1.2.0",
39 | "lodash": "^4.17.15",
40 | "prop-types": "^15.7.2",
41 | "uniqid": "^5.2.0"
42 | },
43 | "devDependencies": {
44 | "@babel/core": "^7.10.2",
45 | "@babel/plugin-proposal-class-properties": "^7.10.1",
46 | "@babel/plugin-syntax-dynamic-import": "^7.8.3",
47 | "@babel/preset-env": "^7.10.2",
48 | "@babel/preset-react": "^7.10.1",
49 | "babel-eslint": "10.1.0",
50 | "eslint": "^7.2.0",
51 | "eslint-config-prettier": "^6.11.0",
52 | "eslint-plugin-import": "^2.21.2",
53 | "eslint-plugin-prettier": "^3.1.3",
54 | "eslint-plugin-react": "^7.20.0",
55 | "husky": "^4.2.5",
56 | "parcel-bundler": "^1.12.3",
57 | "prettier": "^2.0.5",
58 | "react": "^16.13.1",
59 | "react-dom": "^16.13.1",
60 | "rollup": "^2.15.0",
61 | "rollup-plugin-babel": "^4.4.0",
62 | "rollup-plugin-commonjs": "^10.1.0",
63 | "rollup-plugin-node-resolve": "^5.2.0",
64 | "rollup-plugin-terser": "^6.1.0",
65 | "rollup-plugin-uglify": "^6.0.3"
66 | },
67 | "peerDependencies": {
68 | "react": "^16.13.1",
69 | "react-dom": "^16.13.1"
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import PT from "prop-types";
3 | import ReactDOM from "react-dom";
4 | import {
5 | LightgalleryProvider,
6 | LightgalleryItem,
7 | withLightgallery,
8 | useLightgallery,
9 | } from "../dist/index.js";
10 | //
11 | import "./styles.css";
12 | import "lightgallery.js/dist/css/lightgallery.css";
13 |
14 | const GROUP1 = [
15 | [
16 | "https://images.unsplash.com/photo-1592549585866-486f41343aaf?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
17 | "https://images.unsplash.com/photo-1592549585866-486f41343aaf?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
18 | ],
19 | [
20 | "https://images.unsplash.com/photo-1594614271360-0ed9a570ae15?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
21 | "https://images.unsplash.com/photo-1594614271360-0ed9a570ae15?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
22 | ],
23 | ];
24 |
25 | const GROUP2 = [
26 | "https://images.unsplash.com/photo-1594818898109-44704fb548f6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
27 | "https://images.unsplash.com/photo-1594818896795-35ad7bcf3c6a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
28 | "https://images.unsplash.com/photo-1594818896744-57eca4d47b07?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
29 | "https://images.unsplash.com/photo-1594818897077-aec41f55241f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1951&q=80",
30 | ];
31 |
32 | const PhotoItem = ({ image, thumb, group }) => (
33 |
34 |
35 |
36 |
37 |
38 | );
39 | PhotoItem.propTypes = {
40 | image: PT.string.isRequired,
41 | thumb: PT.string,
42 | group: PT.string.isRequired,
43 | };
44 |
45 | const OpenButtonWithHoc = withLightgallery(
46 | ({ openGallery, className, ...rest }) => {
47 | return (
48 |