Skip to content

Commit

Permalink
feat(kit): Progress add options with DI (#8065)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy authored Jul 10, 2024
1 parent d39b76e commit e00cd8c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
8 changes: 7 additions & 1 deletion projects/experimental/directives/cell/cell.styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}

[tuiSubtitle] {
font: var(--tui-font-text-xs-s);
font: var(--tui-font-text-xs-2);
}

& > *:not(:first-child),
Expand All @@ -93,6 +93,9 @@
& > [tuiAccessories] tui-avatar,
& > [tuiAccessories] tui-avatar-stack tui-avatar {
--t-size: 1.5rem;

font: var(--tui-font-text-m);
font-size: 0.5625rem;
}
}

Expand Down Expand Up @@ -136,6 +139,9 @@
& > [tuiAccessories] tui-avatar,
& > [tuiAccessories] tui-avatar-stack tui-avatar {
--t-size: 2.5rem;

font: var(--tui-font-text-m);
font-weight: bold;
}
}

Expand Down
1 change: 1 addition & 0 deletions projects/kit/components/progress/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './progress.module';
export * from './progress.options';
export * from './progress-bar/progress-bar.component';
export * from './progress-bar/progress-color-segments.directive';
export * from './progress-circle/progress-circle.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
--tui-clear: var(--tui-clear-inverse);
}

&[data-size='xxs'] {
--t-height: 0.125rem;
}

&[data-size='m'] {
--t-height: 1.5rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
MODE_PROVIDER,
TUI_MODE,
TuiBrightness,
TuiSizeXS,
TuiSizeXXL,
TuiSizeXXS,
} from '@taiga-ui/core';
import {Observable} from 'rxjs';

import {TUI_PROGRESS_OPTIONS, TuiProgressOptions} from '../progress.options';

@Component({
selector: 'progress[tuiProgressBar]',
template: '',
Expand All @@ -27,11 +29,15 @@ import {Observable} from 'rxjs';
export class TuiProgressBarComponent {
@Input()
@HostBinding('style.--tui-progress-color')
color?: string;
color: string | null = this.options.color;

@Input()
@HostBinding('attr.data-size')
size: TuiSizeXS | TuiSizeXXL = 'm';
size: TuiSizeXXL | TuiSizeXXS = this.options.size;

constructor(@Inject(TUI_MODE) readonly mode$: Observable<TuiBrightness | null>) {}
constructor(
@Inject(TUI_MODE) readonly mode$: Observable<TuiBrightness | null>,
@Inject(TUI_PROGRESS_OPTIONS)
private readonly options: TuiProgressOptions,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import {Observable, of} from 'rxjs';
import {delay} from 'rxjs/operators';

import {TUI_PROGRESS_OPTIONS, TuiProgressOptions} from '../progress.options';

@Component({
selector: 'tui-progress-circle',
templateUrl: './progress-circle.template.html',
Expand All @@ -41,11 +43,11 @@ export class TuiProgressCircleComponent {

@Input()
@HostBinding('style.--tui-progress-color')
color: string | null = null;
color: string | null = this.options.color;

@Input()
@HostBinding('attr.data-size')
size: TuiSizeXXL | TuiSizeXXS = 'm';
size: TuiSizeXXL | TuiSizeXXS = this.options.size;

readonly animationDelay$ = of(true).pipe(delay(0));

Expand All @@ -54,6 +56,8 @@ export class TuiProgressCircleComponent {
@Inject(WINDOW) private readonly win: Window,
@Inject(ElementRef) private readonly el: ElementRef<HTMLElement>,
@Inject(TUI_MODE) readonly mode$: Observable<TuiBrightness | null>,
@Inject(TUI_PROGRESS_OPTIONS)
private readonly options: TuiProgressOptions,
) {}

@HostBinding('style.--progress-ratio')
Expand Down
21 changes: 21 additions & 0 deletions projects/kit/components/progress/progress.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type {Provider} from '@angular/core';
import {tuiCreateToken, tuiProvideOptions} from '@taiga-ui/cdk';
import type {TuiSizeXXL, TuiSizeXXS} from '@taiga-ui/core';

export interface TuiProgressOptions {
readonly color: string | null;
readonly size: TuiSizeXXL | TuiSizeXXS;
}

export const TUI_PROGRESS_DEFAULT_OPTIONS: TuiProgressOptions = {
color: null,
size: 'm',
};

export const TUI_PROGRESS_OPTIONS = tuiCreateToken(TUI_PROGRESS_DEFAULT_OPTIONS);

export function tuiProgressOptionsProvider(
options: Partial<TuiProgressOptions>,
): Provider {
return tuiProvideOptions(TUI_PROGRESS_OPTIONS, options, TUI_PROGRESS_DEFAULT_OPTIONS);
}

0 comments on commit e00cd8c

Please sign in to comment.