fix: correct bar dragging behavior and remove duplicate value display

Fixed two issues with draggable bars:

1. Bar length now updates correctly during drag:
   - Convert dragged unit value back to the selected unit
   - Update input value with converted amount
   - Keep selectedUnit unchanged (user still inputting in same unit)
   - Disable transitions on ALL bars while ANY bar is dragging
   - This makes bars resize smoothly and correctly as you drag

2. Removed duplicate value display from bars:
   - Value is already shown above each bar
   - Removed redundant value display from inside the colored segment
   - Keeps only the percentage indicator inside bars
   - Cleaner, less cluttered visual design

The dragging now works intuitively: dragging any bar adjusts the input
value (in the currently selected unit) to match the dragged bar's value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-08 10:45:50 +01:00
parent bc71768d6a
commit bb1b4c5d29
2 changed files with 7 additions and 13 deletions

View File

@@ -125,9 +125,11 @@ export default function MainConverter() {
// Handle value change from draggable bars // Handle value change from draggable bars
const handleValueChange = useCallback((value: number, unit: string) => { const handleValueChange = useCallback((value: number, unit: string) => {
setInputValue(value.toString()); // Convert the dragged unit's value back to the currently selected unit
setSelectedUnit(unit); const convertedValue = convertUnit(value, unit, selectedUnit);
}, []); setInputValue(convertedValue.toString());
// Keep selectedUnit the same - user is still inputting in that unit
}, [selectedUnit]);
return ( return (
<div className="w-full max-w-6xl mx-auto space-y-6"> <div className="w-full max-w-6xl mx-auto space-y-6">

View File

@@ -227,7 +227,7 @@ export default function VisualComparison({
<div <div
className={cn( className={cn(
"absolute inset-y-0 left-0", "absolute inset-y-0 left-0",
isDragging ? "transition-none" : "transition-all duration-500 ease-out" draggingUnit ? "transition-none" : "transition-all duration-500 ease-out"
)} )}
style={{ style={{
width: `${item.percentage}%`, width: `${item.percentage}%`,
@@ -235,18 +235,10 @@ export default function VisualComparison({
}} }}
/> />
{/* Percentage label overlay */} {/* Percentage label overlay */}
<div className="absolute inset-0 flex items-center justify-between px-3 text-xs font-bold pointer-events-none"> <div className="absolute inset-0 flex items-center px-3 text-xs font-bold pointer-events-none">
<span className="text-foreground drop-shadow-sm"> <span className="text-foreground drop-shadow-sm">
{Math.round(item.percentage)}% {Math.round(item.percentage)}%
</span> </span>
<span
className="tabular-nums drop-shadow-sm"
style={{
color: item.percentage > 30 ? 'white' : 'var(--foreground)',
}}
>
{item.percentage > 30 && formatNumber(item.value)}
</span>
</div> </div>
{/* Drag hint on hover */} {/* Drag hint on hover */}