refactor(SW-194): use design system button
This commit is contained in:
@@ -6,23 +6,26 @@ import SectionContainer from "@/components/Section/Container"
|
|||||||
import SectionHeader from "@/components/Section/Header"
|
import SectionHeader from "@/components/Section/Header"
|
||||||
import Accordion from "@/components/TempDesignSystem/Accordion"
|
import Accordion from "@/components/TempDesignSystem/Accordion"
|
||||||
import AccordionItem from "@/components/TempDesignSystem/Accordion/AccordionItem"
|
import AccordionItem from "@/components/TempDesignSystem/Accordion/AccordionItem"
|
||||||
|
import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton"
|
||||||
import { ShowMoreButton } from "../../ContentType/HotelPage/ShowMoreButton"
|
|
||||||
|
|
||||||
import styles from "./accordion.module.css"
|
import styles from "./accordion.module.css"
|
||||||
|
|
||||||
import type { AccordionProps } from "@/types/components/blocks/Accordion"
|
import type { AccordionProps } from "@/types/components/blocks/Accordion"
|
||||||
|
|
||||||
export default function AccordionSection({ accordion, title }: AccordionProps) {
|
export default function AccordionSection({ accordion, title }: AccordionProps) {
|
||||||
const [allItemsVisible, setAllItemsVisible] = useState(false)
|
const initialPageSize = 5
|
||||||
function handleToggleShowMore() {
|
const [pageSize, setPageSize] = useState(initialPageSize)
|
||||||
setAllItemsVisible((previousState) => !previousState)
|
const showMoreVisible = accordion.length > initialPageSize
|
||||||
|
const showLessVisible = pageSize >= accordion.length
|
||||||
|
|
||||||
|
function handleShowMore() {
|
||||||
|
setPageSize(showLessVisible ? initialPageSize : accordion.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClassName(idx: number): string {
|
function getClassName(idx: number): string {
|
||||||
if (!allItemsVisible && idx > 4) {
|
if (showMoreVisible && idx > pageSize - 1) {
|
||||||
return styles.hiddenItem
|
return styles.hiddenItem
|
||||||
} else if (!allItemsVisible && idx == 4) {
|
} else if (showMoreVisible && idx == pageSize - 1) {
|
||||||
return styles.lastItem
|
return styles.lastItem
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
@@ -34,11 +37,12 @@ export default function AccordionSection({ accordion, title }: AccordionProps) {
|
|||||||
<Accordion theme={"light"} variant={"card"}>
|
<Accordion theme={"light"} variant={"card"}>
|
||||||
{accordion.map((acc, idx: number) => (
|
{accordion.map((acc, idx: number) => (
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
key={acc.question + idx}
|
key={`${acc.question}-${idx}`}
|
||||||
title={acc.question}
|
title={acc.question}
|
||||||
className={getClassName(idx)}
|
className={getClassName(idx)}
|
||||||
>
|
>
|
||||||
<JsonToHtml
|
<JsonToHtml
|
||||||
|
key={`${acc.question}-${idx}`}
|
||||||
embeds={acc.answer.embedded_itemsConnection.edges}
|
embeds={acc.answer.embedded_itemsConnection.edges}
|
||||||
nodes={acc.answer.json?.children[0].children}
|
nodes={acc.answer.json?.children[0].children}
|
||||||
/>
|
/>
|
||||||
@@ -46,12 +50,12 @@ export default function AccordionSection({ accordion, title }: AccordionProps) {
|
|||||||
))}
|
))}
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
{accordion.length > 5 ? (
|
{showMoreVisible ? (
|
||||||
<ShowMoreButton
|
<ShowMoreButton
|
||||||
|
loadMoreData={handleShowMore}
|
||||||
|
showLess={showLessVisible}
|
||||||
textShowMore="See all FAQ"
|
textShowMore="See all FAQ"
|
||||||
textShowLess="See less FAQ"
|
textShowLess="See less FAQ"
|
||||||
allItemsVisible={allItemsVisible}
|
|
||||||
handleToggleShowMore={handleToggleShowMore}
|
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</SectionContainer>
|
</SectionContainer>
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export default function ShowMoreButton({
|
|||||||
intent,
|
intent,
|
||||||
disabled,
|
disabled,
|
||||||
showLess,
|
showLess,
|
||||||
|
textShowMore = "Show less",
|
||||||
|
textShowLess = "Show more",
|
||||||
loadMoreData,
|
loadMoreData,
|
||||||
}: ShowMoreButtonProps) {
|
}: ShowMoreButtonProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
@@ -36,7 +38,7 @@ export default function ShowMoreButton({
|
|||||||
intent="text"
|
intent="text"
|
||||||
>
|
>
|
||||||
<ChevronDownIcon className={styles.icon} />
|
<ChevronDownIcon className={styles.icon} />
|
||||||
{intl.formatMessage({ id: showLess ? "Show less" : "Show more" })}
|
{intl.formatMessage({ id: showLess ? textShowLess : textShowMore })}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ export interface ShowMoreButtonProps
|
|||||||
VariantProps<typeof showMoreButtonVariants> {
|
VariantProps<typeof showMoreButtonVariants> {
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
showLess?: boolean
|
showLess?: boolean
|
||||||
|
textShowMore?: string
|
||||||
|
textShowLess?: string
|
||||||
loadMoreData: () => void
|
loadMoreData: () => void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Accordion } from "@/server/routers/contentstack/schemas/blocks/accordion"
|
import type { Accordion } from "@/server/routers/contentstack/schemas/blocks/accordion"
|
||||||
|
|
||||||
export type AccordionProps = {
|
export type AccordionProps = {
|
||||||
accordion: Accordion["accordion"]["faq"]
|
accordion: Accordion["accordion"]["faq"]
|
||||||
|
|||||||
Reference in New Issue
Block a user