Skip to content

Commit

Permalink
feat(design): convert paginator component to standalone (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint authored and damienwebdev committed Sep 27, 2024
1 parent 7ca68fd commit 8caa5e1
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 30 deletions.
49 changes: 45 additions & 4 deletions libs/design/paginator/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
# Paginator
Paginator is used to break up large amounts of content into multiple pages, enabling users to easily navigate between pages of content.

## Default Paginator
<design-land-example-viewer-container example="basic-paginator"></design-land-example-viewer-container>

## Usage

### Within a standalone component
To use paginator in a standalone component, import `DAFF_PAGINATOR_COMPONENTS` directly into your custom component:

```ts
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
standalone: true,
imports: [
DAFF_PAGINATOR_COMPONENTS,
],
})
export class CustomComponent {}
```

### Within a module (deprecated)
To use paginator in a module, import `DaffPaginatorModule` into your custom module:

```ts
import { NgModule } from '@angular/core';

import { DaffPaginatorModule } from '@daffodil/design/paginator';

@NgModule({
declarations: [
CustomComponent,
],
exports: [
CustomComponent,
],
imports: [
DaffPaginatorModule,
],
})
export class CustomComponentModule { }
```

> This method is deprecated. It's recommended to update all custom components to standalone.
## Truncation
An ellipsis is used to truncate pages when the number of pages exceed the maximum display limit. Double truncation appears when the current page is separated by more than three pages from both the first and last page.

## Accessibility
Use `aria-label` or `aria-labelledby` to give a meaningful label to `daff-paginator` that describes the content controlled by the paginator. If more than one paginator component is used on a page, each will need a unique `aria-label`.

## Usage
<design-land-example-viewer-container example="basic-paginator"></design-land-example-viewer-container>
Use `aria-label` or `aria-labelledby` to give a meaningful label to `daff-paginator` that describes the content controlled by the paginator. If more than one paginator component is used on a page, each will need a unique `aria-label`.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Component,
} from '@angular/core';

import { DaffPaginatorModule } from '@daffodil/design/paginator';
import { DAFF_PAGINATOR_COMPONENTS } from '@daffodil/design/paginator';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -12,7 +12,7 @@ import { DaffPaginatorModule } from '@daffodil/design/paginator';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffPaginatorModule,
DAFF_PAGINATOR_COMPONENTS,
],
})
export class BasicPaginatorComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
map,
} from 'rxjs';

import { DaffPaginatorModule } from '@daffodil/design/paginator';
import { DAFF_PAGINATOR_COMPONENTS } from '@daffodil/design/paginator';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -18,7 +18,7 @@ import { DaffPaginatorModule } from '@daffodil/design/paginator';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffPaginatorModule,
DAFF_PAGINATOR_COMPONENTS,
AsyncPipe,
],
})
Expand Down
5 changes: 3 additions & 2 deletions libs/design/paginator/src/paginator.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

import { DaffPaginatorComponent } from './paginator/paginator.component';

/**
* @deprecated in favor of {@link DAFF_PAGINATOR_COMPONENTS}
*/
@NgModule({
imports: [
CommonModule,
RouterModule,
FontAwesomeModule,
],
declarations: [
DaffPaginatorComponent,
],
exports: [
Expand Down
5 changes: 5 additions & 0 deletions libs/design/paginator/src/paginator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DaffPaginatorComponent } from './paginator/paginator.component';

export const DAFF_PAGINATOR_COMPONENTS = <const> [
DaffPaginatorComponent,
];
37 changes: 21 additions & 16 deletions libs/design/paginator/src/paginator/paginator.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
tick,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import {
ActivatedRoute,
RouterModule,
} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';

import { DaffPaginatorComponent } from './paginator.component';
Expand All @@ -24,16 +27,21 @@ import {
@Component({ template: '' })
class TestComponent {}

@Component({ template: `
<daff-paginator
aria-label="id"
[numberOfPages]="numberOfPagesValue"
[currentPage]="currentPageValue"
[linkMode]="linkModeValue"
[url]="urlValue"
[queryParam]="queryParamValue"
></daff-paginator>
` })
@Component({
template: `
<daff-paginator
aria-label="id"
[numberOfPages]="numberOfPagesValue"
[currentPage]="currentPageValue"
[linkMode]="linkModeValue"
[url]="urlValue"
[queryParam]="queryParamValue">
</daff-paginator>`,
standalone: true,
imports: [
DaffPaginatorComponent,
],
})

class WrapperComponent {
numberOfPagesValue = 20;
Expand All @@ -55,8 +63,8 @@ describe('@daffodil/design/paginator | DaffPaginatorComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
DaffPaginatorModule,
RouterTestingModule.withRoutes([
WrapperComponent,
RouterModule.forRoot([
{
path: '',
component: TestComponent,
Expand All @@ -67,9 +75,6 @@ describe('@daffodil/design/paginator | DaffPaginatorComponent', () => {
},
]),
],
declarations: [
WrapperComponent,
],
})
.compileComponents();
}));
Expand Down
20 changes: 16 additions & 4 deletions libs/design/paginator/src/paginator/paginator.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
NgFor,
NgIf,
} from '@angular/common';
import {
Component,
Input,
Expand All @@ -8,7 +12,11 @@ import {
OnChanges,
ChangeDetectionStrategy,
} from '@angular/core';
import { Params } from '@angular/router';
import {
Params,
RouterModule,
} from '@angular/router';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import {
faChevronRight,
faChevronLeft,
Expand All @@ -21,14 +29,18 @@ import {

const visiblePageRange = 2;

/**
* @inheritdoc
*/
@Component({
selector: 'daff-paginator',
styleUrls: ['./paginator.component.scss'],
templateUrl: './paginator.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
FaIconComponent,
RouterModule,
NgIf,
NgFor,
],
})
export class DaffPaginatorComponent implements OnChanges {

Expand Down
1 change: 1 addition & 0 deletions libs/design/paginator/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { DaffPaginatorModule } from './paginator.module';
export { DaffPaginatorComponent } from './paginator/paginator.component';
export { DAFF_PAGINATOR_COMPONENTS } from './paginator';

0 comments on commit 8caa5e1

Please sign in to comment.