diff --git a/src/app/home/DanakSuggestedService.tsx b/src/app/home/DanakSuggestedService.tsx index 5e367cf..b6cab77 100644 --- a/src/app/home/DanakSuggestedService.tsx +++ b/src/app/home/DanakSuggestedService.tsx @@ -17,7 +17,7 @@ const DanakSuggestedService: FC = () => { { data?.data?.danakSuggestServices?.map((item) => { return ( - + ) }) } diff --git a/src/app/products/DetailService.tsx b/src/app/products/DetailService.tsx index 5b1882d..5755b71 100644 --- a/src/app/products/DetailService.tsx +++ b/src/app/products/DetailService.tsx @@ -1,5 +1,6 @@ 'use client' import { FC, Fragment } from 'react' +import ExpandableContent from '@/components/ExpandableContent' import { useGetProductBySlug } from './hooks/useProductData' import ServiceHeader from './components/ServiceHeader' import moment from 'moment-jalaali' @@ -94,8 +95,7 @@ const DetailService: FC<{ id: string }> = ({ id }) => { توضیحات کامل {getDetailService.data?.data?.danakService?.metaDescription && ( -

-

+ )} diff --git a/src/app/products/components/ServiceHeader.tsx b/src/app/products/components/ServiceHeader.tsx index 5e6de49..dee3584 100644 --- a/src/app/products/components/ServiceHeader.tsx +++ b/src/app/products/components/ServiceHeader.tsx @@ -40,9 +40,9 @@ const ServiceHeader: FC = (props: Props) => { icon
-
+

{data?.name} -

+

{data?.description} diff --git a/src/components/ExpandableContent.tsx b/src/components/ExpandableContent.tsx new file mode 100644 index 0000000..0ef28e9 --- /dev/null +++ b/src/components/ExpandableContent.tsx @@ -0,0 +1,60 @@ +'use client' +import { FC, memo, useEffect, useRef, useState } from 'react' +import Button from '@/components/Button' +import { clx } from '@/helpers/utils' + +type Props = { + html: string; + collapsedHeightClass?: string; // e.g. 'max-h-36' for ~6 lines with leading-6 + className?: string; +} + +const ExpandableContent: FC = memo(({ html, collapsedHeightClass = 'max-h-36', className }) => { + const [expanded, setExpanded] = useState(false) + const [isOverflowing, setIsOverflowing] = useState(false) + const containerRef = useRef(null) + + useEffect(() => { + const el = containerRef.current + if (!el) return + if (expanded) { + setIsOverflowing(false) + return + } + setIsOverflowing(el.scrollHeight > el.clientHeight + 1) + }, [html, expanded]) + + return ( +

+
+
+ {!expanded && isOverflowing && ( +
+ )} +
+ {isOverflowing || expanded ? ( +
+
+ ) : null} +
+ ) +}) + +ExpandableContent.displayName = 'ExpandableContent' + +export default ExpandableContent + +