MCPcopy Create free account
hub / github.com/PageAI-Pro/page-ui / StepCode

Function StepCode

components/blog/StepCode.tsx:37–101  ·  view source on GitHub ↗
({
  children,
  className,
}: {
  children: React.ReactNode;
  className?: string;
})

Source from the content-addressed store, hash-verified

35};
36
37export const StepCode = ({
38 children,
39 className,
40}: {
41 children: React.ReactNode;
42 className?: string;
43}) => {
44 const ref = useRef<HTMLDivElement>(null);
45 const isOverflow = useIsOverflowing({ ref });
46
47 const [showOverflow, setShowOverflow] = useState(false);
48
49 useEffect(() => {
50 const { current } = ref;
51 if (!current) return;
52 const currentPre = current.querySelector('pre');
53 if (!currentPre) return;
54
55 if (showOverflow) {
56 currentPre.style.maxHeight = 'none';
57 } else {
58 currentPre.style.maxHeight = '350px';
59 }
60 }, [showOverflow]);
61
62 return (
63 <>
64 <style>
65 {`
66 .content pre {
67 margin: 1rem 0 0 0;
68 max-height: 350px;
69 }
70 `}
71 </style>
72 <div
73 ref={ref}
74 className={cn(
75 'content group flex flex-col relative no-underline',
76 className,
77 )}
78 >
79 {children}
80
81 {isOverflow && !showOverflow ? (
82 <Button
83 onClick={() => setShowOverflow(true)}
84 size="sm"
85 className="mt-2"
86 >
87 Expand
88 </Button>
89 ) : (
90 <Button
91 onClick={() => setShowOverflow(false)}
92 size="sm"
93 className="mt-2"
94 >

Callers

nothing calls this directly

Calls 2

cnFunction · 0.90
useIsOverflowingFunction · 0.85

Tested by

no test coverage detected