{"version":3,"file":"BookReviewText-vFfkobWe.js","sources":["../../../app/javascript/components/shared/ExpandableElement.tsx","../../../app/javascript/components/BookReview/BookReviewText.tsx"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\nimport {\n ReactElement,\n useState,\n KeyboardEvent,\n useRef,\n useEffect,\n} from \"react\";\nimport { motion } from \"framer-motion\";\n\ninterface Props {\n children: ReactElement;\n expanded?: boolean;\n className?: string;\n expandClass?: string;\n allowCollapse?: boolean;\n}\n\nexport default function ExpandableElement({\n expanded: isExpanded = false,\n expandClass = \"\",\n className = \"\",\n allowCollapse = true,\n children,\n}: Props) {\n const [expanded, setExpanded] = useState(isExpanded);\n const contentRef = useRef(null);\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n useEffect(() => {\n if (contentRef.current) {\n setIsOverflowing(contentRef.current.scrollHeight > 88);\n }\n }, [children]);\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if ((allowCollapse && event.key === \"Enter\") || event.key === \" \") {\n setExpanded(!expanded);\n }\n };\n\n const dynamicProps = allowCollapse\n ? {\n onClick: () => (allowCollapse ? setExpanded(!expanded) : false),\n onKeyDown: handleKeyDown,\n role: \"button\",\n tabIndex: 0,\n \"aria-expanded\": expanded,\n }\n : {};\n\n return (\n
\n \n
{children}
\n {!expanded && isOverflowing && (\n
\n )}\n \n
\n );\n}\n","import { serialize } from \"components/editor/serializers\";\nimport { SlateDocument } from \"components/editor/types\";\nimport ExpandableElement from \"components/shared/ExpandableElement\";\nimport Text from \"hardcover-ui/components/Text\";\nimport { ReactElement } from \"react\";\n\nexport interface Props {\n reviewSlate: SlateDocument;\n expandClass?: string;\n expanded?: boolean;\n allowCollapse?: boolean;\n}\n\nexport default function BookReviewText({\n reviewSlate,\n expandClass = \"max-h-24\",\n expanded = true,\n allowCollapse = true,\n}: Props) {\n let ReviewElement: ReactElement;\n if (reviewSlate.document?.children?.length > 0) {\n try {\n ReviewElement = serialize(reviewSlate);\n } catch (e) {\n ReviewElement = (\n \n We ran into an error trying to show this review: {e.message}. Try\n editing to fix this error, or let us know at jules@hardcover.app with\n a link to this page.\n \n );\n }\n }\n\n if (ReviewElement) {\n return (\n \n {ReviewElement}\n \n );\n }\n\n return (\n \n No review written.\n \n );\n}\n"],"names":["ExpandableElement","isExpanded","expandClass","className","allowCollapse","children","expanded","setExpanded","useState","contentRef","useRef","isOverflowing","setIsOverflowing","useEffect","dynamicProps","event","jsx","jsxs","motion","_a","BookReviewText","reviewSlate","ReviewElement","_b","serialize","e","Text"],"mappings":"oLAkBA,SAAwBA,EAAkB,CACxC,SAAUC,EAAa,GACvB,YAAAC,EAAc,GACd,UAAAC,EAAY,GACZ,cAAAC,EAAgB,GAChB,SAAAC,CACF,EAAU,OACR,KAAM,CAACC,EAAUC,CAAW,EAAIC,WAASP,CAAU,EAC7CQ,EAAaC,SAAuB,IAAI,EACxC,CAACC,EAAeC,CAAgB,EAAIJ,WAAS,EAAK,EAExDK,EAAAA,UAAU,IAAM,CACVJ,EAAW,SACIG,EAAAH,EAAW,QAAQ,aAAe,EAAE,CACvD,EACC,CAACJ,CAAQ,CAAC,EAQb,MAAMS,EAAeV,EACjB,CACE,QAAS,IAAOA,EAAgBG,EAAY,CAACD,CAAQ,EAAI,GACzD,UATiBS,GAAyC,EACzDX,GAAiBW,EAAM,MAAQ,SAAYA,EAAM,MAAQ,MAC5DR,EAAY,CAACD,CAAQ,CACvB,EAOI,KAAM,SACN,SAAU,EACV,gBAAiBA,GAEnB,GAEJ,OACGU,EAAAA,IAAA,MAAA,CAAI,UAAU,iBAAkB,GAAGF,EAClC,SAAAG,EAAA,KAACC,EAAO,IAAP,CACC,UAAW,2CACT,CAACZ,GAAYK,EAAgB,GAAGT,CAAW,kBAAoB,EACjE,IAAIC,CAAS,GACb,QAAS,CACP,OAAQG,IACJa,EAAAV,EAAW,UAAX,YAAAU,EAAoB,eAAgB,OACpC,QACN,EACA,QAAS,GACT,WAAY,CACV,KAAM,SACN,UAAW,IACX,QAAS,GACT,K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