Skip to content

Commit

Permalink
feat(cdk): add TuiValuesOf
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Jul 2, 2023
1 parent a5e1574 commit bee91e0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Directive, Inject, Input, OnDestroy, OnInit, Optional} from '@angular/core';
import {NgControl} from '@angular/forms';
import {TuiHeadDirective} from '@taiga-ui/addon-table/components';
import {TuiValuesOf} from '@taiga-ui/cdk';
import {defer, EMPTY, merge} from 'rxjs';
import {distinctUntilChanged} from 'rxjs/operators';

Expand All @@ -27,7 +28,7 @@ export class TuiTableFilterDirective<T> implements OnInit, OnDestroy, TuiTableFi
@Inject(TuiHeadDirective)
private readonly head: TuiHeadDirective<T> | null,
@Inject(AbstractTuiTableFilter)
private readonly delegate: AbstractTuiTableFilter<T[keyof T], any>,
private readonly delegate: AbstractTuiTableFilter<TuiValuesOf<T>, any>,
@Inject(NgControl) private readonly control: NgControl,
@Inject(TuiTableFiltersDirective) readonly filters: TuiTableFiltersDirective<T>,
) {}
Expand Down
1 change: 1 addition & 0 deletions projects/cdk/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './matcher';
export * from './overscroll-mode';
export * from './rounding';
export * from './time-mode';
export * from './values-of';
1 change: 1 addition & 0 deletions projects/cdk/types/values-of.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TuiValuesOf<T> = T[keyof T];
4 changes: 3 additions & 1 deletion projects/cdk/utils/miscellaneous/uniq-by.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {TuiValuesOf} from '@taiga-ui/cdk/types/values-of';

export function tuiUniqBy<T extends Record<string, any>>(
array: readonly T[],
key: keyof T,
Expand All @@ -6,7 +8,7 @@ export function tuiUniqBy<T extends Record<string, any>>(
array
.reduce(
(map, item) => (map.has(item[key]) ? map : map.set(item[key], item)),
new Map<T[keyof T], T>(),
new Map<TuiValuesOf<T>, T>(),
)
.values(),
);
Expand Down
18 changes: 9 additions & 9 deletions projects/core/components/expand/expand.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import {
TemplateRef,
ViewChild,
} from '@angular/core';
import {TUI_PARENT_ANIMATION} from '@taiga-ui/cdk';
import {TUI_PARENT_ANIMATION, TuiValuesOf} from '@taiga-ui/cdk';
import {TUI_EXPAND_LOADED} from '@taiga-ui/core/constants';

import {TuiExpandContentDirective} from './expand-content.directive';

enum State {
Idle,
Loading,
Prepared,
Animated,
}
const State = {
Idle: 0,
Loading: 1,
Prepared: 2,
Animated: 3,
} as const;

const LOADER_HEIGHT = 48;

Expand All @@ -37,7 +37,7 @@ export class TuiExpandComponent {
@ViewChild('wrapper')
private readonly contentWrapper?: ElementRef<HTMLDivElement>;

private state = State.Idle;
private state: TuiValuesOf<typeof State> = State.Idle;

@Input()
async = false;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class TuiExpandComponent {
}
}

private retrigger(state: State): void {
private retrigger(state: TuiValuesOf<typeof State>): void {
this.state = State.Prepared;

// We need delay to re-trigger CSS height transition from the correct number
Expand Down
12 changes: 6 additions & 6 deletions projects/demo/src/modules/components/filter/examples/4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {TuiAppearance} from '@taiga-ui/core';
import {BehaviorSubject, Observable} from 'rxjs';
import {map} from 'rxjs/operators';

enum Department {
IT = 'IT',
HR = 'HR',
HeadOffice = 'Heads',
Delivery = 'Delivery',
}
const Department = {
IT: 'IT',
HR: 'HR',
HeadOffice: 'Heads',
Delivery: 'Delivery',
} as const;

@Component({
selector: 'tui-filter-example-4',
Expand Down

0 comments on commit bee91e0

Please sign in to comment.