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 {
...
@@ -3,50 +3,49 @@ import {
ArrowLeftIcon
,
ArrowLeftIcon
,
ArrowRightIcon
,
ArrowRightIcon
,
}
from
'@hypothesis/frontend-shared/lib/next'
;
}
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
classnames
from
'classnames'
;
import
type
{
JSX
}
from
'preact'
;
import
{
pageNumberOptions
}
from
'../util/pagination'
;
import
{
pageNumberOptions
}
from
'../util/pagination'
;
/**
type
NavigationButtonProps
=
PresentationalProps
&
* @typedef {import('@hypothesis/frontend-shared/lib/types').PresentationalProps} PresentationalProps
ButtonCommonProps
&
* @typedef {import('@hypothesis/frontend-shared/lib/components/input/ButtonBase').ButtonCommonProps} ButtonCommonProps
Omit
<
JSX
.
HTMLAttributes
<
HTMLButtonElement
>
,
'icon'
|
'size'
>
;
* @typedef {Omit<import('preact').JSX.HTMLAttributes<HTMLButtonElement>, 'icon'|'size'>} HTMLButtonAttributes
*/
/**
function
NavigationButton
({
...
buttonProps
}:
NavigationButtonProps
)
{
* Style a navigation button.
*
* @param {PresentationalProps & ButtonCommonProps & HTMLButtonAttributes} props
*/
function
NavigationButton
({
...
buttonProps
})
{
return
(
return
(
<
ButtonBase
<
ButtonBase
classes=
{
classnames
(
classes=
{
classnames
(
'px-3.5 py-2.5 gap-x-1 font-semibold'
,
'px-3.5 py-2.5 gap-x-1 font-semibold'
,
// These colors are the same as the "dark" variant of IconButton
// 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
}
{
...
buttonProps
}
/>
/>
);
);
}
}
/**
export
type
PaginationNavigationProps
=
{
* @typedef PaginationNavigationProps
/** 1-indexed page number of currently-visible page of results */
* @prop {number} currentPage - The currently-visible page of results. Pages
currentPage
:
number
;
* start at 1 (not 0).
onChangePage
:
(
page
:
number
)
=>
void
;
* @prop {(page: number) => void} onChangePage - Callback for changing page
totalPages
:
number
;
* @prop {number} totalPages
};
*/
/**
/**
* Render pagination navigation controls, with buttons to go next, previous
* Render pagination navigation controls, with buttons to go next, previous
* and nearby pages. Buttons corresponding to nearby pages are shown on wider
* and nearby pages. Buttons corresponding to nearby pages are shown on wider
* screens; for narrow screens only Prev and Next buttons are shown.
* 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
// Pages are 1-indexed
const
hasNextPage
=
currentPage
<
totalPages
;
const
hasNextPage
=
currentPage
<
totalPages
;
const
hasPreviousPage
=
currentPage
>
1
;
const
hasPreviousPage
=
currentPage
>
1
;
...
@@ -56,7 +55,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
...
@@ -56,7 +55,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
* @param {number} pageNumber
* @param {number} pageNumber
* @param {HTMLElement} element
* @param {HTMLElement} element
*/
*/
const
changePageTo
=
(
pageNumber
,
e
lement
)
=>
{
const
changePageTo
=
(
pageNumber
:
number
,
element
:
HTMLE
lement
)
=>
{
onChangePage
(
pageNumber
);
onChangePage
(
pageNumber
);
// Because changing pagination page doesn't reload the page (as it would
// Because changing pagination page doesn't reload the page (as it would
// in a "traditional" HTML context), the clicked-upon navigation button
// in a "traditional" HTML context), the clicked-upon navigation button
...
@@ -75,10 +74,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
...
@@ -75,10 +74,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
<
NavigationButton
<
NavigationButton
title=
"Go to previous page"
title=
"Go to previous page"
onClick=
{
e
=>
onClick=
{
e
=>
changePageTo
(
changePageTo
(
currentPage
-
1
,
e
.
target
as
HTMLElement
)
currentPage
-
1
,
/** @type {HTMLElement} */
(
e
.
target
)
)
}
}
>
>
<
ArrowLeftIcon
/>
<
ArrowLeftIcon
/>
...
@@ -112,9 +108,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
...
@@ -112,9 +108,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
key=
{
`page-${idx}`
}
key=
{
`page-${idx}`
}
title=
{
`Go to page ${page}`
}
title=
{
`Go to page ${page}`
}
pressed=
{
page
===
currentPage
}
pressed=
{
page
===
currentPage
}
onClick
=
{
e
=>
onClick=
{
e
=>
changePageTo
(
page
,
e
.
target
as
HTMLElement
)
}
changePageTo
(
page
,
/** @type {HTMLElement} */
(
e
.
target
))
}
>
>
{
page
.
toString
()
}
{
page
.
toString
()
}
</
NavigationButton
>
</
NavigationButton
>
...
@@ -134,10 +128,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
...
@@ -134,10 +128,7 @@ function PaginationNavigation({ currentPage, onChangePage, totalPages }) {
<
NavigationButton
<
NavigationButton
title=
"Go to next page"
title=
"Go to next page"
onClick=
{
e
=>
onClick=
{
e
=>
changePageTo
(
changePageTo
(
currentPage
+
1
,
e
.
target
as
HTMLElement
)
currentPage
+
1
,
/** @type {HTMLElement} */
(
e
.
target
)
)
}
}
>
>
next
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