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(ui): add interminate state for CoreProgressBar - WF-152 #713

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all 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
45 changes: 38 additions & 7 deletions src/ui/src/components/core/content/CoreProgressBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
class="CoreProgressBar"
:class="{ 'CoreProgressBar--clickable': isClickable }"
role="progressbar"
:aria-valuetext="progressionText"
:aria-valuetext="progression === undefined ? null : progressionText"
:aria-valuemin="min"
:aria-valuemax="max"
:aria-valuenow="value"
:aria-valuenow="progression === undefined ? null : value"
:aria-busy="progression < 1 || progression === undefined"
:tabindex="isClickable ? '0' : null"
@keydown.enter="handleClick"
@click="handleClick"
Expand All @@ -25,6 +26,10 @@
<div class="CoreProgressBar__bar">
<div
class="CoreProgressBar__bar__value"
:class="{
'CoreProgressBar__bar__value--indeterminate':
progression === undefined,
}"
:style="progressValueStyle"
></div>
</div>
Expand Down Expand Up @@ -64,7 +69,6 @@ const definition: WriterComponentDefinition = {
value: {
name: "Value",
type: FieldType.Number,
default: "0.25",
},
min: {
name: "Minimum value",
Expand Down Expand Up @@ -120,14 +124,20 @@ const min = computed(() => Number(fields.min.value));
const max = computed(() => Number(fields.max.value));
const displayPercentage = useFieldValueAsYesNo(fields, "displayPercentage");

const progression = computed(
() => (value.value - min.value) / (max.value - min.value),
);
const progression = computed<number | undefined>(() => {
if (value.value === undefined || Number.isNaN(value.value)) {
return undefined;
}
return (value.value - min.value) / (max.value - min.value);
});

const progressionText = usePercentageFormatter(progression);

const progressValueStyle = computed<CSSProperties>(() => ({
width: `${progression.value * 100}%`,
width:
progression.value === undefined
? undefined
: `${progression.value * 100}%`,
}));

const isClickable = computed(() => {
Expand Down Expand Up @@ -185,4 +195,25 @@ function handleClick(ev: MouseEvent | KeyboardEvent) {
.CoreProgressBar__title__progress {
text-align: right;
}

.CoreProgressBar__bar__value--indeterminate {
position: absolute;
animation: indeterminateAnimation 2s ease-in-out infinite;
width: 25%;
}

@keyframes indeterminateAnimation {
0% {
left: -25%;
right: 100%;
}
60% {
left: 100%;
right: -25%;
}
100% {
left: 100%;
right: -25%;
}
}
</style>
Loading