-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1899 from adarshpunj/main
added new element: ui.pagination
- Loading branch information
Showing
5 changed files
with
55 additions
and
0 deletions.
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,26 @@ | ||
from typing import Any, Callable, Optional | ||
|
||
from nicegui.elements.mixins.disableable_element import DisableableElement | ||
from nicegui.elements.mixins.value_element import ValueElement | ||
|
||
|
||
class Pagination(ValueElement, DisableableElement): | ||
|
||
def __init__(self, min: int, max: int, *, direction_links: bool = False, | ||
value: Optional[int] = ..., on_change: Optional[Callable[..., Any]] = None) -> None: | ||
"""Pagination | ||
A pagination element wrapping Quasar's `QPagination <https://quasar.dev/vue-components/pagination>`_ component. | ||
:param min: minimum page number | ||
:param max: maximum page number | ||
:param direction_links: whether to show first/last page links | ||
:param value: initial page (defaults to `min` if no value is provided) | ||
:param on_change: callback to be invoked when the value changes | ||
""" | ||
super().__init__(tag='q-pagination', value=value, on_value_change=on_change) | ||
self._props['min'] = min | ||
self._props['max'] = max | ||
self._props['direction-links'] = direction_links | ||
if value is ...: | ||
self.value = min |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from nicegui import ui | ||
|
||
from .screen import Screen | ||
|
||
|
||
def test_pagination(screen: Screen): | ||
p = ui.pagination(1, 10, direction_links=True) | ||
ui.label().bind_text_from(p, 'value', lambda v: f'Page {v}') | ||
|
||
screen.open('/') | ||
screen.should_contain('Page 1') | ||
|
||
screen.click('7') | ||
screen.should_contain('Page 7') | ||
|
||
screen.click('keyboard_arrow_left') | ||
screen.should_contain('Page 6') | ||
|
||
screen.click('keyboard_arrow_right') | ||
screen.should_contain('Page 7') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from nicegui import ui | ||
|
||
|
||
def main_demo() -> None: | ||
p = ui.pagination(1, 5, direction_links=True) | ||
ui.label().bind_text_from(p, 'value', lambda v: f'Page {v}') |