import React from 'react'; type SlotProps = { children?: React.ReactNode }; function Header({ children }: SlotProps) { return <div data-testid="header">{children}</div>; } function Body({ children }: SlotProps) { return <div data-testid="body">{children}</div>; } function Footer({ children }: SlotProps) { return <div data-testid="footer">{children}</div>; } export function Card({ children }: { children?: React.ReactNode }) { // TODO: React.Children.toArray로 children을 배열로 만들고, // 각 element의 type을 Card.Header / Card.Body / Card.Footer와 비교하여 // header, body, footer 변수에 슬롯을 담으세요. // TODO: 항상 Header -> Body -> Footer 순서로 렌더하고 // 누락된 슬롯은 렌더하지 않습니다. return ( <section data-testid="card"> {/* TODO: header / body / footer 슬롯을 순서대로 렌더 */} </section> ); } Card.Header = Header; Card.Body = Body; Card.Footer = Footer;
Tests