Skip to content

Commit

Permalink
feat(pagination): new pagination snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
WillianLomeu committed Aug 27, 2024
1 parent 81e7b19 commit b75b6f4
Show file tree
Hide file tree
Showing 4 changed files with 617 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5600,6 +5600,10 @@ declare namespace LocalJSX {
"itemsPage"?: any;
"language"?: string;
"numberItems"?: number;
/**
* Evento emitido quando o valor da página atual é alterado. Pode ser escutado para realizar ações específicas ao mudar de página.
*/
"onBdsItemsPerPageChange"?: (event: BdsPaginationCustomEvent<any>) => void;
/**
* Evento emitido quando o valor da página atual é alterado. Pode ser escutado para realizar ações específicas ao mudar de página.
*/
Expand Down
14 changes: 9 additions & 5 deletions src/components/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export class Pagination {
* Pode ser escutado para realizar ações específicas ao mudar de página.
*/
@Event() bdsPaginationChange: EventEmitter;
/**
* Evento emitido quando o valor da página atual é alterado.
* Pode ser escutado para realizar ações específicas ao mudar de página.
*/
@Event() bdsItemsPerPageChange: EventEmitter;

// Variável que armazena o número do primeiro item sendo exibido na página atual
startItem: number;
Expand Down Expand Up @@ -132,15 +137,14 @@ export class Pagination {
try {
this.itemsPage = JSON.parse(this.itemsPage.replace(/'/g, '"'));
} catch (error) {
console.error('Failed to parse itemsPage:', error);
this.itemsPage = [];
}
}
}

countItem() {
this.pages = this.numberItems / this.itemValue;
console.log(this.numberItems, this.itemValue, this.pages);
const pages = this.numberItems / this.itemValue;
this.pages = Math.ceil(pages);
}

countPage() {
Expand Down Expand Up @@ -209,19 +213,19 @@ export class Pagination {
this.updateItemRange();
}

@Watch('itemValue')
itemSelected(index) {
this.itemValue = index;
this.itemsPerPage = index;
this.openOptions();
this.countItem();
this.updateItemRange();
this.bdsItemsPerPageChange.emit(this.itemsPerPage);
}

updateItemRange() {
console.log(this.value, this.itemsPerPage);
this.startItem = (this.value - 1) * this.itemsPerPage + 1;
this.endItem = Math.min(this.value * this.itemsPerPage, this.numberItems);
console.log(this.startItem, this.endItem);
}

get currentLanguage() {
Expand Down
7 changes: 4 additions & 3 deletions src/components/pagination/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

## Events

| Event | Description | Type |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| `bdsPaginationChange` | Evento emitido quando o valor da página atual é alterado. Pode ser escutado para realizar ações específicas ao mudar de página. | `CustomEvent<any>` |
| Event | Description | Type |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| `bdsItemsPerPageChange` | Evento emitido quando o valor da página atual é alterado. Pode ser escutado para realizar ações específicas ao mudar de página. | `CustomEvent<any>` |
| `bdsPaginationChange` | Evento emitido quando o valor da página atual é alterado. Pode ser escutado para realizar ações específicas ao mudar de página. | `CustomEvent<any>` |


## Dependencies
Expand Down
Loading

0 comments on commit b75b6f4

Please sign in to comment.