MCPcopy
hub / github.com/OpenCut-app/OpenCut / Section

Function Section

apps/web/src/components/section.tsx:33–81  ·  view source on GitHub ↗
({
	children,
	collapsible = false,
	defaultOpen = true,
	sectionKey,
	className,
	showTopBorder = false,
	showBottomBorder = true,
}: SectionProps)

Source from the content-addressed store, hash-verified

31}
32
33export function Section({
34 children,
35 collapsible = false,
36 defaultOpen = true,
37 sectionKey,
38 className,
39 showTopBorder = false,
40 showBottomBorder = true,
41}: SectionProps) {
42 const cached = sectionKey ? sectionExpandedCache.get(sectionKey) : undefined;
43 const [isOpen, setIsOpen] = useState(cached ?? defaultOpen);
44
45 useEffect(() => {
46 if (!sectionKey) return;
47 if (
48 process.env.NODE_ENV !== "production" &&
49 mountedSectionKeys.has(sectionKey)
50 ) {
51 console.error(
52 `[Section] duplicate sectionKey mounted simultaneously: "${sectionKey}"`,
53 );
54 }
55 mountedSectionKeys.add(sectionKey);
56 return () => {
57 mountedSectionKeys.delete(sectionKey);
58 };
59 }, [sectionKey]);
60
61 const toggle = () => {
62 const next = !isOpen;
63 setIsOpen(next);
64 if (sectionKey) sectionExpandedCache.set(sectionKey, next);
65 };
66
67 return (
68 <SectionCtx.Provider value={{ isOpen, toggle, collapsible }}>
69 <div
70 className={cn(
71 "flex flex-col",
72 showTopBorder && "border-t first:border-t-0",
73 showBottomBorder && "border-b",
74 className,
75 )}
76 >
77 {children}
78 </div>
79 </SectionCtx.Provider>
80 );
81}
82
83interface SectionHeaderProps {
84 children?: React.ReactNode;

Callers

nothing calls this directly

Calls 4

cnFunction · 0.90
hasMethod · 0.80
addMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected