yet-another-react-lightbox 1.2.3 → 1.3.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Yet Another React Lightbox
2
2
 
3
- Modern lightbox component for React.
3
+ Modern React lightbox component.
4
4
 
5
5
  ## Overview
6
6
 
@@ -8,11 +8,9 @@ Modern lightbox component for React.
8
8
  [![Bundle Size](https://img.shields.io/bundlephobia/minzip/yet-another-react-lightbox?color=blue)](https://bundlephobia.com/package/yet-another-react-lightbox)
9
9
  [![License MIT](https://img.shields.io/npm/l/yet-another-react-lightbox?color=blue)](LICENSE)
10
10
 
11
- Coming soon...
12
-
13
11
  ## Documentation
14
12
 
15
- Coming soon...
13
+ [https://yet-another-react-lightbox.vercel.app/](https://yet-another-react-lightbox.vercel.app/)
16
14
 
17
15
  ## Installation
18
16
 
@@ -30,10 +28,10 @@ yarn add yet-another-react-lightbox
30
28
 
31
29
  ```javascript
32
30
  import * as React from "react";
33
- import { Lightbox } from "yet-another-react-lightbox";
31
+ import Lightbox from "yet-another-react-lightbox";
34
32
  import "yet-another-react-lightbox/styles.css";
35
33
 
36
- const Page = () => {
34
+ const App = () => {
37
35
  const [open, setOpen] = React.useState(false);
38
36
 
39
37
  return (
@@ -55,7 +53,7 @@ const Page = () => {
55
53
  );
56
54
  };
57
55
 
58
- export default Page;
56
+ export default App;
59
57
  ```
60
58
 
61
59
  ## License
@@ -1,9 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { LightboxProps } from "./types.js";
3
- declare type MakePartial<T> = T extends object ? Partial<T> : T;
4
- declare type NestedPartial<T extends object> = {
5
- [P in keyof T]?: MakePartial<T[P]>;
3
+ declare type DeepPartial<T, K extends keyof T> = Omit<T, K> & {
4
+ [P in keyof Pick<T, K>]?: Partial<Pick<T, K>[P]>;
6
5
  };
7
- declare type NestedOptional<T, K extends keyof T> = Omit<T, K> & NestedPartial<Pick<T, K>>;
8
- export declare const Lightbox: (props: NestedOptional<Partial<LightboxProps>, "carousel" | "animation" | "render" | "toolbar" | "on">) => JSX.Element;
6
+ export declare const Lightbox: (props: DeepPartial<Partial<LightboxProps>, "carousel" | "animation" | "render" | "toolbar" | "on">) => JSX.Element;
9
7
  export {};
package/dist/Lightbox.js CHANGED
@@ -25,7 +25,7 @@ const LightboxComponent = (props) => {
25
25
  };
26
26
  LightboxComponent.propTypes = LightboxPropTypes;
27
27
  export const Lightbox = (props) => {
28
- const { carousel, animation, render, toolbar, on, ...restProps } = props;
29
- const { carousel: defaultCarousel, animation: defaultAnimation, render: defaultRender, toolbar: defaultToolbar, on: defaultOn, ...restDefaultProps } = LightboxDefaultProps;
30
- return (React.createElement(LightboxComponent, { carousel: { ...defaultCarousel, ...carousel }, animation: { ...defaultAnimation, ...animation }, render: { ...defaultRender, ...render }, toolbar: { ...defaultToolbar, ...toolbar }, on: { ...defaultOn, ...on }, ...restDefaultProps, ...restProps }));
28
+ const { carousel, animation, render, toolbar, controller, on, ...restProps } = props;
29
+ const { carousel: defaultCarousel, animation: defaultAnimation, render: defaultRender, toolbar: defaultToolbar, controller: defaultController, on: defaultOn, ...restDefaultProps } = LightboxDefaultProps;
30
+ return (React.createElement(LightboxComponent, { carousel: { ...defaultCarousel, ...carousel }, animation: { ...defaultAnimation, ...animation }, render: { ...defaultRender, ...render }, toolbar: { ...defaultToolbar, ...toolbar }, controller: { ...defaultController, ...controller }, on: { ...defaultOn, ...on }, ...restDefaultProps, ...restProps }));
31
31
  };
@@ -42,8 +42,10 @@ export const Controller = ({ children, ...props }) => {
42
42
  }, [containerRef]);
43
43
  React.useEffect(() => {
44
44
  var _a;
45
- (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
46
- }, [containerRef]);
45
+ if (refs.current.props.controller.focus) {
46
+ (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
47
+ }
48
+ }, [containerRef, refs]);
47
49
  React.useEffect(() => {
48
50
  var _a, _b;
49
51
  (_b = (_a = refs.current.props.on).view) === null || _b === void 0 ? void 0 : _b.call(_a, state.currentIndex);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import { Lightbox } from "./Lightbox.js";
1
2
  export * from "./types.js";
2
3
  export * from "./Lightbox.js";
4
+ export default Lightbox;
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
+ import { Lightbox } from "./Lightbox.js";
1
2
  export * from "./types.js";
2
3
  export * from "./Lightbox.js";
4
+ export default Lightbox;
@@ -31,9 +31,12 @@ declare global {
31
31
  msRequestFullscreen?: () => void;
32
32
  }
33
33
  }
34
- export declare type FullscreenButtonProps = Pick<LightboxProps, "labels"> & {
34
+ declare type FullscreenButtonProps = Pick<LightboxProps, "labels"> & {
35
35
  auto: boolean;
36
36
  render: Render;
37
37
  };
38
- export declare const FullscreenButton: ({ auto, labels, render }: FullscreenButtonProps) => JSX.Element | null;
39
- export declare const Fullscreen: Plugin;
38
+ declare const FullscreenButton: ({ auto, labels, render }: FullscreenButtonProps) => JSX.Element | null;
39
+ declare const Fullscreen: Plugin;
40
+ export type { FullscreenButtonProps };
41
+ export { Fullscreen, FullscreenButton };
42
+ export default Fullscreen;
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { createIcon, IconButton, label, useController, useLatest } from "../core/index.js";
3
3
  const EnterFullscreenIcon = createIcon("EnterFullscreen", React.createElement("path", { d: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" }));
4
4
  const ExitFullscreenIcon = createIcon("ExitFullscreen", React.createElement("path", { d: "M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" }));
5
- export const FullscreenButton = ({ auto, labels, render }) => {
5
+ const FullscreenButton = ({ auto, labels, render }) => {
6
6
  const [fullscreen, setFullscreen] = React.useState(false);
7
7
  const latestAuto = useLatest(auto);
8
8
  const { containerRef } = useController();
@@ -92,7 +92,7 @@ export const FullscreenButton = ({ auto, labels, render }) => {
92
92
  return null;
93
93
  return render.buttonFullscreen ? (React.createElement(React.Fragment, null, render.buttonFullscreen({ fullscreen, toggleFullscreen }))) : (React.createElement(IconButton, { label: fullscreen ? label(labels, "Exit Fullscreen") : label(labels, "Enter Fullscreen"), icon: fullscreen ? ExitFullscreenIcon : EnterFullscreenIcon, renderIcon: fullscreen ? render.iconExitFullscreen : render.iconEnterFullscreen, onClick: toggleFullscreen }));
94
94
  };
95
- export const Fullscreen = ({ augment }) => {
95
+ const Fullscreen = ({ augment }) => {
96
96
  augment(({ toolbar: { buttons, ...restToolbar }, ...restProps }) => ({
97
97
  toolbar: {
98
98
  buttons: [
@@ -104,3 +104,5 @@ export const Fullscreen = ({ augment }) => {
104
104
  ...restProps,
105
105
  }));
106
106
  };
107
+ export { Fullscreen, FullscreenButton };
108
+ export default Fullscreen;
@@ -5,6 +5,8 @@ declare module "../types.js" {
5
5
  inline?: React.HTMLAttributes<HTMLDivElement>;
6
6
  }
7
7
  }
8
- export declare const InlineContainer: Component;
9
- export declare const InlineModule: import("../types.js").Module;
10
- export declare const Inline: Plugin;
8
+ declare const InlineContainer: Component;
9
+ declare const InlineModule: import("../types.js").Module;
10
+ declare const Inline: Plugin;
11
+ export { Inline, InlineModule, InlineContainer };
12
+ export default Inline;
@@ -1,9 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../core/index.js";
3
- export const InlineContainer = ({ inline, children }) => React.createElement("div", { ...inline }, children);
4
- export const InlineModule = createModule("inline", InlineContainer);
5
- export const Inline = ({ augment, replace, remove }) => {
6
- augment(({ toolbar: { buttons, ...restToolbar }, open, close, ...restProps }) => ({
3
+ const InlineContainer = ({ inline, children }) => React.createElement("div", { ...inline }, children);
4
+ const InlineModule = createModule("inline", InlineContainer);
5
+ const Inline = ({ augment, replace, remove }) => {
6
+ augment(({ toolbar: { buttons, ...restToolbar }, open, close, controller: { focus, ...restController }, ...restProps }) => ({
7
7
  open: true,
8
8
  close: () => { },
9
9
  toolbar: {
@@ -11,8 +11,11 @@ export const Inline = ({ augment, replace, remove }) => {
11
11
  ...restToolbar,
12
12
  },
13
13
  inline: { style: { width: "100%", height: "100%" } },
14
+ controller: { focus: false, ...restController },
14
15
  ...restProps,
15
16
  }));
16
17
  remove("no-scroll");
17
18
  replace("portal", InlineModule);
18
19
  };
20
+ export { Inline, InlineModule, InlineContainer };
21
+ export default Inline;
@@ -15,7 +15,9 @@ declare module "../types.js" {
15
15
  SlideVideo: SlideVideo;
16
16
  }
17
17
  }
18
- export declare const VideoSlide: ({ slide: { sources, poster, width, height } }: {
18
+ declare const VideoSlide: ({ slide: { sources, poster, width, height } }: {
19
19
  slide: SlideVideo;
20
20
  }) => JSX.Element;
21
- export declare const Video: Plugin;
21
+ declare const Video: Plugin;
22
+ export { Video, VideoSlide };
23
+ export default Video;
@@ -12,7 +12,7 @@ SlideTypesPropTypes.push(PropTypes.shape({
12
12
  type: PropTypes.string.isRequired,
13
13
  }).isRequired),
14
14
  }));
15
- export const VideoSlide = ({ slide: { sources, poster, width, height } }) => {
15
+ const VideoSlide = ({ slide: { sources, poster, width, height } }) => {
16
16
  const { setContainerRef, containerRect } = useContainerRect();
17
17
  const scaleWidthAndHeight = () => {
18
18
  if (!width || !height || !containerRect)
@@ -28,7 +28,7 @@ export const VideoSlide = ({ slide: { sources, poster, width, height } }) => {
28
28
  height: "100%",
29
29
  }, className: clsx(cssClass("video_container"), cssClass("flex_center")) }, containerRect && (React.createElement("video", { controls: true, playsInline: true, poster: poster, ...scaleWidthAndHeight() }, sources.map(({ src, type }, index) => (React.createElement("source", { key: index, src: src, type: type })))))))));
30
30
  };
31
- export const Video = ({ augment }) => {
31
+ const Video = ({ augment }) => {
32
32
  augment(({ render: { slide: renderSlide, ...restRender }, ...restProps }) => ({
33
33
  render: {
34
34
  slide: (slide) => {
@@ -42,3 +42,5 @@ export const Video = ({ augment }) => {
42
42
  ...restProps,
43
43
  }));
44
44
  };
45
+ export { Video, VideoSlide };
46
+ export default Video;
package/dist/types.d.ts CHANGED
@@ -13,16 +13,19 @@ export interface SlideTypes {
13
13
  SlideImage: SlideImage;
14
14
  }
15
15
  export declare type Slide = SlideTypes[keyof SlideTypes];
16
- export interface Carousel {
16
+ export interface CarouselSettings {
17
17
  finite: boolean;
18
18
  preload: number;
19
19
  padding: string | number;
20
20
  spacing: string | number;
21
21
  }
22
- export interface Animation {
22
+ export interface AnimationSettings {
23
23
  fade: number;
24
24
  swipe: number;
25
25
  }
26
+ export interface ControllerSettings {
27
+ focus: boolean;
28
+ }
26
29
  export interface Render {
27
30
  slide?: (slide: Slide) => React.ReactNode;
28
31
  iconPrev?: () => React.ReactNode;
@@ -49,9 +52,10 @@ export interface LightboxProps {
49
52
  render: Render;
50
53
  labels: Labels;
51
54
  plugins: Plugin[];
52
- toolbar: Toolbar;
53
- carousel: Carousel;
54
- animation: Animation;
55
+ toolbar: ToolbarSettings;
56
+ carousel: CarouselSettings;
57
+ animation: AnimationSettings;
58
+ controller: ControllerSettings;
55
59
  on: Callbacks;
56
60
  }
57
61
  export declare const SlideTypesPropTypes: PropTypes.Validator<any>[];
@@ -86,6 +90,9 @@ export declare const LightboxPropTypes: {
86
90
  fade: PropTypes.Validator<number>;
87
91
  swipe: PropTypes.Validator<number>;
88
92
  }>>;
93
+ controller: PropTypes.Validator<PropTypes.InferProps<{
94
+ focus: PropTypes.Validator<boolean>;
95
+ }>>;
89
96
  on: PropTypes.Validator<PropTypes.InferProps<{
90
97
  view: PropTypes.Requireable<(...args: any[]) => any>;
91
98
  entering: PropTypes.Requireable<(...args: any[]) => any>;
@@ -101,16 +108,17 @@ export declare const LightboxDefaultProps: {
101
108
  slides: Slide[];
102
109
  render: Render;
103
110
  plugins: Plugin[];
104
- toolbar: Toolbar;
111
+ toolbar: ToolbarSettings;
105
112
  labels: Labels;
106
- animation: Animation;
107
- carousel: Carousel;
113
+ animation: AnimationSettings;
114
+ carousel: CarouselSettings;
115
+ controller: ControllerSettings;
108
116
  on: Callbacks;
109
117
  };
110
118
  export declare type Labels = {
111
119
  [key: string]: string;
112
120
  };
113
- export interface Toolbar {
121
+ export interface ToolbarSettings {
114
122
  buttons: ("close" | React.ReactNode)[];
115
123
  }
116
124
  export declare type ComponentProps = Omit<LightboxProps, "plugins">;
package/dist/types.js CHANGED
@@ -44,6 +44,9 @@ export const LightboxPropTypes = {
44
44
  fade: PropTypes.number.isRequired,
45
45
  swipe: PropTypes.number.isRequired,
46
46
  }).isRequired,
47
+ controller: PropTypes.shape({
48
+ focus: PropTypes.bool.isRequired,
49
+ }).isRequired,
47
50
  on: PropTypes.shape({
48
51
  view: PropTypes.func,
49
52
  entering: PropTypes.func,
@@ -71,5 +74,8 @@ export const LightboxDefaultProps = {
71
74
  padding: "16px",
72
75
  spacing: "30%",
73
76
  },
77
+ controller: {
78
+ focus: true,
79
+ },
74
80
  on: {},
75
81
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "1.2.3",
4
- "description": "Modern lightbox component for React",
3
+ "version": "1.3.2",
4
+ "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -82,8 +82,8 @@
82
82
  "@types/jest": "^27.5.1",
83
83
  "@types/react": "^18.0.9",
84
84
  "@types/react-dom": "^18.0.5",
85
- "@typescript-eslint/eslint-plugin": "^5.26.0",
86
- "@typescript-eslint/parser": "^5.26.0",
85
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
86
+ "@typescript-eslint/parser": "^5.27.0",
87
87
  "autoprefixer": "^10.4.7",
88
88
  "eslint": "^8.16.0",
89
89
  "eslint-config-airbnb": "^19.0.4",
@@ -97,7 +97,7 @@
97
97
  "husky": "^8.0.1",
98
98
  "jest": "^28.1.0",
99
99
  "jest-environment-jsdom": "^28.1.0",
100
- "lint-staged": "^12.4.2",
100
+ "lint-staged": "^12.4.3",
101
101
  "npm-run-all": "^4.1.5",
102
102
  "postcss": "^8.4.14",
103
103
  "postcss-cli": "^9.1.0",