Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kit): add overload for TuiFilterByInputPipe #8912

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Component, inject} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import type {TuiStringMatcher} from '@taiga-ui/cdk';
import {
TuiDataListWrapper,
TuiFilterByInputPipe,
Expand All @@ -27,7 +28,7 @@ interface User {
encapsulation,
changeDetection,
})
export default class Example {
export default class Example<T extends User = User> {
protected readonly items = inject<readonly string[]>('Pythons' as any);

protected readonly users = [
Expand All @@ -36,18 +37,18 @@ export default class Example {
{id: 3, name: 'Graham Chapman'},
{id: 4, name: 'Michael Palin'},
{id: 5, name: 'Terry Gilliam'},
];
] as unknown as readonly T[];

protected readonly form = new FormGroup({
user: new FormControl<User | null>(null),
user2: new FormControl<User | null>(null),
user: new FormControl<T | null>(null),
user2: new FormControl<T | null>(null),
});

protected readonly stringify = ({name}: User): string => name;
protected readonly stringify = ({name}: T): string => name;

protected readonly matcherString = (name: string, search: string): boolean =>
name.split(' ').pop()!.toLowerCase().startsWith(search.toLowerCase());
name.split(' ').pop()?.toLowerCase().startsWith(search.toLowerCase()) ?? false;

protected readonly matcherUser = (user: User, search: string): boolean =>
protected readonly matcherUser: TuiStringMatcher<T> = (user, search): boolean =>
user.name.toLowerCase().startsWith(search.toLowerCase());
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import {TUI_DATA_LIST_HOST} from '@taiga-ui/core/components/data-list';
import {TuiTextfieldComponent} from '@taiga-ui/core/components/textfield';
import {tuiIsFlat} from '@taiga-ui/kit/utils';

type TuiArrayElement<A> =
A extends ReadonlyArray<infer T>
? A extends ReadonlyArray<ReadonlyArray<infer G>>
? G
: T
: never;

// TODO: Consider replacing TuiTextfieldComponent with proper token once we refactor textfields
@Pipe({
standalone: true,
Expand All @@ -25,7 +18,7 @@ export class TuiFilterByInputPipe implements PipeTransform {
private readonly textfield = inject(TuiTextfieldComponent, {optional: true});
private readonly host = inject(TUI_DATA_LIST_HOST);

public transform<T>(items: T, matcher?: TuiStringMatcher<TuiArrayElement<T>>): T;
public transform<T>(items: readonly T[], matcher?: TuiStringMatcher<T>): readonly T[];
public transform<T>(
items: ReadonlyArray<readonly T[]> | readonly T[] | null,
matcher: TuiStringMatcher<T> = TUI_DEFAULT_MATCHER,
Expand Down
Loading