refactor(SW-194): use design system button on Rooms
This commit is contained in:
@@ -6,8 +6,8 @@ import { useIntl } from "react-intl"
|
|||||||
import SectionContainer from "@/components/Section/Container"
|
import SectionContainer from "@/components/Section/Container"
|
||||||
import SectionHeader from "@/components/Section/Header"
|
import SectionHeader from "@/components/Section/Header"
|
||||||
import Grids from "@/components/TempDesignSystem/Grids"
|
import Grids from "@/components/TempDesignSystem/Grids"
|
||||||
|
import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton"
|
||||||
|
|
||||||
import { ShowMoreButton } from "../ShowMoreButton"
|
|
||||||
import { RoomCard } from "./RoomCard"
|
import { RoomCard } from "./RoomCard"
|
||||||
|
|
||||||
import styles from "./rooms.module.css"
|
import styles from "./rooms.module.css"
|
||||||
@@ -17,7 +17,10 @@ import type { RoomsProps } from "@/types/components/hotelPage/room"
|
|||||||
|
|
||||||
export function Rooms({ rooms }: RoomsProps) {
|
export function Rooms({ rooms }: RoomsProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const [allRoomsVisible, setAllRoomsVisible] = useState(false)
|
const initialPageSize = 5
|
||||||
|
const [pageSize, setPageSize] = useState(initialPageSize)
|
||||||
|
const showMoreVisible = rooms.length > initialPageSize
|
||||||
|
const showLessVisible = pageSize >= rooms.length
|
||||||
const scrollRef = useRef<HTMLDivElement>(null)
|
const scrollRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const mappedRooms = rooms
|
const mappedRooms = rooms
|
||||||
@@ -41,12 +44,11 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
})
|
})
|
||||||
.sort((a, b) => a.sortOrder - b.sortOrder)
|
.sort((a, b) => a.sortOrder - b.sortOrder)
|
||||||
|
|
||||||
function handleToggleShowMore() {
|
function handleShowMore() {
|
||||||
if (scrollRef.current && allRoomsVisible) {
|
if (scrollRef.current && showMoreVisible) {
|
||||||
scrollRef.current.scrollIntoView({ behavior: "smooth" })
|
scrollRef.current.scrollIntoView({ behavior: "smooth" })
|
||||||
}
|
}
|
||||||
|
setPageSize(showLessVisible ? initialPageSize : rooms.length)
|
||||||
setAllRoomsVisible((previousState) => !previousState)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -66,7 +68,7 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
<div
|
<div
|
||||||
key={id}
|
key={id}
|
||||||
className={
|
className={
|
||||||
!allRoomsVisible && index > 2 ? styles.hiddenRoomCard : ""
|
!showLessVisible && index > 2 ? styles.hiddenRoomCard : ""
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<RoomCard
|
<RoomCard
|
||||||
@@ -81,12 +83,12 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
)}
|
)}
|
||||||
</Grids.Stackable>
|
</Grids.Stackable>
|
||||||
|
|
||||||
{mappedRooms.length > 5 ? (
|
{showMoreVisible ? (
|
||||||
<ShowMoreButton
|
<ShowMoreButton
|
||||||
|
loadMoreData={handleShowMore}
|
||||||
|
showLess={showLessVisible}
|
||||||
textShowMore="Show more rooms"
|
textShowMore="Show more rooms"
|
||||||
textShowLess="Show less rooms"
|
textShowLess="Show less rooms"
|
||||||
allItemsVisible={allRoomsVisible}
|
|
||||||
handleToggleShowMore={handleToggleShowMore}
|
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</SectionContainer>
|
</SectionContainer>
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
.ctaContainer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
.showMoreButton {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
.showMoreButton.showLess .chevron {
|
|
||||||
transform: rotate(180deg);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user