Skip to content

Commit cdb47be

Browse files
Yann Lojewskiy4nnL
authored andcommitted
feat(pagination): add arrows mode
Signed-off-by: Yann Lojewski <[email protected]>
1 parent e1e7d98 commit cdb47be

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

packages/apps/workshop/stories/design-system/components/pagination/pagination-webcomponent.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const mode = {
1717
Button: 'button',
1818
Select: 'select',
1919
Input: 'input',
20+
Arrows: 'arrows',
2021
},
2122
default: '',
2223
};

packages/components/pagination/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ angular.module('myModule', ['oui.pagination'])
3434

3535
| Attribute | Type | Binding | One-time Binding | Values | Default | Description
3636
| ---- | ---- | ---- | ---- | ---- | ---- | ----
37+
| `mode` | string | @? | no | n/a | n/a | Set the pagination mode. It can be one these values : `button`, `select`, `input` or `arrows`
3738
| `current-offset` | number | < | no | n/a | n/a | offset of the current page first item
3839
| `page-size` | number | <? | no | n/a | `25` | number of items per page
3940
| `page-size-max` | number | <? | no | n/a | n/a | max page size of the page sizes list

packages/components/pagination/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Dropdown from '@ovh-ux/ui-kit.dropdown';
33
import Pagination from './js/pagination.component';
44
import PaginationConfigurationProvider from './js/pagination.provider';
55

6+
67
const moduleName = 'oui.pagination';
78

89
angular
@@ -12,4 +13,5 @@ angular
1213
.component('ouiPagination', Pagination)
1314
.provider('ouiPaginationConfiguration', PaginationConfigurationProvider);
1415

16+
export { MODES } from './js/pagination.controller';
1517
export default moduleName;

packages/components/pagination/src/js/pagination.controller.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { addDefaultParameter } from '@ovh-ux/ui-kit.core/src/js/component-utils'
22
import clamp from 'lodash/clamp';
33
import range from 'lodash/range';
44

5-
const MODES = [
5+
export const MODES = [
66
'button',
77
'select',
88
'input',
9+
'arrows',
910
];
1011

1112
const MAX_THRESHOLD_MODE = {
@@ -23,6 +24,10 @@ export default class {
2324
this.config = ouiPaginationConfiguration;
2425
}
2526

27+
get isArrowsMode() {
28+
return this.mode === 'arrows';
29+
}
30+
2631
getCurrentPage() {
2732
return Math.floor((this.currentOffset - 1) / this.currentPageSize) + 1;
2833
}

packages/components/pagination/src/js/pagination.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<div class="oui-pagination-result">
1+
<div class="oui-pagination-result"
2+
ng-if="!$ctrl.isArrowsMode">
23
<label class="oui-select oui-select_inline">
34
<select class="oui-pagination-result__selector oui-select__input"
45
ng-change="$ctrl.onPageSizeChange($ctrl.currentPageSize)"
@@ -60,6 +61,7 @@
6061

6162
<!-- Input -->
6263
<form class="oui-pagination-items oui-pagination-items_input"
64+
ng-if="!$ctrl.isArrowsMode"
6365
ng-switch-default
6466
novalidate>
6567
<span aria-hidden="true"

packages/components/pagination/src/js/pagination.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,21 @@ describe('ouiPagination', () => {
283283
expect(items.hasClass('oui-pagination-items_input')).toBe(true);
284284
});
285285

286+
it('should display items in arrows mode', () => {
287+
const element = TestUtils.compileTemplate(`
288+
<oui-pagination
289+
mode="arrows"
290+
current-offset="1"
291+
total-items="100">
292+
</oui-pagination>
293+
`);
294+
295+
expect(getPaginationNavPrevious(element)).toBeDefined();
296+
expect(getPaginationNavNext(element)).toBeDefined();
297+
expect(getPaginationResult(element)).toBeFalsy();
298+
expect(getPaginationItems(element)).toBeFalsy();
299+
});
300+
286301
it('should change the mode automatically based on the pageCount', () => {
287302
let items;
288303
const element = TestUtils.compileTemplate(`

0 commit comments

Comments
 (0)