refactor(SW-194): break out button to separate component

This commit is contained in:
Matilda Landström
2024-10-01 17:19:02 +02:00
parent b0d5415d03
commit 7ba7896bbe
4 changed files with 60 additions and 17 deletions

View File

@@ -3,18 +3,17 @@
import { useRef, useState } from "react"
import { useIntl } from "react-intl"
import { ChevronDownIcon } from "@/components/Icons"
import SectionContainer from "@/components/Section/Container"
import SectionHeader from "@/components/Section/Header"
import Button from "@/components/TempDesignSystem/Button"
import Grids from "@/components/TempDesignSystem/Grids"
import { ShowMoreButton } from "../ShowMoreButton"
import { RoomCard } from "./RoomCard"
import styles from "./rooms.module.css"
import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation"
import { RoomsProps } from "@/types/components/hotelPage/room"
import type { RoomsProps } from "@/types/components/hotelPage/room"
export function Rooms({ rooms }: RoomsProps) {
const intl = useIntl()
@@ -82,20 +81,14 @@ export function Rooms({ rooms }: RoomsProps) {
)}
</Grids.Stackable>
<div className={styles.ctaContainer}>
<Button
onClick={handleToggleShowMore}
theme="base"
intent="text"
variant="icon"
className={`${styles.showMoreButton} ${allRoomsVisible ? styles.showLess : ""}`}
>
<ChevronDownIcon className={styles.chevron} />
{intl.formatMessage({
id: allRoomsVisible ? "Show less" : "Show more",
})}
</Button>
</div>
{mappedRooms.length > 5 ? (
<ShowMoreButton
textShowMore="Show more rooms"
textShowLess="Show less rooms"
allItemsVisible={allRoomsVisible}
handleToggleShowMore={handleToggleShowMore}
/>
) : null}
</SectionContainer>
)
}

View File

@@ -0,0 +1,10 @@
.ctaContainer {
display: flex;
justify-content: center;
}
.showMoreButton {
border: none;
}
.showMoreButton.showLess .chevron {
transform: rotate(180deg);
}

View File

@@ -0,0 +1,34 @@
import { useIntl } from "react-intl"
import { ChevronDownIcon } from "@/components/Icons"
import Button from "@/components/TempDesignSystem/Button"
import styles from "./button.module.css"
import type { ShowMoreButtonProps } from "@/types/components/hotelPage/button"
export function ShowMoreButton({
textShowMore,
textShowLess,
allItemsVisible,
handleToggleShowMore,
}: ShowMoreButtonProps) {
const intl = useIntl()
return (
<div className={styles.ctaContainer}>
<Button
onClick={handleToggleShowMore}
intent="text"
variant="icon"
className={`${styles.showMoreButton} ${allItemsVisible ? styles.showLess : ""}`}
type="button"
theme="base"
>
<ChevronDownIcon className={styles.chevron} />
{intl.formatMessage({
id: allItemsVisible ? textShowLess : textShowMore,
})}
</Button>
</div>
)
}

View File

@@ -0,0 +1,6 @@
export type ShowMoreButtonProps = {
textShowMore: string
textShowLess: string
allItemsVisible: boolean
handleToggleShowMore: () => void
}