-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add page navigation for the new feedback dashboard (#28826)
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
- Loading branch information
Showing
10 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Added arrow-left and arrow-right icons to the Gridicon component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/packages/forms/changelog/add-jetpack-forms-dashboard-page-navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
Added a page navigation component for the new feedback dashboard |
77 changes: 77 additions & 0 deletions
77
projects/packages/forms/src/dashboard/components/page-navigation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Gridicon } from '@automattic/jetpack-components'; | ||
import { useCallback } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { filter, flatten, map, range } from 'lodash'; | ||
import PageNumber from './page-number'; | ||
|
||
import './style.scss'; | ||
|
||
const PageNavigation = ( { currentPage, expandedRange = 3, onSelectPage, pages } ) => { | ||
const goToPrevious = useCallback( () => onSelectPage( currentPage - 1 ), [ | ||
currentPage, | ||
onSelectPage, | ||
] ); | ||
const goToNext = useCallback( () => onSelectPage( currentPage + 1 ), [ | ||
currentPage, | ||
onSelectPage, | ||
] ); | ||
|
||
const currentRange = range( | ||
Math.max( 0, currentPage - expandedRange + 1 ), | ||
Math.min( pages, currentPage + expandedRange - 1 ) + 1 | ||
); | ||
const totalRange = filter( | ||
flatten( [ | ||
expandedRange < currentPage && 1, | ||
expandedRange + 1 < currentPage && ( currentPage === expandedRange + 2 ? 2 : Infinity ), | ||
currentRange, | ||
currentPage < pages - expandedRange && | ||
( currentPage === pages - expandedRange ? pages - 1 : Infinity ), | ||
currentPage < pages - expandedRange + 1 && pages, | ||
] ) | ||
); | ||
|
||
return ( | ||
<div className="jp-forms__page-navigation"> | ||
<button | ||
disabled={ currentPage === 1 } | ||
className="jp-forms__page-navigation-button" | ||
onClick={ goToPrevious } | ||
> | ||
<Gridicon icon="arrow-left" size={ 18 } /> | ||
{ __( 'Previous', 'jetpack-forms' ) } | ||
</button> | ||
|
||
{ map( totalRange, ( n, index ) => | ||
! isFinite( n ) ? ( | ||
<button | ||
key={ `placeholder-${ index }` } | ||
className="jp-forms__page-navigation-placeholder" | ||
disabled | ||
> | ||
… | ||
</button> | ||
) : ( | ||
<PageNumber | ||
key={ n } | ||
className="jp-forms__page-navigation-button" | ||
active={ n === currentPage } | ||
page={ n } | ||
onSelect={ onSelectPage } | ||
/> | ||
) | ||
) } | ||
|
||
<button | ||
disabled={ currentPage === pages } | ||
className="jp-forms__page-navigation-button" | ||
onClick={ goToNext } | ||
> | ||
{ __( 'Next', 'jetpack-forms' ) } | ||
<Gridicon icon="arrow-right" size={ 18 } /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PageNavigation; |
18 changes: 18 additions & 0 deletions
18
projects/packages/forms/src/dashboard/components/page-navigation/page-number.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useCallback } from '@wordpress/element'; | ||
import classNames from 'classnames'; | ||
|
||
const PageNumber = ( { active, className, page, onSelect } ) => { | ||
const buttonClass = classNames( 'jp-forms__page-navigation-page-number', className, { | ||
'is-active': active, | ||
} ); | ||
|
||
const selectPage = useCallback( () => onSelect( page ), [ page, onSelect ] ); | ||
|
||
return ( | ||
<button className={ buttonClass } onClick={ selectPage }> | ||
{ page } | ||
</button> | ||
); | ||
}; | ||
|
||
export default PageNumber; |
55 changes: 55 additions & 0 deletions
55
projects/packages/forms/src/dashboard/components/page-navigation/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.jp-forms__page-navigation { | ||
background-color: #fff; | ||
border: 1px solid #dcdcde; | ||
border-radius: 3px; | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-direction: row; | ||
height: 36px; | ||
justify-content: center; | ||
padding: 0; | ||
width: fit-content; | ||
} | ||
|
||
.jp-forms__page-navigation-button, | ||
.jp-forms__page-navigation-button:hover, | ||
.jp-forms__page-navigation-placeholder:hover, | ||
.jp-forms__page-navigation-placeholder { | ||
background: transparent; | ||
border: 0; | ||
box-sizing: border-box; | ||
color: #101517; | ||
cursor: pointer; | ||
display: inline-flex; | ||
font-weight: bold; | ||
font-size: 13px; | ||
height: 34px; | ||
line-height: 18px; | ||
text-align: center; | ||
padding: 8px 12px; | ||
|
||
&.is-active { | ||
background-color: #101517; | ||
color: #fff; | ||
} | ||
|
||
&:disabled { | ||
cursor: default; | ||
|
||
&:first-child, &:last-child { | ||
color: #dcdcde; | ||
} | ||
} | ||
|
||
.gridicon { | ||
display: inline-flex; | ||
|
||
&.gridicons-arrow-left { | ||
margin-right: 3px; | ||
} | ||
|
||
&.gridicons-arrow-right { | ||
margin-left: 3px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-jetpack-forms-dashboard-page-navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
This change doesn't affect the plugin. |