| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import * as React from 'react'; |
| 11 | import {Fragment} from 'react'; |
| 12 | |
| 13 | // A large tree of similarly-named components (Table, TableRow, TableCell, ...). |
| 14 | // This mirrors a real virtualized table and is meant for exercising the |
| 15 | // component-tree search box in DevTools: |
| 16 | // 1. Open DevTools and search "Table" — there are 100+ matches. |
| 17 | // 2. Type a number into the result-index field (left of "| N") to jump |
| 18 | // directly to a specific match instead of scrolling/pressing Enter. |
| 19 | // 3. Select a match, clear the search, then retype the same text — the |
| 20 | // search advances to the *next* match instead of snapping back. |
| 21 | |
| 22 | const ROWS = 25; |
| 23 | const COLS = 4; |
| 24 | |
| 25 | function TableCell({row, col}: {row: number, col: number}): React.Node { |
| 26 | return <td>{`r${row}c${col}`}</td>; |
| 27 | } |
| 28 | |
| 29 | function TableColumnHeader({col}: {col: number}): React.Node { |
| 30 | return <th>{`Column ${col}`}</th>; |
| 31 | } |
| 32 | |
| 33 | function TableRow({row}: {row: number}): React.Node { |
| 34 | return ( |
| 35 | <tr> |
| 36 | {Array.from({length: COLS}, (_, col) => ( |
| 37 | <TableCell key={col} row={row} col={col} /> |
| 38 | ))} |
| 39 | </tr> |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | function TableHeaderRow(): React.Node { |
| 44 | return ( |
| 45 | <tr> |
| 46 | {Array.from({length: COLS}, (_, col) => ( |
| 47 | <TableColumnHeader key={col} col={col} /> |
| 48 | ))} |
| 49 | </tr> |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | function TableBody(): React.Node { |
| 54 | return ( |
| 55 | <tbody> |
| 56 | {Array.from({length: ROWS}, (_, row) => ( |
| 57 | <TableRow key={row} row={row} /> |
| 58 | ))} |
| 59 | </tbody> |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | function Table(): React.Node { |
| 64 | return ( |
| 65 | <table> |
| 66 | <thead> |
| 67 | <TableHeaderRow /> |
| 68 | </thead> |
| 69 | <TableBody /> |
| 70 | </table> |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | export default function SearchableTable(): React.Node { |
| 75 | return ( |
| 76 | <Fragment> |
| 77 | <h1>Searchable Table</h1> |
| 78 | <Table /> |
| 79 | </Fragment> |
| 80 | ); |
| 81 | } |