diff --git a/example/src/components/Carousel1.js b/example/src/components/Carousel1.js index c709141..16c6cf4 100644 --- a/example/src/components/Carousel1.js +++ b/example/src/components/Carousel1.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import TwoWayMap from '../utils/TwoWayMap'; import Carousel from 'react-gallery-carousel'; import 'react-gallery-carousel/dist/index.css'; @@ -9,7 +9,7 @@ const Carousel1 = () => { 1: 'Get%20Started', 2: 'Usage' }); - + const [isMaximized, setIsMaximized] = useState(false) return (
@@ -17,6 +17,7 @@ const Carousel1 = () => { Example 1: Customized carousel with user-managed slides{' '} code +

isMaximized: {`${isMaximized}`}

This example has custom elements in slides (user-managed slides) using the children prop; and custom widget positions. @@ -36,6 +37,7 @@ const Carousel1 = () => { index={Number( indexToTitle.getReversed(window.location.hash.replace('#', '')) )} + onMaximizedStatusChange={(status) => setIsMaximized(status)} // onIndexChange={({ curIndex }) => { // const title = indexToTitle.get(curIndex); // window.history.replaceState( @@ -49,6 +51,7 @@ const Carousel1 = () => { >

Introduction

+

isMaximized: {`${isMaximized}`}

react-gallery-carousel is a mobile-friendly dependency-free React carousel component with support for touch, @@ -71,6 +74,7 @@ const Carousel1 = () => {

Get Started

+

isMaximized: {`${isMaximized}`}

npm install react-gallery-carousel --save
or @@ -78,6 +82,7 @@ const Carousel1 = () => { yarn add react-gallery-carousel
+

isMaximized: {`${isMaximized}`}

Usage

The default carousel shown below as example 2 is created by:

{''} diff --git a/src/components/Carousel/Carousel.js b/src/components/Carousel/Carousel.js index da42737..9d9fad4 100644 --- a/src/components/Carousel/Carousel.js +++ b/src/components/Carousel/Carousel.js @@ -120,6 +120,7 @@ const GalleryCarousel = (props, ref) => { const handleSizeButtonClick = () => { setIsMaximized((isMaximized) => !isMaximized); + props.onMaximizedStatusChange(!isMaximized) }; /* handle UI updates */ @@ -301,7 +302,12 @@ const GalleryCarousel = (props, ref) => { ); /* handle keyboard events */ - useKeys(documentRef, { Escape: () => setIsMaximized(() => false) }); + useKeys(documentRef, { + Escape: () => { + props.onMaximizedStatusChange(false) + setIsMaximized(() => false) + } + }); useKeyboard(carouselRef); @@ -505,7 +511,7 @@ const GalleryCarousel = (props, ref) => { { widgetsObj[ - positionsToWidgets.get(position).replace(/AtMax$/, '') + positionsToWidgets.get(position).replace(/AtMax$/, '') ] } diff --git a/src/components/Carousel/props.js b/src/components/Carousel/props.js index 78c38a8..e0c3d04 100644 --- a/src/components/Carousel/props.js +++ b/src/components/Carousel/props.js @@ -62,6 +62,7 @@ export const propTypes = { shouldMinimizeOnClick: PropTypes.bool.isRequired, shouldMinimizeOnSwipeDown: PropTypes.bool.isRequired, onIndexChange: PropTypes.func.isRequired, + onMaximizedChange: PropTypes.func.isRequired, className: PropTypes.string, style: PropTypes.object, objectFit: objectFitStyles.isRequired, @@ -99,11 +100,12 @@ export const defaultProps = { shouldMaximizeOnClick: false, shouldMinimizeOnClick: false, shouldMinimizeOnSwipeDown: true, - onIndexChange: () => {}, - onSwipeMoveX: () => {}, - onSwipeMoveY: () => {}, - onSwipeEndDown: () => {}, - onTap: () => {}, + onIndexChange: () => { }, + onSwipeMoveX: () => { }, + onSwipeMoveY: () => { }, + onSwipeEndDown: () => { }, + onTap: () => { }, + onMaximizedStatusChange: () => { }, objectFit: 'cover', objectFitAtMax: 'contain' };