ember-assembly
Version:
A collection of beautiful UI components built by Goods
71 lines (60 loc) • 1.56 kB
text/typescript
import Component from '@ember/component';
// @ts-ignore: Ignore import of compiled template
import template from './template';
import { gt } from '@ember/object/computed';
import { computed, action } from '@ember/object';
export default class UiPagination extends Component {
layout = template;
tagName: string = '';
start!: number;
count!: number;
total!: number;
onChangeStart!: any;
showPrevious!: boolean;
get showNext(): boolean {
return this.start + this.count < this.total;
}
get currentPagination(): any {
if (this.total == 0) {
return {
label: '0',
};
}
let max = Math.min(this.start + this.count, this.total);
return {
label: `${this.start + 1} - ${max} of ${this.total}`,
};
}
get paginationOptions(): object[] {
let pages: any[] = [];
for (let i = 0; i < this.total; i += this.count) {
let max = Math.min(i + this.count, this.total);
pages.push({
label: `${i + 1} - ${max}`,
value: i,
});
}
return pages;
}
onNext() {
if (this.start + this.count > this.total) {
return;
}
this.onChangeStart(this.start + this.count);
}
onPrevious() {
if (this.start - this.count < 0) {
return;
}
this.onChangeStart(this.start - this.count);
}
onSetPage(pageOption: any) {
this.onChangeStart(pageOption.value);
}
}