"use client"; import { useLayoutEffect, useRef, useState, type ReactNode, type SVGAttributes } from "react"; import { Button } from "@lemonsqueezy/wedges"; export function PreviewCode({ children }: { children: ReactNode }) { const [isExpanded, setIsExpanded] = useState(false); const [shouldShow, setShouldShow] = useState(false); const elRef = useRef(null); useLayoutEffect(() => { // Get the height of the `code` element if (!elRef.current) { return; } const container = elRef.current; const codeEl = container.querySelector("code"); const codeHeight = codeEl?.clientHeight; // our container height is 302px, if the code element is taller than that, we should show the expand button if (codeHeight && codeHeight > 302) { setShouldShow(true); } }, []); return (
{children} {shouldShow ? (
); } function ExpandIcon(props: SVGAttributes) { const { className, ...otherProps } = props; return ( ); } function MinimizeIcon(props: SVGAttributes) { const { className, ...otherProps } = props; return ( ); }