Merged in feat/SW-2800-lightbox-history-state (pull request #2147)
feat(SW-2800): closing image gallery and lightbox on using browser navigation * feat(SW-2800): closing image gallery and lightbox on using browser navigation Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
93a155f1e4
commit
41e09f082a
@@ -37,10 +37,6 @@ export default function HotelReservationSidePeek() {
|
|||||||
room.roomTypes.some((type) => type.code === roomTypeCode)
|
room.roomTypes.some((type) => type.code === roomTypeCode)
|
||||||
)
|
)
|
||||||
|
|
||||||
function handleCloseClick() {
|
|
||||||
window.history.back()
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeSidePeek) {
|
if (activeSidePeek) {
|
||||||
window.history.pushState(null, "", window.location.href)
|
window.history.pushState(null, "", window.location.href)
|
||||||
@@ -71,7 +67,7 @@ export default function HotelReservationSidePeek() {
|
|||||||
hotel={{ ...hotelData.hotel, url: hotelData.url }}
|
hotel={{ ...hotelData.hotel, url: hotelData.url }}
|
||||||
restaurants={hotelData.restaurants}
|
restaurants={hotelData.restaurants}
|
||||||
activeSidePeek={activeSidePeek}
|
activeSidePeek={activeSidePeek}
|
||||||
close={handleCloseClick}
|
close={closeFn}
|
||||||
showCTA={showCTA}
|
showCTA={showCTA}
|
||||||
/>
|
/>
|
||||||
<AmenitiesSidePeek
|
<AmenitiesSidePeek
|
||||||
@@ -79,7 +75,7 @@ export default function HotelReservationSidePeek() {
|
|||||||
restaurants={hotelData.restaurants}
|
restaurants={hotelData.restaurants}
|
||||||
additionalHotelData={hotelData.additionalData}
|
additionalHotelData={hotelData.additionalData}
|
||||||
activeSidePeek={activeSidePeek}
|
activeSidePeek={activeSidePeek}
|
||||||
close={handleCloseClick}
|
close={closeFn}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -87,7 +83,7 @@ export default function HotelReservationSidePeek() {
|
|||||||
<RoomSidePeek
|
<RoomSidePeek
|
||||||
room={selectedRoom}
|
room={selectedRoom}
|
||||||
activeSidePeek={activeSidePeek}
|
activeSidePeek={activeSidePeek}
|
||||||
close={handleCloseClick}
|
close={closeFn}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function ImageGallery({
|
|||||||
hideLabel,
|
hideLabel,
|
||||||
}: ImageGalleryProps) {
|
}: ImageGalleryProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const [lightboxIsOpen, setLightboxIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
const [imageError, setImageError] = useState(false)
|
const [imageError, setImageError] = useState(false)
|
||||||
const imageProps = fill ? { fill, sizes } : { height, width: height * 1.5 }
|
const imageProps = fill ? { fill, sizes } : { height, width: height * 1.5 }
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ function ImageGallery({
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Button
|
<Button
|
||||||
className={styles.triggerArea}
|
className={styles.triggerArea}
|
||||||
onPress={() => setLightboxIsOpen(true)}
|
onPress={() => setIsOpen(true)}
|
||||||
aria-label={intl.formatMessage({
|
aria-label={intl.formatMessage({
|
||||||
defaultMessage: "Open image gallery",
|
defaultMessage: "Open image gallery",
|
||||||
})}
|
})}
|
||||||
@@ -61,8 +61,8 @@ function ImageGallery({
|
|||||||
<Lightbox
|
<Lightbox
|
||||||
images={images}
|
images={images}
|
||||||
dialogTitle={title}
|
dialogTitle={title}
|
||||||
isOpen={lightboxIsOpen}
|
isOpen={isOpen}
|
||||||
onClose={() => setLightboxIsOpen(false)}
|
onClose={() => setIsOpen(false)}
|
||||||
hideLabel={hideLabel}
|
hideLabel={hideLabel}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -53,6 +53,10 @@
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.galleryContainer {
|
||||||
|
align-content: start;
|
||||||
|
}
|
||||||
|
|
||||||
.closeButton {
|
.closeButton {
|
||||||
justify-self: start;
|
justify-self: start;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,20 @@ export default function Lightbox({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handlePopState() {
|
||||||
|
handleClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
window.history.pushState(null, "", window.location.href)
|
||||||
|
window.addEventListener("popstate", handlePopState)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("popstate", handlePopState)
|
||||||
|
}
|
||||||
|
/* eslint-disable-next-line react-hooks/exhaustive-deps */
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalOverlay
|
<ModalOverlay
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
@@ -79,7 +93,7 @@ export default function Lightbox({
|
|||||||
) : (
|
) : (
|
||||||
<Gallery
|
<Gallery
|
||||||
images={images}
|
images={images}
|
||||||
onClose={onClose}
|
onClose={handleClose}
|
||||||
onSelectImage={(image) => {
|
onSelectImage={(image) => {
|
||||||
setSelectedImageIndex(
|
setSelectedImageIndex(
|
||||||
images.findIndex((img) => img === image)
|
images.findIndex((img) => img === image)
|
||||||
|
|||||||
Reference in New Issue
Block a user