Created
December 25, 2020 18:43
-
-
Save DarkoTrpevski/4896ae27107b150a113aaaf23b5a626d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*Example | |
//Where ( listOfItems ) is an array of items | |
<List items={listOfItems} dir="vertical"> | |
{(listOfItem) => ( | |
<dl> | |
<dt>Name</dt> | |
<dd>{listOfItem.name}</dd> | |
<dt>Created</dt> | |
<dd>{listOfItem.since}</dd> | |
<dt>Author</dt> | |
<dd>{listOfItem.author}</dd> | |
</dl> | |
)} | |
</List> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
interface Props<T> { | |
children: (item: T) => React.ReactNode, | |
items: T[], | |
dir?: 'horizontal' | 'vertical', | |
dividers?: boolean, | |
windowing?: boolean | |
} | |
interface IdObj { | |
id: string | number | |
} | |
const List = <T extends IdObj>({ children, dir, dividers, items, windowing }: Props<T>) => { | |
return ( | |
<div> | |
{items.map((item, idx) => ( | |
<div key={idx} className="item"> | |
{children(item)} | |
</div> | |
))} | |
</div> | |
) | |
} | |
export default List; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment