|
| 1 | +import classNames from '~/lib/classNames' |
| 2 | +import { formatBytes } from '~/lib/util' |
| 3 | +import { IconAlertTriangle, IconServer } from '@tabler/icons-react' |
| 4 | + |
| 5 | +interface StorageProjectionBarProps { |
| 6 | + totalSize: number // Total disk size in bytes |
| 7 | + currentUsed: number // Currently used space in bytes |
| 8 | + projectedAddition: number // Additional space that will be used in bytes |
| 9 | +} |
| 10 | + |
| 11 | +export default function StorageProjectionBar({ |
| 12 | + totalSize, |
| 13 | + currentUsed, |
| 14 | + projectedAddition, |
| 15 | +}: StorageProjectionBarProps) { |
| 16 | + const projectedTotal = currentUsed + projectedAddition |
| 17 | + const currentPercent = (currentUsed / totalSize) * 100 |
| 18 | + const projectedPercent = (projectedAddition / totalSize) * 100 |
| 19 | + const projectedTotalPercent = (projectedTotal / totalSize) * 100 |
| 20 | + const remainingAfter = totalSize - projectedTotal |
| 21 | + const willExceed = projectedTotal > totalSize |
| 22 | + |
| 23 | + // Determine warning level based on projected total |
| 24 | + const getProjectedColor = () => { |
| 25 | + if (willExceed) return 'bg-desert-red' |
| 26 | + if (projectedTotalPercent >= 90) return 'bg-desert-orange' |
| 27 | + if (projectedTotalPercent >= 75) return 'bg-desert-tan' |
| 28 | + return 'bg-desert-olive' |
| 29 | + } |
| 30 | + |
| 31 | + const getProjectedGlow = () => { |
| 32 | + if (willExceed) return 'shadow-desert-red/50' |
| 33 | + if (projectedTotalPercent >= 90) return 'shadow-desert-orange/50' |
| 34 | + if (projectedTotalPercent >= 75) return 'shadow-desert-tan/50' |
| 35 | + return 'shadow-desert-olive/50' |
| 36 | + } |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className="bg-desert-stone-lighter/30 rounded-lg p-4 border border-desert-stone-light"> |
| 40 | + <div className="flex items-center justify-between mb-3"> |
| 41 | + <div className="flex items-center gap-2"> |
| 42 | + <IconServer size={20} className="text-desert-green" /> |
| 43 | + <span className="font-semibold text-desert-green">Storage</span> |
| 44 | + </div> |
| 45 | + <div className="text-sm text-desert-stone-dark font-mono"> |
| 46 | + {formatBytes(projectedTotal, 1)} / {formatBytes(totalSize, 1)} |
| 47 | + {projectedAddition > 0 && ( |
| 48 | + <span className="text-desert-stone ml-2"> |
| 49 | + (+{formatBytes(projectedAddition, 1)} selected) |
| 50 | + </span> |
| 51 | + )} |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + |
| 55 | + {/* Progress bar */} |
| 56 | + <div className="relative"> |
| 57 | + <div className="h-8 bg-desert-green-lighter/20 rounded-lg border border-desert-stone-light overflow-hidden"> |
| 58 | + {/* Current usage - darker/subdued */} |
| 59 | + <div |
| 60 | + className="absolute h-full bg-desert-stone transition-all duration-300" |
| 61 | + style={{ width: `${Math.min(currentPercent, 100)}%` }} |
| 62 | + /> |
| 63 | + {/* Projected addition - highlighted */} |
| 64 | + {projectedAddition > 0 && ( |
| 65 | + <div |
| 66 | + className={classNames( |
| 67 | + 'absolute h-full transition-all duration-300 shadow-lg', |
| 68 | + getProjectedColor(), |
| 69 | + getProjectedGlow() |
| 70 | + )} |
| 71 | + style={{ |
| 72 | + left: `${Math.min(currentPercent, 100)}%`, |
| 73 | + width: `${Math.min(projectedPercent, 100 - currentPercent)}%`, |
| 74 | + }} |
| 75 | + /> |
| 76 | + )} |
| 77 | + </div> |
| 78 | + |
| 79 | + {/* Percentage label */} |
| 80 | + <div |
| 81 | + className={classNames( |
| 82 | + 'absolute top-1/2 -translate-y-1/2 font-bold text-sm', |
| 83 | + projectedTotalPercent > 15 |
| 84 | + ? 'left-3 text-desert-white drop-shadow-md' |
| 85 | + : 'right-3 text-desert-green' |
| 86 | + )} |
| 87 | + > |
| 88 | + {Math.round(projectedTotalPercent)}% |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + |
| 92 | + {/* Legend and warnings */} |
| 93 | + <div className="flex items-center justify-between mt-3"> |
| 94 | + <div className="flex items-center gap-4 text-xs"> |
| 95 | + <div className="flex items-center gap-1.5"> |
| 96 | + <div className="w-3 h-3 rounded bg-desert-stone" /> |
| 97 | + <span className="text-desert-stone-dark">Current ({formatBytes(currentUsed, 1)})</span> |
| 98 | + </div> |
| 99 | + {projectedAddition > 0 && ( |
| 100 | + <div className="flex items-center gap-1.5"> |
| 101 | + <div className={classNames('w-3 h-3 rounded', getProjectedColor())} /> |
| 102 | + <span className="text-desert-stone-dark"> |
| 103 | + Selected (+{formatBytes(projectedAddition, 1)}) |
| 104 | + </span> |
| 105 | + </div> |
| 106 | + )} |
| 107 | + </div> |
| 108 | + |
| 109 | + {willExceed ? ( |
| 110 | + <div className="flex items-center gap-1.5 text-desert-red text-xs font-medium"> |
| 111 | + <IconAlertTriangle size={14} /> |
| 112 | + <span>Exceeds available space by {formatBytes(projectedTotal - totalSize, 1)}</span> |
| 113 | + </div> |
| 114 | + ) : ( |
| 115 | + <div className="text-xs text-desert-stone"> |
| 116 | + {formatBytes(remainingAfter, 1)} will remain free |
| 117 | + </div> |
| 118 | + )} |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + ) |
| 122 | +} |
0 commit comments