| 24 | }; |
| 25 | |
| 26 | export const Table: StatelessComponent<TableProps> = (props: StatelessProps<TableProps>) => { |
| 27 | return ( |
| 28 | <table className={props.className}> |
| 29 | {props.children} |
| 30 | {props.rows.map((row, i) => ( |
| 31 | <tr |
| 32 | className={props.rowClassName || ''} |
| 33 | onClick={e => props.onRowClick && props.onRowClick(e as any as MouseEvent, i)} |
| 34 | tabIndex={props.onRowClick ? 0 : -1} |
| 35 | onKeyUp={e => { |
| 36 | if (e.key === KeyCodes.ENTER && props.onRowClick) { |
| 37 | props.onRowClick(e as any as KeyboardEvent, i); |
| 38 | } |
| 39 | }} |
| 40 | > |
| 41 | {row.cells.map((cell, i) => ( |
| 42 | <td |
| 43 | className={cell.className || ''} |
| 44 | title={cell.title || ''} |
| 45 | >{cell.content}</td> |
| 46 | ))} |
| 47 | </tr> |
| 48 | ))} |
| 49 | </table> |
| 50 | ); |
| 51 | }; |