Skip to content

Commit b22be12

Browse files
committed
feat(progress-bar): Add community progress bar #299
1 parent a50389b commit b22be12

4 files changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<progress
2+
class="tedi-progress__bar"
3+
[id]="progressId()"
4+
[max]="100"
5+
[value]="value()"
6+
[attr.aria-describedby]="feedbackTextId()"
7+
></progress>
8+
9+
<span tedi-label size="small" class="tedi-progress__indicator"
10+
>{{ value() }}%</span
11+
>
12+
13+
@if (feedbackText(); as feedback) {
14+
<tedi-feedback-text
15+
[attr.id]="feedbackTextId()"
16+
[text]="feedback.text"
17+
[type]="feedback.type"
18+
[position]="feedback.position"
19+
/>
20+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@use "@tedi-design-system/core/bootstrap-utility/breakpoints";
2+
3+
.tedi-progress {
4+
--_bar-height: var(--progress-bar-height, 8px);
5+
--_bar-radius: var(--progress-bar-radius, 4px);
6+
--_bar-background: var(--progress-bar-background-passive, #f9f9f9);
7+
--_bar-border: var(--progress-bar-border-default, #838494);
8+
--_progress-background: var(--progress-bar-background-active, #005aa3);
9+
10+
display: grid;
11+
grid-template-areas: "bar bar" ". indicator";
12+
grid-template-rows: 24px;
13+
grid-template-columns: 1fr auto;
14+
column-gap: var(--layout-grid-gutters-08, 8px);
15+
16+
&__bar {
17+
-webkit-appearance: none;
18+
-moz-appearance: none;
19+
appearance: none;
20+
grid-area: bar;
21+
height: var(--_bar-height);
22+
border-radius: var(--_bar-radius);
23+
border: 1px solid var(--_bar-border);
24+
width: 100%;
25+
align-self: center;
26+
27+
&::-webkit-progress-bar {
28+
background: var(--_bar-background);
29+
border-radius: var(--_bar-radius);
30+
}
31+
32+
&::-webkit-progress-value {
33+
background: var(--_progress-background);
34+
border-radius: var(--_bar-radius);
35+
}
36+
37+
&::-moz-progress-bar {
38+
background: var(--_progress-background);
39+
border-radius: var(--_bar-radius);
40+
}
41+
}
42+
43+
&__indicator {
44+
grid-area: indicator;
45+
}
46+
47+
&--small {
48+
--_bar-height: var(--progress-bar-height-sm, 4px);
49+
}
50+
51+
&--horizontal {
52+
@include breakpoints.media-breakpoint-up(sm) {
53+
grid-template-areas: "bar indicator";
54+
}
55+
}
56+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { booleanAttribute, ChangeDetectionStrategy, Component, computed, input, ViewEncapsulation } from "@angular/core";
2+
import { ComponentInputs, FeedbackTextComponent, generateUUID, LabelComponent } from "@tedi-design-system/angular/tedi";
3+
4+
@Component({
5+
selector: "tedi-progress-bar",
6+
imports: [FeedbackTextComponent, LabelComponent],
7+
templateUrl: "./progress-bar.component.html",
8+
styleUrl: "./progress-bar.component.scss",
9+
changeDetection: ChangeDetectionStrategy.OnPush,
10+
encapsulation: ViewEncapsulation.None,
11+
host: {
12+
"[class.tedi-progress]": "true",
13+
"[class.tedi-progress--small]": "small()",
14+
"[class.tedi-progress--horizontal]": "direction() === 'horizontal'",
15+
},
16+
})
17+
export class ProgressBarComponent {
18+
progressId = input<string>();
19+
value = input<number>(0);
20+
direction = input<'horizontal' | 'vertical'>("horizontal");
21+
small = input(false, { transform: booleanAttribute });
22+
feedbackText = input<ComponentInputs<FeedbackTextComponent>>();
23+
24+
feedbackTextId = computed(() => {
25+
if (this.feedbackText()) {
26+
return generateUUID();
27+
}
28+
return;
29+
});
30+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { Meta, moduleMetadata, StoryObj } from "@storybook/angular";
2+
import { ProgressBarComponent } from "./progress-bar.component";
3+
4+
export default {
5+
title: "Community/Helpers/ProgressBar",
6+
component: ProgressBarComponent,
7+
decorators: [
8+
moduleMetadata({
9+
imports: [ProgressBarComponent],
10+
}),
11+
],
12+
argTypes: {
13+
progressId: {
14+
description:
15+
"Optional id for the progress element to bind with label etc.",
16+
control: "text",
17+
table: {
18+
type: { summary: "string" },
19+
},
20+
},
21+
value: {
22+
description: "Progress value between 0 and 100",
23+
control: { type: "number", min: 0, max: 100, step: 1 },
24+
table: {
25+
type: { summary: "number" },
26+
defaultValue: { summary: "0" },
27+
},
28+
},
29+
direction: {
30+
description: "Orientation of the progress bar",
31+
control: { type: "radio" },
32+
options: ["horizontal", "vertical"],
33+
table: {
34+
type: { summary: "'horizontal' | 'vertical'" },
35+
defaultValue: { summary: "horizontal" },
36+
},
37+
},
38+
small: {
39+
description: "Whether it's the small variant",
40+
control: "boolean",
41+
table: {
42+
type: { summary: "boolean" },
43+
defaultValue: { summary: "false" },
44+
},
45+
},
46+
feedbackText: {
47+
description:
48+
"Optional feedback text displayed alongside the progress bar. Accepts `FeedbackTextComponent` inputs.",
49+
control: "object",
50+
table: {
51+
type: { summary: "ComponentInputs<FeedbackTextComponent>" },
52+
},
53+
},
54+
},
55+
} as Meta<ProgressBarComponent>;
56+
57+
export const Default: StoryObj<ProgressBarComponent> = {
58+
args: {
59+
value: 50,
60+
direction: "horizontal",
61+
small: false,
62+
},
63+
};
64+
65+
export const Small: StoryObj<ProgressBarComponent> = {
66+
args: {
67+
value: 50,
68+
direction: "horizontal",
69+
small: true,
70+
},
71+
};
72+
73+
export const WithFeedback: StoryObj<ProgressBarComponent> = {
74+
args: {
75+
value: 50,
76+
feedbackText: { text: "Uploading…", type: "hint", position: "left" },
77+
},
78+
};
79+
80+
export const Vertical: StoryObj<ProgressBarComponent> = {
81+
args: {
82+
value: 50,
83+
feedbackText: { text: "Uploading…", type: "hint", position: "left" },
84+
direction: "vertical",
85+
},
86+
};

0 commit comments

Comments
 (0)