Frontendx
README.md
SOLUTION.md
main.tsxentry
App.tsx
App.css
index.html
vite.config.ts
Installed
react@^19.2.0
react-dom@^19.2.0

Poll Widget

harduireactstate-managementcomponentUberMetaGoogleUI Component

Description

Build a poll widget for a live product survey. Show a question and a list of options. Every option must display its current vote count, percentage, and a progress bar whose width represents its share of the total votes.

A user chooses an option and clicks Join Poll to add one vote to that option. After voting, replace Join Poll with Withdraw. Clicking Withdraw removes the user's vote from the selected option and restores the Join Poll action. Percentages and progress bars must update immediately after either action.

Organize the implementation into small reusable components such as Option, ProgressBar, and Button. Keep the vote counts, selected option, total, percentages, and widths derived from React state rather than hard-coded values.

Example 1

Question: Which frontend tool do you use most?
Options: React, Vue, Svelte
Choose React and click Join Poll. React gains one vote and the button changes to Withdraw.

Example 2

Click Withdraw. The selected option loses one vote, its progress bar shrinks, and Join Poll is shown again.

Constraints

  • Render at least three poll options.
  • A user can have at most one active vote.
  • The total is the sum of all option vote counts.
  • A progress bar width is the option vote count divided by the total, expressed as a percentage.
  • Handle a zero-vote total without producing NaN or an invalid CSS width.
  • The interface must expose an accessible question heading, option controls, and action buttons.
Keep the selected option in state and derive the total from the option counts.
Test Results

Poll Widget

Build a poll widget with live progress bars, vote and withdraw actions, and dynamic styling.