File tree Expand file tree Collapse file tree 5 files changed +12
-52
lines changed
Expand file tree Collapse file tree 5 files changed +12
-52
lines changed Original file line number Diff line number Diff line change 55 *
66 * Copyright Oxide Computer Company
77 */
8- import { useState } from 'react'
98import tunnel from 'tunnel-rat'
109
1110import {
@@ -30,28 +29,3 @@ export function Pagination({ inline = false, ...props }: PaginationProps) {
3029}
3130
3231Pagination . 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 '../index.tsx '
11+ import { usePagination } from '../use-pagination '
1212
1313describe ( 'usePagination' , ( ) => {
1414 it ( 'starts with empty state' , ( ) => {
Original file line number Diff line number Diff line change 1+ /*
2+ * This Source Code Form is subject to the terms of the Mozilla Public
3+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+ *
6+ * Copyright Oxide Computer Company
7+ */
8+
9+ export * from './Pagination'
10+ export * from './use-pagination'
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
339
3410type PageToken = string | undefined
3511
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.tsx " ]
22+ "@oxide/pagination" : [" libs/pagination/index.ts " ]
2323 },
2424 "resolveJsonModule" : true ,
2525 "rootDir" : " ." ,
You can’t perform that action at this time.
0 commit comments