Line data Source code
1 : type ProgressPercent = number | undefined
2 :
3 2355 : const progressBarContainerClass = 'absolute inset-0'
4 2355 : const progressBarBaseClass =
5 : 'pointer-events-none absolute inset-y-0 left-0 h-full transition-[width]'
6 2355 : const progressBarPrimaryClass = `${progressBarBaseClass} bg-primary/30`
7 2355 : const progressBarSecondaryClass = `${progressBarBaseClass} bg-primary/15`
8 :
9 0 : function clampPercent(value: number) {
10 0 : return Math.min(100, Math.max(0, value))
11 : }
12 :
13 166 : function normalizeProgressPercent(value: ProgressPercent) {
14 166 : if (value === undefined || !Number.isFinite(value)) return undefined
15 :
16 0 : return clampPercent(value)
17 : }
18 :
19 166 : function hasProgressPercent(value: ProgressPercent) {
20 166 : return normalizeProgressPercent(value) !== undefined
21 : }
22 :
23 0 : function progressPercentStyle(value: ProgressPercent) {
24 0 : const normalized = normalizeProgressPercent(value)
25 :
26 0 : if (normalized === undefined) return undefined
27 :
28 0 : return { width: `${normalized}%` }
29 : }
30 :
31 83 : export function useProgressBarBackground() {
32 83 : return {
33 : progressBarContainerClass,
34 : progressBarPrimaryClass,
35 : progressBarSecondaryClass,
36 : hasProgressPercent,
37 : progressPercentStyle
38 : }
39 : }
|