Frontend School

Dynamic Progress Bar Component

Machine Coding
medium

Dynamic Progress Bar Component

Medium
Frontend
React
UI
Progress Bar
State Management
Accessibility

Overview

Users are often guided through multi-step processes, such as profile setup wizards, file uploads, or complex form submissions. To enhance user experience and provide clear, immediate feedback, it's crucial to have a robust and visually informative progress bar component. This component will manage user expectations by clearly indicating the current completion status of a task, improving task engagement and reducing perceived wait times.

What you need to do / Task

Your task is to implement a ProgressBar React component that can dynamically display progress, an optional label, and an error state. You will then integrate this component into a simulated application flow within App.tsx.

  1. Create ProgressBar Component: Implement a functional React component named ProgressBar that accepts the following props:
    • progress: A number between 0 and 100, representing the completion percentage.
    • label (optional): A string to display alongside the percentage (e.g., "Uploading files", "Step 3/5").
    • isError (optional): A boolean indicating if the task is in an error state.
  2. Visual Representation: The component should visually represent the progress as a horizontal bar that fills from left to right.
  3. Dynamic Updates: Ensure the progress bar visually animates smoothly when its progress prop changes.
  4. Textual Display: Display the current percentage (e.g., "75%") and the optional label prominently.
  5. Error State: Implement a distinct visual style for when isError is true (e.g., change the bar color to red, display "Error" instead of percentage).
  6. Integration: Use your ProgressBar component in App.tsx to display the simulated task progress, label, and error states controlled by the provided buttons and manual input.

UI/UX expectations

  • The progress bar should be a clear horizontal element, filling visually from left to right based on the progress value.
  • The current percentage value (e.g., "50%") must be clearly visible, preferably centered or aligned within or above the bar.
  • If a label is provided, it should be displayed alongside the percentage (e.g., "Step 3/5: Processing... 60%").
  • Smooth Transitions: The visual filling of the bar should have a smooth animation (e.g., using CSS transition) when the progress value changes.
  • Error State: When isError is true, the bar should adopt a distinct visual style (e.g., a red background for the filled portion) and the textual display should clearly indicate an error (e.g., "Error").
  • Accessibility: The component should use appropriate ARIA attributes (e.g., role="progressbar", aria-valuenow, aria-valuemin, aria-valuemax, aria-label) to ensure it's accessible to screen readers.

Acceptance criteria

  • The ProgressBar component renders correctly with default progress (0).
  • The visual progress bar fills accurately from 0% to 100% as the progress prop changes.
  • The current percentage value is always displayed correctly.
  • The optional label is displayed when provided.
  • Progress updates animate smoothly, providing a fluid user experience.
  • When isError is true, the progress bar displays a distinct visual error state.
  • The component includes appropriate ARIA attributes for accessibility.

Constraints

Constraints & assumptions

  • You must use React functional components.
  • Do not use external UI component libraries (e.g., Material UI, Ant Design) for the progress bar itself; implement it using standard HTML, CSS, and React.
  • The progress prop will always be a number between 0 and 100 (inclusive).
  • Assume a modern browser environment.
  • The logic for simulating progress updates and managing the currentProgress, taskLabel, and isTaskError states is already provided in App.tsx; your focus is on the ProgressBar component and its integration.

Out of scope

  • Full-fledged application state management beyond useState and useEffect within App.tsx.
  • Advanced custom animation libraries or complex SVG-based progress visualizations.
  • Extensive error recovery mechanisms or complex backend API integrations.

What interviewers evaluate

  • Component Design: Correctness and robustness of the ProgressBar component implementation, including proper prop handling and state management.
  • UI/UX & Responsiveness: Attention to visual details, smooth transitions, and adherence to specified UI/UX expectations.
  • Accessibility: Proper use of ARIA attributes to ensure the component is usable by individuals with disabilities.
  • Code Quality: Clean, readable, and maintainable code structure, demonstrating idiomatic React practices and effective CSS application.

Loading editor...