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

fix: Fixed display of 0% inside label in progress bar #326

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -5,6 +5,15 @@
label-progress
size="lg"
/>

<div class="mb-4" />

<fwb-progress
:progress="0"
label-position="inside"
label-progress
size="lg"
/>
</template>

<script setup>
Expand Down
13 changes: 9 additions & 4 deletions src/components/FwbProgress/FwbProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
>
<div
:class="innerClasses"
:style="{ width: progress + '%' }"
class="rounded-full font-medium text-blue-100 text-center p-0.5"
:style="{ width: safeProgress + '%' }"
class="rounded-full font-medium text-blue-100 text-center p-0.5 min-w-max box-border"
>
<template v-if="labelProgress && labelPosition === 'inside'">
{{ progress }}%
Expand All @@ -31,8 +31,8 @@
</template>

<script lang="ts" setup>
import { toRefs } from 'vue'
import { useProgressClasses } from './composables/useProgressClasses'
import { computed, toRefs } from 'vue'
import { progressSafeSizes, useProgressClasses } from './composables/useProgressClasses'
import type { ProgressLabelPosition, ProgressSize, ProgressVariant } from './types'

interface IProgressProps {
Expand All @@ -53,6 +53,11 @@ const props = withDefaults(defineProps<IProgressProps>(), {
size: 'md',
})

const safeProgress = computed(() => {
const size = progressSafeSizes[props.size]
return props.progress <= size ? size : props.progress
})

const {
innerClasses,
outerClasses,
Expand Down
7 changes: 7 additions & 0 deletions src/components/FwbProgress/composables/useProgressClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const progressSizeClasses: Record<ProgressSize, string> = {
xl: 'h-6 text-base leading-tight',
}

export const progressSafeSizes: Record<ProgressSize, number> = {
sm: 1,
md: 2,
lg: 3,
xl: 4,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Action Required: progressSafeSizes is currently not utilized in the codebase.

The progressSafeSizes constant is exported in useProgressClasses.ts but is not referenced in any other files. Please verify if this constant is intended for future implementations. If it is not needed, consider removing it to keep the codebase clean and maintainable.

🔗 Analysis chain

LGTM! New constant added for progress bar size mapping.

The new progressSafeSizes constant appears to be related to the PR objective of fixing the display of small values in progress bars. It provides a numeric mapping for each progress bar size, which could be useful for determining minimum width or visibility thresholds for labels.

To ensure this constant is being utilized as intended, please run the following script to check its usage across the codebase:

If the constant is not used anywhere, consider adding a TODO comment to implement its usage or remove it if it's no longer needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of progressSafeSizes in other files

# Test: Search for progressSafeSizes usage
rg --type typescript -A 5 'progressSafeSizes'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the usage of progressSafeSizes in TypeScript files by searching .ts and .tsx extensions

# Test: Search for progressSafeSizes usage in .ts and .tsx files
rg -A 5 'progressSafeSizes' --type-add 'custom_ts:(**/*.ts|**/*.tsx)' --type custom_ts

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the usage of progressSafeSizes in TypeScript files by searching .ts and .tsx extensions

# Test: Search for progressSafeSizes usage in .ts and .tsx files
rg 'progressSafeSizes' -g '*.ts' -g '*.tsx' -A 5

Length of output: 517


export type UseProgressClassesProps = {
color: Ref<ProgressVariant>
size: Ref<ProgressSize>
Expand Down
Loading