Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
6471f316
Commit
6471f316
authored
Nov 08, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Nov 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert PaginationNavigation to TS
parent
55e561f4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
33 deletions
+24
-33
PaginationNavigation.tsx
src/sidebar/components/PaginationNavigation.tsx
+24
-33
No files found.
src/sidebar/components/PaginationNavigation.
js
→
src/sidebar/components/PaginationNavigation.
tsx
View file @
6471f316
...
...
@@ -3,50 +3,49 @@ import {
ArrowLeftIcon
,
ArrowRightIcon
,
}
from
'@hypothesis/frontend-shared/lib/next'
;
import
type
{
PresentationalProps
}
from
'@hypothesis/frontend-shared/lib/types'
;
import
type
{
ButtonCommonProps
}
from
'@hypothesis/frontend-shared/lib/components/input/ButtonBase'
;
import
classnames
from
'classnames'
;
import
type
{
JSX
}
from
'preact'
;
import
{
pageNumberOptions
}
from
'../util/pagination'
;
/**
* @typedef {import('@hypothesis/frontend-shared/lib/types').PresentationalProps} PresentationalProps
* @typedef {import('@hypothesis/frontend-shared/lib/components/input/ButtonBase').ButtonCommonProps} ButtonCommonProps
* @typedef {Omit<import('preact').JSX.HTMLAttributes<HTMLButtonElement>, 'icon'|'size'>} HTMLButtonAttributes
*/
type
NavigationButtonProps
=
PresentationalProps
&
ButtonCommonProps
&
Omit
<
JSX
.
HTMLAttributes
<
HTMLButtonElement
>
,
'icon'
|
'size'
>
;
/**
* Style a navigation button.
*
* @param {PresentationalProps & ButtonCommonProps & HTMLButtonAttributes} props
*/
function
NavigationButton
({
...
buttonProps
})
{
function
NavigationButton
({
...
buttonProps
}:
NavigationButtonProps
)
{
return
(
<
ButtonBase
classes=
{
classnames
(
'px-3.5 py-2.5 gap-x-1 font-semibold'
,
// These colors are the same as the "dark" variant of IconButton
'text-grey-7 bg-grey-2 enabled:hover:text-grey-9 enabled:hover:bg-grey-3 disabled:text-grey-5 aria-pressed:bg-grey-3 aria-expanded:bg-grey-3'
'text-grey-7 bg-grey-2 enabled:hover:text-grey-9 enabled:hover:bg-grey-3'
,
'disabled:text-grey-5 aria-pressed:bg-grey-3 aria-expanded:bg-grey-3'
)
}
{
...
buttonProps
}
/>
);
}
/**
* @typedef PaginationNavigationProps
* @prop {number} currentPage - The currently-visible page of results. Pages
* start at 1 (not 0).
* @prop {(page: number) => void} onChangePage - Callback for changing page
* @prop {number} totalPages
*/
export
type
PaginationNavigationProps
=
{
/** 1-indexed page number of currently-visible page of results */
currentPage
:
number
;
onChangePage
:
(
page
:
number
)
=>
void
;
totalPages
:
number
;
};
/**
* Render pagination navigation controls, with buttons to go next, previous
* and nearby pages. Buttons corresponding to nearby pages are shown on wider
* screens; for narrow screens only Prev and Next buttons are shown.
*
* @param {PaginationNavigationProps} props
*/
function
PaginationNavigation
({
currentPage
,
onChangePage
,
totalPages
})
{
function
PaginationNavigation
({
currentPage
,
onChangePage
,
totalPages
,
}:
PaginationNavigationProps
)
{
// Pages are 1-indexed
const
hasNextPage
=
currentPage
<
totalPages
;
const
hasPreviousPage
=
currentPage
>
1
;
...
...
@@ -56,7 +55,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
* @param {number} pageNumber
* @param {HTMLElement} element
*/
const
changePageTo
=
(
pageNumber
,
e
lement
)
=>
{
const
changePageTo
=
(
pageNumber
:
number
,
element
:
HTMLE
lement
)
=>
{
onChangePage
(
pageNumber
);
// Because changing pagination page doesn't reload the page (as it would
// in a "traditional" HTML context), the clicked-upon navigation button
...
...
@@ -75,10 +74,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
<
NavigationButton
title=
"Go to previous page"
onClick=
{
e
=>
changePageTo
(
currentPage
-
1
,
/** @type {HTMLElement} */
(
e
.
target
)
)
changePageTo
(
currentPage
-
1
,
e
.
target
as
HTMLElement
)
}
>
<
ArrowLeftIcon
/>
...
...
@@ -112,9 +108,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
key=
{
`page-${idx}`
}
title=
{
`Go to page ${page}`
}
pressed=
{
page
===
currentPage
}
onClick
=
{
e
=>
changePageTo
(
page
,
/** @type {HTMLElement} */
(
e
.
target
))
}
onClick=
{
e
=>
changePageTo
(
page
,
e
.
target
as
HTMLElement
)
}
>
{
page
.
toString
()
}
</
NavigationButton
>
...
...
@@ -134,10 +128,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
<
NavigationButton
title=
"Go to next page"
onClick=
{
e
=>
changePageTo
(
currentPage
+
1
,
/** @type {HTMLElement} */
(
e
.
target
)
)
changePageTo
(
currentPage
+
1
,
e
.
target
as
HTMLElement
)
}
>
next
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment