({
onChange,
total,
offset = 0,
limit = total,
singular = 'row',
plural = singular + 's',
}: SortedTablePaginatorProps)
| 80 | }; |
| 81 | |
| 82 | export const SortedTablePaginator: typeof SortedTablePaginatorDecl = ({ |
| 83 | onChange, |
| 84 | total, |
| 85 | offset = 0, |
| 86 | limit = total, |
| 87 | singular = 'row', |
| 88 | plural = singular + 's', |
| 89 | }: SortedTablePaginatorProps) => { |
| 90 | if (offset > total || offset < 0) { |
| 91 | offset = 0; |
| 92 | onChange(0); |
| 93 | } |
| 94 | const handlePrevClick = useCallbackOrUndefined( |
| 95 | () => onChange(offset - limit), |
| 96 | [onChange, offset, limit], |
| 97 | offset > 0, |
| 98 | ); |
| 99 | const handleNextClick = useCallbackOrUndefined( |
| 100 | () => onChange(offset + limit), |
| 101 | [onChange, offset, limit], |
| 102 | offset + limit < total, |
| 103 | ); |
| 104 | return ( |
| 105 | <> |
| 106 | {total > limit && ( |
| 107 | <> |
| 108 | <button |
| 109 | className="previous" |
| 110 | disabled={offset == 0} |
| 111 | onClick={handlePrevClick} |
| 112 | > |
| 113 | {LEFT_ARROW} |
| 114 | </button> |
| 115 | <button |
| 116 | className="next" |
| 117 | disabled={offset + limit >= total} |
| 118 | onClick={handleNextClick} |
| 119 | > |
| 120 | {RIGHT_ARROW} |
| 121 | </button> |
| 122 | {offset + 1} to {mathMin(total, offset + limit)} |
| 123 | {' of '} |
| 124 | </> |
| 125 | )} |
| 126 | {total} {total != 1 ? plural : singular} |
| 127 | </> |
| 128 | ); |
| 129 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…