(props: Props)
| 10 | |
| 11 | /** A list of files in a dropdown menu. This is more compact with many files. */ |
| 12 | export function FileDropdown(props: Props) { |
| 13 | const {filePairs, selectedIndex, fileChangeHandler} = props; |
| 14 | |
| 15 | const linkOrNone = (idx: number) => { |
| 16 | if (idx < 0 || idx >= filePairs.length) { |
| 17 | return <i>none</i>; |
| 18 | } else { |
| 19 | return ( |
| 20 | <a |
| 21 | href="#" |
| 22 | onClick={() => { |
| 23 | fileChangeHandler(idx); |
| 24 | }}> |
| 25 | {filePairDisplayName(filePairs[idx])} |
| 26 | </a> |
| 27 | ); |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | const prevLink = linkOrNone(props.selectedIndex - 1); |
| 32 | const nextLink = linkOrNone(props.selectedIndex + 1); |
| 33 | |
| 34 | const options = filePairs.map((filePair, idx) => ( |
| 35 | <option key={idx} value={idx}> |
| 36 | {filePairDisplayName(filePair)} ({filePair.type}) |
| 37 | </option> |
| 38 | )); |
| 39 | |
| 40 | return ( |
| 41 | <div className="file-dropdown"> |
| 42 | Prev (k): {prevLink} |
| 43 | <br /> |
| 44 | <select |
| 45 | value={selectedIndex} |
| 46 | onChange={e => { |
| 47 | fileChangeHandler(Number(e.target.value)); |
| 48 | }}> |
| 49 | {options} |
| 50 | </select> |
| 51 | <br /> |
| 52 | Next (j): {nextLink} |
| 53 | </div> |
| 54 | ); |
| 55 | } |
nothing calls this directly
no test coverage detected