Created
June 6, 2017 10:12
-
-
Save jacek213/77914ddc30edf4ac8eef052bf1ddd992 to your computer and use it in GitHub Desktop.
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
# @cjsx React.DOM | |
@PaginatorSection = React.createClass | |
displayName: 'PaginatorSection' | |
_handleOnClick: (pageNumber) -> | |
@props.onPaginate(pageNumber) | |
_handleNextClick: (e) -> | |
e.preventDefault(); | |
@_handleOnClick(@props.currentPage + 1) | |
_handlePrevClick: (e) -> | |
e.preventDefault(); | |
@_handleOnClick(@props.currentPage - 1) | |
_handleFirstClick: (e) -> | |
e.preventDefault(); | |
@_handleOnClick(1) | |
_handleLastClick: (e) -> | |
e.preventDefault(); | |
@_handleOnClick(@props.totalPages) | |
_isFirst: -> | |
@props.currentPage == 1 | |
_isLast: -> | |
@props.currentPage == @props.totalPages | |
_cssClass: (i) -> | |
if i == @props.currentPage | |
'active' | |
render: -> | |
if @props.totalPages > 1 | |
<div className="pagination pagination-compact"> | |
<ul className="pagination pagination-compact"> | |
{ | |
unless @_isFirst() | |
<li> | |
<a href="#" onClick={@_handleFirstClick}>«</a> | |
</li> | |
} | |
{ | |
unless @_isFirst() | |
<li> | |
<a href="#" onClick={@_handlePrevClick}>‹</a> | |
</li> | |
} | |
{ | |
for i in [1..@props.totalPages] | |
<li key={i} className={@_cssClass(i)}> | |
<PaginatorLink pageNumber={i} onPaginatorLinkClick={@_handleOnClick} /> | |
</li> | |
} | |
{ | |
unless @_isLast() | |
<li> | |
<a href="#" onClick={@_handleNextClick}>›</a> | |
</li> | |
} | |
{ | |
unless @_isLast() | |
<li> | |
<a href="#" onClick={@_handleLastClick}>»</a> | |
</li> | |
} | |
</ul> | |
</div> | |
else | |
<span></span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment