File tree Expand file tree Collapse file tree 5 files changed +52
-12
lines changed
Expand file tree Collapse file tree 5 files changed +52
-12
lines changed Original file line number Diff line number Diff line change 55 *
66 * Copyright Oxide Computer Company
77 */
8+ import { useState } from 'react'
89import tunnel from 'tunnel-rat'
910
1011import {
@@ -29,3 +30,28 @@ export function Pagination({ inline = false, ...props }: PaginationProps) {
2930}
3031
3132Pagination . Target = Tunnel . Out
33+
34+ type PageToken = string | undefined
35+
36+ export function usePagination ( ) {
37+ const [ prevPages , setPrevPages ] = useState < PageToken [ ] > ( [ ] )
38+ const [ currentPage , setCurrentPage ] = useState < PageToken > ( )
39+
40+ const goToPrevPage = ( ) => {
41+ const prevPage = prevPages . pop ( )
42+ setCurrentPage ( prevPage )
43+ setPrevPages ( prevPages )
44+ }
45+
46+ const goToNextPage = ( nextPageToken : string ) => {
47+ setPrevPages ( [ ...prevPages , currentPage ] )
48+ setCurrentPage ( nextPageToken )
49+ }
50+
51+ return {
52+ currentPage,
53+ goToNextPage,
54+ goToPrevPage,
55+ hasPrev : prevPages . length > 0 ,
56+ }
57+ }
Original file line number Diff line number Diff line change 88import { act , renderHook } from '@testing-library/react'
99import { describe , expect , it } from 'vitest'
1010
11- import { usePagination } from '../use-pagination '
11+ import { usePagination } from '../index.tsx '
1212
1313describe ( 'usePagination' , ( ) => {
1414 it ( 'starts with empty state' , ( ) => {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 66 * Copyright Oxide Computer Company
77 */
88import { useState } from 'react'
9+ import tunnel from 'tunnel-rat'
10+
11+ import {
12+ Pagination as UIPagination ,
13+ type PaginationProps as UIPaginationProps ,
14+ } from '@oxide/ui'
15+
16+ const Tunnel = tunnel ( 'pagination' )
17+
18+ interface PaginationProps extends UIPaginationProps {
19+ /** If true pagination will be rendered wherever `Pagination.Target` is included */
20+ inline ?: boolean
21+ }
22+ export function Pagination ( { inline = false , ...props } : PaginationProps ) {
23+ if ( inline ) return < UIPagination { ...props } />
24+
25+ return (
26+ < Tunnel . In >
27+ < UIPagination className = "gutter h-14 py-5" { ...props } />
28+ </ Tunnel . In >
29+ )
30+ }
31+
32+ Pagination . Target = Tunnel . Out
933
1034type PageToken = string | undefined
1135
Original file line number Diff line number Diff line change 1919 "@oxide/ui" : [" libs/ui/index.ts" ],
2020 "@oxide/util" : [" libs/util/index.ts" ],
2121 "@oxide/table" : [" libs/table/index.ts" ],
22- "@oxide/pagination" : [" libs/pagination/index.ts " ]
22+ "@oxide/pagination" : [" libs/pagination/index.tsx " ]
2323 },
2424 "resolveJsonModule" : true ,
2525 "rootDir" : " ." ,
You can’t perform that action at this time.
0 commit comments