react-image-gallery 1.2.12 → 1.3.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.
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+
4
+ import ImageGallery from "./ImageGallery";
5
+
6
+ describe("<ImageGallery />", () => {
7
+ const defaultProps = {
8
+ items: [
9
+ {
10
+ original: "test.png",
11
+ thumbnail: "test_thumb.png",
12
+ },
13
+ ],
14
+ };
15
+
16
+ it("renders slides", () => {
17
+ render(<ImageGallery {...defaultProps} />);
18
+ const elements = screen.getAllByLabelText("Go to Slide 1");
19
+ // expect a thumbnail and slide label
20
+ expect(elements.length).toBe(2);
21
+ });
22
+ });
@@ -1,17 +1,17 @@
1
- import React from 'react';
2
- import { bool, func, string } from 'prop-types';
1
+ import React from "react";
2
+ import { bool, func, string } from "prop-types";
3
3
 
4
4
  const defaultProps = {
5
- description: '',
6
- fullscreen: '',
5
+ description: "",
6
+ fullscreen: "",
7
7
  isFullscreen: false,
8
- originalAlt: '',
9
- originalHeight: '',
10
- originalWidth: '',
11
- originalTitle: '',
12
- sizes: '',
13
- srcSet: '',
14
- loading: 'eager',
8
+ originalAlt: "",
9
+ originalHeight: "",
10
+ originalWidth: "",
11
+ originalTitle: "",
12
+ sizes: "",
13
+ srcSet: "",
14
+ loading: "eager",
15
15
  };
16
16
 
17
17
  const Item = React.memo((props) => {
@@ -29,8 +29,8 @@ const Item = React.memo((props) => {
29
29
  sizes,
30
30
  srcSet,
31
31
  loading,
32
- } = {...defaultProps, ...props};
33
- const itemSrc = isFullscreen ? (fullscreen || original) : original;
32
+ } = { ...defaultProps, ...props };
33
+ const itemSrc = isFullscreen ? fullscreen || original : original;
34
34
 
35
35
  return (
36
36
  <React.Fragment>
@@ -43,22 +43,18 @@ const Item = React.memo((props) => {
43
43
  width={originalWidth}
44
44
  sizes={sizes}
45
45
  title={originalTitle}
46
- onLoad={event => handleImageLoaded(event, original)}
46
+ onLoad={(event) => handleImageLoaded(event, original)}
47
47
  onError={onImageError}
48
48
  loading={loading}
49
49
  />
50
- {
51
- description && (
52
- <span className="image-gallery-description">
53
- {description}
54
- </span>
55
- )
56
- }
50
+ {description && (
51
+ <span className="image-gallery-description">{description}</span>
52
+ )}
57
53
  </React.Fragment>
58
54
  );
59
55
  });
60
56
 
61
- Item.displayName = 'Item';
57
+ Item.displayName = "Item";
62
58
 
63
59
  Item.propTypes = {
64
60
  description: string,
@@ -1,10 +1,14 @@
1
- import React from 'react';
2
- import { number, oneOf, string } from 'prop-types';
1
+ import React from "react";
2
+ import { number, oneOf, string } from "prop-types";
3
3
 
4
4
  const left = <polyline points="15 18 9 12 15 6" />;
5
5
  const right = <polyline points="9 18 15 12 9 6" />;
6
- const maximize = <path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />;
7
- const minimize = <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3" />;
6
+ const maximize = (
7
+ <path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
8
+ );
9
+ const minimize = (
10
+ <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3" />
11
+ );
8
12
  const play = <polygon points="5 3 19 12 5 21 5 3" />;
9
13
  const pause = (
10
14
  <React.Fragment>
@@ -24,15 +28,11 @@ const iconMapper = {
24
28
 
25
29
  const defaultProps = {
26
30
  strokeWidth: 1,
27
- viewBox: '0 0 24 24',
31
+ viewBox: "0 0 24 24",
28
32
  };
29
33
 
30
34
  const SVG = (props) => {
31
- const {
32
- strokeWidth,
33
- viewBox,
34
- icon,
35
- } = {...defaultProps, ...props};
35
+ const { strokeWidth, viewBox, icon } = { ...defaultProps, ...props };
36
36
  return (
37
37
  <svg
38
38
  className="image-gallery-svg"
@@ -52,14 +52,8 @@ const SVG = (props) => {
52
52
  SVG.propTypes = {
53
53
  strokeWidth: number,
54
54
  viewBox: string,
55
- icon: oneOf([
56
- 'left',
57
- 'right',
58
- 'maximize',
59
- 'minimize',
60
- 'play',
61
- 'pause',
62
- ]).isRequired,
55
+ icon: oneOf(["left", "right", "maximize", "minimize", "play", "pause"])
56
+ .isRequired,
63
57
  };
64
58
 
65
59
  export default SVG;
@@ -1,27 +1,19 @@
1
- import React from 'react';
2
- import {
3
- string,
4
- node,
5
- number,
6
- func,
7
- } from 'prop-types';
8
- import { useSwipeable } from 'react-swipeable';
1
+ import React from "react";
2
+ import { string, node, number, func } from "prop-types";
3
+ import { useSwipeable } from "react-swipeable";
9
4
 
10
5
  const defaultProps = {
11
- className: '',
6
+ className: "",
12
7
  delta: 0,
13
8
  onSwiping: () => {},
14
9
  onSwiped: () => {},
15
10
  };
16
11
 
17
12
  const SwipeWrapper = (props) => {
18
- const {
19
- children,
20
- className,
21
- delta,
22
- onSwiping,
23
- onSwiped,
24
- } = {...defaultProps, ...props};
13
+ const { children, className, delta, onSwiping, onSwiped } = {
14
+ ...defaultProps,
15
+ ...props,
16
+ };
25
17
  const swipeHandlers = useSwipeable({
26
18
  delta,
27
19
  onSwiping,
@@ -1,11 +1,8 @@
1
- import React from 'react';
2
- import { bool, func } from 'prop-types';
3
- import SVG from 'src/SVG';
1
+ import React from "react";
2
+ import { bool, func } from "prop-types";
3
+ import SVG from "src/components/SVG";
4
4
 
5
- const Fullscreen = React.memo(({
6
- isFullscreen,
7
- onClick,
8
- }) => {
5
+ const Fullscreen = React.memo(({ isFullscreen, onClick }) => {
9
6
  return (
10
7
  <button
11
8
  type="button"
@@ -13,17 +10,16 @@ const Fullscreen = React.memo(({
13
10
  onClick={onClick}
14
11
  aria-label="Open Fullscreen"
15
12
  >
16
- <SVG strokeWidth={2} icon={isFullscreen ? 'minimize' : 'maximize'} />
13
+ <SVG strokeWidth={2} icon={isFullscreen ? "minimize" : "maximize"} />
17
14
  </button>
18
15
  );
19
16
  });
20
17
 
21
- Fullscreen.displayName = 'Fullscreen';
18
+ Fullscreen.displayName = "Fullscreen";
22
19
 
23
20
  Fullscreen.propTypes = {
24
21
  isFullscreen: bool.isRequired,
25
22
  onClick: func.isRequired,
26
23
  };
27
24
 
28
-
29
25
  export default Fullscreen;
@@ -1,11 +1,8 @@
1
- import React from 'react';
2
- import { bool, func } from 'prop-types';
3
- import SVG from 'src/SVG';
1
+ import React from "react";
2
+ import { bool, func } from "prop-types";
3
+ import SVG from "src/components/SVG";
4
4
 
5
- const LeftNav = React.memo(({
6
- disabled,
7
- onClick,
8
- }) => {
5
+ const LeftNav = React.memo(({ disabled, onClick }) => {
9
6
  return (
10
7
  <button
11
8
  type="button"
@@ -19,12 +16,11 @@ const LeftNav = React.memo(({
19
16
  );
20
17
  });
21
18
 
22
- LeftNav.displayName = 'LeftNav';
19
+ LeftNav.displayName = "LeftNav";
23
20
 
24
21
  LeftNav.propTypes = {
25
22
  disabled: bool.isRequired,
26
23
  onClick: func.isRequired,
27
24
  };
28
25
 
29
-
30
26
  export default LeftNav;
@@ -1,11 +1,8 @@
1
- import React from 'react';
2
- import { bool, func } from 'prop-types';
3
- import SVG from 'src/SVG';
1
+ import React from "react";
2
+ import { bool, func } from "prop-types";
3
+ import SVG from "src/components/SVG";
4
4
 
5
- const PlayPause = React.memo(({
6
- isPlaying,
7
- onClick,
8
- }) => {
5
+ const PlayPause = React.memo(({ isPlaying, onClick }) => {
9
6
  return (
10
7
  <button
11
8
  type="button"
@@ -13,17 +10,16 @@ const PlayPause = React.memo(({
13
10
  onClick={onClick}
14
11
  aria-label="Play or Pause Slideshow"
15
12
  >
16
- <SVG strokeWidth={2} icon={isPlaying ? 'pause' : 'play'} />
13
+ <SVG strokeWidth={2} icon={isPlaying ? "pause" : "play"} />
17
14
  </button>
18
15
  );
19
16
  });
20
17
 
21
- PlayPause.displayName = 'PlayPause';
18
+ PlayPause.displayName = "PlayPause";
22
19
 
23
20
  PlayPause.propTypes = {
24
21
  isPlaying: bool.isRequired,
25
22
  onClick: func.isRequired,
26
23
  };
27
24
 
28
-
29
25
  export default PlayPause;
@@ -1,11 +1,8 @@
1
- import React from 'react';
2
- import { bool, func } from 'prop-types';
3
- import SVG from 'src/SVG';
1
+ import React from "react";
2
+ import { bool, func } from "prop-types";
3
+ import SVG from "src/components/SVG";
4
4
 
5
- const RightNav = React.memo(({
6
- disabled,
7
- onClick,
8
- }) => {
5
+ const RightNav = React.memo(({ disabled, onClick }) => {
9
6
  return (
10
7
  <button
11
8
  type="button"
@@ -19,12 +16,11 @@ const RightNav = React.memo(({
19
16
  );
20
17
  });
21
18
 
22
- RightNav.displayName = 'RightNav';
19
+ RightNav.displayName = "RightNav";
23
20
 
24
21
  RightNav.propTypes = {
25
22
  disabled: bool.isRequired,
26
23
  onClick: func.isRequired,
27
24
  };
28
25
 
29
-
30
26
  export default RightNav;
package/webpack.build.js CHANGED
@@ -1,57 +1,56 @@
1
-
2
- const path = require('path');
3
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
- const RemovePlugin = require('remove-files-webpack-plugin');
1
+ const path = require("path");
2
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
3
+ const RemovePlugin = require("remove-files-webpack-plugin");
5
4
 
6
5
  const config = {
7
- mode: 'production',
6
+ mode: "production",
8
7
  };
9
8
 
10
9
  const jsOutput = Object.assign({}, config, {
11
- entry: [ './src/ImageGallery.js', ],
10
+ entry: ["./src/components/ImageGallery.jsx"],
12
11
  output: {
13
- path: path.resolve(__dirname, 'build'),
14
- filename: 'image-gallery.js',
15
- library: 'ImageGallery',
16
- globalObject: 'this',
17
- libraryTarget: 'umd',
12
+ path: path.resolve(__dirname, "build"),
13
+ filename: "image-gallery.js",
14
+ library: "ImageGallery",
15
+ globalObject: "this",
16
+ libraryTarget: "umd",
18
17
  },
19
18
  resolve: {
20
19
  alias: {
21
- src: path.resolve(__dirname, 'src/'),
20
+ src: path.resolve(__dirname, "src/"),
22
21
  },
23
- extensions: ['.js']
22
+ extensions: [".js", ".jsx"],
24
23
  },
25
24
  module: {
26
25
  rules: [
27
26
  {
28
- test: /\.js$/,
27
+ test: /\.(js|jsx)$/,
29
28
  exclude: /node_modules/,
30
- loader: 'babel-loader',
31
- }
32
- ]
29
+ loader: "babel-loader",
30
+ },
31
+ ],
33
32
  },
34
33
  externals: {
35
34
  // Don't bundle react or react-dom
36
35
  react: {
37
- commonjs: 'react',
38
- commonjs2: 'react',
39
- amd: 'react',
40
- root: 'React',
36
+ commonjs: "react",
37
+ commonjs2: "react",
38
+ amd: "react",
39
+ root: "React",
41
40
  },
42
- 'react-dom': {
43
- commonjs: 'react-dom',
44
- commonjs2: 'react-dom',
45
- amd: 'react-dom',
46
- root: 'ReactDOM',
41
+ "react-dom": {
42
+ commonjs: "react-dom",
43
+ commonjs2: "react-dom",
44
+ amd: "react-dom",
45
+ root: "ReactDOM",
47
46
  },
48
47
  },
49
48
  });
50
49
 
51
50
  const cssOutput = Object.assign({}, config, {
52
- entry: './styles/scss/image-gallery.scss',
51
+ entry: "./styles/scss/image-gallery.scss",
53
52
  output: {
54
- path: path.resolve(__dirname, 'styles/css'),
53
+ path: path.resolve(__dirname, "styles/css"),
55
54
  },
56
55
  module: {
57
56
  rules: [
@@ -60,16 +59,16 @@ const cssOutput = Object.assign({}, config, {
60
59
  use: [
61
60
  MiniCssExtractPlugin.loader,
62
61
  // Translates CSS into CommonJS
63
- 'css-loader',
62
+ "css-loader",
64
63
  // Compiles Sass to CSS
65
- 'sass-loader',
64
+ "sass-loader",
66
65
  ],
67
- }
68
- ]
66
+ },
67
+ ],
69
68
  },
70
69
  plugins: [
71
70
  new MiniCssExtractPlugin({
72
- filename: 'image-gallery.css',
71
+ filename: "image-gallery.css",
73
72
  }),
74
73
  new RemovePlugin({
75
74
  /**
@@ -78,36 +77,36 @@ const cssOutput = Object.assign({}, config, {
78
77
  after: {
79
78
  test: [
80
79
  {
81
- folder: 'styles/css',
80
+ folder: "styles/css",
82
81
  method: (absoluteItemPath) => {
83
- return new RegExp(/\.js$/, 'm').test(absoluteItemPath);
82
+ return new RegExp(/\.js$/, "m").test(absoluteItemPath);
84
83
  },
85
- }
86
- ]
87
- }
84
+ },
85
+ ],
86
+ },
88
87
  }),
89
88
  ],
90
89
  });
91
90
 
92
91
  const jsDemoOutput = Object.assign({}, config, {
93
- entry: [ './example/app.js', ],
92
+ entry: ["./example/App.jsx"],
94
93
  output: {
95
- path: path.resolve(__dirname, 'demo'),
96
- filename: 'demo.mini.js',
94
+ path: path.resolve(__dirname, "demo"),
95
+ filename: "demo.mini.js",
97
96
  },
98
97
  resolve: {
99
98
  alias: {
100
- src: path.resolve(__dirname, 'src/'),
99
+ src: path.resolve(__dirname, "src/"),
101
100
  },
102
- extensions: ['.js']
101
+ extensions: [".js", ".jsx"],
103
102
  },
104
103
  module: {
105
104
  rules: [
106
105
  {
107
- test: /\.js$/,
108
- loader: 'babel-loader',
109
- }
110
- ]
106
+ test: /\.(js|jsx)$/,
107
+ loader: "babel-loader",
108
+ },
109
+ ],
111
110
  },
112
111
  plugins: [
113
112
  new RemovePlugin({
@@ -117,21 +116,21 @@ const jsDemoOutput = Object.assign({}, config, {
117
116
  after: {
118
117
  test: [
119
118
  {
120
- folder: 'demo',
119
+ folder: "demo",
121
120
  method: (absoluteItemPath) => {
122
121
  return new RegExp(/\.txt$/).test(absoluteItemPath);
123
122
  },
124
- }
125
- ]
126
- }
123
+ },
124
+ ],
125
+ },
127
126
  }),
128
127
  ],
129
128
  });
130
129
 
131
130
  const cssDemoOutput = Object.assign({}, config, {
132
- entry: ['./styles/scss/image-gallery.scss', './example/app.css'],
131
+ entry: ["./styles/scss/image-gallery.scss", "./example/App.css"],
133
132
  output: {
134
- path: path.resolve(__dirname, 'demo'),
133
+ path: path.resolve(__dirname, "demo"),
135
134
  },
136
135
  module: {
137
136
  rules: [
@@ -140,16 +139,16 @@ const cssDemoOutput = Object.assign({}, config, {
140
139
  use: [
141
140
  MiniCssExtractPlugin.loader,
142
141
  // Translates CSS into CommonJS
143
- 'css-loader',
142
+ "css-loader",
144
143
  // Compiles Sass to CSS
145
- 'sass-loader',
144
+ "sass-loader",
146
145
  ],
147
- }
148
- ]
146
+ },
147
+ ],
149
148
  },
150
149
  plugins: [
151
150
  new MiniCssExtractPlugin({
152
- filename: 'demo.mini.css',
151
+ filename: "demo.mini.css",
153
152
  }),
154
153
  new RemovePlugin({
155
154
  /**
@@ -158,13 +157,13 @@ const cssDemoOutput = Object.assign({}, config, {
158
157
  after: {
159
158
  test: [
160
159
  {
161
- folder: 'demo',
160
+ folder: "demo",
162
161
  method: (absoluteItemPath) => {
163
162
  return new RegExp(/\.js$/).test(absoluteItemPath);
164
163
  },
165
- }
166
- ]
167
- }
164
+ },
165
+ ],
166
+ },
168
167
  }),
169
168
  ],
170
169
  });
package/webpack.config.js CHANGED
@@ -1,25 +1,28 @@
1
-
2
- const path = require('path');
3
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
1
+ const path = require("path");
2
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
4
3
 
5
4
  module.exports = {
6
- entry: ['./example/app.js', './example/app.css', './styles/scss/image-gallery.scss'],
5
+ entry: [
6
+ "./example/App.jsx",
7
+ "./example/App.css",
8
+ "./styles/scss/image-gallery.scss",
9
+ ],
7
10
  output: {
8
- path: path.resolve(__dirname, 'example'),
9
- filename: 'example.js',
10
- publicPath: '/dist/'
11
+ path: path.resolve(__dirname, "example"),
12
+ filename: "example.js",
13
+ publicPath: "/dist/",
11
14
  },
12
15
  resolve: {
13
- extensions: ['.js'],
16
+ extensions: [".js", ".jsx"],
14
17
  alias: {
15
- src: path.resolve(__dirname, 'src/'),
18
+ src: path.resolve(__dirname, "src/"),
16
19
  },
17
20
  },
18
21
  module: {
19
22
  rules: [
20
23
  {
21
24
  test: /\.(js|jsx)$/,
22
- loader: 'babel-loader',
25
+ loader: "babel-loader",
23
26
  },
24
27
  {
25
28
  test: /\.(css|scss)$/i,
@@ -31,19 +34,19 @@ module.exports = {
31
34
  // Compiles Sass to CSS
32
35
  "sass-loader",
33
36
  ],
34
- }
35
- ]
37
+ },
38
+ ],
36
39
  },
37
40
  plugins: [
38
41
  new MiniCssExtractPlugin({
39
- filename: 'image-gallery.css',
42
+ filename: "image-gallery.css",
40
43
  }),
41
44
  ],
42
45
  devServer: {
43
- host: '0.0.0.0',
46
+ host: "0.0.0.0",
44
47
  port: 8001,
45
48
  historyApiFallback: {
46
- rewrites: [{ from: /\//, to: '/example/index.html' }],
49
+ rewrites: [{ from: /\//, to: "/example/index.html" }],
47
50
  },
48
51
  },
49
52
  };
package/.babelrc DELETED
@@ -1 +0,0 @@
1
- { "presets": ["@babel/preset-env", "@babel/preset-react"] }
package/.notes DELETED
@@ -1,2 +0,0 @@
1
- Great carousel lib
2
- https://splidejs.com/integration/react-splide/
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
-
4
- import ImageGallery from '../src/ImageGallery';
5
-
6
- describe('<ImageGallery />', () => {
7
- const defaultProps = {
8
- items: [],
9
- };
10
-
11
- it('matches snapshot', () => {
12
- const component = shallow(<ImageGallery {...defaultProps} />);
13
- expect(component).toMatchSnapshot();
14
- });
15
- });
@@ -1,3 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<ImageGallery /> matches snapshot 1`] = `ShallowWrapper {}`;
@@ -1,4 +0,0 @@
1
- import Adapter from 'enzyme-adapter-react-16';
2
- import { configure } from 'enzyme';
3
-
4
- configure({ adapter: new Adapter() });