Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8681817

Browse files
presleyppull[bot]
authored andcommitted
Feat: hide pagination widget when not needed (#4957)
* Hide pagination widget when not needed. Don't merge until count is in.* Format* Refactor* Remove story* Fix bug* Format
1 parent26fd6f3 commit8681817

File tree

2 files changed

+42
-48
lines changed

2 files changed

+42
-48
lines changed

‎site/src/components/PaginationWidget/PaginationWidget.stories.tsx‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ const Template: Story<PaginationWidgetProps> = (
2525
args:PaginationWidgetProps,
2626
)=><PaginationWidget{...args}/>
2727

28-
exportconstUnknownPageNumbers=Template.bind({})
29-
UnknownPageNumbers.args={
30-
numRecords:undefined,
31-
}
32-
3328
exportconstLessThan8Pages=Template.bind({})
3429
LessThan8Pages.args={
3530
numRecords:84,

‎site/src/components/PaginationWidget/PaginationWidget.tsx‎

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ export const PaginationWidget = ({
3434
constcurrentPage=paginationState.context.page
3535
constnumRecordsPerPage=paginationState.context.limit
3636

37-
constnumPages=numRecords
38-
?Math.ceil(numRecords/numRecordsPerPage)
39-
:undefined
37+
constnumPages=numRecords ?Math.ceil(numRecords/numRecordsPerPage) :0
4038
constfirstPageActive=currentPage===1&&numPages!==0
4139
constlastPageActive=currentPage===numPages&&numPages!==0
40+
// if beyond page 1, show pagination widget even if there's only one true page, so user can navigate back
41+
constshowWidget=numPages>1||currentPage>1
4242

4343
return(
44-
<divstyle={containerStyle}className={styles.defaultContainerStyles}>
45-
<Button
46-
className={styles.prevLabelStyles}
47-
aria-label="Previous page"
48-
disabled={firstPageActive}
49-
onClick={()=>send({type:"PREVIOUS_PAGE"})}
50-
>
51-
<KeyboardArrowLeft/>
52-
<div>{prevLabel}</div>
53-
</Button>
54-
<Maybecondition={numPages!==undefined}>
44+
<Maybecondition={showWidget}>
45+
<divstyle={containerStyle}className={styles.defaultContainerStyles}>
46+
<Button
47+
className={styles.prevLabelStyles}
48+
aria-label="Previous page"
49+
disabled={firstPageActive}
50+
onClick={()=>send({type:"PREVIOUS_PAGE"})}
51+
>
52+
<KeyboardArrowLeft/>
53+
<div>{prevLabel}</div>
54+
</Button>
5555
<ChooseOne>
5656
<Condcondition={isMobile}>
5757
<PageButton
@@ -61,37 +61,36 @@ export const PaginationWidget = ({
6161
/>
6262
</Cond>
6363
<Cond>
64-
{numPages&&
65-
buildPagedList(numPages,currentPage).map((page)=>
66-
typeofpage!=="number" ?(
67-
<PageButton
68-
key={`Page${page}`}
69-
activePage={currentPage}
70-
placeholder="..."
71-
disabled
72-
/>
73-
) :(
74-
<PageButton
75-
key={`Page${page}`}
76-
activePage={currentPage}
77-
page={page}
78-
numPages={numPages}
79-
onPageClick={()=>send({type:"GO_TO_PAGE", page})}
80-
/>
81-
),
82-
)}
64+
{buildPagedList(numPages,currentPage).map((page)=>
65+
typeofpage!=="number" ?(
66+
<PageButton
67+
key={`Page${page}`}
68+
activePage={currentPage}
69+
placeholder="..."
70+
disabled
71+
/>
72+
) :(
73+
<PageButton
74+
key={`Page${page}`}
75+
activePage={currentPage}
76+
page={page}
77+
numPages={numPages}
78+
onPageClick={()=>send({type:"GO_TO_PAGE", page})}
79+
/>
80+
),
81+
)}
8382
</Cond>
8483
</ChooseOne>
85-
</Maybe>
86-
<Button
87-
aria-label="Next page"
88-
disabled={lastPageActive}
89-
onClick={()=>send({type:"NEXT_PAGE"})}
90-
>
91-
<div>{nextLabel}</div>
92-
<KeyboardArrowRight/>
93-
</Button>
94-
</div>
84+
<Button
85+
aria-label="Next page"
86+
disabled={lastPageActive}
87+
onClick={()=>send({type:"NEXT_PAGE"})}
88+
>
89+
<div>{nextLabel}</div>
90+
<KeyboardArrowRight/>
91+
</Button>
92+
</div>
93+
</Maybe>
9594
)
9695
}
9796

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp