From 92bbfcf5330753fb70b3beca79604a3f1915edab Mon Sep 17 00:00:00 2001 From: Bianca Widstam Date: Tue, 17 Dec 2024 12:35:10 +0000 Subject: [PATCH] Merged in fix/SW-1122-breakfast-text-equal-height (pull request #1098) fix(SW-1122): fix equal breakfast text height for non availability cards * fix(SW-1122): fix equal breakfast text height for non availability cards Approved-by: Pontus Dreij Approved-by: Niclas Edenvin --- .../RoomSelection/FlexibilityOption/index.tsx | 6 +- .../RoomSelection/RoomCard/index.tsx | 8 ++- .../RoomCard/roomCard.module.css | 1 - .../SelectRate/RoomSelection/index.tsx | 59 ++++++++++--------- .../SelectRate/RoomSelection/utils.ts | 6 +- 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx index 5e13bd1e9..32e1b3d7f 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx @@ -7,7 +7,7 @@ import Label from "@/components/TempDesignSystem/Form/Label" import Popover from "@/components/TempDesignSystem/Popover" import Caption from "@/components/TempDesignSystem/Text/Caption" -import { rateCardEqualHeightSelector } from "../utils" +import { RATE_CARD_EQUAL_HEIGHT_CLASS } from "../utils" import PriceTable from "./PriceList" import styles from "./flexibilityOption.module.css" @@ -27,7 +27,7 @@ export default function FlexibilityOption({ if (!product) { return ( -
+
@@ -73,7 +73,7 @@ export default function FlexibilityOption({ value={publicPrice?.rateCode} onClick={onClick} /> -
+
-
+
{getBreakfastMessage(rates.flexRate)} diff --git a/components/HotelReservation/SelectRate/RoomSelection/RoomCard/roomCard.module.css b/components/HotelReservation/SelectRate/RoomSelection/RoomCard/roomCard.module.css index 9847ba98b..1a2bfd83d 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/RoomCard/roomCard.module.css +++ b/components/HotelReservation/SelectRate/RoomSelection/RoomCard/roomCard.module.css @@ -12,7 +12,6 @@ } .card.noAvailability { - justify-content: flex-start; opacity: 0.6; } diff --git a/components/HotelReservation/SelectRate/RoomSelection/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/index.tsx index 3c6b75707..0e71c5fde 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/index.tsx @@ -8,7 +8,9 @@ import RateSummary from "./RateSummary" import RoomCard from "./RoomCard" import { getHotelReservationQueryParams, - rateCardEqualHeightSelector, + RATE_CARD_EQUAL_HEIGHT_CLASS, + RATE_CARDS_AVAILABLE_HEIGHT_CLASS, + RATE_CARDS_NOT_AVAILABLE_HEIGHT_CLASS, } from "./utils" import styles from "./roomSelection.module.css" @@ -34,41 +36,44 @@ export default function RoomSelection({ const equalizePriceOptionHeights = useCallback(() => { if (!roomRefs.current.length) return + const optionsSelector = `.${RATE_CARD_EQUAL_HEIGHT_CLASS}` + const availableSelector = `.${RATE_CARDS_AVAILABLE_HEIGHT_CLASS}` + const notAvailableSelector = `.${RATE_CARDS_NOT_AVAILABLE_HEIGHT_CLASS}` + const DEFAULT_RATE_CARD_HEIGHT = 420 + + const maxOptionHeights: number[] = [] + let maxPriceCardHeight = DEFAULT_RATE_CARD_HEIGHT + roomRefs.current.forEach((room) => { - const options = room.querySelectorAll( - `.${rateCardEqualHeightSelector}` - ) - options.forEach((option) => { + const options = room.querySelectorAll(optionsSelector) + options.forEach((option, i) => { option.style.height = "auto" + const optionHeight = option.getBoundingClientRect().height + maxOptionHeights[i] = Math.max(maxOptionHeights[i] || 0, optionHeight) }) + + const priceCard = room.querySelector(availableSelector) as HTMLElement + if (priceCard) { + const priceCardHeight = priceCard.getBoundingClientRect().height + maxPriceCardHeight = Math.max(maxPriceCardHeight, priceCardHeight) + } }) - const numOptions = - roomRefs.current[0]?.querySelectorAll( - `.${rateCardEqualHeightSelector}` - ).length || 0 - - for (let i = 0; i < numOptions; i++) { - let maxHeight = 0 - - roomRefs.current.forEach((room) => { - const option = room.querySelectorAll( - `.${rateCardEqualHeightSelector}` - )[i] + roomRefs.current.forEach((room) => { + const options = room.querySelectorAll(optionsSelector) + options.forEach((option, i) => { if (option) { - maxHeight = Math.max(maxHeight, option.offsetHeight) + option.style.height = `${maxOptionHeights[i]}px` } }) - roomRefs.current.forEach((room) => { - const option = room.querySelectorAll( - `.${rateCardEqualHeightSelector}` - )[i] - if (option) { - option.style.height = `${maxHeight}px` - } - }) - } + const noPriceCard = room.querySelector( + notAvailableSelector + ) as HTMLElement + if (noPriceCard) { + noPriceCard.style.height = `${maxPriceCardHeight}px` + } + }) }, []) useEffect(() => { diff --git a/components/HotelReservation/SelectRate/RoomSelection/utils.ts b/components/HotelReservation/SelectRate/RoomSelection/utils.ts index 92ef0be01..d66fe9b9b 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/utils.ts +++ b/components/HotelReservation/SelectRate/RoomSelection/utils.ts @@ -102,4 +102,8 @@ export function createQueryParamsForEnterDetails( return searchParams } -export const rateCardEqualHeightSelector = "rateCardEqualHeight" +export const RATE_CARD_EQUAL_HEIGHT_CLASS = "rateCardEqualHeightSelector" +export const RATE_CARDS_AVAILABLE_HEIGHT_CLASS = + "rateCardAvailableEqualHeightSelector" +export const RATE_CARDS_NOT_AVAILABLE_HEIGHT_CLASS = + "rateCardNotAvailableEqualHeightSelector"