Implemented data parameters

This commit is contained in:
datalore 2023-11-02 23:38:12 +01:00
parent 3cb85e6273
commit ae80324a46
4 changed files with 26 additions and 15 deletions

View File

@ -1,15 +1,21 @@
import styles from './bingo.module.css' import styles from './bingo.module.css'
import BingoRow from './bingorow.tsx' import BingoRow from './bingorow.tsx'
export default function Bingo(){ interface Props{
size: number;
items: string[];
}
export default function Bingo({size, items}: Props){
let rows: string[][] = [];
for(let i = 0; i < items.length; i++)
{
rows[i] = items.slice(i * size, (i + 1) * size);
}
return( return(
<table className={styles.table}> <table className={styles.table}>
<tbody> <tbody>
<BingoRow/> {rows.map((item, index) => <BingoRow key={index} items={item}/>)}
<BingoRow/>
<BingoRow/>
<BingoRow/>
<BingoRow/>
</tbody> </tbody>
</table> </table>
); );

View File

@ -1,7 +1,11 @@
import styles from './bingo.module.css' import styles from './bingo.module.css'
export default function BingoItem(){ interface Props{
text: string;
}
export default function BingoItem({text}: Props){
return( return(
<td className={styles.td}>Item</td> <td className={styles.td}>{text}</td>
); );
} }

View File

@ -1,13 +1,13 @@
import BingoItem from './bingoitem.tsx' import BingoItem from './bingoitem.tsx'
export default function BingoRow(){ interface Props{
items: string[];
}
export default function BingoRow({items}: Props){
return( return(
<tr> <tr>
<BingoItem/> {items.map((item, index) => <BingoItem key={index} text={item}/>)}
<BingoItem/>
<BingoItem/>
<BingoItem/>
<BingoItem/>
</tr> </tr>
); );
} }

View File

@ -2,10 +2,11 @@ import styles from './page.module.css'
import Bingo from './components/bingo.tsx' import Bingo from './components/bingo.tsx'
export default function Home(){ export default function Home(){
const items=["test1", "test2", "test3", "test4", "test5"];
return( return(
<main className={styles.main}> <main className={styles.main}>
<h1 align="center">Buzzword Bingo</h1> <h1 align="center">Buzzword Bingo</h1>
<Bingo/> <Bingo size={2} items={items}/>
</main> </main>
); );
} }