Skip to content

Commit

Permalink
feat(cdk): add TuiSuggestiveString
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Sep 17, 2024
1 parent 58cd205 commit c856a41
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions projects/cdk/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './mapper';
export * from './matcher';
export * from './rounding';
export * from './safe-html';
export * from './suggestive-string';
export * from './values-of';
3 changes: 3 additions & 0 deletions projects/cdk/types/suggestive-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type FallbackString<T extends string> = Omit<string, T>;

export type TuiSuggestiveString<T extends string> = FallbackString<T> | T;
5 changes: 3 additions & 2 deletions projects/core/directives/appearance/appearance.options.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type {ExistingProvider, ProviderToken} from '@angular/core';
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';
import {tuiCreateToken, tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous';

/**
* Bundled appearances for autocomplete purposes, not exported on purpose
*/
type Appearance =
type Appearance = TuiSuggestiveString<
| 'accent'
| 'destructive'
| 'error'
Expand All @@ -22,7 +23,7 @@ type Appearance =
| 'textfield'
| 'warning'
| 'whiteblock'
| (Record<never, never> & string);
>;

export interface TuiAppearanceOptions {
readonly appearance: Appearance;
Expand Down
19 changes: 7 additions & 12 deletions projects/core/pipes/flag/flag.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import type {PipeTransform} from '@angular/core';
import {inject, Pipe} from '@angular/core';
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';
import {TUI_ASSETS_PATH} from '@taiga-ui/core/tokens';
import type {TuiCountryIsoCode} from '@taiga-ui/i18n/types';

type IsoCode = TuiSuggestiveString<TuiCountryIsoCode>;

@Pipe({
standalone: true,
name: 'tuiFlag',
})
export class TuiFlagPipe implements PipeTransform {
private readonly staticPath = inject(TUI_ASSETS_PATH);

public transform(
countryIsoCode: TuiCountryIsoCode | (Record<never, never> & string),
): string;
public transform(
countryIsoCode: TuiCountryIsoCode | (Record<never, never> & string) | undefined,
): string | null;
public transform(
countryIsoCode?: TuiCountryIsoCode | (Record<never, never> & string) | null,
): string | null;
public transform(
countryIsoCode?: TuiCountryIsoCode | (Record<never, never> & string) | null,
): string | null {
public transform(countryIsoCode: IsoCode): string;
public transform(countryIsoCode: IsoCode | undefined): string | null;
public transform(countryIsoCode?: IsoCode | null): string | null;
public transform(countryIsoCode?: IsoCode | null): string | null {
if (!countryIsoCode) {
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions projects/i18n/types/language-names.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type TuiLanguageName =
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';

export type TuiLanguageName = TuiSuggestiveString<
| 'belarusian'
| 'chinese'
| 'dutch'
Expand All @@ -18,4 +20,4 @@ export type TuiLanguageName =
| 'turkish'
| 'ukrainian'
| 'vietnamese'
| (Record<never, never> & string);
>;
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Directive, Input} from '@angular/core';
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';

@Directive({
standalone: true,
selector: '[tuiSlot]',
})
export class TuiBadgedContentDirective {
@Input()
public tuiSlot: 'bottom' | 'top' | (Record<never, never> & string) = 'top';
public tuiSlot: TuiSuggestiveString<'bottom' | 'top'> = 'top';
}
3 changes: 2 additions & 1 deletion projects/layout/components/app-bar/app-bar.directive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Directive, Input} from '@angular/core';
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';

@Directive({
standalone: true,
selector: '[tuiSlot]',
})
export class TuiAppBarDirective {
@Input()
public tuiSlot: 'left' | 'right' | (Record<never, never> & string) = 'left';
public tuiSlot: TuiSuggestiveString<'left' | 'right'> = 'left';
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Directive, Input} from '@angular/core';
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';

@Directive({
standalone: true,
selector: '[tuiSlot]',
})
export class TuiBlockStatusDirective {
@Input()
public tuiSlot: 'action' | 'top' | (Record<never, never> & string) = 'top';
public tuiSlot: TuiSuggestiveString<'action' | 'top'> = 'top';
}
6 changes: 2 additions & 4 deletions projects/legacy/directives/wrapper/wrapper.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Directive, Input} from '@angular/core';
import type {TuiSuggestiveString} from '@taiga-ui/cdk/types';
import type {TuiInteractiveState} from '@taiga-ui/core/types';

/**
Expand Down Expand Up @@ -46,10 +47,7 @@ export class TuiWrapperDirective {
return this.focus && !this.disabled;
}

protected get interactiveState():
| TuiInteractiveState
| (Record<never, never> & string)
| null {
protected get interactiveState(): TuiSuggestiveString<TuiInteractiveState> | null {
if (this.disabled) {
return 'disabled';
}
Expand Down

0 comments on commit c856a41

Please sign in to comment.