Untitled
unknown
tsx
2 years ago
1.4 kB
3
Indexable
Never
import React from 'react'; function useClassNames(...names: Array<string | undefined>) { return names.filter(Boolean).join(' '); } interface IClassNameProps { className?: string; } interface ILinkProps extends IClassNameProps { href: string; } const Link: React.FC<ILinkProps> = props => { const className = useClassNames('Link', props.className); return <a href={props.href} className={className}>{props.children}</a>; }; interface ICardProps extends IClassNameProps { header: JSX.Element } const Card: React.FC<ICardProps> = props => { const className = useClassNames('Card', props.className); return ( <div className={className}> <Link href="#" className="Card-HeaderLink"> <h2>{props.header}</h2> </Link> {props.children} </div> ); }; interface ICardListProps extends IClassNameProps { items: Array<{ header: string, text: string }> } const CardList: React.FC<ICardListProps> = props => { const className = useClassNames('CardList', props.className); return ( <div className={className}> <Link href="#" className="CardList-HeaderLink"> <h1>Список карточек</h1> </Link> {props.items.map(item => ( <Card key={item.header} className="CardList-Item" header={item.header}>{item.text}</Card> ))} </div> ); };