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

feat(kit): new tuiProgressFixedGradient for ProgressBar #9648

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -18,7 +18,9 @@ <h6 class="description">With fancy color gradient</h6>
<p>
Set component's input property
<code>color</code>
to get more complex color combinations.
to get more complex color combinations. Use directive
<code>tuiProgressFixedGradient</code>
to make gradient fixed.
nsbarsukov marked this conversation as resolved.
Show resolved Hide resolved
</p>

<progress
Expand All @@ -29,6 +31,15 @@ <h6 class="description">With fancy color gradient</h6>
[value]="fastValue$ | async"
></progress>

<progress
color="linear-gradient(to right, var(--tui-chart-categorical-02), var(--tui-chart-categorical-14), var(--tui-chart-categorical-12))"
max="100"
tuiProgressBar
tuiProgressFixedGradient
class="progress"
[value]="fastValue$ | async"
></progress>

<h6 class="description">Multicolor segments</h6>
<p>
Use
Expand Down
1 change: 1 addition & 0 deletions projects/kit/components/progress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './progress';
export * from './progress.options';
export * from './progress-bar/progress-bar.component';
export * from './progress-bar/progress-color-segments.directive';
export * from './progress-bar/progress-fixed-gradient.directive';
export * from './progress-circle/progress-circle.component';
export * from './progress-label/progress-label.component';
export * from './progress-segmented/progress-segmented.directive';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Directive, ElementRef, inject} from '@angular/core';

@Directive({
standalone: true,
selector: 'progress[tuiProgressBar][tuiProgressFixedGradient]',
host: {
'[style.--tui-progress-percent]': "progressPercent + '%'",
afferenslucem marked this conversation as resolved.
Show resolved Hide resolved
},
})
export class TuiProgressFixedGradientDirective {
private readonly nativeElement = inject(ElementRef<HTMLProgressElement>);

public get progressPercent(): number {
nsbarsukov marked this conversation as resolved.
Show resolved Hide resolved
const value = this.nativeElement.nativeElement.value;
const max = this.nativeElement.nativeElement.max;

if (!max) {
return 0;
}

return Math.min((value / max) * 100, 100);
nsbarsukov marked this conversation as resolved.
Show resolved Hide resolved
afferenslucem marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 2 additions & 0 deletions projects/kit/components/progress/progress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {TuiProgressBar} from './progress-bar/progress-bar.component';
import {TuiProgressColorSegments} from './progress-bar/progress-color-segments.directive';
import {TuiProgressFixedGradientDirective} from './progress-bar/progress-fixed-gradient.directive';
import {TuiProgressCircle} from './progress-circle/progress-circle.component';
import {TuiProgressLabel} from './progress-label/progress-label.component';
import {TuiProgressSegmented} from './progress-segmented/progress-segmented.directive';
Expand All @@ -8,6 +9,7 @@ export const TuiProgress = [
TuiProgressBar,
TuiProgressCircle,
TuiProgressColorSegments,
TuiProgressFixedGradientDirective,
TuiProgressLabel,
TuiProgressSegmented,
] as const;
11 changes: 11 additions & 0 deletions projects/kit/styles/components/progress-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
border-radius: inherit;
}

&[tuiProgressFixedGradient] {
afferenslucem marked this conversation as resolved.
Show resolved Hide resolved
.progressValue({
border-radius: inherit;
nsbarsukov marked this conversation as resolved.
Show resolved Hide resolved
width: 100% !important;
afferenslucem marked this conversation as resolved.
Show resolved Hide resolved

clip-path: inset(0 calc(100% - var(--tui-progress-percent)) 0 0 round var(--tui-radius-m));

transition: clip-path var(--tui-duration) linear;
});
}

&::-webkit-progress-bar {
background: transparent;
border-radius: inherit;
Expand Down
Loading