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 4 commits into
base: main
Choose a base branch
from

Conversation

andreyjamer
Copy link
Contributor

@andreyjamer andreyjamer commented Sep 30, 2024

There is a bug with progress bar for small values. When the bar is too small, then the inside label is almost invisible.

Summary by CodeRabbit

  • New Features

    • Enhanced progress bar component with improved progress value handling
    • Added new progress bar examples with different progress states (0% and 50%)
  • Documentation

    • Updated example components to demonstrate progress bar variations with inside and outside label positions

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The pull request introduces enhancements to the Flowbite Vue 3 Progress component. The changes include adding a new computed property safeProgress in the FwbProgress.vue component to manage progress bar display and width, and updating example files to demonstrate the component with additional progress bar instances. The modifications focus on improving the component's rendering and providing more comprehensive usage examples.

Changes

File Change Summary
docs/components/progress/examples/FwbProgressExampleLabelInside.vue Added a second <fwb-progress> component with progress value of 0
docs/components/progress/examples/FwbProgressExampleLabelOutside.vue Added a second <fwb-progress> component with progress value of 0 and a spacing <div>
src/components/FwbProgress/FwbProgress.vue Added safeProgress and displayBar computed properties, introduced progressSafeSizes constant

Sequence Diagram

sequenceDiagram
    participant Component as FwbProgress
    participant Props as Progress Props
    participant Computed as Computed Properties
    
    Props->>Computed: Input progress value
    Computed->>Computed: Calculate safeProgress
    Computed->>Computed: Determine displayBar
    Computed-->>Component: Render progress bar
Loading

Poem

🐰 Hop along the progress bar's track,
Where zeros and fifties now interact!
Computed magic, a rabbit's delight,
Sizing progress with pixel-perfect might.
Vue components dance, so sleek and so bright! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 707bc93 and 2976b07.

📒 Files selected for processing (2)
  • docs/components/progress/examples/FwbProgressExampleLabelOutside.vue (1 hunks)
  • src/components/FwbProgress/FwbProgress.vue (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/FwbProgress/FwbProgress.vue
🔇 Additional comments (2)
docs/components/progress/examples/FwbProgressExampleLabelOutside.vue (2)

9-9: LGTM! Good spacing practice.

The added margin improves visual separation between progress bars in the example.


11-16: Verify if this example is necessary for the PR objective.

While adding an example with 0% progress is good for documentation completeness, the PR objective specifically mentions fixing the visibility of 0% inside labels. Since this example uses label-position="outside", it might not directly demonstrate the fix for the reported issue.

Let's verify if there's a corresponding example with label-position="inside":

✅ Verification successful

The example is valuable for documentation completeness

While this example with label-position="outside" isn't strictly necessary for demonstrating the 0% inside label fix, it provides valuable comparison alongside the existing inside label example (FwbProgressExampleLabelInside.vue). Having both examples helps users understand the difference between label positions at 0% progress.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there's a corresponding example with inside label position
# that demonstrates the fix for 0% label visibility

# Look for progress component examples with inside label position
rg -l "label-position=\"inside\"" docs/components/progress/examples/

Length of output: 136


Script:

#!/bin/bash
# Check the content of the inside label example
cat docs/components/progress/examples/FwbProgressExampleLabelInside.vue

Length of output: 400

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Sep 30, 2024

Deploy Preview for sensational-seahorse-8635f8 ready!

Name Link
🔨 Latest commit 2976b07
🔍 Latest deploy log https://app.netlify.com/sites/sensational-seahorse-8635f8/deploys/677f877b74f62b00085d86b9
😎 Deploy Preview https://deploy-preview-326--sensational-seahorse-8635f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
src/components/FwbProgress/FwbProgress.vue (1)

56-59: Effective implementation of safeProgress computed property.

The safeProgress computed property is a great solution to ensure minimum visibility for small progress values. It cleverly uses the progressSafeSizes object to determine a minimum size based on the component's size prop.

This implementation effectively addresses the PR's main objective of fixing the display of small percentages in the progress bar.

Consider adding a brief comment explaining the purpose of progressSafeSizes and what values it contains. This would enhance code maintainability. For example:

// progressSafeSizes contains minimum percentage values for each size variant
// to ensure visibility of small progress values
const safeProgress = computed(() => {
  const size = progressSafeSizes[props.size]
  return props.progress <= size ? size : props.progress
})
src/components/FwbProgress/composables/useProgressClasses.ts (1)

Line range hint 1-67: Consider additional changes to address small value visibility

While the new progressSafeSizes constant is a step in the right direction, the current implementation doesn't seem to directly address the issue of displaying small values (like 0%) in progress bars. Consider the following suggestions:

  1. Implement a minimum width for the colored portion of the progress bar when the value is greater than 0% but very small.
  2. Add a class to ensure the label remains visible even when the progress bar is small.

Here's a potential implementation to consider:

// Add this function to handle minimum width
function getProgressWidth(value: number): string {
  return value > 0 && value < 1 ? '1%' : `${value}%`;
}

// Modify the useProgressClasses function to include this logic
export function useProgressClasses(props: UseProgressClassesProps) {
  // ... existing code ...

  const progressWidth = computed(() => getProgressWidth(props.value.value));
  
  const bindClasses = computed(() => {
    return classNames(
      barColorClasses[props.color.value],
      progressSizeClasses[props.size.value],
      'min-w-[1.5em]', // Ensures a minimum width for label visibility
    )
  })

  // ... rest of the function ...

  return {
    innerClasses: bindClasses,
    outerClasses,
    outsideLabelClasses,
    progressWidth,
  }
}

This suggestion ensures that:

  1. The progress bar always has a minimum width to display the label.
  2. For very small non-zero values, the progress bar will still be visible.

Please adjust the implementation as needed to fit your specific requirements and component structure.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 846f6f6 and 707bc93.

📒 Files selected for processing (3)
  • docs/components/progress/examples/FwbProgressExampleLabelInside.vue (1 hunks)
  • src/components/FwbProgress/FwbProgress.vue (3 hunks)
  • src/components/FwbProgress/composables/useProgressClasses.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/components/progress/examples/FwbProgressExampleLabelInside.vue
🔇 Additional comments (2)
src/components/FwbProgress/FwbProgress.vue (2)

22-23: Excellent changes to improve small progress value visibility!

The modifications in these lines effectively address the issue of displaying small progress values:

  1. Using safeProgress instead of progress for the width ensures a minimum visible width for the progress bar.
  2. Adding the min-w-max class guarantees that the inner div will always be wide enough to display its content, solving the problem of the "0%" label being nearly invisible.

These changes align perfectly with the PR objective of fixing the display of small percentages in the progress bar.


34-34: Correct import for computed property.

Good job importing the computed function from Vue. This is necessary for defining the safeProgress computed property and follows the best practice of importing only the required functions.

Comment on lines 34 to 39
export const progressSafeSizes: Record<ProgressSize, number> = {
sm: 1,
md: 2,
lg: 3,
xl: 4,
}
Copy link
Contributor

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

@Sqrcz Sqrcz self-assigned this Dec 6, 2024
Copy link
Collaborator

@Sqrcz Sqrcz left a comment

Choose a reason for hiding this comment

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

Hey,

This is clearly something that we need to fix ;)

But... If you tak a look at Flowbite's Progress Bar component... i think it shows smal percents a little better (you'll have to change style to width: 0% to see it):
image

Compared to what we have with your fix... it doesn't look like 0%:
image

@andreyjamer
Please let me know if you can make it look like the Figma component? (it's the source of truth in terms of the design for us here)

And Happy New Year! 🎉

@andreyjamer
Copy link
Contributor Author

Hey!
I guess, I was not clear in my explanation of the fix. The current display of small percents is actually the problem.
It looks nice only in dark theme.
image
But, there is an issue with rounded corners. You see, the left side is not rounded anymore.
And this is how it looks for light theme:
image
The value is not visible at all. And the same problem with rounded corners.

Another case is the progress bar with label outside the bar. In current implementation it loses the rounded corners on the left
image

In my fix, the bar always has a minimum width for the particular size, so the left part is always rounded. And the bar is not displayed if the value is 0 and the label is outside.

@Sqrcz
Copy link
Collaborator

Sqrcz commented Jan 9, 2025

Hmm... it clears a lot now ;)

It looks more like Flowbite problem in general... especially the light theme. I think we should move this issue there.

I've created new Issue here: themesberg/flowbite#1016 you can comment/upvote if you want ;)

Let's wait with this for the response there (we don't want to go ahead of the Flowbite's main repo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants