-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk): add
TuiRepeatTimes
pipe (#9262)
- Loading branch information
Showing
13 changed files
with
111 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
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,12 @@ | ||
import {Pipe, type PipeTransform} from '@angular/core'; | ||
import {tuiClamp} from '@taiga-ui/cdk/utils'; | ||
|
||
@Pipe({ | ||
standalone: true, | ||
name: 'tuiRepeatTimes', | ||
}) | ||
export class TuiRepeatTimesPipe implements PipeTransform { | ||
public transform(n: number): number[] { | ||
return Array.from({length: tuiClamp(n, 0, n)}, (_, i) => i); | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
projects/cdk/pipes/repeat-times/test/repeat-times.pipe.spec.ts
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,16 @@ | ||
import {TuiRepeatTimesPipe} from '@taiga-ui/cdk'; | ||
|
||
describe('TuiRepeatTimes pipe', () => { | ||
const pipe = new TuiRepeatTimesPipe(); | ||
|
||
it('works', () => { | ||
expect(pipe.transform(-2)).toEqual([]); | ||
expect(pipe.transform(-1)).toEqual([]); | ||
expect(pipe.transform(0)).toEqual([]); | ||
expect(pipe.transform(1)).toEqual([0]); | ||
expect(pipe.transform(2)).toEqual([0, 1]); | ||
expect(pipe.transform(3)).toEqual([0, 1, 2]); | ||
expect(pipe.transform(4)).toEqual([0, 1, 2, 3]); | ||
expect(pipe.transform(5)).toEqual([0, 1, 2, 3, 4]); | ||
}); | ||
}); |
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
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
3 changes: 3 additions & 0 deletions
3
projects/demo/src/modules/pipes/repeat-times/examples/1/index.html
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,3 @@ | ||
<ng-container *ngFor="let index of 5 | tuiRepeatTimes"> | ||
{{ index }} | ||
</ng-container> |
14 changes: 14 additions & 0 deletions
14
projects/demo/src/modules/pipes/repeat-times/examples/1/index.ts
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,14 @@ | ||
import {NgForOf} from '@angular/common'; | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiRepeatTimesPipe} from '@taiga-ui/cdk'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [NgForOf, TuiRepeatTimesPipe], | ||
templateUrl: './index.html', | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export default class Example {} |
15 changes: 15 additions & 0 deletions
15
projects/demo/src/modules/pipes/repeat-times/examples/import/import.md
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,15 @@ | ||
```ts | ||
import {TuiRepeatTimesPipe} from '@taiga-ui/cdk'; | ||
|
||
//... | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ | ||
// ... | ||
TuiRepeatTimesPipe, | ||
], | ||
// ... | ||
}) | ||
export class Example {} | ||
``` |
5 changes: 5 additions & 0 deletions
5
projects/demo/src/modules/pipes/repeat-times/examples/import/template.md
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,5 @@ | ||
```html | ||
@for (index of 3 | tuiRepeatTimes; track index) { | ||
<div class="t-cell"></div> | ||
} | ||
``` |
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,17 @@ | ||
<tui-doc-page | ||
header="RepeatTimes" | ||
package="CDK" | ||
type="pipes" | ||
> | ||
<ng-template pageTab> | ||
<tui-doc-example | ||
id="base" | ||
description="Pipe for making an array of elements by length" | ||
heading="Base" | ||
[component]="1 | tuiComponent" | ||
[content]="1 | tuiExample" | ||
/> | ||
</ng-template> | ||
|
||
<tui-setup *pageTab="'Setup'" /> | ||
</tui-doc-page> |
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,11 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {TuiDemo} from '@demo/utils'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [TuiDemo], | ||
templateUrl: './index.html', | ||
changeDetection, | ||
}) | ||
export default class Page {} |