// Generated with util/create-component.js import React, { useEffect, useRef, useState } from "react"; import NsImage from "../shared/ns-image"; import StarRating from "../StarRating"; import Button from "../UI/Button"; import Heading from "../UI/Heading"; import { Caret } from "../UI/Icon"; import Text from "../UI/Text"; import { ProductReviewProps } from "./ProductReview.types"; const ProductReview: React.FC = (props) => { const { writerNm, goodsPt, regDt, content, imageUrls, isUseful = false, onClickUseful, } = props.data; const contentRef = useRef(null); const [_isUseful, setIsUseful] = useState(isUseful); const [hasOpenBtn, setHasOpenBtn] = useState(false); const [isOpened, setIsOpened] = useState(false); useEffect(() => { const contentDivScroll = (contentRef.current as HTMLDivElement) .scrollHeight; const contentTextScroll = (contentRef.current ?.childNodes[0] as HTMLParagraphElement).scrollHeight; if (contentTextScroll > contentDivScroll || imageUrls.length > 0) setHasOpenBtn(true); }, [contentRef.current]); return (
{ const target = e.target as HTMLElement; if ( target.nodeName === "BUTTON" || target.nodeName === "IMG" || target.tagName === "H3" ) return; setIsOpened(!isOpened); }} >
{writerNm}
{regDt && regDt.substring(0, 10).replace(/-/g, ".")}
{content}
{imageUrls.length > 0 && !isOpened && ( )}
{/* -7 photo */} {isOpened && imageUrls.length <= 7 && (
{imageUrls.map((image) => { return (
); })}
)} {/* +7 photo */} {isOpened && imageUrls.length > 7 && (
{imageUrls.map((image, i: number) => { return (
= 6 && "pc:hidden"}`} >
); })}
)}
{hasOpenBtn && (
리뷰 {isOpened ? "접기" : "펼치기"}
)}
); }; export default ProductReview; const ThumnailImage = (props: { imageUrl: string; imageCount: number; openedReivew?: boolean; }) => { const { imageUrl, imageCount, openedReivew = false } = props; return (
{imageCount > 1 && (
+{imageCount - 1}
)}
); };